X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=third-party%2Fnet.sf.jung2%2Fsrc%2Fmain%2Fjava%2Fedu%2Fuci%2Fics%2Fjung%2Falgorithms%2Flayout%2FPolarPoint.java;fp=third-party%2Fnet.sf.jung2%2Fsrc%2Fmain%2Fjava%2Fedu%2Fuci%2Fics%2Fjung%2Falgorithms%2Flayout%2FPolarPoint.java;h=aa3dc7b411235fadba367e9a0efbccc8245c4871;hp=0000000000000000000000000000000000000000;hb=42210c03b0a4c54706320ba9f55794c0abd4d201;hpb=7576b38152b393793b1c9ec3df0ff86685f95236 diff --git a/third-party/net.sf.jung2/src/main/java/edu/uci/ics/jung/algorithms/layout/PolarPoint.java b/third-party/net.sf.jung2/src/main/java/edu/uci/ics/jung/algorithms/layout/PolarPoint.java new file mode 100644 index 0000000000..aa3dc7b411 --- /dev/null +++ b/third-party/net.sf.jung2/src/main/java/edu/uci/ics/jung/algorithms/layout/PolarPoint.java @@ -0,0 +1,103 @@ +/* +* Copyright (c) 2003, the JUNG Project and the Regents of the University +* of California +* All rights reserved. +* +* This software is open-source under the BSD license; see either +* "license.txt" or +* http://jung.sourceforge.net/license.txt for a description. +*/ +package edu.uci.ics.jung.algorithms.layout; + +import java.awt.geom.Point2D; + +/** + * Represents a point in polar coordinates: distance and angle from the origin. + * Includes conversions between polar and Cartesian + * coordinates (Point2D). + * + * @author Tom Nelson - tomnelson@dev.java.net + */ +public class PolarPoint +{ + double theta; + double radius; + + /** + * Creates a new instance with radius and angle each 0. + */ + public PolarPoint() { + this(0,0); + } + + /** + * Creates a new instance with radius {@code radius} and angle {@code theta}. + */ + public PolarPoint(double theta, double radius) { + this.theta = theta; + this.radius = radius; + } + + /** + * Returns the angle for this point. + */ + public double getTheta() { return theta; } + + /** + * Returns the radius for this point. + */ + public double getRadius() { return radius; } + + /** + * Sets the angle for this point to {@code theta}. + */ + public void setTheta(double theta) { this.theta = theta; } + + /** + * Sets the radius for this point to {@code theta}. + */ + public void setRadius(double radius) { this.radius = radius; } + + /** + * Returns the result of converting polar to Cartesian coordinates. + */ + public static Point2D polarToCartesian(PolarPoint polar) { + return polarToCartesian(polar.getTheta(), polar.getRadius()); + } + + /** + * Returns the result of converting (theta, radius) to Cartesian coordinates. + */ + public static Point2D polarToCartesian(double theta, double radius) { + return new Point2D.Double(radius*Math.cos(theta), radius*Math.sin(theta)); + } + + /** + * Returns the result of converting point to polar coordinates. + */ + public static PolarPoint cartesianToPolar(Point2D point) { + return cartesianToPolar(point.getX(), point.getY()); + } + + /** + * Returns the result of converting (x, y) to polar coordinates. + */ + public static PolarPoint cartesianToPolar(double x, double y) { + double theta = Math.atan2(y,x); + double radius = Math.sqrt(x*x+y*y); + return new PolarPoint(theta, radius); + } + + @Override + public String toString() { + return "PolarPoint[" + radius + "," + theta +"]"; + } + + /** + * Sets the angle and radius of this point to those of {@code p}. + */ + public void setLocation(PolarPoint p) { + this.theta = p.getTheta(); + this.radius = p.getRadius(); + } +} \ No newline at end of file