Eclipse Draw2d
3.8.0.201206011245

org.eclipse.draw2d.geometry
Class Point

java.lang.Object
  extended by org.eclipse.draw2d.geometry.Point
All Implemented Interfaces:
Serializable, Cloneable, Translatable
Direct Known Subclasses:
AbsoluteBendpoint, PrecisionPoint

public class Point
extends Object
implements Cloneable, Serializable, Translatable

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

Field Summary
static Point SINGLETON
          A singleton for use in short calculations
 int x
          x value
 int y
          y value
 
Constructor Summary
Point()
          Constructs a Point at location (0,0).
Point(double x, double y)
          Deprecated. Use PrecisionPoint or Point(int, int) instead.
Point(int x, int y)
          Constructs a Point at the specified x and y locations.
Point(Point p)
          Constructs a Point at the same location as the given SWT Point.
Point(Point p)
          Constructs a Point at the same location as the given Point.
 
Method Summary
 boolean equals(int x, int y)
          Returns true if this Points x and y are equal to the given x and y.
 boolean equals(Object o)
          Test for equality.
 Point getCopy()
           
 Dimension getDifference(Point p)
          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 getDistance2(Point p)
          Deprecated. Use getDistance(Point) and square the result instead.
 int getDistanceOrthogonal(Point p)
          Deprecated. May not be guaranteed by precision subclasses and should thus not be used any more.
 Point getNegated()
          Creates a Point with negated x and y values.
 int getPosition(Point p)
          Calculates the relative position of the specified Point to this Point.
 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 x and y factors.
 Point getSWTPoint()
          Creates a new SWT Point from this Point.
 Point getTranslated(Dimension d)
          Creates a new Point which is translated by the values of the input Dimension.
 Point getTranslated(double x, double y)
          Creates a new Point which is translated by the specified x and y values
 Point getTranslated(int x, int y)
          Creates a new Point which is translated by the specified x and y values
 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.
 Point 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 by dx and vertically by dy.
 double preciseX()
          Returns double x coordinate
 double preciseY()
          Returns double y coordinate
 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 setLocation(int x, int 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(int x)
          Sets the x value of this Point to the given value.
 Point setY(int y)
          Sets the y value of this Point to the given value;
 String toString()
           
 Point translate(Dimension d)
          Shifts this Point by the values of the Dimension along each axis, and returns this for convenience.
 Point translate(double x, double y)
          Shifts this Point by the values supplied along each axes, and returns this for convenience.
 Point translate(int dx, int dy)
          Shifts this Point by the values supplied along each axes, 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.
 Point transpose()
          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
 

Field Detail

SINGLETON

public static final Point SINGLETON
A singleton for use in short calculations


x

public int x
x value


y

public int y
y value

Constructor Detail

Point

public Point()
Constructs a Point at location (0,0).

Since:
2.0

Point

public Point(double x,
             double y)
Deprecated. Use PrecisionPoint or Point(int, int) instead.

Constructs a Point at the specified x and y locations.

Parameters:
x - x value
y - 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 value
y - y value
Since:
2.0

Point

public Point(Point p)
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

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.
Since:
2.0
Method Detail

max

public static Point max(Point p1,
                        Point p2)
Creates a new Point representing the MAX of two provided Points.

Parameters:
p1 - first point
p2 - 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 point
p2 - second point
Returns:
A new Point representing the Min()

equals

public boolean equals(int x,
                      int y)
Returns true if this Points x and y are equal to the given x and y.

Parameters:
x - the x value
y - the y value
Returns:
true if this point's x and y are equal to those given.
Since:
3.7

equals

public boolean equals(Object o)
Test for equality.

Overrides:
equals in class Object
Parameters:
o - Object being tested for equality
Returns:
true if both x and y values are equal
Since:
2.0

getCopy

public Point getCopy()
Returns:
a copy of this Point
Since:
2.0

getDifference

public Dimension getDifference(Point p)
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

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
Since:
2.0

getDistance2

public int getDistance2(Point p)
Deprecated. Use getDistance(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, then Integer.MAX_VALUE will be returned.

Parameters:
p - The reference Point
Returns:
distance2
Since:
2.0

getDistanceOrthogonal

public int getDistanceOrthogonal(Point p)
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

public Point getNegated()
Creates a Point with negated x and y values.

Returns:
A new Point
Since:
2.0

getPosition

public int getPosition(Point p)
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

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
Since:
2.0

getScaled

public Point getScaled(double xFactor,
                       double yFactor)
Creates a new Point from this Point by scaling by the specified x and y factors.

Parameters:
xFactor - x scale factor
yFactor - y scale factor
Returns:
A new Point
Since:
3.8

getSWTPoint

public Point getSWTPoint()
Creates a new SWT Point from this Point.

Returns:
A new SWT Point
Since:
2.0

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
Since:
2.0

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 component
y - vertical component
Returns:
A new Point
Since:
3.8

getTranslated

public Point getTranslated(int x,
                           int y)
Creates a new Point which is translated by the specified x and y values

Parameters:
x - horizontal component
y - vertical component
Returns:
A new Point
Since:
2.0

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
Since:
2.0

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
Since:
2.0

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

negate

public Point 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 interface Translatable
Parameters:
factor - The scale factor
See Also:
Translatable.performScale(double)

performTranslate

public void performTranslate(int dx,
                             int dy)
Description copied from interface: Translatable
Translates this object horizontally by dx and vertically by dy.

Specified by:
performTranslate in interface Translatable
Parameters:
dx - The amount to translate horizontally
dy - The amount to translate vertically
See Also:
Translatable.performTranslate(int, int)

preciseX

public double preciseX()
Returns double x coordinate

Returns:
double x coordinate
Since:
3.4

preciseY

public double preciseY()
Returns double y coordinate

Returns:
double y coordinate
Since:
3.4

scale

public Point scale(double factor)
Scales this Point by the specified amount.

Parameters:
factor - scale factor
Returns:
this for convenience
Since:
2.0

scale

public Point scale(double xFactor,
                   double yFactor)
Scales this Point by the specified values.

Parameters:
xFactor - horizontal scale factor
yFactor - vertical scale factor
Returns:
this for convenience
Since:
2.0

setLocation

public Point setLocation(int x,
                         int y)
Sets the location of this Point to the provided x and y locations.

Parameters:
x - the x location
y - the y location
Returns:
this for convenience
Since:
2.0

setLocation

public Point setLocation(Point p)
Sets the location of this Point to the specified Point.

Parameters:
p - the Location
Returns:
this for convenience
Since:
2.0

setX

public Point setX(int x)
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

public Point setY(int y)
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

public String toString()
Overrides:
toString in class Object
Returns:
String representation.
Since:
2.0

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
Since:
2.0

translate

public Point translate(double x,
                       double y)
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

public Point translate(int dx,
                       int 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
Since:
2.0

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
Since:
2.0

transpose

public Point 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

Eclipse Draw2d
3.8.0.201206011245

Copyright (c) IBM Corp. and others 2000, 2011. All Rights Reserved.