Skip to content
FutureBlitz

    Install

    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

    • Public Field x: Int field #

      Its x component.

    • Public Field y: Int field #

      Its y component.

    • Public Static Method Zero(): Vec2i static method #

      The zero vector, (0, 0).

    • Public Static Method One(): Vec2i static method #

      The vector (1, 1), which multiplying leaves alone.

    • Public Static Method DefaultValue(): Vec2i static method #

      The zero vector, (0, 0).

    • Public Method ToVec2(): Vec2 method #

      The components as Floats, rounded to the nearest one a Float holds.

    • Public Method ToString(): String method #

      Its components, as "(1, 2)".

    • @PanicsAtCaller Operator [](index: Int): Int operator #

      The component at the index: x at 0, and y at 1. Any other index panics.

    • @PanicsAtCaller Operator +(a: Vec2i, b: Vec2i): Vec2i operator #

      a plus b, component by component. Panics in a debug build when a component overflows, and wraps in a release one.

    • @PanicsAtCaller Operator -(a: Vec2i, b: Vec2i): Vec2i operator #

      a minus b, component by component. Panics in a debug build when a component overflows, and wraps in a release one.

    • @PanicsAtCaller Operator *(a: Vec2i, b: Vec2i): Vec2i operator #

      a times b, component by component. Panics in a debug build when a component overflows, and wraps in a release one.

    • @PanicsAtCaller Operator /(a: Vec2i, b: Vec2i): Vec2i operator #

      a divided by b, component by component. Each rounded toward 0. A component of 0 in b panics.

    • @PanicsAtCaller Operator *(a: Vec2i, scale: Int): Vec2i operator #

      a times scale.

    • @PanicsAtCaller Operator *(scale: Int, a: Vec2i): Vec2i operator #

      scale times a.

    • @PanicsAtCaller Operator /(a: Vec2i, scale: Int): Vec2i operator #

      a divided by scale.

    • @PanicsAtCaller Operator -(a: Vec2i): Vec2i operator #

      a negated.

    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

    • Public Field x: Int field #

      Its x component.

    • Public Field y: Int field #

      Its y component.

    • Public Field z: Int field #

      Its z component.

    • Public Static Method Zero(): Vec3i static method #

      The zero vector, (0, 0, 0).

    • Public Static Method One(): Vec3i static method #

      The vector (1, 1, 1), which multiplying leaves alone.

    • Public Static Method DefaultValue(): Vec3i static method #

      The zero vector, (0, 0, 0).

    • Public Method ToVec3(): Vec3 method #

      The components as Floats, rounded to the nearest one a Float holds.

    • Public Method ToString(): String method #

      Its components, as "(1, 2, 3)".

    • @PanicsAtCaller Operator [](index: Int): Int operator #

      The component at the index: x at 0, y at 1, and z at 2. Any other index panics.

    • @PanicsAtCaller Operator +(a: Vec3i, b: Vec3i): Vec3i operator #

      a plus b, component by component. Panics in a debug build when a component overflows, and wraps in a release one.

    • @PanicsAtCaller Operator -(a: Vec3i, b: Vec3i): Vec3i operator #

      a minus b, component by component. Panics in a debug build when a component overflows, and wraps in a release one.

    • @PanicsAtCaller Operator *(a: Vec3i, b: Vec3i): Vec3i operator #

      a times b, component by component. Panics in a debug build when a component overflows, and wraps in a release one.

    • @PanicsAtCaller Operator /(a: Vec3i, b: Vec3i): Vec3i operator #

      a divided by b, component by component. Each rounded toward 0. A component of 0 in b panics.

    • @PanicsAtCaller Operator *(a: Vec3i, scale: Int): Vec3i operator #

      a times scale.

    • @PanicsAtCaller Operator *(scale: Int, a: Vec3i): Vec3i operator #

      scale times a.

    • @PanicsAtCaller Operator /(a: Vec3i, scale: Int): Vec3i operator #

      a divided by scale.

    • @PanicsAtCaller Operator -(a: Vec3i): Vec3i operator #

      a negated.

    Functions

    Dot function

    @PanicsAtCaller Public Function Dot(a: Vec2i, b: Vec2i): Int

    The sum of the products of the components.

    std/math/int_vector.fb, line 169

    Dot function

    @PanicsAtCaller Public Function Dot(a: Vec3i, b: Vec3i): Int

    The dot product of a and b.

    std/math/int_vector.fb, line 173

    LengthSquared function

    @PanicsAtCaller Public Function LengthSquared(v: Vec2i): Int

    The length times itself, which is a whole number.

    std/math/int_vector.fb, line 177

    LengthSquared function

    @PanicsAtCaller Public Function LengthSquared(v: Vec3i): Int

    The length of v times itself.

    std/math/int_vector.fb, line 181

    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.

    std/math/int_vector.fb, line 185

    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.

    std/math/int_vector.fb, line 189

    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.

    std/math/int_vector.fb, line 195

    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.

    std/math/int_vector.fb, line 199

    Min function

    Public Function Min(a: Vec2i, b: Vec2i): Vec2i

    The smaller of each component.

    std/math/int_vector.fb, line 205

    Min function

    Public Function Min(a: Vec3i, b: Vec3i): Vec3i

    The smaller of each component.

    std/math/int_vector.fb, line 207

    Max function

    Public Function Max(a: Vec2i, b: Vec2i): Vec2i

    The larger of each component.

    std/math/int_vector.fb, line 210

    Max function

    Public Function Max(a: Vec3i, b: Vec3i): Vec3i

    The larger of each component.

    std/math/int_vector.fb, line 212

    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.

    std/math/int_vector.fb, line 216

    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.

    std/math/int_vector.fb, line 223

    Abs function

    @PanicsAtCaller Public Function Abs(v: Vec2i): Vec2i

    Each component's Abs.

    std/math/int_vector.fb, line 229

    Abs function

    @PanicsAtCaller Public Function Abs(v: Vec3i): Vec3i

    Each component without its sign.

    std/math/int_vector.fb, line 233

    Report an issue with this page or with FutureBlitz on GitHub.