computational.geometry
Class Point

java.lang.Object
  extended by computational.geometry.Point
All Implemented Interfaces:
Shape, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
MergePoint, Polygon.Vertex, SweepingLine.SegmentEndPoint

public class Point
extends java.lang.Object
implements Shape, java.lang.Cloneable, java.io.Serializable

This class represents a point in a 2-dimensional space, specified in integer precision.

Warning: the X-axis is directed left to right, whether the Y-axis is directed top-down, contrary to the usual geometric conventions.

See Also:
Serialized Form

Constructor Summary
Point(int x, int y)
          Constructs a new point with given coordinates.
Point(java.lang.String label, int x, int y)
          Constructs a new point with given coordinates and label.
 
Method Summary
static Point add(Point p0, Point p1)
          Computes the sum of two points, i.e.
 Rectangle boundingBox()
          Returns this point's bounding box, represented as a Rectangle centered in the point's coordinates and with null dimensions.
 java.lang.Object clone()
          Object Extension
 boolean contains(Point p)
          Tells whether the shape encloses a given point.
 int distance2(Point p)
          Returns the squared distance from another point
 void draw(java.awt.Graphics gfx)
          Draw this point, using the current graphics context's color.
 void drawLabels(java.awt.Graphics gfx)
          Draws the shape's associated labels, using the graphics context's color.
 void drawPoints(java.awt.Graphics gfx)
          Draws the shape's defining points, using the graphics context's color.
 boolean equals(java.lang.Object obj)
          Determines whether or not two points are equal.
 java.lang.String getLabel()
          Returns the string label associated to this point.
 java.util.List getPoints()
          Returns a list containing copies of the shape's defining points.
 int getX()
          Returns the point's X-coordinate.
 int getY()
          Returns the point's Y-coordinate.
 void setLabel(java.lang.String label)
          Sets the point's label.
static Point sub(Point p0, Point p1)
          Computes the difference between two points, i.e.
 java.lang.String toString()
          Returns a string representation of this point.
 void translate(int dx, int dy)
          Translates this points by the given amount.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Point

public Point(int x,
             int y)
Constructs a new point with given coordinates.

Parameters:
x - the point's X-coordinate.
y - the point's Y-coordinate.

Point

public Point(java.lang.String label,
             int x,
             int y)
Constructs a new point with given coordinates and label.

Parameters:
label - the string label associated to this point.
x - the point's X-coordinate.
y - the point's Y-coordinate.
Method Detail

add

public static Point add(Point p0,
                        Point p1)
Computes the sum of two points, i.e. the sum of the two vectors geometrically equivalent to that points.

Parameters:
p0 - the first point.
p1 - the second point.
Returns:
the sum of the two points.

boundingBox

public Rectangle boundingBox()
Returns this point's bounding box, represented as a Rectangle centered in the point's coordinates and with null dimensions.

Returns:
a Rectangle bounding this point.

clone

public java.lang.Object clone()
Object Extension

Overrides:
clone in class java.lang.Object

contains

public boolean contains(Point p)
Description copied from interface: Shape
Tells whether the shape encloses a given point. To the aims of this test, we consider the shape to be closed, so that a point lying on the shape's boundaries results as enclosed in the shape.

Specified by:
contains in interface Shape
Parameters:
p - the point we test for encloseness.
Returns:
true iff the point is enclosed in the shape.

distance2

public int distance2(Point p)
Returns the squared distance from another point

Parameters:
p - the other point.
Returns:
the squared distance from p.

draw

public void draw(java.awt.Graphics gfx)
Draw this point, using the current graphics context's color.

Specified by:
draw in interface Shape
Parameters:
gfx - the graphics context where this point has to be drawn.

drawLabels

public void drawLabels(java.awt.Graphics gfx)
Description copied from interface: Shape
Draws the shape's associated labels, using the graphics context's color.

Specified by:
drawLabels in interface Shape
Parameters:
gfx - the graphics context where this shape's labels have to be drawn.

drawPoints

public void drawPoints(java.awt.Graphics gfx)
Description copied from interface: Shape
Draws the shape's defining points, using the graphics context's color.

Specified by:
drawPoints in interface Shape
Parameters:
gfx - the graphics context where this shape's points have to be drawn.

equals

public boolean equals(java.lang.Object obj)
Determines whether or not two points are equal. Two instances of Point are equal if the values of their x and y member fields, representing their position in the coordinate space, are the same.

Overrides:
equals in class java.lang.Object
Parameters:
obj - an object to be compared with this Point
Returns:
true if the object to be compared is an instance of Point and has the same values; false otherwise.

getLabel

public java.lang.String getLabel()
Returns the string label associated to this point. The returned string may possibly be empty, but may never be null.

Specified by:
getLabel in interface Shape
Returns:
the string label associated to this point.

getPoints

public java.util.List getPoints()
Description copied from interface: Shape
Returns a list containing copies of the shape's defining points.

Specified by:
getPoints in interface Shape
Returns:
the shape's cloned defining points.

getX

public int getX()
Returns the point's X-coordinate.

Returns:
the point's X-coordinate.

getY

public int getY()
Returns the point's Y-coordinate.

Returns:
the point's Y-coordinate.

setLabel

public void setLabel(java.lang.String label)
Sets the point's label.

Specified by:
setLabel in interface Shape
Parameters:
the - point's new label.

sub

public static Point sub(Point p0,
                        Point p1)
Computes the difference between two points, i.e. the difference of the two vectors geometrically equivalent to that points.

Parameters:
p0 - the first point.
p1 - the second point.
Returns:
the difference of the two points.

toString

public java.lang.String toString()
Returns a string representation of this point. The string is composed of the point's label (if any), and the point's (x,y) coordinates.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this point.

translate

public void translate(int dx,
                      int dy)
Translates this points by the given amount.

Specified by:
translate in interface Shape
Parameters:
dx - the amount to translate along the X-axis
dx - the amount to translate along the Y-axis