Package org.eclipse.gef.geometry.planar
Class Point
- java.lang.Object
-
- org.eclipse.gef.geometry.planar.Point
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
public class Point extends java.lang.Object implements java.lang.Cloneable, java.io.SerializableRepresents a point (x, y) in 2-dimensional space. This class provides various methods for manipulating this point or creating new derived geometrical objects.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Pointclone()Overwritten with public visibility as proposed inCloneable.booleanequals(double x, double y)Returnstrueif this Points x and y are equal to the given x and y.booleanequals(java.lang.Object o)Test for equality.static RectanglegetBounds(Point... points)static PointgetCentroid(Point... points)Computes the centroid of the givenPoints.static Point[]getConvexHull(Point... points)Computes the convex hull of the given set ofPoints using the Graham scan algorithm.PointgetCopy()static Point[]getCopy(Point... points)Copies an array of points, by copying each point contained in the array.PointgetDifference(Point other)doublegetDistance(Point p)Calculates the distance from this Point to the one specified.PointgetNegated()Creates a Point with negated x and y values.static Point[]getReverseCopy(Point... points)Returns a copy of the given array of points, where the points are placed in reversed order.PointgetScaled(double factor)Creates a new Point from this Point by scaling by the specified amount.PointgetScaled(double xFactor, double yFactor)Creates a new Point from this Point by scaling by the specified values.PointgetScaled(double factorX, double factorY, Point center)Returns a newPointscaled by the given scale-factors.PointgetTransformed(AffineTransform transformation)Transforms a copy of thisPointusing the givenAffineTransform.PointgetTranslated(double x, double y)Creates a new Point which is translated by the specified x and y valuesPointgetTranslated(Dimension d)Creates a new Point which is translated by the values of the input Dimension.PointgetTranslated(Point p)Creates a new Point which is translated by the values of the provided Point.PointgetTransposed()Creates a new Point with the transposed values of this Point.inthashCode()static Pointmax(Point p1, Point p2)Creates a new Point representing the MAX of two provided Points.static Pointmin(Point p1, Point p2)Creates a new Point representing the MIN of two provided Points.static Pointnearest(Point referencePoint, Point... candidates)Returns (one of) the candidate(s) with minimal distance to the given reference point.Pointnegate()Negates the x and y values of this Point.static voidrotateCCW(Point[] points, Angle angle, double cx, double cy)static voidrotateCW(Point[] points, Angle angle, double cx, double cy)Pointscale(double factor)Scales this Point by the specified amount.Pointscale(double xFactor, double yFactor)Scales this Point by the specified values.Pointscale(double factorX, double factorY, Point center)Scales thisPointby the given scale-factors.static voidscale(Point[] points, double fx, double fy, double cx, double cy)PointsetLocation(double x, double y)Sets the location of this Point to the provided x and y locations.PointsetLocation(Point p)Sets the location of this Point to the specified Point.PointsetX(double x)Sets the x value of this Point to the given value.PointsetY(double y)Sets the y value of this Point to the given value;java.lang.StringtoString()Pointtransform(AffineTransform transformation)Transforms thisPointin-place using the givenAffineTransform.Pointtranslate(double dx, double dy)Shifts this Point by the values supplied along each axes, and returns this for convenience.Pointtranslate(Dimension d)Shifts this Point by the values of the Dimension along each axis, and returns this for convenience.Pointtranslate(Point p)Shifts the location of this Point by the location of the input Point along each of the axes, and returns this for convenience.static voidtranslate(Point[] points, double dx, double dy)Translates an array ofPoints by translating each individual point by a given x and y offset.Pointtranspose()Transposes this object.doublex()Returns the x value of this Point.doubley()Returns the y value of this Point.
-
-
-
Constructor Detail
-
Point
public Point()
Constructs a Point at location (0,0).
-
Point
public Point(double x, double y)Constructs a Point at the specified x and y locations.- Parameters:
x- x valuey- y value
-
Point
public Point(Point p)
Constructs a Point at the same location as the given Point.- Parameters:
p- Point from which the initial values are taken.
-
-
Method Detail
-
getConvexHull
public static Point[] getConvexHull(Point... points)
Computes the convex hull of the given set ofPoints using the Graham scan algorithm.
-
getCopy
public static final Point[] getCopy(Point... points)
Copies an array of points, by copying each point contained in the array.
-
getReverseCopy
public static final Point[] getReverseCopy(Point... points)
Returns a copy of the given array of points, where the points are placed in reversed order.
-
max
public static Point max(Point p1, Point p2)
Creates a new Point representing the MAX of two provided Points.- Parameters:
p1- first pointp2- second point- Returns:
- A new Point representing the Max()
-
min
public static Point min(Point p1, Point p2)
Creates a new Point representing the MIN of two provided Points.- Parameters:
p1- first pointp2- second point- Returns:
- A new Point representing the Min()
-
nearest
public static Point nearest(Point referencePoint, Point... candidates)
Returns (one of) the candidate(s) with minimal distance to the given reference point.- Parameters:
referencePoint- The reference point, to which distance has to be minimal.candidates- The points from which to choose the one with minimal distance.- Returns:
- One of the candidates with minimal distance.
-
scale
public static void scale(Point[] points, double fx, double fy, double cx, double cy)
Scales the given array ofPoints by the given x and y scale factors around the given centerPoint(cx, cy).- Parameters:
points- The array ofPoints to scale.fx- The horizontal scale factor.fy- Ther vertical scale factor.cx- The x-coordinate of the scale's pivot point.cy- The y-coordinate of the scale's pivot point.
-
translate
public static void translate(Point[] points, double dx, double dy)
Translates an array ofPoints by translating each individual point by a given x and y offset.
-
clone
public Point clone()
Overwritten with public visibility as proposed inCloneable.- Overrides:
clonein classjava.lang.Object
-
equals
public boolean equals(double x, double y)Returnstrueif this Points x and y are equal to the given x and y.- Parameters:
x- the x valuey- the y value- Returns:
trueif this point's x and y are equal to those given.
-
equals
public boolean equals(java.lang.Object o)
Test for equality.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- Object being tested for equality- Returns:
- true if both x and y values are equal
-
getCopy
public Point getCopy()
- Returns:
- a copy of this Point
-
getDistance
public double getDistance(Point p)
Calculates the distance from this Point to the one specified.- Parameters:
p- The Point being compared to this- Returns:
- The distance
-
getNegated
public Point getNegated()
Creates a Point with negated x and y values.- Returns:
- A new Point
-
getScaled
public Point getScaled(double factor)
Creates a new Point from this Point by scaling by the specified amount.- Parameters:
factor- scale factor- Returns:
- A new Point
-
getScaled
public Point getScaled(double xFactor, double yFactor)
Creates a new Point from this Point by scaling by the specified values.- Parameters:
xFactor- horizontal scale factoryFactor- vertical scale factor- Returns:
- A new Point
-
getTransformed
public Point getTransformed(AffineTransform transformation)
Transforms a copy of thisPointusing the givenAffineTransform.- Parameters:
transformation- TheAffineTransformto apply.- Returns:
- A copy of this
Point, transformed by the givenAffineTransform.
-
getTranslated
public Point getTranslated(Dimension d)
Creates a new Point which is translated by the values of the input Dimension.- Parameters:
d- Dimension which provides the translation amounts.- Returns:
- A new Point
-
getTranslated
public Point getTranslated(double x, double y)
Creates a new Point which is translated by the specified x and y values- Parameters:
x- horizontal componenty- vertical component- Returns:
- A new Point
-
getTranslated
public Point getTranslated(Point p)
Creates a new Point which is translated by the values of the provided Point.- Parameters:
p- Point which provides the translation amounts.- Returns:
- A new Point
-
getTransposed
public Point getTransposed()
Creates a new Point with the transposed values of this Point. Can be useful in orientation change calculations.- Returns:
- A new Point
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object- See Also:
Object.hashCode()
-
negate
public Point negate()
Negates the x and y values of this Point.- Returns:
thisfor convenience
-
scale
public Point scale(double factor)
Scales this Point by the specified amount.- Parameters:
factor- scale factor- Returns:
thisfor convenience
-
scale
public Point scale(double xFactor, double yFactor)
Scales this Point by the specified values.- Parameters:
xFactor- horizontal scale factoryFactor- vertical scale factor- Returns:
thisfor convenience
-
scale
public Point scale(double factorX, double factorY, Point center)
Scales thisPointby the given scale-factors. The scaling is performed relative to the givenPointcenter.- Parameters:
factorX- The horizontal scale-factorfactorY- The vertical scale-factorcenter- The relativePointfor the scaling- Returns:
thisfor convenience
-
setLocation
public Point setLocation(double x, double y)
Sets the location of this Point to the provided x and y locations.- Parameters:
x- the x locationy- the y location- Returns:
thisfor convenience
-
setLocation
public Point setLocation(Point p)
Sets the location of this Point to the specified Point.- Parameters:
p- the Location- Returns:
thisfor convenience
-
setX
public Point setX(double x)
Sets the x value of this Point to the given value.- Parameters:
x- The new x value- Returns:
- this for convenience
-
setY
public Point setY(double y)
Sets the y value of this Point to the given value;- Parameters:
y- The new y value- Returns:
- this for convenience
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- See Also:
Object.toString()
-
transform
public Point transform(AffineTransform transformation)
Transforms thisPointin-place using the givenAffineTransform.- Parameters:
transformation- TheAffineTransformto apply.- Returns:
thisfor convenience.
-
translate
public Point translate(Dimension d)
Shifts this Point by the values of the Dimension along each axis, and returns this for convenience.- Parameters:
d- Dimension by which the origin is being shifted.- Returns:
thisfor convenience
-
translate
public Point translate(double dx, double dy)
Shifts this Point by the values supplied along each axes, and returns this for convenience.- Parameters:
dx- Amount by which point is shifted along X axis.dy- Amount by which point is shifted along Y axis.- Returns:
thisfor convenience
-
translate
public Point translate(Point p)
Shifts the location of this Point by the location of the input Point along each of the axes, and returns this for convenience.- Parameters:
p- Point to which the origin is being shifted.- Returns:
thisfor convenience
-
transpose
public Point transpose()
Transposes this object. X and Y values are exchanged.- Returns:
thisfor convenience
-
x
public double x()
Returns the x value of this Point.- Returns:
- The current x value
-
y
public double y()
Returns the y value of this Point.- Returns:
- The current y value
-
-