Import std.math.vector
std.math.vector
Vec2, Vec3, and Vec4: points and directions, as Floats, in the space std.math works in: right-handed, Y up, and -Z forward. Each is a Struct of its components, x, y, z, and w, in that order with nothing between, so SIMD can work on it as it stands. Their Operators work component by component, and a Float scales: v * 2, 2 * v, and v / 2. The math on them is Functions, as on Floats: Dot, Cross, Length, Normalize, Lerp, and the rest, beside the scalar ones of their names. Lengths and distances are worked out in Doubles, so no Float overflows on the way.
std/math/vector.fb
Types
Vec2
struct
Public Struct Vec2 Implements Numeric, Hashable, Printable, Defaultable
A point or direction in 2D.
-
Its x component.
-
Its y component.
-
The number that adding leaves alone: 0.
Doc from
std.core.interfaces.Numeric.Zero. -
The number that multiplying leaves alone: 1.
Doc from
std.core.interfaces.Numeric.One. -
The value to start from, like 0 for a number, "" for a String, or an empty collection.
-
The components as Ints, toward 0, as As converts them: one outside an Int's range panics.
-
Its text, as a string interpolation like "{value}" shows it.
Doc from
std.core.interfaces.Printable.ToString. -
The component at the index: x at 0, and y at 1. Any other index panics.
-
aandbadded up.Doc from
std.core.interfaces.Numeric.Operator+. -
btaken away froma.Doc from
std.core.interfaces.Numeric.Operator-. -
aandbmultiplied together.Doc from
std.core.interfaces.Numeric.Operator*. -
adivided byb.Doc from
std.core.interfaces.Numeric.Operator/. -
atimesscale. -
scaletimesa. -
adivided byscale. -
anegated.
Vec3
struct
Public Struct Vec3 Implements Numeric, Hashable, Printable, Defaultable
A point or direction in 3D.
-
Its x component.
-
Its y component.
-
Its z component.
-
The number that adding leaves alone: 0.
Doc from
std.core.interfaces.Numeric.Zero. -
The number that multiplying leaves alone: 1.
Doc from
std.core.interfaces.Numeric.One. -
The value to start from, like 0 for a number, "" for a String, or an empty collection.
-
Up: +Y.
-
Down: -Y.
-
Right: +X.
-
Left: -X.
-
-Z, where a camera with no rotation looks.
-
Back: +Z, toward the camera.
-
Its x and y, as a Vec2.
-
The components as Ints, toward 0, as As converts them: one outside an Int's range panics.
-
Its text, as a string interpolation like "{value}" shows it.
Doc from
std.core.interfaces.Printable.ToString. -
The component at the index: x at 0, y at 1, and z at 2. Any other index panics.
-
aandbadded up.Doc from
std.core.interfaces.Numeric.Operator+. -
btaken away froma.Doc from
std.core.interfaces.Numeric.Operator-. -
aandbmultiplied together.Doc from
std.core.interfaces.Numeric.Operator*. -
adivided byb.Doc from
std.core.interfaces.Numeric.Operator/. -
atimesscale. -
scaletimesa. -
adivided byscale. -
anegated.
Vec4
struct
Public Struct Vec4 Implements Numeric, Hashable, Printable, Defaultable
A point or direction in 4D, or a 3D one with a w, as a Mat4 transforms it.
-
Its x component.
-
Its y component.
-
Its z component.
-
Its w component.
-
The number that adding leaves alone: 0.
Doc from
std.core.interfaces.Numeric.Zero. -
The number that multiplying leaves alone: 1.
Doc from
std.core.interfaces.Numeric.One. -
The value to start from, like 0 for a number, "" for a String, or an empty collection.
-
Its x and y, as a Vec2.
-
Its x, y, and z, as a Vec3.
-
Its text, as a string interpolation like "{value}" shows it.
Doc from
std.core.interfaces.Printable.ToString. -
The component at the index: x at 0, y at 1, z at 2, and w at 3. Any other index panics.
-
aandbadded up.Doc from
std.core.interfaces.Numeric.Operator+. -
btaken away froma.Doc from
std.core.interfaces.Numeric.Operator-. -
aandbmultiplied together.Doc from
std.core.interfaces.Numeric.Operator*. -
adivided byb.Doc from
std.core.interfaces.Numeric.Operator/. -
atimesscale. -
scaletimesa. -
adivided byscale. -
anegated.
Functions
Dot
function
Public Function Dot(a: Vec2, b: Vec2): Float
The sum of the products of the components: for unit vectors, the cosine of the angle between.
Dot
function
Public Function Dot(a: Vec3, b: Vec3): Float
The sum of the products of the components: for unit vectors, the cosine of the angle between.
Dot
function
Public Function Dot(a: Vec4, b: Vec4): Float
The sum of the products of the components.
Cross
function
Public Function Cross(a: Vec2, b: Vec2): Float
The Z of the two as 3D vectors' Cross: above 0 when b turns counterclockwise from a.
Cross
function
Public Function Cross(a: Vec3, b: Vec3): Vec3
The vector at right angles to both, by the right-hand rule: Cross(Right, Up) is Back, and its length is the area of the parallelogram the two make.
Length
function
Public Function Length(v: Vec2): Float
How long the vector is.
Length
function
Public Function Length(v: Vec3): Float
How long v is.
Length
function
Public Function Length(v: Vec4): Float
How long v is.
LengthSquared
function
Public Function LengthSquared(v: Vec2): Float
The length times itself, which takes no square root, for comparing lengths, in Floats.
LengthSquared
function
Public Function LengthSquared(v: Vec3): Float
How long v is, times itself, which takes no square root.
LengthSquared
function
Public Function LengthSquared(v: Vec4): Float
How long v is, times itself, which takes no square root.
Distance
function
Public Function Distance(a: Vec2, b: Vec2): Float
How far apart the two points are.
Distance
function
Public Function Distance(a: Vec3, b: Vec3): Float
How far apart the two points are.
DistanceSquared
function
Public Function DistanceSquared(a: Vec2, b: Vec2): Float
The distance times itself, which takes no square root, for comparing distances, in Floats.
DistanceSquared
function
Public Function DistanceSquared(a: Vec3, b: Vec3): Float
How far apart a and b are, times itself, which takes no square root.
Normalize
function
Public Function Normalize(v: Vec2): Vec2
The vector in the same direction, of length 1, and the zero vector for the zero vector.
Normalize
function
Public Function Normalize(v: Vec3): Vec3
The vector in the same direction, of length 1, and the zero vector for the zero vector.
Normalize
function
Public Function Normalize(v: Vec4): Vec4
The vector in the same direction, of length 1, and the zero vector for the zero vector.
Lerp
function
Public Function Lerp(a: Vec2, b: Vec2, t: Float): Vec2
The point t of the way from a to b: a at 0, and b itself at 1, though b - a
rounds.
Lerp
function
Public Function Lerp(a: Vec3, b: Vec3, t: Float): Vec3
The point t of the way from a to b: a at 0, and b itself at 1, though b - a
rounds.
Lerp
function
Public Function Lerp(a: Vec4, b: Vec4, t: Float): Vec4
The point t of the way from a to b: a at 0, and b itself at 1, though b - a
rounds.
Min
function
Public Function Min(a: Vec2, b: Vec2): Vec2
The smaller of each component.
Min
function
Public Function Min(a: Vec3, b: Vec3): Vec3
The smaller of each component.
Min
function
Public Function Min(a: Vec4, b: Vec4): Vec4
The smaller of each component.
Max
function
Public Function Max(a: Vec2, b: Vec2): Vec2
The larger of each component.
Max
function
Public Function Max(a: Vec3, b: Vec3): Vec3
The larger of each component.
Max
function
Public Function Max(a: Vec4, b: Vec4): Vec4
The larger of each component.
Clamp
function
@PanicsAtCaller Public Function Clamp(v: Vec2, low: Vec2, high: Vec2): Vec2
Each component kept between low's and high's, as Clamp keeps a Float. A component whose low
is above its high panics.
Clamp
function
@PanicsAtCaller Public Function Clamp(v: Vec3, low: Vec3, high: Vec3): Vec3
Each component kept between low's and high's, as Clamp keeps a Float. A component whose low
is above its high panics.
Clamp
function
@PanicsAtCaller Public Function Clamp(v: Vec4, low: Vec4, high: Vec4): Vec4
Each component kept between low's and high's, as Clamp keeps a Float. A component whose low
is above its high panics.
Abs
function
Public Function Abs(v: Vec2): Vec2
Each component of v without its sign.
Abs
function
Public Function Abs(v: Vec3): Vec3
Each component of v without its sign.
Abs
function
Public Function Abs(v: Vec4): Vec4
Each component of v without its sign.
Floor
function
Public Function Floor(v: Vec2): Vec2
Each component of v rounded down.
Floor
function
Public Function Floor(v: Vec3): Vec3
Each component of v rounded down.
Floor
function
Public Function Floor(v: Vec4): Vec4
Each component of v rounded down.
Ceil
function
Public Function Ceil(v: Vec2): Vec2
Each component of v rounded up.
Ceil
function
Public Function Ceil(v: Vec3): Vec3
Each component of v rounded up.
Ceil
function
Public Function Ceil(v: Vec4): Vec4
Each component of v rounded up.
Round
function
Public Function Round(v: Vec2): Vec2
Each component of v rounded to the nearest whole number.
Round
function
Public Function Round(v: Vec3): Vec3
Each component of v rounded to the nearest whole number.
Round
function
Public Function Round(v: Vec4): Vec4
Each component of v rounded to the nearest whole number.
Reflect
function
Public Function Reflect(v: Vec2, normal: Vec2): Vec2
The direction v bounces off a surface with this normal, of length 1, in: as a ball does off
a wall.
Reflect
function
Public Function Reflect(v: Vec3, normal: Vec3): Vec3
The direction v bounces off a surface with this normal, of length 1, in: as a ball does off
a wall.
Project
function
Public Function Project(v: Vec2, onto: Vec2): Vec2
The part of v along onto, the zero vector when onto is, worked out in Doubles.
Project
function
Public Function Project(v: Vec3, onto: Vec3): Vec3
The part of v along onto, the zero vector when onto is, worked out in Doubles.
Angle
function
Public Function Angle(a: Vec2, b: Vec2): Float
The angle between the two, in radians, from 0 to Pi, and 0 when either is the zero vector, worked out in Doubles.
Angle
function
Public Function Angle(a: Vec3, b: Vec3): Float
The angle between the two, in radians, from 0 to Pi, and 0 when either is the zero vector, worked out in Doubles.
Rotate
function
Public Function Rotate(v: Vec2, angle: Float): Vec2
The vector turned counterclockwise by the angle, in radians.
Perpendicular
function
Public Function Perpendicular(v: Vec2): Vec2
The vector a quarter turn counterclockwise: (-y, x).
MoveTowards
function
Public Function MoveTowards(current: Vec2, target: Vec2, maxDistance: Float): Vec2
Current moved toward target by maxDistance, or to target when it's no further, worked out
in Doubles.
MoveTowards
function
Public Function MoveTowards(current: Vec3, target: Vec3, maxDistance: Float): Vec3
Current moved toward target by maxDistance, or to target when it's no further, worked out
in Doubles.
IsClose
function
Public Function IsClose(a: Vec2, b: Vec2): Bool
Whether each component is close to b's, as IsClose tells for Floats.
IsClose
function
Public Function IsClose(a: Vec3, b: Vec3): Bool
Whether each component is close to b's, as IsClose tells for Floats.
IsClose
function
Public Function IsClose(a: Vec4, b: Vec4): Bool
Whether each component is close to b's, as IsClose tells for Floats.
IsClose
function
Public Function IsClose(a: Vec2, b: Vec2, tolerance: Float): Bool
Whether each component is no further from b's than tolerance.
IsClose
function
Public Function IsClose(a: Vec3, b: Vec3, tolerance: Float): Bool
Whether each component is no further from b's than tolerance.
IsClose
function
Public Function IsClose(a: Vec4, b: Vec4, tolerance: Float): Bool
Whether each component is no further from b's than tolerance.
Report an issue with this page or with FutureBlitz on GitHub.