Documentation
¶
Overview ¶
Package Vector3 provides a 3D vector using integer coordinates.
Index ¶
- Variables
- func AsArray(vec XYZ) [3]int32
- func Distance(v, to XYZ) Float.X
- func DistanceSquared(v, to XYZ) int
- func Index[I Int.Any](v XYZ, i I) int
- func Length(v XYZ) Float.X
- func LengthSquared(v XYZ) int
- type Axis
- type XYZ
- func Abs(v XYZ) XYZ
- func Add(a, b XYZ) XYZ
- func AddX[X Int.Any | Float.Any](a XYZ, b X) XYZ
- func Clamp(v, min, max XYZ) XYZ
- func Clampi[X Int.Any](v XYZ, min, max X) XYZ
- func Div(a, b XYZ) XYZ
- func DivX[X Int.Any | Float.Any](a XYZ, b X) XYZ
- func Max(a, b XYZ) XYZ
- func Maxi[X Int.Any](a XYZ, b X) XYZ
- func Min(a, b XYZ) XYZ
- func Mini[X Int.Any](a XYZ, b X) XYZ
- func Mod(a, b XYZ) XYZ
- func ModX[X Int.Any | Float.Any](a XYZ, b X) XYZ
- func Mul(a, b XYZ) XYZ
- func MulX[X Int.Any | Float.Any](a XYZ, b X) XYZ
- func Neg(v XYZ) XYZ
- func New[X Int.Any | Float.Any](x, y, z X) XYZ
- func Sign(v XYZ) XYZ
- func Snapped(v, step XYZ) XYZ
- func Snappedi[X Int.Any](v XYZ, step X) XYZ
- func Sub(a, b XYZ) XYZ
- func SubX[X Int.Any | Float.Any](a XYZ, b X) XYZ
Constants ¶
This section is empty.
Variables ¶
var ( Zero = XYZ{0, 0, 0} // Zero vector, a vector with all components set to 0. One = XYZ{1, 1, 1} // One vector, a vector with all components set to 1. MinXYZ = XYZ{math.MinInt32, math.MinInt32, math.MinInt32} // Min vector, a vector with all components equal to [math.MinInt32]. Can be used as a negative integer equivalent of Vector3.INF. MaxXYZ = XYZ{math.MaxInt32, math.MaxInt32, math.MaxInt32} // Max vector, a vector with all components equal to [math.MaxInt32]. Can be used as a positive integer equivalent of Vector3.INF. Left = XYZ{-1, 0, 0} // Left unit vector. Represents the local direction of left, and the global direction of west. Right = XYZ{1, 0, 0} // Right unit vector. Represents the local direction of right, and the global direction of east. Up = XYZ{0, -1, 0} // Up unit vector. Down = XYZ{0, 1, 0} // Down unit vector. // Forward unit vector. Represents the local direction of forward, and the global direction // of north. Keep in mind that the forward direction for lights, cameras, etc is different // from 3D assets like characters, which face towards the camera by convention. Use [ModelFront] // and similar constants when working in 3D asset space. Forward = XYZ{0, 0, -1} Back = XYZ{0, 0, 1} // Back unit vector. Represents the local direction of back, and the global direction of south. )
Functions ¶
func DistanceSquared ¶
DistanceSquared returns the squared distance between this vector and to.
This method runs faster than [Vector3.DistanceTo], so prefer it if you need to compare vectors or need the squared distance for some formula.
func LengthSquared ¶
LengthSquared returns the squared length (squared magnitude) of this vector.
This method runs faster than length, so prefer it if you need to compare vectors or need the squared distance for some formula.
Types ¶
type Axis ¶
type Axis int
type XYZ ¶
type XYZ = struct { X int32 // The vector's X component. Y int32 // The vector's Y component. Z int32 // The vector's Z component. }
XYZ is a 3-element structure that can be used to represent 3D grid coordinates or any other triplet of integers.
It uses integer coordinates and is therefore preferable to Vector3 when exact precision is required. Note that the values are limited to 32 bits, and unlike Vector3 this cannot be configured with a build tag. Use int or PackedInt64Array if 64-bit values are needed.
func Clamp ¶
Clamp returns a new vector with all components clamped between the components of min and max, by running [Int.Clamp] on each component.
func Clampi ¶
Clampi returns a new vector with all components clamped between the components of min and max, by running [Int.Clamp] on each component.
func Sign ¶
Sign returns a new vector with each component set to 1 if it's positive, -1 if it's negative, and 0 if it's zero. The result is identical to calling [Signi] on each component.
func Snapped ¶
Snapped returns a new vector with each component snapped to the closest multiple of the corresponding component in step.