Generated vector API reference
This page is generated from the typed algebra model that emits Field's heap, frame-arena, and MemorySegment vector implementations. For intuition and worked examples, start with Linear algebra in Field.
One algebra, three storage forms
| Storage | Types | Lifetime and use |
|---|---|---|
| Heap | Vector2f, Vector3f, Vector4f |
Ordinary mutable values; persistent state and the normal case |
| Frame arena | ArenaVec2f, ArenaVec3f, ArenaVec4f |
Temporary values inside frameScratch or an explicit FrameArena scope |
| Segment view | SegmentVec2f, SegmentVec3f, SegmentVec4f |
Non-owning views into packed, aligned, direct, foreign, or mapped memory |
All destination overloads write into dest, return it, permit input/destination aliasing, and allocate no result.
Further forms share the same model: the heap types also come in double precision (Vector2d, Vector3d, Vector4d, heap-only) and half precision (Vector8h, heap-only — eight IEEE-754 binary16 lanes that pack into a single vec4 of GPU memory), and the afield.math.linalg.bulk package provides flat-FloatArray SIMD kernels (addRange, normalizeRange, …) with scalar- and broadcast-vector overloads for whole-array field operations.
Vector2f
A mutable 2D vector of 32-bit floating-point components.
Components: x, y.
In a Field code box, ordinary heap values use vec(x, y). In a typed context, val value: Vec2 = [0, 1] uses the generated collection-literal constructor. The frame-arena (ArenaVec2f) and segment (SegmentVec2f) forms carry the same operation surface.
| Operation and example | Meaning |
|---|---|
add(other: Vector2fc)value.add(other) |
Adds another vector component by component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
sub(other: Vector2fc)value.sub(other) |
Subtracts another vector component by component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
mul(other: Vector2fc)value.mul(other) |
Multiplies corresponding components. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
div(other: Vector2fc)value.div(other) |
Divides corresponding components. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
add(scalar: Float)value.add(scalar) |
Adds a scalar to each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
sub(scalar: Float)value.sub(scalar) |
Subtracts a scalar from each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
mul(scalar: Float)value.mul(scalar) |
Scales every component by a scalar. Scalar multiplication changes the arrow's length; a negative scalar also reverses its direction. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
div(scalar: Float)value.div(scalar) |
Divides every component by a scalar. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
negate()value.negate() |
Reverses the vector by negating every component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
absolute()value.absolute() |
Replaces every component with its absolute value. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
min(other: Vector2fc)value.min(other) |
Selects the smaller value independently in each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
max(other: Vector2fc)value.max(other) |
Selects the larger value independently in each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
min(scalar: Float)value.min(scalar) |
Caps every component at a scalar upper bound. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
max(scalar: Float)value.max(scalar) |
Raises every component to a scalar lower bound. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
lerp(other: Vector2fc, t: Float)value.lerp(other, 0.5f) |
Linearly interpolates from this vector toward another. At t = 0 the result is this vector; at t = 1 it is other. Values between zero and one trace the straight line between them. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
fma(scalar: Float, other: Vector2fc)value.fma(0.1f, direction) |
Computes this + other * scalar component by component. This is the common position-plus-scaled-direction pattern used for rays, velocities, and Euler integration. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
dot(other: Vector2fc)value.dot(other) |
Measures how strongly two vectors point in the same direction. Positive means broadly aligned, zero means perpendicular, and negative means opposed. For unit vectors the result is the cosine of the angle between them. |
lengthSquared()value.lengthSquared() |
Returns the squared length of this vector. Use this for comparisons when you do not need the actual distance; it avoids a square root. |
distanceSquared(other: Vector2fc)value.distanceSquared(other) |
Returns the squared straight-line distance to another vector. Use this for nearest/farthest comparisons when you do not need the actual distance. |
length()value.length() |
Returns this vector's Euclidean length (magnitude). |
distance(other: Vector2fc)value.distance(other) |
Returns the straight-line distance to another vector. |
normalize()value.normalize() |
Keeps the vector's direction while scaling its length to one. A zero-length vector has no direction; normalizing it follows floating-point arithmetic and produces non-finite components. Check lengthSquared() first when zero is possible. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
isFinite() |
Reports whether every component is finite. |
Vector3f
A mutable 3D vector of 32-bit floating-point components.
Components: x, y, z.
In a Field code box, ordinary heap values use vec(x, y, z). In a typed context, val value: Vec3 = [0, 1, 2] uses the generated collection-literal constructor. The frame-arena (ArenaVec3f) and segment (SegmentVec3f) forms carry the same operation surface.
| Operation and example | Meaning |
|---|---|
add(other: Vector3fc)value.add(other) |
Adds another vector component by component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
sub(other: Vector3fc)value.sub(other) |
Subtracts another vector component by component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
mul(other: Vector3fc)value.mul(other) |
Multiplies corresponding components. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
div(other: Vector3fc)value.div(other) |
Divides corresponding components. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
add(scalar: Float)value.add(scalar) |
Adds a scalar to each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
sub(scalar: Float)value.sub(scalar) |
Subtracts a scalar from each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
mul(scalar: Float)value.mul(scalar) |
Scales every component by a scalar. Scalar multiplication changes the arrow's length; a negative scalar also reverses its direction. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
div(scalar: Float)value.div(scalar) |
Divides every component by a scalar. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
negate()value.negate() |
Reverses the vector by negating every component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
absolute()value.absolute() |
Replaces every component with its absolute value. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
min(other: Vector3fc)value.min(other) |
Selects the smaller value independently in each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
max(other: Vector3fc)value.max(other) |
Selects the larger value independently in each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
min(scalar: Float)value.min(scalar) |
Caps every component at a scalar upper bound. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
max(scalar: Float)value.max(scalar) |
Raises every component to a scalar lower bound. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
lerp(other: Vector3fc, t: Float)value.lerp(other, 0.5f) |
Linearly interpolates from this vector toward another. At t = 0 the result is this vector; at t = 1 it is other. Values between zero and one trace the straight line between them. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
fma(scalar: Float, other: Vector3fc)value.fma(0.1f, direction) |
Computes this + other * scalar component by component. This is the common position-plus-scaled-direction pattern used for rays, velocities, and Euler integration. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
dot(other: Vector3fc)value.dot(other) |
Measures how strongly two vectors point in the same direction. Positive means broadly aligned, zero means perpendicular, and negative means opposed. For unit vectors the result is the cosine of the angle between them. |
lengthSquared()value.lengthSquared() |
Returns the squared length of this vector. Use this for comparisons when you do not need the actual distance; it avoids a square root. |
distanceSquared(other: Vector3fc)value.distanceSquared(other) |
Returns the squared straight-line distance to another vector. Use this for nearest/farthest comparisons when you do not need the actual distance. |
length()value.length() |
Returns this vector's Euclidean length (magnitude). |
distance(other: Vector3fc)value.distance(other) |
Returns the straight-line distance to another vector. |
normalize()value.normalize() |
Keeps the vector's direction while scaling its length to one. A zero-length vector has no direction; normalizing it follows floating-point arithmetic and produces non-finite components. Check lengthSquared() first when zero is possible. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
cross(other: Vector3fc)value.cross(other) |
Returns a vector perpendicular to this vector and another 3D vector. The direction follows the right-hand rule. Its length is the area of the parallelogram spanned by the inputs, so parallel vectors produce zero. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
isFinite() |
Reports whether every component is finite. |
Vector4f
A mutable 4D vector of 32-bit floating-point components.
Components: x, y, z, w.
In a Field code box, ordinary heap values use vec(x, y, z, w). In a typed context, val value: Vec4 = [0, 1, 2, 3] uses the generated collection-literal constructor. The frame-arena (ArenaVec4f) and segment (SegmentVec4f) forms carry the same operation surface.
| Operation and example | Meaning |
|---|---|
add(other: Vector4fc)value.add(other) |
Adds another vector component by component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
sub(other: Vector4fc)value.sub(other) |
Subtracts another vector component by component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
mul(other: Vector4fc)value.mul(other) |
Multiplies corresponding components. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
div(other: Vector4fc)value.div(other) |
Divides corresponding components. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
add(scalar: Float)value.add(scalar) |
Adds a scalar to each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
sub(scalar: Float)value.sub(scalar) |
Subtracts a scalar from each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
mul(scalar: Float)value.mul(scalar) |
Scales every component by a scalar. Scalar multiplication changes the arrow's length; a negative scalar also reverses its direction. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
div(scalar: Float)value.div(scalar) |
Divides every component by a scalar. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
negate()value.negate() |
Reverses the vector by negating every component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
absolute()value.absolute() |
Replaces every component with its absolute value. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
min(other: Vector4fc)value.min(other) |
Selects the smaller value independently in each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
max(other: Vector4fc)value.max(other) |
Selects the larger value independently in each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
min(scalar: Float)value.min(scalar) |
Caps every component at a scalar upper bound. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
max(scalar: Float)value.max(scalar) |
Raises every component to a scalar lower bound. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
lerp(other: Vector4fc, t: Float)value.lerp(other, 0.5f) |
Linearly interpolates from this vector toward another. At t = 0 the result is this vector; at t = 1 it is other. Values between zero and one trace the straight line between them. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
fma(scalar: Float, other: Vector4fc)value.fma(0.1f, direction) |
Computes this + other * scalar component by component. This is the common position-plus-scaled-direction pattern used for rays, velocities, and Euler integration. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
dot(other: Vector4fc)value.dot(other) |
Measures how strongly two vectors point in the same direction. Positive means broadly aligned, zero means perpendicular, and negative means opposed. For unit vectors the result is the cosine of the angle between them. |
lengthSquared()value.lengthSquared() |
Returns the squared length of this vector. Use this for comparisons when you do not need the actual distance; it avoids a square root. |
distanceSquared(other: Vector4fc)value.distanceSquared(other) |
Returns the squared straight-line distance to another vector. Use this for nearest/farthest comparisons when you do not need the actual distance. |
length()value.length() |
Returns this vector's Euclidean length (magnitude). |
distance(other: Vector4fc)value.distance(other) |
Returns the straight-line distance to another vector. |
normalize()value.normalize() |
Keeps the vector's direction while scaling its length to one. A zero-length vector has no direction; normalizing it follows floating-point arithmetic and produces non-finite components. Check lengthSquared() first when zero is possible. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
isFinite() |
Reports whether every component is finite. |
Vector2d
A mutable 2D vector of 64-bit floating-point components.
Components: x, y.
The double-precision, heap-only sibling of Vector2f; the arena, segment, and bulk forms are single-precision only.
| Operation and example | Meaning |
|---|---|
add(other: Vector2dc)value.add(other) |
Adds another vector component by component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
sub(other: Vector2dc)value.sub(other) |
Subtracts another vector component by component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
mul(other: Vector2dc)value.mul(other) |
Multiplies corresponding components. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
div(other: Vector2dc)value.div(other) |
Divides corresponding components. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
add(scalar: Double)value.add(scalar) |
Adds a scalar to each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
sub(scalar: Double)value.sub(scalar) |
Subtracts a scalar from each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
mul(scalar: Double)value.mul(scalar) |
Scales every component by a scalar. Scalar multiplication changes the arrow's length; a negative scalar also reverses its direction. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
div(scalar: Double)value.div(scalar) |
Divides every component by a scalar. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
negate()value.negate() |
Reverses the vector by negating every component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
absolute()value.absolute() |
Replaces every component with its absolute value. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
min(other: Vector2dc)value.min(other) |
Selects the smaller value independently in each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
max(other: Vector2dc)value.max(other) |
Selects the larger value independently in each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
min(scalar: Double)value.min(scalar) |
Caps every component at a scalar upper bound. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
max(scalar: Double)value.max(scalar) |
Raises every component to a scalar lower bound. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
lerp(other: Vector2dc, t: Double)value.lerp(other, 0.5) |
Linearly interpolates from this vector toward another. At t = 0 the result is this vector; at t = 1 it is other. Values between zero and one trace the straight line between them. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
fma(scalar: Double, other: Vector2dc)value.fma(0.1, direction) |
Computes this + other * scalar component by component. This is the common position-plus-scaled-direction pattern used for rays, velocities, and Euler integration. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
dot(other: Vector2dc)value.dot(other) |
Measures how strongly two vectors point in the same direction. Positive means broadly aligned, zero means perpendicular, and negative means opposed. For unit vectors the result is the cosine of the angle between them. |
lengthSquared()value.lengthSquared() |
Returns the squared length of this vector. Use this for comparisons when you do not need the actual distance; it avoids a square root. |
distanceSquared(other: Vector2dc)value.distanceSquared(other) |
Returns the squared straight-line distance to another vector. Use this for nearest/farthest comparisons when you do not need the actual distance. |
length()value.length() |
Returns this vector's Euclidean length (magnitude). |
distance(other: Vector2dc)value.distance(other) |
Returns the straight-line distance to another vector. |
normalize()value.normalize() |
Keeps the vector's direction while scaling its length to one. A zero-length vector has no direction; normalizing it follows floating-point arithmetic and produces non-finite components. Check lengthSquared() first when zero is possible. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
isFinite() |
Reports whether every component is finite. |
Vector3d
A mutable 3D vector of 64-bit floating-point components.
Components: x, y, z.
The double-precision, heap-only sibling of Vector3f; the arena, segment, and bulk forms are single-precision only.
| Operation and example | Meaning |
|---|---|
add(other: Vector3dc)value.add(other) |
Adds another vector component by component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
sub(other: Vector3dc)value.sub(other) |
Subtracts another vector component by component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
mul(other: Vector3dc)value.mul(other) |
Multiplies corresponding components. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
div(other: Vector3dc)value.div(other) |
Divides corresponding components. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
add(scalar: Double)value.add(scalar) |
Adds a scalar to each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
sub(scalar: Double)value.sub(scalar) |
Subtracts a scalar from each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
mul(scalar: Double)value.mul(scalar) |
Scales every component by a scalar. Scalar multiplication changes the arrow's length; a negative scalar also reverses its direction. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
div(scalar: Double)value.div(scalar) |
Divides every component by a scalar. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
negate()value.negate() |
Reverses the vector by negating every component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
absolute()value.absolute() |
Replaces every component with its absolute value. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
min(other: Vector3dc)value.min(other) |
Selects the smaller value independently in each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
max(other: Vector3dc)value.max(other) |
Selects the larger value independently in each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
min(scalar: Double)value.min(scalar) |
Caps every component at a scalar upper bound. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
max(scalar: Double)value.max(scalar) |
Raises every component to a scalar lower bound. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
lerp(other: Vector3dc, t: Double)value.lerp(other, 0.5) |
Linearly interpolates from this vector toward another. At t = 0 the result is this vector; at t = 1 it is other. Values between zero and one trace the straight line between them. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
fma(scalar: Double, other: Vector3dc)value.fma(0.1, direction) |
Computes this + other * scalar component by component. This is the common position-plus-scaled-direction pattern used for rays, velocities, and Euler integration. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
dot(other: Vector3dc)value.dot(other) |
Measures how strongly two vectors point in the same direction. Positive means broadly aligned, zero means perpendicular, and negative means opposed. For unit vectors the result is the cosine of the angle between them. |
lengthSquared()value.lengthSquared() |
Returns the squared length of this vector. Use this for comparisons when you do not need the actual distance; it avoids a square root. |
distanceSquared(other: Vector3dc)value.distanceSquared(other) |
Returns the squared straight-line distance to another vector. Use this for nearest/farthest comparisons when you do not need the actual distance. |
length()value.length() |
Returns this vector's Euclidean length (magnitude). |
distance(other: Vector3dc)value.distance(other) |
Returns the straight-line distance to another vector. |
normalize()value.normalize() |
Keeps the vector's direction while scaling its length to one. A zero-length vector has no direction; normalizing it follows floating-point arithmetic and produces non-finite components. Check lengthSquared() first when zero is possible. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
cross(other: Vector3dc)value.cross(other) |
Returns a vector perpendicular to this vector and another 3D vector. The direction follows the right-hand rule. Its length is the area of the parallelogram spanned by the inputs, so parallel vectors produce zero. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
isFinite() |
Reports whether every component is finite. |
Vector4d
A mutable 4D vector of 64-bit floating-point components.
Components: x, y, z, w.
The double-precision, heap-only sibling of Vector4f; the arena, segment, and bulk forms are single-precision only.
| Operation and example | Meaning |
|---|---|
add(other: Vector4dc)value.add(other) |
Adds another vector component by component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
sub(other: Vector4dc)value.sub(other) |
Subtracts another vector component by component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
mul(other: Vector4dc)value.mul(other) |
Multiplies corresponding components. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
div(other: Vector4dc)value.div(other) |
Divides corresponding components. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
add(scalar: Double)value.add(scalar) |
Adds a scalar to each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
sub(scalar: Double)value.sub(scalar) |
Subtracts a scalar from each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
mul(scalar: Double)value.mul(scalar) |
Scales every component by a scalar. Scalar multiplication changes the arrow's length; a negative scalar also reverses its direction. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
div(scalar: Double)value.div(scalar) |
Divides every component by a scalar. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
negate()value.negate() |
Reverses the vector by negating every component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
absolute()value.absolute() |
Replaces every component with its absolute value. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
min(other: Vector4dc)value.min(other) |
Selects the smaller value independently in each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
max(other: Vector4dc)value.max(other) |
Selects the larger value independently in each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
min(scalar: Double)value.min(scalar) |
Caps every component at a scalar upper bound. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
max(scalar: Double)value.max(scalar) |
Raises every component to a scalar lower bound. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
lerp(other: Vector4dc, t: Double)value.lerp(other, 0.5) |
Linearly interpolates from this vector toward another. At t = 0 the result is this vector; at t = 1 it is other. Values between zero and one trace the straight line between them. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
fma(scalar: Double, other: Vector4dc)value.fma(0.1, direction) |
Computes this + other * scalar component by component. This is the common position-plus-scaled-direction pattern used for rays, velocities, and Euler integration. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
dot(other: Vector4dc)value.dot(other) |
Measures how strongly two vectors point in the same direction. Positive means broadly aligned, zero means perpendicular, and negative means opposed. For unit vectors the result is the cosine of the angle between them. |
lengthSquared()value.lengthSquared() |
Returns the squared length of this vector. Use this for comparisons when you do not need the actual distance; it avoids a square root. |
distanceSquared(other: Vector4dc)value.distanceSquared(other) |
Returns the squared straight-line distance to another vector. Use this for nearest/farthest comparisons when you do not need the actual distance. |
length()value.length() |
Returns this vector's Euclidean length (magnitude). |
distance(other: Vector4dc)value.distance(other) |
Returns the straight-line distance to another vector. |
normalize()value.normalize() |
Keeps the vector's direction while scaling its length to one. A zero-length vector has no direction; normalizing it follows floating-point arithmetic and produces non-finite components. Check lengthSquared() first when zero is possible. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
isFinite() |
Reports whether every component is finite. |
Vector8h
A mutable 8D vector of 16-bit floating-point components.
Components: x, y, z, w, a, b, c, d.
The half-precision (IEEE-754 binary16), heap-only vector. Its eight lanes pack into 16 bytes — one GLSL vec4 — through get(index, buffer), so a push-constant block holds twice as many as the equivalent Vector4f pair would. Arithmetic is evaluated in Float; every result is stored back as binary16, so component reads return the rounded value.
| Operation and example | Meaning |
|---|---|
add(other: Vector8hc)value.add(other) |
Adds another vector component by component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
sub(other: Vector8hc)value.sub(other) |
Subtracts another vector component by component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
mul(other: Vector8hc)value.mul(other) |
Multiplies corresponding components. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
div(other: Vector8hc)value.div(other) |
Divides corresponding components. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
add(scalar: Float)value.add(scalar) |
Adds a scalar to each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
sub(scalar: Float)value.sub(scalar) |
Subtracts a scalar from each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
mul(scalar: Float)value.mul(scalar) |
Scales every component by a scalar. Scalar multiplication changes the arrow's length; a negative scalar also reverses its direction. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
div(scalar: Float)value.div(scalar) |
Divides every component by a scalar. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
negate()value.negate() |
Reverses the vector by negating every component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
absolute()value.absolute() |
Replaces every component with its absolute value. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
min(other: Vector8hc)value.min(other) |
Selects the smaller value independently in each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
max(other: Vector8hc)value.max(other) |
Selects the larger value independently in each component. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
min(scalar: Float)value.min(scalar) |
Caps every component at a scalar upper bound. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
max(scalar: Float)value.max(scalar) |
Raises every component to a scalar lower bound. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
lerp(other: Vector8hc, t: Float)value.lerp(other, 0.5f) |
Linearly interpolates from this vector toward another. At t = 0 the result is this vector; at t = 1 it is other. Values between zero and one trace the straight line between them. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
fma(scalar: Float, other: Vector8hc)value.fma(0.1f, direction) |
Computes this + other * scalar component by component. This is the common position-plus-scaled-direction pattern used for rays, velocities, and Euler integration. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
dot(other: Vector8hc)value.dot(other) |
Measures how strongly two vectors point in the same direction. Positive means broadly aligned, zero means perpendicular, and negative means opposed. For unit vectors the result is the cosine of the angle between them. |
lengthSquared()value.lengthSquared() |
Returns the squared length of this vector. Use this for comparisons when you do not need the actual distance; it avoids a square root. |
distanceSquared(other: Vector8hc)value.distanceSquared(other) |
Returns the squared straight-line distance to another vector. Use this for nearest/farthest comparisons when you do not need the actual distance. |
length()value.length() |
Returns this vector's Euclidean length (magnitude). |
distance(other: Vector8hc)value.distance(other) |
Returns the straight-line distance to another vector. |
normalize()value.normalize() |
Keeps the vector's direction while scaling its length to one. A zero-length vector has no direction; normalizing it follows floating-point arithmetic and produces non-finite components. Check lengthSquared() first when zero is possible. Overloads without dest update this vector; pass a distinct destination to preserve the receiver. |
isFinite() |
Reports whether every component is finite. |
Swizzles
Every float heap vector (Vector2f, Vector3f, Vector4f) carries the modeled combinatorial swizzle surface. The generator emits the combinations systematically, and generated-source checks plus behavior tests guard the surface; generation is not a substitute for verification.
- For each source vector, every length-2, length-3 and length-4 sequence of its components is a read swizzle — an extension
valon the read interface, so any view can use it. Sequences may reorder (v.zyx), repeat (v.xx), and expand beyond the source arity (v.xxxx). - Components can be spelled two ways: positional
x/y/z/wor colorr/g/b/a. The two are never mixed within one swizzle. - A read swizzle returns a same-scalar
VectorKfcof the swizzle's own arity (v.xyis aVector2fc,v.xyzaVector3fc). - When a swizzle's indices are all distinct it also has a writable
varon the mutable type, so GLSL-style assignment works:v.xy = other.zw. Repeated-index swizzles (v.xx) have no unambiguous target and stay read-only.
Ergonomic operators
The float heap vectors also carry a small generated operator surface for live coding:
| Operator | Meaning |
|---|---|
v(y = 2f) |
Returns a copy with the named components replaced; unnamed components keep this vector's values. |
v.normalized() / v.normalized(dest) |
Unit direction as a new value / into reusable storage. Zero remains zero; optional epsilon sets the zero threshold. Finite inputs only. |
v { normalize() } |
Returns a copy after applying the block to it, leaving this vector untouched. |
a %= b |
In-place assignment: copies b's components into a. |
v len 10 |
Returns a copy rescaled to the given length, keeping direction. |
Rotations and matrices
Alongside the vectors, the library provides rotation and matrix types whose core equations are generated from the same transform model and which interoperate with the heap vectors.
| Type | Purpose | Key operations |
|---|---|---|
Quaternionf |
Represents a 3D rotation. Compose rotations with mul or interpolate orientations with slerp and nlerp. |
setAngleAxis, rotateX/Y/Z, mul, invert, conjugate, normalize, slerp, nlerp, rotationTo, lookAlong, transform(Vector3f) |
Matrix3f |
Represents a linear transform in three dimensions. Use the inverse transpose of a position transform's linear part to transform surface normals. | rotation, scale, mul, invert, transpose, determinant, transform(Vector3f) |
Matrix3d |
Provides a double-precision 3×3 transform for numerically sensitive calculations. Its extra precision is useful when single-precision rounding is significant. | mul, invert, transpose, determinant |
Matrix4f |
Represents affine and projective transforms, including cameras. Distinguish positions from directions so translation is applied only where intended. | translate, scale, rotate, mul, invert, transpose, perspective, ortho, frustum, lookAt, transformPosition, transformDirection |
Storage layouts
| Vector | Layout choices |
|---|---|
| Vec2 | PACKED_8, ALIGNED_8, ALIGNED_16 |
| Vec3 | PACKED_12, ALIGNED_16 |
| Vec4 | PACKED_16, ALIGNED_16 |
A layout name describes both array stride and required base alignment. A segment view never owns the memory and never performs Vulkan synchronization.