public class PointI
extends java.lang.Object
int coordinates.
This class is similar in spirit to Android's android.graphics.Point and provides
basic point operations such as setting coordinates, negation, offsetting, equality checks,
and computing vector length.
| Modifier and Type | Field and Description |
|---|---|
int |
x
X coordinate.
|
int |
y
Y coordinate.
|
| Constructor and Description |
|---|
PointI()
Creates a point at the origin
(0, 0). |
PointI(int x,
int y)
Creates a point with the specified coordinates.
|
PointI(PointI p)
Copy constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(int x,
int y)
Returns whether this point's coordinates equal
(x, y). |
boolean |
equals(java.lang.Object o)
Indicates whether some other object is "equal to" this one.
|
int |
hashCode()
Returns a hash code value for this point.
|
float |
length()
Returns the Euclidean length of the vector from
(0,0) to this point: hypot(x, y). |
static float |
length(int x,
int y)
Returns the Euclidean length of the vector from
(0,0) to (x,y). |
void |
negate()
Negates this point in place:
(x, y) -> (-x, -y). |
void |
offset(float dx,
float dy)
Offsets this point in place by
(dx, dy). |
void |
set(int x,
int y)
Sets this point's coordinates.
|
void |
set(PointI p)
Sets this point's coordinates to match another point.
|
java.lang.String |
toString()
Returns a string representation of this point.
|
public PointI()
(0, 0).public PointI(int x,
int y)
x - x coordinatey - y coordinatepublic PointI(PointI p)
PointI with the same coordinates as p.p - the point to copy fromjava.lang.NullPointerException - if p is nullpublic final void set(int x,
int y)
x - new x coordinatey - new y coordinatepublic final void set(PointI p)
p - the source pointjava.lang.NullPointerException - if p is nullpublic final void negate()
(x, y) -> (-x, -y).public final void offset(float dx,
float dy)
(dx, dy).
Note: dx and dy are float and will be converted to int
using Java's compound-assignment conversion rules (i.e. fractional parts are truncated).
dx - delta xdy - delta ypublic final boolean equals(int x,
int y)
(x, y).x - x coordinate to comparey - y coordinate to comparetrue if both coordinates match; otherwise falsepublic boolean equals(java.lang.Object o)
equals in class java.lang.Objecto - the reference object with which to comparetrue if this object is equal to o; otherwise falsepublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.ObjectPointI(x, y)public final float length()
(0,0) to this point: hypot(x, y).public static float length(int x,
int y)
(0,0) to (x,y).x - x componenty - y component