public final class YPoint extends Object implements Comparable
This class implements the immutable design pattern.
Modifier and Type | Field and Description |
---|---|
static YPoint |
ORIGIN
A YPoint constant with coordinates (0,0).
|
Constructor and Description |
---|
YPoint()
Creates a new YPoint at location (0,0).
|
YPoint(double x,
double y)
Creates a new YPoint object for a given position.
|
Modifier and Type | Method and Description |
---|---|
static YPoint |
add(YPoint p1,
YPoint p2)
Adds two points and returns 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.
|
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(Object o)
Tests a point to equality to another point.
|
double |
getX()
Gets the x-coordinate of the point object.
|
double |
getY()
Gets 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.
|
String |
toString()
Returns the coordinates of the point as string.
|
public static final YPoint ORIGIN
public YPoint()
public YPoint(double x, double y)
x
- the x coordinate of the point.y
- the y coordinate of the point.public static final YPoint add(YPoint p1, YPoint p2)
p1
- an arbitrary instance of YPoint.p2
- an arbitrary instance of YPoint.public final int compareTo(Object o)
YPoints are ordered by ascending x-coordinates. If the x-coordinates of two points equal, then these points are ordered by ascending y-coordinates.
compareTo
in interface Comparable
public static final double distance(double x1, double y1, double x2, double y2)
x1
- x-coordinate of first pointy1
- y-coordinate of first pointx2
- x-coordinate of second pointy2
- y-coordinate of second pointpublic static final double distance(YPoint p1, YPoint p2)
p1
- an arbitrary pointp2
- an arbitrary pointpublic final double distanceTo(double x, double y)
x
- the x coordinate of an arbitrary pointy
- the y coordinate of an arbitrary pointpublic final double distanceTo(YPoint p)
p
- an arbitrary pointpublic boolean equals(Object o)
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.
public final double getX()
public final double getY()
public static final YPoint midPoint(YPoint p1, YPoint p2)
p1
- an arbitrary instance of YPoint.p2
- an arbitrary instance of YPoint.public final YPoint moveBy(double x, double y)
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.public static final YPoint subtract(YPoint p1, YPoint p2)
p1
- an arbitrary instance of YPoint.p2
- an arbitrary instance of YPoint.public static final YPoint swap(YPoint p)
p
- an arbitrary instance of YPoint.