Package nl.colorize.multimedialib.math
Record Class Vector
java.lang.Object
java.lang.Record
nl.colorize.multimedialib.math.Vector
A two-dimensional vector expressed using an origin, a direction, and a
magnitude. All coordinates are defined with float precision.
The direction of the vector is defined by an angle in degrees. An angle of 0 degrees represents the vector (1, 0). Angles greater than 0 rotate in a clockwise direction, so an angle of 180 degress would represent the vector (-1, 0).
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thedirection
record component.final boolean
Indicates whether some other object is "equal to" this one.static Vector
float
getX()
float
getY()
final int
hashCode()
Returns a hash code value for this object.float
Returns the value of themagnitude
record component.origin()
Returns the value of theorigin
record component.toPoint()
toString()
Returns a string representation of this record class.withDirection
(float newDirection) withDirection
(Angle newDirection) withMagnitude
(float newMagnitude)
-
Constructor Details
-
Vector
-
Vector
public Vector(float direction, float magnitude) -
Vector
Creates an instance of aVector
record class.- Parameters:
origin
- the value for theorigin
record componentdirection
- the value for thedirection
record componentmagnitude
- the value for themagnitude
record component
-
-
Method Details
-
getX
public float getX() -
getY
public float getY() -
toPoint
-
withDirection
-
withDirection
-
withMagnitude
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
fromPoint
-
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object)
; primitive components are compared with '=='. -
origin
Returns the value of theorigin
record component.- Returns:
- the value of the
origin
record component
-
direction
Returns the value of thedirection
record component.- Returns:
- the value of the
direction
record component
-
magnitude
public float magnitude()Returns the value of themagnitude
record component.- Returns:
- the value of the
magnitude
record component
-