y.geom
Class YPoint

java.lang.Object
  |
  +--y.geom.YPoint
All Implemented Interfaces:
Comparable

public final class YPoint
extends Object
implements Comparable

This class represents a point in the plane with double coordinates. This class implements the immutable design pattern.


Field Summary
static YPoint ORIGIN
          A YPoint constant with coordinates (0,0).
 double x
          The x coordinate of the point.
 double y
          The y coordinate of the point.
 
Constructor Summary
YPoint()
          Creates a new YPoint at location (0,0)
YPoint(double x, double y)
          Creates a new YPoint object for a given position.
 
Method Summary
static YPoint add(YPoint p1, YPoint p2)
          Adds two points and return the result.
 int compareTo(Object o)
          Comparable implementation.
static double distance(double x1, double y1, double x2, double y2)
          Returns the euclidean distance between two points.
static double distance(YPoint p1, YPoint p2)
          Returns the euclidean distance between two points.
 boolean equals(Object o)
          Tests a point to equality to another point.
 double getX()
          Returns the x-coordinate of the point object.
 double getY()
          Returns the y-coordinate of the point object.
 int hashCode()
           
static YPoint midPoint(YPoint p1, YPoint p2)
          Returns a point that geometrically lies in in the middel of the line formed by the given points.
 YPoint moveBy(double x, double y)
          Returns the point, got by moving this point to another position.
static YPoint swap(YPoint p)
          Returns a copy of the given point with exchanged x- and y-coordinates.
 String toString()
          Returns the coordinates of the point as string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public final double x
The x coordinate of the point.


y

public final double y
The y coordinate of the point.


ORIGIN

public static final YPoint ORIGIN
A YPoint constant with coordinates (0,0).

Constructor Detail

YPoint

public YPoint()
Creates a new YPoint at location (0,0)


YPoint

public YPoint(double x,
              double y)
Creates a new YPoint object for a given position.

Parameters:
x - the x coordinate of the point.
y - the y coordinate of the point.
Method Detail

getX

public final double getX()
Returns the x-coordinate of the point object.

Returns:
the value of the x-coordinate.

getY

public final double getY()
Returns the y-coordinate of the point object.

Returns:
the value of the y-coordinate.

distance

public static double distance(YPoint p1,
                              YPoint p2)
Returns the euclidean distance between two points.

Parameters:
p1 - an arbitrary point
p2 - an arbitrary point
Returns:
the euclidian distance between p1 and p2.

distance

public static double distance(double x1,
                              double y1,
                              double x2,
                              double y2)
Returns the euclidean distance between two points.

Parameters:
x1 - x-coord of first point
y1 - y-coord of first point
x2 - x-coord of second point
y2 - y-coord of second point
Returns:
the euclidian distance between first and second point

add

public static YPoint add(YPoint p1,
                         YPoint p2)
Adds two points and return the result.

Parameters:
p1 - an arbitrary instance of YPoint.
p2 - an arbitrary instance of YPoint.

midPoint

public static YPoint midPoint(YPoint p1,
                              YPoint p2)
Returns a point that geometrically lies in in the middel of the line formed by the given points.

Parameters:
p1 - an arbitrary instance of YPoint.
p2 - an arbitrary instance of YPoint.

swap

public static YPoint swap(YPoint p)
Returns a copy of the given point with exchanged x- and y-coordinates.

Parameters:
p - an arbitrary instance of YPoint.

moveBy

public YPoint moveBy(double x,
                     double y)
Returns the point, got by moving this point to another position.

Parameters:
x - the value which is added on the x-coordinate of the point.
y - the value which is added on the y-coordinate of the point.
Returns:
a new instance of YPoint which is the result of the moving operation.

equals

public boolean equals(Object o)
Tests a point to equality to another point. This test returns true if the o is also an instance of YPoint and has the same coordinates as the instance on which equals is invoked.

Overrides:
equals in class Object
Parameters:
o - an arbitrary instance.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Returns the coordinates of the point as string.

Overrides:
toString in class Object

compareTo

public int compareTo(Object o)
Comparable implementation. YPoints are ordered by ascending x-coordinates. If the x-coordinates of two points equal, then these points are ordered by ascending y-coordinates.

Specified by:
compareTo in interface Comparable

© Copyright 2000-2003,
yWorks GmbH.
All rights reserved.

2003