Documentation
¶
Overview ¶
Package Vector2i provides a 2D vector using integer coordinates.
Index ¶
- Variables
- func AsArray(vec XY) [3]int32
- func Aspect(v XY) Float.X
- func Distance(a, b XY) Float.X
- func DistanceSquared(a, b XY) int
- func Index[I Int.Any](v XY, i I) int
- func Length(vec XY) Float.X
- func LengthSquared(vec XY) Float.X
- type Axis
- type XY
- func Abs(v XY) XY
- func Add(a, b XY) XY
- func AddX[X Float.Any | Int.Any](a XY, b X) XY
- func Clamp(vec, min, max XY) XY
- func Clampi[X Int.Any](vec XY, min, max X) XY
- func Div(a, b XY) XY
- func DivX[X Float.Any | Int.Any](a XY, b X) XY
- func Max(a, b XY) XY
- func Maxi[X Int.Any](a XY, b X) XY
- func Min(a, b XY) XY
- func Mini[X Int.Any](a XY, b X) XY
- func Mod(a, b XY) XY
- func ModX[X Float.Any | Int.Any](a XY, b X) XY
- func Mul(a, b XY) XY
- func MulX[X Float.Any | Int.Any](a XY, b X) XY
- func Neg(v XY) XY
- func New[X Int.Any | Float.Any](x, y X) XY
- func Sign(v XY) XY
- func Snapped(v, step XY) XY
- func Snappedi[X Int.Any](v XY, step X) XY
- func Sub(a, b XY) XY
- func SubX[X Float.Any | Int.Any](a XY, b X) XY
Constants ¶
This section is empty.
Variables ¶
var ( Zero = XY{0, 0} // Zero vector, a vector with all components set to 0. One = XY{1, 1} // One vector, a vector with all components set to 1. MinXY = XY{math.MinInt32, math.MinInt32} // Min vector, a vector with all components equal to [math.MinInt32]. Can be used as a negative integer equivalent of [Vector2.Inf]. MaxXY = XY{math.MaxInt32, math.MaxInt32} // Max vector, a vector with all components equal to [math.MaxInt32]. Can be used as a positive integer equivalent of [Vector2.Inf]. Left = XY{-1, 0} // Left vector, a unit vector pointing left (-1, 0). Right = XY{1, 0} // Right vector, a unit vector pointing right (1, 0). Up = XY{0, -1} // Up vector, a unit vector pointing up (0, -1). Down = XY{0, 1} // Down vector, a unit vector pointing down (0, 1). )
Functions ¶
func DistanceSquared ¶
DistanceSquared returns the squared distance between this vector and to.
This method runs faster than distance_to, 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.
Types ¶
type Axis ¶
type Axis int
type XY ¶
A 2-element structure that can be used to represent 2D grid coordinates or any other pair of integers.
It uses integer coordinates and is therefore preferable to Vector2 when exact precision is required. Note that the values are limited to 32 bits, and unlike Vector2 this cannot be configured with an engine build option. Use int, int64 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 clamp on each component.
func Clampi ¶
Clampi returns a new vector with all components clamped between the components of min and max.
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.