Import std.math.int_vector
std.math.int_vector
Integer 2D and 3D vectors, for grid cells and the steps between them.
Vec2i and Vec3i: points and steps on a grid, as Ints, for cells, tiles, and voxels, and as Map keys. Their Operators work component by component, and an Int scales; dividing rounds toward 0, as Ints do, and dividing by 0, or overflow in debug builds, panics where it's called, as it does for an Int.
Examples
Local a = Vec3i(1, 2, 3)
Expect(Dot(a, Vec3i(1, 1, 1)) == 6 && LengthSquared(a) == 14)
Expect(ManhattanDistance(a, Vec3i(0, 0, 0)) == 6 && ChebyshevDistance(a, Vec3i(0, 0, 0)) == 3)
Expect(Min(a, Vec3i(2, 0, 4)) == Vec3i(1, 0, 3) && Max(a, Vec3i(2, 0, 4)) == Vec3i(2, 2, 4))
Expect(Clamp(Vec3i(-5, 5, 9), Vec3i(0, 0, 0), Vec3i(3, 3, 3)) == Vec3i(0, 3, 3))
Expect(Abs(Vec3i(-1, 2, -3)) == Vec3i(1, 2, 3))std/math/int_vector.fb
Types
Vec2i
struct
Public Struct Vec2i Implements Numeric, Hashable, Printable, Defaultable
A cell or step on a 2D grid.
Examples
Local a = Vec2i(1, 2)
Local b = Vec2i(4, 6)
Expect(a + b == Vec2i(5, 8))
Expect(ManhattanDistance(a, b) == 7 && ChebyshevDistance(a, b) == 4)
// Cells are Map keys.
Local walls = {Vec2i(0, 0): True}
Expect(walls.Contains(Vec2i(0, 0)) && !walls.Contains(a))std/math/int_vector.fb, line 36
-
Its x component.
-
Its y component.
-
The zero vector, (0, 0).
-
The vector (1, 1), which multiplying leaves alone.
-
The zero vector, (0, 0).
-
The components as Floats, rounded to the nearest one a Float holds.
-
Its components, as "(1, 2)".
-
The component at the index: x at 0, and y at 1. Any other index panics.
-
aplusb, component by component. Panics in a debug build when a component overflows, and wraps in a release one. -
aminusb, component by component. Panics in a debug build when a component overflows, and wraps in a release one. -
atimesb, component by component. Panics in a debug build when a component overflows, and wraps in a release one. -
adivided byb, component by component. Each rounded toward 0. A component of 0 inbpanics. -
atimesscale. -
scaletimesa. -
adivided byscale. -
anegated.
Vec3i
struct
Public Struct Vec3i Implements Numeric, Hashable, Printable, Defaultable
A cell or step on a 3D grid.
std/math/int_vector.fb, line 101
-
Its x component.
-
Its y component.
-
Its z component.
-
The zero vector, (0, 0, 0).
-
The vector (1, 1, 1), which multiplying leaves alone.
-
The zero vector, (0, 0, 0).
-
The components as Floats, rounded to the nearest one a Float holds.
-
Its components, as "(1, 2, 3)".
-
The component at the index: x at 0, y at 1, and z at 2. Any other index panics.
-
aplusb, component by component. Panics in a debug build when a component overflows, and wraps in a release one. -
aminusb, component by component. Panics in a debug build when a component overflows, and wraps in a release one. -
atimesb, component by component. Panics in a debug build when a component overflows, and wraps in a release one. -
adivided byb, component by component. Each rounded toward 0. A component of 0 inbpanics. -
atimesscale. -
scaletimesa. -
adivided byscale. -
anegated.
Functions
Dot
function
@PanicsAtCaller Public Function Dot(a: Vec2i, b: Vec2i): Int
The sum of the products of the components.
Dot
function
@PanicsAtCaller Public Function Dot(a: Vec3i, b: Vec3i): Int
The dot product of a and b.
LengthSquared
function
@PanicsAtCaller Public Function LengthSquared(v: Vec2i): Int
The length times itself, which is a whole number.
LengthSquared
function
@PanicsAtCaller Public Function LengthSquared(v: Vec3i): Int
The length of v times itself.
ManhattanDistance
function
@PanicsAtCaller Public Function ManhattanDistance(a: Vec2i, b: Vec2i): Int
How many steps along the axes go from a to b: the taxicab distance.
ManhattanDistance
function
@PanicsAtCaller Public Function ManhattanDistance(a: Vec3i, b: Vec3i): Int
How many steps along the axes go from a to b: the taxicab distance.
ChebyshevDistance
function
@PanicsAtCaller Public Function ChebyshevDistance(a: Vec2i, b: Vec2i): Int
How many steps go from a to b where a diagonal is one step too: the chessboard distance.
ChebyshevDistance
function
@PanicsAtCaller Public Function ChebyshevDistance(a: Vec3i, b: Vec3i): Int
How many steps go from a to b where a diagonal is one step too: the chessboard distance.
Min
function
Public Function Min(a: Vec2i, b: Vec2i): Vec2i
The smaller of each component.
Min
function
Public Function Min(a: Vec3i, b: Vec3i): Vec3i
The smaller of each component.
Max
function
Public Function Max(a: Vec2i, b: Vec2i): Vec2i
The larger of each component.
Max
function
Public Function Max(a: Vec3i, b: Vec3i): Vec3i
The larger of each component.
Clamp
function
@PanicsAtCaller Public Function Clamp(v: Vec2i, low: Vec2i, high: Vec2i): Vec2i
Each component kept between low's and high's, as Clamp keeps an Int. A component whose low
is above its high panics.
Clamp
function
@PanicsAtCaller Public Function Clamp(v: Vec3i, low: Vec3i, high: Vec3i): Vec3i
Each component kept between low's and high's, as Clamp keeps an Int. A component whose low
is above its high panics.
Abs
function
@PanicsAtCaller Public Function Abs(v: Vec2i): Vec2i
Each component's Abs.
Abs
function
@PanicsAtCaller Public Function Abs(v: Vec3i): Vec3i
Each component without its sign.
Report an issue with this page or with FutureBlitz on GitHub.