Vector4i

package
v0.0.0-...-7db9c1f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package Vector4i provides a 4D vector using integer coordinates.

Index

Constants

This section is empty.

Variables

View Source
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 AsArray

func AsArray(vec XYZW) [4]int32

func Distance

func Distance(v, to XYZW) Float.X

Distance returns the distance between this vector and to.

func DistanceSquared

func DistanceSquared(v, to XYZW) int

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 Index

func Index[I Int.Any](v XYZW, i I) int

func Length

func Length(v XYZW) Float.X

Length the length (magnitude) of this vector.

func LengthSquared

func LengthSquared(v XYZW) int

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].
)

func MaxAxis

func MaxAxis(v XYZW) Axis

MaxAxis returns the axis of the vector's highest value. See Axis constants. If all components are equal, this method returns X.

func MinAxis

func MinAxis(v XYZW) Axis

MinAxis returns the axis of the vector's lowest value. See Axis constants. If all components are equal, this method returns Z.

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 Abs

func Abs(v XYZW) XYZW

Abs returns a new vector with all components in absolute values (i.e. positive).

func Add

func Add(a, b XYZW) XYZW

func AddX

func AddX[X Int.Any | Float.Any](a XYZW, b X) XYZW

func Clamp

func Clamp(v, min, max XYZW) XYZW

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

func Clampi[X Int.Any](v XYZW, min, max X) XYZW

Clampi returns a new vector with all components clamped between the components of min and max, by running [Int.Clamp] on each component.

func Div

func Div(a, b XYZW) XYZW

func DivX

func DivX[X Int.Any | Float.Any](a XYZW, b X) XYZW

func Max

func Max(a, b XYZW) XYZW

Max returns the component-wise maximum of this and with.

func Maxi

func Maxi[X Int.Any](a XYZW, b X) XYZW

Max returns the component-wise maximum of this and with.

func Min

func Min(a, b XYZW) XYZW

Min returns the component-wise minimum of this and with.

func Mini

func Mini[X Int.Any](a XYZW, b X) XYZW

Mini returns the component-wise minimum of this and with.

func Mod

func Mod(a, b XYZW) XYZW

func ModX

func ModX[X Int.Any | Float.Any](a XYZW, b X) XYZW

func Mul

func Mul(a, b XYZW) XYZW

func MulX

func MulX[X Int.Any | Float.Any](a XYZW, b X) XYZW

func Neg

func Neg(v XYZW) XYZW

func New

func New[X Int.Any | Float.Any](x, y, z, w X) XYZW

New returns a XYZW with the given components.

func Sign

func Sign(v XYZW) XYZW

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

func Snapped(v, step XYZW) XYZW

Snapped returns a new vector with each component snapped to the closest multiple of the corresponding component in step.

func Snappedi

func Snappedi[X Int.Any](v XYZW, step X) XYZW

Snappedi returns a new vector with each component snapped to the closest multiple of the corresponding component in step.

func Sub

func Sub(a, b XYZW) XYZW

func SubX

func SubX[X Int.Any | Float.Any](a XYZW, b X) XYZW

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL