Package bagel.util
Class Vector2
java.lang.Object
bagel.util.Vector2
Immutable class representing a two-dimensional real vector.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the result of adding rhs to this vector.asPoint()Converts the vector to aPointwith the same x and y values.div(double scalar) Returns the result of dividing this vector by scalar.doubleReturns the dot (scalar) product of this vector and rhs.booleanPerforms exact equality checking.doublelength()Returns the length of this vector.doubleReturns the square of the length of this vector.mul(double scalar) Returns the result of multiplying this vector by scalar.Returns this vector normalised to have a length of 1 by dividing by its length.Returns the result of subtracting rhs from this vector.toString()
-
Field Details
-
x
public final double x -
y
public final double y -
right
A unit vector pointing to the right. -
left
A unit vector pointing to the left. -
up
A unit vector pointing upwards. -
down
A unit vector pointing downwards.
-
-
Constructor Details
-
Vector2
public Vector2()Construct the zero vector. -
Vector2
public Vector2(double x, double y) Create a vector with a given x and y coordinate.
-
-
Method Details
-
add
Returns the result of adding rhs to this vector. -
sub
Returns the result of subtracting rhs from this vector. -
mul
Returns the result of multiplying this vector by scalar. -
div
Returns the result of dividing this vector by scalar. -
dot
Returns the dot (scalar) product of this vector and rhs. Calculated by `this.x * rhs.x + this.y * rhs.y`. -
length
public double length()Returns the length of this vector. -
lengthSquared
public double lengthSquared()Returns the square of the length of this vector. -
asPoint
Converts the vector to aPointwith the same x and y values. -
normalised
Returns this vector normalised to have a length of 1 by dividing by its length. -
equals
Performs exact equality checking. -
toString
-