Package org.eclipse.draw2d.geometry
Class Point
java.lang.Object
org.eclipse.draw2d.geometry.Point
- All Implemented Interfaces:
Serializable
,Cloneable
,Translatable
- Direct Known Subclasses:
AbsoluteBendpoint
,PrecisionPoint
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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPoint()
Constructs a Point at location (0,0).Point
(double x, double y) Deprecated.Point
(int x, int y) Constructs a Point at the specified x and y locations.Constructs a Point at the same location as the given Point.Constructs a Point at the same location as the given SWT Point. -
Method Summary
Modifier and TypeMethodDescriptionboolean
equals
(int x, int y) Returnstrue
if this Points x and y are equal to the given x and y.boolean
Test for equality.getCopy()
Calculates the difference in between this Point and the one specified.double
getDistance
(Point p) Calculates the distance from this Point to the one specified.int
Deprecated.UsegetDistance(Point)
and square the result instead.int
Deprecated.May not be guaranteed by precision subclasses and should thus not be used any more.Creates a Point with negated x and y values.int
getPosition
(Point p) Calculates the relative position of the specified Point to this Point.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 x and y factors.Creates a new SWTPoint
from this Point.getTranslated
(double x, double y) Creates a new Point which is translated by the specified x and y valuesgetTranslated
(int x, int 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.negate()
Negates the x and y values of this Point.void
performScale
(double factor) Scales this object by the scale factor.void
performTranslate
(int dx, int dy) Translates this object horizontally bydx
and vertically bydy
.double
preciseX()
Returnsdouble
x coordinatedouble
preciseY()
Returnsdouble
y coordinatescale
(double factor) Scales this Point by the specified amount.scale
(double xFactor, double yFactor) Scales this Point by the specified values.setLocation
(int x, int 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
(int x) Sets the x value of this Point to the given value.setY
(int y) Sets the y value of this Point to the given value;toString()
translate
(double x, double y) Shifts this Point by the values supplied along each axes, and returns this for convenience.translate
(int dx, int 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.Transposes this object.int
x()
Returns the x value of this Point.int
y()
Returns the y value of this Point.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.draw2d.geometry.Translatable
performTranslate, performTranslate, performTranslate
-
Field Details
-
SINGLETON
A singleton for use in short calculations -
x
public int xx value -
y
public int yy value
-
-
Constructor Details
-
Point
public Point()Constructs a Point at location (0,0).- Since:
- 2.0
-
Point
public Point(double x, double y) Deprecated.UsePrecisionPoint
orPoint(int, int)
instead.Constructs a Point at the specified x and y locations.- Parameters:
x
- x valuey
- y value- Since:
- 2.0
-
Point
public Point(int x, int y) Constructs a Point at the specified x and y locations.- Parameters:
x
- x valuey
- y value- Since:
- 2.0
-
Point
Constructs a Point at the same location as the given SWT Point.- Parameters:
p
- Point from which the initial values are taken.- Since:
- 2.0
-
Point
Constructs a Point at the same location as the given Point.- Parameters:
p
- Point from which the initial values are taken.- Since:
- 2.0
-
Point
- Parameters:
copy
- Dimension from which the initial values are taken.- Since:
- 3.13
-
-
Method Details
-
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()
-
equals
public boolean equals(int x, int 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.- Since:
- 3.7
-
equals
Test for equality. -
getCopy
- Returns:
- a copy of this Point
- Since:
- 2.0
-
getDifference
Calculates the difference in between this Point and the one specified.- Parameters:
p
- The Point being subtracted from this Point- Returns:
- A new Dimension representing the difference
- Since:
- 2.0
-
getDistance
Calculates the distance from this Point to the one specified.- Parameters:
p
- The Point being compared to this- Returns:
- The distance
- Since:
- 2.0
-
getDistance2
Deprecated.UsegetDistance(Point)
and square the result instead.Calculates the distance squared between this Point and the one specified. If the distance squared is larger than the maximum integer value, thenInteger.MAX_VALUE
will be returned.- Parameters:
p
- The reference Point- Returns:
- distance2
- Since:
- 2.0
-
getDistanceOrthogonal
Deprecated.May not be guaranteed by precision subclasses and should thus not be used any more.Calculates the orthogonal distance to the specified point. The orthogonal distance is the sum of the horizontal and vertical differences.- Parameters:
p
- The reference Point- Returns:
- the orthogonal distance
-
getNegated
Creates a Point with negated x and y values.- Returns:
- A new Point
- Since:
- 2.0
-
getPosition
Calculates the relative position of the specified Point to this Point.- Parameters:
p
- The reference Point- Returns:
- NORTH, SOUTH, EAST, or WEST, as defined in
PositionConstants
-
getScaled
Creates a new Point from this Point by scaling by the specified amount.- Parameters:
factor
- scale factor- Returns:
- A new Point
- Since:
- 2.0
-
getScaled
Creates a new Point from this Point by scaling by the specified x and y factors.- Parameters:
xFactor
- x scale factoryFactor
- y scale factor- Returns:
- A new Point
- Since:
- 3.8
-
getSWTPoint
Creates a new SWTPoint
from this Point.- Returns:
- A new SWT Point
- Since:
- 2.0
-
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
- Since:
- 2.0
-
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
- Since:
- 3.8
-
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
- Since:
- 2.0
-
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
- Since:
- 2.0
-
getTransposed
Creates a new Point with the transposed values of this Point. Can be useful in orientation change calculations.- Returns:
- A new Point
- Since:
- 2.0
-
hashCode
public int hashCode() -
negate
Negates the x and y values of this Point.- Returns:
this
for convenience- Since:
- 2.0
-
performScale
public void performScale(double factor) Description copied from interface:Translatable
Scales this object by the scale factor.- Specified by:
performScale
in interfaceTranslatable
- Parameters:
factor
- The scale factor- See Also:
-
performTranslate
public void performTranslate(int dx, int dy) Description copied from interface:Translatable
Translates this object horizontally bydx
and vertically bydy
.- Specified by:
performTranslate
in interfaceTranslatable
- Parameters:
dx
- The amount to translate horizontallydy
- The amount to translate vertically- See Also:
-
preciseX
public double preciseX()Returnsdouble
x coordinate- Returns:
double
x coordinate- Since:
- 3.4
-
preciseY
public double preciseY()Returnsdouble
y coordinate- Returns:
double
y coordinate- Since:
- 3.4
-
scale
Scales this Point by the specified amount.- Parameters:
factor
- scale factor- Returns:
this
for convenience- Since:
- 2.0
-
scale
Scales this Point by the specified values.- Parameters:
xFactor
- horizontal scale factoryFactor
- vertical scale factor- Returns:
this
for convenience- Since:
- 2.0
-
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- Since:
- 2.0
-
setLocation
Sets the location of this Point to the specified Point.- Parameters:
p
- the Location- Returns:
this
for convenience- Since:
- 2.0
-
setX
Sets the x value of this Point to the given value.- Parameters:
x
- The new x value- Returns:
- this for convenience
- Since:
- 3.7
-
setY
Sets the y value of this Point to the given value;- Parameters:
y
- The new y value- Returns:
- this for convenience
- Since:
- 3.7
-
toString
-
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- Since:
- 2.0
-
translate
Shifts this Point by the values supplied along each axes, and returns this for convenience.- Parameters:
x
- Amount by which point is shifted along X axis.y
- Amount by which point is shifted along Y axis.- Returns:
this
for convenience- Since:
- 3.8
-
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- Since:
- 2.0
-
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- Since:
- 2.0
-
transpose
Transposes this object. X and Y values are exchanged.- Returns:
this
for convenience- Since:
- 2.0
-
x
public int x()Returns the x value of this Point.- Returns:
- The current x value
- Since:
- 3.7
-
y
public int y()Returns the y value of this Point.- Returns:
- The current y value
- Since:
- 3.7
-
PrecisionPoint
orPoint(int, int)
instead.