Vectorize is a small and lightweight library to store 2-, 3- and 4-dimensional vectors in integer, float and double precision. It offers basic vector operations such as addition, subtraction, multiplication and division, amongst other utility functions.
To add Vectorize as a dependency to your project, add the following repository to your pom.xml
:
<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/PolyRocketMatt/vectorize</url>
</repository>
</repositories>
Then, add the following dependency:
<dependencies>
<dependency>
<groupId>com.github.polyrocketmatt</groupId>
<artifactId>vectorize</artifactId>
<version>2.0.X</version>
</dependency>
</dependencies>
Currently, the latest version is 2.0.3
.
A JavaDoc is available here
Vectorize offers the following types:
Int2
,Int3
,Int4
: 2-, 3- and 4-dimensional integer vectorsFloat2
,Float3
,Float4
: 2-, 3- and 4-dimensional float vectorsDouble2
,Double3
,Double4
: 2-, 3- and 4-dimensional double vectors
The following utility methods are available:
Vector<T>.add(Vector<T> other)
: Adds two vectors of the same typeVector<T>.add(T x, T y, ...)
: Adds components to a vectorVector<T>.subtract(Vector<T> other)
: Subtracts two vectors of the same typeVector<T>.subtract(T x, T y, ...)
: Subtracts components from a vectorVector<T>.multiply(Vector<T> other)
: Multiplies two vectors of the same typeVector<T>.multiply(T x, T y, ...)
: Multiplies components of a vectorVector<T>.divide(Vector<T> other)
: Divides two vectors of the same typeVector<T>.divide(T x, T y, ...)
: Divides components of a vectorVector<T>.pow(Vector<T> power)
: Raises two vectors of the same type to the power of each otherVector<T>.add(T scalar)
: Adds a scalar to a vectorVector<T>.subtract(T scalar)
: Subtracts a scalar from a vectorVector<T>.multiply(T scalar)
: Multiplies a vector by a scalarVector<T>.divide(T scalar)
: Divides a vector by a scalarVector<T>.pow(T power)
: Raises a vector to the power of a scalarVector<T>.negate()
: Negates a vectorVector<T>.abs()
: Returns the absolute value of a vectorVector<T>.normalize(Vector<T> other)
: Returns the normalized vector of a vectorVector<T>.dot(Vector<T> other)
: Returns the dot product of two vectorsVector<T>.angle(Vector<T> other)
: Returns the angle between two vectorsVector<T>.length()
: Returns the length of a vectorVector<T>.lengthSquared()
: Returns the squared length of a vectorVector<T>.distance(Vector<T> other)
: Returns the distance between two vectorsVector<T>.distanceSquared(Vector<T> other)
: Returns the squared distance between two vectorsVector<T>.floor()
: Returns the floor of a vectorVector<T>.ceil()
Returns the ceil of a vectorVector<T>.fract()
Returns the fractional part of a vector
Conversion methods are available to convert between different vector types and arrays. Furthermore, 2-, and 3- vectors allow for special operations.
2D vectors allow for the following special operations:
Vector2<T>.rotate(Vector2<T> other)
: Rotates a vector by another vectorVector2<T>.yx()
: Returns a vector with the X and Y components swapped
3D vectors allow for the following special operations:
Vector3<T>.cross(Vector3<T> other)
: Returns the cross product of two vectorsVector3<T>.rotateX(Vector3<T> other)
: Rotates a vector by another vector around the X axisVector3<T>.rotateY(Vector3<T> other)
: Rotates a vector by another vector around the Y axisVector3<T>.rotateZ(Vector3<T> other)
: Rotates a vector by another vector around the Z axisVector3<T>.zyx()
: Returns a vector with the X, Y and Z components swapped
Vector2<T>.add(T x, T y)
was addedVector3<T>.add(T x, T y, T z)
was addedVector4<T>.add(T x, T y, T z, T w)
was addedVector2<T>.subtract(T x, T y)
was addedVector3<T>.subtract(T x, T y, T z)
was addedVector4<T>.subtract(T x, T y, T z, T w)
was addedVector2<T>.multiply(T x, T y)
was addedVector3<T>.multiply(T x, T y, T z)
was addedVector4<T>.multiply(T x, T y, T z, T w)
was addedVector2<T>.divide(T x, T y)
was addedVector3<T>.divide(T x, T y, T z)
was addedVector4<T>.divide(T x, T y, T z, T w)
was added
- Vector components are now
public
Swizzle2<T>
andSwizzle3<T>
are now functional interfacesVector<T>.floor()
was addedVector<T>.ceil()
was addedVector<T>.fract()
was added
- Minor improvements to the structure of the library
Icon provided by Freepik