Package org.eclipse.gef.geometry.planar
Class Point
java.lang.Object
org.eclipse.gef.geometry.planar.Point
- All Implemented Interfaces:
Serializable
,Cloneable
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:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclone()
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
Test for equality.static Rectangle
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.getCopy()
static final Point[]
Copies an array of points, by copying each point contained in the array.getDifference
(Point other) double
getDistance
(Point p) Calculates the distance from this Point to the one specified.Creates a Point with negated x and y values.static final Point[]
getReverseCopy
(Point... points) Returns a copy of the given array of points, where the points are placed in reversed order.getScaled
(double factor) Creates a new Point from this Point by scaling by the specified amount.getScaled
(double xFactor, double yFactor) Creates a new Point from this Point by scaling by the specified values.Returns a newPoint
scaled by the given scale-factors.getTransformed
(AffineTransform transformation) Transforms a copy of thisPoint
using the givenAffineTransform
.getTranslated
(double x, double y) Creates a new Point which is translated by the specified x and y valuesCreates a new Point which is translated by the values of the input Dimension.Creates a new Point which is translated by the values of the provided Point.Creates a new Point with the transposed values of this Point.int
hashCode()
static Point
Creates a new Point representing the MAX of two provided Points.static Point
Creates a new Point representing the MIN of two provided Points.static Point
Returns (one of) the candidate(s) with minimal distance to the given reference point.negate()
Negates the x and y values of this Point.static void
static void
scale
(double factor) Scales this Point by the specified amount.scale
(double xFactor, double yFactor) Scales this Point by the specified values.Scales thisPoint
by the given scale-factors.static void
setLocation
(double x, double y) Sets the location of this Point to the provided x and y locations.setLocation
(Point p) Sets the location of this Point to the specified Point.setX
(double x) Sets the x value of this Point to the given value.setY
(double y) Sets the y value of this Point to the given value;toString()
transform
(AffineTransform transformation) Transforms thisPoint
in-place using the givenAffineTransform
.translate
(double dx, double dy) Shifts this Point by the values supplied along each axes, and returns this for convenience.Shifts this Point by the values of the Dimension along each axis, and returns this for convenience.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
Translates an array ofPoint
s by translating each individual point by a given x and y offset.Transposes this object.double
x()
Returns the x value of this Point.double
y()
Returns the y value of this Point.
-
Field Details
-
x
public double xThe x value. -
y
public double yThe y value.
-
-
Constructor Details
-
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
Constructs a Point at the same location as the given Point.- Parameters:
p
- Point from which the initial values are taken.
-
-
Method Details
-
getBounds
-
getCentroid
-
getConvexHull
Computes the convex hull of the given set ofPoint
s using the Graham scan algorithm. -
getCopy
Copies an array of points, by copying each point contained in the array. -
getReverseCopy
Returns a copy of the given array of points, where the points are placed in reversed order. -
max
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
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
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.
-
rotateCCW
-
rotateCW
-
scale
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
Translates an array ofPoint
s by translating each individual point by a given x and y offset. -
clone
Overwritten with public visibility as proposed inCloneable
. -
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
Test for equality. -
getCopy
- Returns:
- a copy of this Point
-
getDifference
-
getDistance
Calculates the distance from this Point to the one specified.- Parameters:
p
- The Point being compared to this- Returns:
- The distance
-
getNegated
Creates a Point with negated x and y values.- Returns:
- A new Point
-
getScaled
Creates a new Point from this Point by scaling by the specified amount.- Parameters:
factor
- scale factor- Returns:
- A new Point
-
getScaled
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
-
getScaled
-
getTransformed
Transforms a copy of thisPoint
using the givenAffineTransform
.- Parameters:
transformation
- TheAffineTransform
to apply.- Returns:
- A copy of this
Point
, transformed by the givenAffineTransform
.
-
getTranslated
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
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
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
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() -
negate
Negates the x and y values of this Point.- Returns:
this
for convenience
-
scale
Scales this Point by the specified amount.- Parameters:
factor
- scale factor- Returns:
this
for convenience
-
scale
Scales this Point by the specified values.- Parameters:
xFactor
- horizontal scale factoryFactor
- vertical scale factor- Returns:
this
for convenience
-
scale
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
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
Sets the location of this Point to the specified Point.- Parameters:
p
- the Location- Returns:
this
for convenience
-
setX
Sets the x value of this Point to the given value.- Parameters:
x
- The new x value- Returns:
- this for convenience
-
setY
Sets the y value of this Point to the given value;- Parameters:
y
- The new y value- Returns:
- this for convenience
-
toString
-
transform
Transforms thisPoint
in-place using the givenAffineTransform
.- Parameters:
transformation
- TheAffineTransform
to apply.- Returns:
this
for convenience.
-
translate
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
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
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
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
-