Package com.takenoko.vector
Class Vector
java.lang.Object
com.takenoko.vector.Vector
- Direct Known Subclasses:
PositionVector
The Vector class represents a vector in a 2D hexagonal grid.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd two vectors.doubleDetermine the distance between two vectors.booleanDetermine the neighbors of the vector.inthashCode()doublelength()Determine the length of the vector.multiply(double i) Multiply the vector by a scalar.Normalize the vector.doubleq()doubler()rotate60()Rotate the vector by 60 degrees.doubles()Subtract two vectors.toString()
-
Field Details
-
q
private final double q -
r
private final double r -
s
private final double s
-
-
Constructor Details
-
Vector
public Vector(double q, double r, double s) Constructor for the Vector class. The vector is represented by its coordinates in a 2D hexagonal grid. The vector must respect q+r+s=0.- Parameters:
q- The q coordinate of the vector.r- The r coordinate of the vector.s- The s coordinate of the vector.
-
-
Method Details
-
add
Add two vectors.- Parameters:
other- The vector to add to this vector.- Returns:
- The sum of this vector and the other vector.
-
sub
Subtract two vectors.- Parameters:
other- The vector to subtract to this vector.- Returns:
- The difference of this vector and the other vector.
-
rotate60
Rotate the vector by 60 degrees.- Returns:
- The rotated vector.
-
length
public double length()Determine the length of the vector.- Returns:
- The length of the vector.
-
distance
Determine the distance between two vectors.- Parameters:
other- The other vector.- Returns:
- The distance between the two vectors.
-
equals
-
hashCode
public int hashCode() -
getNeighbors
Determine the neighbors of the vector.- Returns:
- The neighbors around the vector.
-
multiply
Multiply the vector by a scalar.- Parameters:
i- The number of times to multiply the vector.- Returns:
- The multiplied vector.
-
normalize
Normalize the vector.- Returns:
- The normalized vector.
-
q
public double q() -
r
public double r() -
s
public double s() -
toString
-
toPositionVector
-