Search this API

y.geom
Class YPoint

java.lang.Object
  extended by y.geom.YPoint
All Implemented Interfaces:
java.lang.Comparable

public final class YPoint
extends java.lang.Object
implements java.lang.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 returns the result.
 int compareTo(java.lang.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.
 double distanceTo(double x, double y)
          Returns the euclidean distance between this point and a given point.
 double distanceTo(YPoint p)
          Returns the euclidean distance between this point and a given point.
 boolean equals(java.lang.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 middle 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 subtract(YPoint p1, YPoint p2)
          Subtracts two points (p1 - p2) and returns the result.
static YPoint swap(YPoint p)
          Returns a copy of the given point with exchanged x- and y-coordinates.
 java.lang.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.

distanceTo

public double distanceTo(double x,
                         double y)
Returns the euclidean distance between this point and a given point.

Parameters:
x - the x coordinate of an arbitrary point
y - the y coordinate of an arbitrary point
Returns:
the Euclidean distance between this point and the point (x,y).

distanceTo

public double distanceTo(YPoint p)
Returns the euclidean distance between this point and a given point.

Parameters:
p - an arbitrary point
Returns:
the Euclidean distance between this point and p.

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 Euclidean 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-coordinate of first point
y1 - y-coordinate of first point
x2 - x-coordinate of second point
y2 - y-coordinate of second point
Returns:
the euclidean distance between first and second point

add

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

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

subtract

public static YPoint subtract(YPoint p1,
                              YPoint p2)
Subtracts two points (p1 - p2) and returns 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 middle 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(java.lang.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 java.lang.Object
Parameters:
o - an arbitrary instance.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

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

Overrides:
toString in class java.lang.Object

compareTo

public int compareTo(java.lang.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 java.lang.Comparable

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