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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thedirectionrecord component.final booleanIndicates whether some other object is "equal to" this one.static VectorfloatgetX()floatgetY()final inthashCode()Returns a hash code value for this object.floatReturns the value of themagnituderecord component.origin()Returns the value of theoriginrecord 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 aVectorrecord class.- Parameters:
origin- the value for theoriginrecord componentdirection- the value for thedirectionrecord componentmagnitude- the value for themagnituderecord 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 theoriginrecord component.- Returns:
- the value of the
originrecord component
-
direction
Returns the value of thedirectionrecord component.- Returns:
- the value of the
directionrecord component
-
magnitude
public float magnitude()Returns the value of themagnituderecord component.- Returns:
- the value of the
magnituderecord component
-