public class Coord extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
int |
x
The x-coordinate.
|
int |
y
The y-coordinate (the ordinate)
|
Modifier | Constructor and Description |
---|---|
protected |
Coord() |
protected |
Coord(int x,
int y) |
Modifier and Type | Method and Description |
---|---|
Coord |
add(Coord other)
Separately combines the x and y positions of this Coord and other, producing a different Coord as their "sum."
|
Coord |
add(double operand)
Separately adds the x and y positions of this Coord to operand, rounding to the nearest int for each of x
and y and producing a different Coord as their "sum."
|
Coord |
add(int operand)
Separately adds the x and y positions of this Coord to operand, producing a different Coord as their
"sum."
|
Coord |
average(Coord other)
Separately averages the x and y positions of this Coord with other, producing a different Coord as their
"midpoint."
|
static double |
degrees(Coord from,
Coord to)
Gets the angle in degrees to go between two Coords; 0 is up.
|
double |
distance(Coord co) |
double |
distance(double x2,
double y2) |
double |
distanceSq(Coord co) |
double |
distanceSq(double x2,
double y2) |
Coord |
divide(Coord other)
Separately divides the x and y positions of this Coord by other, producing a different Coord as their
"quotient." If other has 0 for x or y, this will throw an exception, as dividing by 0 is expected to do.
|
Coord |
divide(double operand)
Separately divides the x and y positions of this Coord by operand, flooring to a lower int for each of x and
y and producing a different Coord as their "quotient." If operand is 0.0, expect strange results (infinity and
NaN are both possibilities).
|
Coord |
divide(int operand)
Separately divides the x and y positions of this Coord by operand, producing a different Coord as their
"quotient." If operand is 0, this will throw an exception, as dividing by 0 is expected to do.
|
Coord |
divideRounding(double operand)
Separately divides the x and y positions of this Coord by operand, rounding to the nearest int for each of x and
y and producing a different Coord as their "quotient." If operand is 0.0, expect strange results (infinity and
NaN are both possibilities).
|
boolean |
equals(Object o) |
static void |
expandPool(int xIncrease,
int yIncrease) |
static Coord |
get(int x,
int y) |
static int |
getCacheHeight()
Gets the height of the pool used as a cache for Coords, not including negative Coords.
|
static int |
getCacheWidth()
Gets the width of the pool used as a cache for Coords, not including negative Coords.
|
Coord |
getLocation()
Provided for compatibility with earlier code that used the AWT Point API.
|
int |
getX() |
int |
getY() |
int |
hashCode() |
boolean |
isAdjacent(Coord c) |
boolean |
isWithin(int width,
int height)
Returns true if x is between 0 (inclusive) and width (exclusive) and y is between 0 (inclusive) and height
(exclusive), false otherwise.
|
boolean |
isWithinRectangle(int minX,
int minY,
int maxX,
int maxY)
Returns true if x is between minX (inclusive) and maxX (exclusive) and y is between minY (inclusive) and maxY
(exclusive), false otherwise.
|
Coord |
multiply(Coord other)
Separately multiplies the x and y positions of other from this Coord, producing a different Coord as their
"product."
|
Coord |
multiply(double operand)
Separately multiplies the x and y positions of this Coord by operand, rounding to the nearest int for each of x
and y and producing a different Coord as their "product."
|
Coord |
multiply(int operand)
Separately multiplies the x and y positions of this Coord by operand, producing a different Coord as their
"product."
|
Coord |
scale(int i) |
Coord |
scale(int i,
int j) |
Coord |
setX(int x) |
Coord |
setY(int y) |
Coord |
subtract(Coord other)
Separately subtracts the x and y positions of other from this Coord, producing a different Coord as their
"difference."
|
Coord |
subtract(double operand)
Separately subtracts operand from the x and y positions of this Coord, rounding to the nearest int for each of x
and y and producing a different Coord as their "difference."
|
Coord |
subtract(int operand)
Separately subtracts operand from the x and y positions of this Coord, producing a different Coord as their
"difference."
|
Direction |
toGoTo(Coord adjacent)
|
String |
toString() |
Coord |
translate(Direction d) |
Coord |
translate(int x,
int y)
Takes this Coord, adds x to its x and y to its y, and returns the Coord at that position.
|
Coord |
translateCapped(int x,
int y,
int width,
int height)
Takes this Coord, adds x to its x and y to its y, limiting x from 0 to width and limiting y from 0 to height,
and returns the Coord at that position.
|
public final int x
public final int y
public static double degrees(Coord from, Coord to)
from
- the starting Coord to measure fromto
- the ending Coord to measure tofrom
to to
; 0 is uppublic Coord getLocation()
public Coord translate(int x, int y)
x
- the amount of x distance to movey
- the amount of y distance to movepublic Coord translateCapped(int x, int y, int width, int height)
x
- the amount of x distance to movey
- the amount of y distance to movewidth
- one higher than the maximum x value this can use; typically the length of an arrayheight
- one higher than the maximum y value this can use; typically the length of an arraypublic Coord add(Coord other)
other
- another Coordx = this.x + other.x; y = this.y + other.y
public Coord add(int operand)
operand
- a value to add each of x and y tox = this.x + operand; y = this.y + operand
public Coord add(double operand)
operand
- a value to add each of x and y tox = this.x + operand; y = this.y +
operand
, with both x and y rounded accordinglypublic Coord subtract(Coord other)
other
- another Coordx = this.x - other.x; y = this.y - other.y
public Coord subtract(int operand)
operand
- a value to subtract from each of x and yx = this.x - operand; y = this.y - operand
public Coord subtract(double operand)
operand
- a value to subtract from each of x and yx = this.x - operand; y = this.y -
operand
, with both x and y rounded accordinglypublic Coord multiply(Coord other)
other
- another Coordx = this.x * other.x; y = this.y * other.y
public Coord multiply(int operand)
operand
- a value to multiply each of x and y byx = this.x * operand; y = this.y * operand
public Coord multiply(double operand)
operand
- a value to multiply each of x and y byx = this.x * operand; y = this.y *
operand
, with both x and y rounded accordinglypublic Coord divide(Coord other)
other
- another Coordx = this.x / other.x; y = this.y / other.y
public Coord divide(int operand)
operand
- a value to divide each of x and y byx = this.x / operand; y = this.y / operand
public Coord divide(double operand)
operand
- a value to divide each of x and y byx = this.x / operand; y = this.y /
operand
, with both x and y rounded accordinglypublic Coord divideRounding(double operand)
operand
- a value to divide each of x and y byx = this.x / operand; y = this.y /
operand
, with both x and y rounded accordinglypublic Coord average(Coord other)
other
- another Coordpublic Coord translate(Direction d)
d
- A non-null
direction.d
on this
.public double distance(double x2, double y2)
public double distanceSq(double x2, double y2)
public double distanceSq(Coord co)
public boolean isAdjacent(Coord c)
c
- this
is adjacent to c
. Not that a cell is
not adjacent to itself with this method.public Direction toGoTo(Coord adjacent)
adjacent
- A Coord
that is adjacent
to
this
.this
to adjacent
i.e.
the direction d
such that translate(this, d)
yields adjacent
.IllegalStateException
- If this
isn't adjacent to adjacent
.public boolean isWithin(int width, int height)
width
- the upper limit on x to check, exclusiveheight
- the upper limit on y to check, exclusivepublic boolean isWithinRectangle(int minX, int minY, int maxX, int maxY)
minX
- the lower limit on x to check, inclusiveminY
- the lower limit on y to check, inclusivemaxX
- the upper limit on x to check, exclusivemaxY
- the upper limit on y to check, exclusivepublic int getX()
public int getY()
public static int getCacheWidth()
public static int getCacheHeight()
public static void expandPool(int xIncrease, int yIncrease)
Copyright © 2012–2016. All rights reserved.