Documentation
¶
Overview ¶
Package Vector4i provides a 4D vector using integer coordinates.
Index ¶
- Variables
- func AsArray(vec XYZW) [4]int32
- func Distance(v, to XYZW) Float.X
- func DistanceSquared(v, to XYZW) int
- func Index[I Int.Any](v XYZW, i I) int
- func Length(v XYZW) Float.X
- func LengthSquared(v XYZW) int
- type Axis
- type XYZW
- func Abs(v XYZW) XYZW
- func Add(a, b XYZW) XYZW
- func AddX[X Int.Any | Float.Any](a XYZW, b X) XYZW
- func Clamp(v, min, max XYZW) XYZW
- func Clampi[X Int.Any](v XYZW, min, max X) XYZW
- func Div(a, b XYZW) XYZW
- func DivX[X Int.Any | Float.Any](a XYZW, b X) XYZW
- func Max(a, b XYZW) XYZW
- func Maxi[X Int.Any](a XYZW, b X) XYZW
- func Min(a, b XYZW) XYZW
- func Mini[X Int.Any](a XYZW, b X) XYZW
- func Mod(a, b XYZW) XYZW
- func ModX[X Int.Any | Float.Any](a XYZW, b X) XYZW
- func Mul(a, b XYZW) XYZW
- func MulX[X Int.Any | Float.Any](a XYZW, b X) XYZW
- func Neg(v XYZW) XYZW
- func New[X Int.Any | Float.Any](x, y, z, w X) XYZW
- func Sign(v XYZW) XYZW
- func Snapped(v, step XYZW) XYZW
- func Snappedi[X Int.Any](v XYZW, step X) XYZW
- func Sub(a, b XYZW) XYZW
- func SubX[X Int.Any | Float.Any](a XYZW, b X) XYZW
Constants ¶
This section is empty.
Variables ¶
var ( Zero = XYZW{0, 0, 0, 0} // Zero vector, a vector with all components set to 0. One = XYZW{1, 1, 1, 1} // One vector, a vector with all components set to 1. MinXYZW = XYZW{math.MinInt32, 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 [Vector4.Inf]. MaxXYZW = XYZW{math.MaxInt32, 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 [Vector4.Inf]. )
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
const ( X Axis = iota // Enumerated value for the X axis. Returned by [MaxAxis] and [MinAxis]. Y // Enumerated value for the Y axis. Returned by [MaxAxis] and [MinAxis]. Z // Enumerated value for the Z axis. Returned by [MaxAxis] and [MinAxis]. W // Enumerated value for the W axis. Returned by [MaxAxis] and [MinAxis]. )
type XYZW ¶
type XYZW = struct { X int32 // The vector's X component. Y int32 // The vector's Y component. Z int32 // The vector's Z component. W int32 // The vector's W component. }
XYZW is a 4-element structure that can be used to represent 4D grid coordinates or any other quadruplet of integers.
It uses integer coordinates and is therefore preferable to Vector4 when exact precision is required. Note that the values are limited to 32 bits, and unlike Vector4 this cannot be configured with an engine build option. 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.