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.Serializable
Represents 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 Point
clone()
Overwritten with public visibility as proposed inCloneable
.boolean
equals(double x, double y)
Returnstrue
if this Points x and y are equal to the given x and y.boolean
equals(java.lang.Object o)
Test for equality.static Rectangle
getBounds(Point... points)
static Point
getCentroid(Point... points)
Computes the centroid of the givenPoint
s.static Point[]
getConvexHull(Point... points)
Computes the convex hull of the given set ofPoint
s using the Graham scan algorithm.Point
getCopy()
static Point[]
getCopy(Point... points)
Copies an array of points, by copying each point contained in the array.Point
getDifference(Point other)
double
getDistance(Point p)
Calculates the distance from this Point to the one specified.Point
getNegated()
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.Point
getScaled(double factor)
Creates a new Point from this Point by scaling by the specified amount.Point
getScaled(double xFactor, double yFactor)
Creates a new Point from this Point by scaling by the specified values.Point
getScaled(double factorX, double factorY, Point center)
Returns a newPoint
scaled by the given scale-factors.Point
getTransformed(AffineTransform transformation)
Transforms a copy of thisPoint
using the givenAffineTransform
.Point
getTranslated(double x, double y)
Creates a new Point which is translated by the specified x and y valuesPoint
getTranslated(Dimension d)
Creates a new Point which is translated by the values of the input Dimension.Point
getTranslated(Point p)
Creates a new Point which is translated by the values of the provided Point.Point
getTransposed()
Creates a new Point with the transposed values of this Point.int
hashCode()
static Point
max(Point p1, Point p2)
Creates a new Point representing the MAX of two provided Points.static Point
min(Point p1, Point p2)
Creates a new Point representing the MIN of two provided Points.static Point
nearest(Point referencePoint, Point... candidates)
Returns (one of) the candidate(s) with minimal distance to the given reference point.Point
negate()
Negates the x and y values of this Point.static void
rotateCCW(Point[] points, Angle angle, double cx, double cy)
static void
rotateCW(Point[] points, Angle angle, double cx, double cy)
Point
scale(double factor)
Scales this Point by the specified amount.Point
scale(double xFactor, double yFactor)
Scales this Point by the specified values.Point
scale(double factorX, double factorY, Point center)
Scales thisPoint
by the given scale-factors.static void
scale(Point[] points, double fx, double fy, double cx, double cy)
Point
setLocation(double x, double y)
Sets the location of this Point to the provided x and y locations.Point
setLocation(Point p)
Sets the location of this Point to the specified Point.Point
setX(double x)
Sets the x value of this Point to the given value.Point
setY(double y)
Sets the y value of this Point to the given value;java.lang.String
toString()
Point
transform(AffineTransform transformation)
Transforms thisPoint
in-place using the givenAffineTransform
.Point
translate(double dx, double dy)
Shifts this Point by the values supplied along each axes, and returns this for convenience.Point
translate(Dimension d)
Shifts this Point by the values of the Dimension along each axis, and returns this for convenience.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.static void
translate(Point[] points, double dx, double dy)
Translates an array ofPoint
s by translating each individual point by a given x and y offset.Point
transpose()
Transposes this object.double
x()
Returns the x value of this Point.double
y()
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 ofPoint
s 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 ofPoint
s by the given x and y scale factors around the given centerPoint
(cx, cy).- Parameters:
points
- The array ofPoint
s 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 ofPoint
s by translating each individual point by a given x and y offset.
-
clone
public Point clone()
Overwritten with public visibility as proposed inCloneable
.- Overrides:
clone
in classjava.lang.Object
-
equals
public boolean equals(double x, double y)
Returnstrue
if this Points x and y are equal to the given x and y.- Parameters:
x
- the x valuey
- the y value- Returns:
true
if this point's x and y are equal to those given.
-
equals
public boolean equals(java.lang.Object o)
Test for equality.- Overrides:
equals
in 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 thisPoint
using the givenAffineTransform
.- Parameters:
transformation
- TheAffineTransform
to 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:
hashCode
in classjava.lang.Object
- See Also:
Object.hashCode()
-
negate
public Point negate()
Negates the x and y values of this Point.- Returns:
this
for convenience
-
scale
public Point scale(double factor)
Scales this Point by the specified amount.- Parameters:
factor
- scale factor- Returns:
this
for 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:
this
for convenience
-
scale
public Point scale(double factorX, double factorY, Point center)
Scales thisPoint
by the given scale-factors. The scaling is performed relative to the givenPoint
center.- Parameters:
factorX
- The horizontal scale-factorfactorY
- The vertical scale-factorcenter
- The relativePoint
for the scaling- Returns:
this
for 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:
this
for convenience
-
setLocation
public Point setLocation(Point p)
Sets the location of this Point to the specified Point.- Parameters:
p
- the Location- Returns:
this
for 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:
toString
in classjava.lang.Object
- See Also:
Object.toString()
-
transform
public Point transform(AffineTransform transformation)
Transforms thisPoint
in-place using the givenAffineTransform
.- Parameters:
transformation
- TheAffineTransform
to apply.- Returns:
this
for 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:
this
for 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:
this
for 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:
this
for convenience
-
transpose
public Point transpose()
Transposes this object. X and Y values are exchanged.- Returns:
this
for 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
-
-