public class CellVector
extends java.lang.Object
A CellVector represents a point in continuous space as a two-dimensional vector. CellVectors are mutable; that is, the point that they represent can be changed. However, since the point that a CellVector represents is the basis of its equals() and hashCode() methods, care must be taken not to mutate a CellVector while data structures such as Maps or Sets are using it. CellVectors measure angles in degrees going counterclockwise from directly right and normalize them to be between 0 and 360. All operations on a CellVector return the CellVector itself to allow operations to be easily strung together.
Constructor and Description |
---|
CellVector()
Constructs a CellVector that represents the origin.
|
CellVector(CellVector point)
Constructs a CellVector that represents the specified point.
|
CellVector(double angle)
Constructs a CellVector that represents the point on the unit circle at
the specified angle from the origin.
|
CellVector(long x,
long y)
Constructs a CellVector that represents the specified point.
|
Modifier and Type | Method and Description |
---|---|
CellVector |
add(CellVector vector)
Adds the specified CellVector to this CellVector.
|
static CellVector |
add(CellVector first,
CellVector second)
Returns a new CellVector that represents the sum of the two specified
CellVectors.
|
CellVector |
add(long x,
long y)
Adds the specified coordinates to this CellVector's own.
|
static double |
angleBetween(long x1,
long y1,
long x2,
long y2)
Returns the angle from the point (x1, y1) to the point (x2, y2).
|
double |
angleTo(CellVector point)
Returns the angle from this CellVector's point to that of the specified
CellVector.
|
CellVector |
changeAngle(double angle)
Changes this CellVector's angle by the specified amount while retaining
its magnitude.
|
CellVector |
clear()
Resets this CellVector to represent the origin.
|
long |
cross(CellVector vector)
Returns the non-zero component in fracunits of the cross product of this
CellVector and the specified one.
|
static long |
distanceBetween(long x1,
long y1,
long x2,
long y2)
Returns the distance between the points (x1, y1) and (x2, y2).
|
long |
distanceTo(CellVector point)
Returns the distance from this CellVector's point to that of the
specified CellVector.
|
long |
dot(CellVector vector)
Returns the dot product in fracunits of this CellVector and the specified
one.
|
boolean |
equals(java.lang.Object obj)
Returns whether the specified object is a CellVector that is equal to
this CellVector.
|
CellVector |
flip()
Flips this CellVector across both coordinate axes, negating both of its
coordinates.
|
CellVector |
flip(boolean xFlip,
boolean yFlip)
Flips this CellVector across either, both, or neither of the coordinate
axes, depending on the parameters.
|
CellVector |
flipX()
Flips this CellVector across the x-axis, negating its x-coordinate.
|
CellVector |
flipY()
Flips this CellVector across the y-axis, negating its y-coordinate.
|
double |
getAngle()
Returns this CellVector's angle.
|
long |
getAngleX()
Returns the x-coordinate of the unit vector that points in the direction
of this CellVector's angle.
|
long |
getAngleY()
Returns the y-coordinate of the unit vector that points in the direction
of this CellVector's angle.
|
long |
getMagnitude()
Returns this CellVector's magnitude.
|
long |
getMagnitudeSquared()
Returns the square of this CellVector's magnitude.
|
long |
getX()
Returns the x-coordinate of the point that this CellVector represents.
|
long |
getY()
Returns the y-coordinate of the point that this CellVector represents.
|
int |
hashCode() |
static boolean |
lineSegmentsIntersect(CellVector start1,
CellVector diff1,
CellVector start2,
CellVector diff2)
Returns whether the two specified line segments share any points.
|
static CellVector |
lineSegmentsIntersectionPoint(CellVector start1,
CellVector diff1,
CellVector start2,
CellVector diff2)
Returns the single point at which the two specified line segments
intersect, or null if they intersect at no points or at an infinity of
points.
|
CellVector |
relativeTo(Hitbox hitbox)
Flips this CellVector to reflect the flipped status of the specified
Hitbox and rotates it to reflect the Hitbox's angle of rotation, as if
those properties were formerly relative to the Hitbox.
|
CellVector |
relativeTo(SpaceObject object)
Flips this CellVector to reflect the flipped status of the specified
SpaceObject and rotates it to reflect the SpaceObject's angle of
rotation, as if those properties were formerly relative to the
SpaceObject.
|
CellVector |
scale(long scaleFactor)
Multiplies this CellVector's coordinates by the specified fracunit-scale
factor.
|
CellVector |
setAngle(double angle)
Sets this CellVector's angle to the specified value while retaining its
magnitude.
|
CellVector |
setCoordinates(CellVector point)
Sets this CellVector's point to the specified value.
|
CellVector |
setCoordinates(long x,
long y)
Sets this CellVector's point to the specified coordinates.
|
CellVector |
setMagnitude(long magnitude)
Sets this CellVector's magnitude to the specified value while retaining
its angle.
|
CellVector |
setX(long x)
Sets the x-coordinate of this CellVector's point to the specified value.
|
CellVector |
setY(long y)
Sets the y-coordinate of this CellVector's point to the specified value.
|
CellVector |
sub(CellVector vector)
Subtracts the specified CellVector from this CellVector.
|
static CellVector |
sub(CellVector first,
CellVector second)
Returns a new CellVector that represents the second specified
CellVector subtracted from the first.
|
CellVector |
sub(long x,
long y)
Subtracts the specified coordinates from this CellVector's own.
|
public CellVector()
public CellVector(CellVector point)
point
- The point that this CellVector representspublic CellVector(long x, long y)
x
- The x-coordinate of the point that this CellVector representsy
- The y-coordinate of the point that this CellVector representspublic CellVector(double angle)
angle
- The angle from the origin of the point on the unit circle
that this CellVector representspublic final int hashCode()
hashCode
in class java.lang.Object
public final boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- The object to be compared with this CellVectorpublic final CellVector clear()
public final long getX()
public final CellVector setX(long x)
x
- The point's new x-coordinatepublic final long getY()
public final CellVector setY(long y)
y
- The point's new y-coordinatepublic final CellVector setCoordinates(CellVector point)
point
- The new pointpublic final CellVector setCoordinates(long x, long y)
x
- The point's new x-coordinatey
- The point's new y-coordinatepublic final CellVector flip()
public final CellVector flipX()
public final CellVector flipY()
public final CellVector flip(boolean xFlip, boolean yFlip)
xFlip
- If true, this CellVector will be flipped across the x-axisyFlip
- If true, this CellVector will be flipped across the y-axispublic final long getMagnitudeSquared()
public final long getMagnitude()
public final CellVector setMagnitude(long magnitude)
magnitude
- The new magnitudepublic final CellVector scale(long scaleFactor)
scaleFactor
- The factor by which to scale this CellVectorpublic final double getAngle()
public final long getAngleX()
public final long getAngleY()
public final CellVector setAngle(double angle)
angle
- The new anglepublic final CellVector changeAngle(double angle)
angle
- The amount by which to change the anglepublic final CellVector add(CellVector vector)
vector
- The CellVector to be addedpublic final CellVector add(long x, long y)
x
- The x-coordinate to be addedy
- The y-coordinate to be addedpublic static CellVector add(CellVector first, CellVector second)
first
- The first CellVectorsecond
- The second CellVectorpublic final CellVector sub(CellVector vector)
vector
- The CellVector to be subtractedpublic final CellVector sub(long x, long y)
x
- The x-coordinate to be subtractedy
- The y-coordinate to be subtractedpublic static CellVector sub(CellVector first, CellVector second)
first
- The first CellVectorsecond
- The second CellVectorpublic final long dot(CellVector vector)
vector
- The CellVector to take the dot product withpublic final long cross(CellVector vector)
vector
- The CellVector to take the cross product withpublic final CellVector relativeTo(Hitbox hitbox)
hitbox
- The Hitbox to reflectpublic final CellVector relativeTo(SpaceObject object)
object
- The SpaceObject to reflectpublic final long distanceTo(CellVector point)
point
- The point to return the distance topublic static long distanceBetween(long x1, long y1, long x2, long y2)
x1
- The x-coordinate of the first pointy1
- The y-coordinate of the first pointx2
- The x-coordinate of the second pointy2
- The y-coordinate of the second pointpublic final double angleTo(CellVector point)
point
- The point to return the angle topublic static double angleBetween(long x1, long y1, long x2, long y2)
x1
- The x-coordinate of the first pointy1
- The y-coordinate of the first pointx2
- The x-coordinate of the second pointy2
- The y-coordinate of the second pointpublic static boolean lineSegmentsIntersect(CellVector start1, CellVector diff1, CellVector start2, CellVector diff2)
start1
- One of the first line segment's endpointsdiff1
- The difference of the first line segment's endpointsstart2
- One of the second line segment's endpointsdiff2
- The difference of the second line segment's endpointspublic static CellVector lineSegmentsIntersectionPoint(CellVector start1, CellVector diff1, CellVector start2, CellVector diff2)
start1
- One of the first line segment's endpointsdiff1
- The difference of the first line segment's endpointsstart2
- One of the second line segment's endpointsdiff2
- The difference of the second line segment's endpoints