An abstract 3D Vector type that maps to native fixed-length array in target language, with all methods inlined

Static methods

staticinlinecross(v1:Vec3, v2:Vec3):Vec3

Compute the cross product of two vectors

Parameters:

v1

the first vector

v2

the second vector

Returns:

the cross product

staticinlinedist(v1:Vec3, v2:Vec3):Float

Compute the (Euclidean) distance between two vectors

Parameters:

v1

the first vector

v2

the second vector

Returns:

the distance

staticinlinedist2(v1:Vec3, v2:Vec3):Float

Compute the square of the (Euclidean) distance between two vectors

Parameters:

v1

the first vector

v2

the second vector

Returns:

distance^2

staticinlinedot(v1:Vec3, v2:Vec3):Float

Compute the dot product of two vectors

Parameters:

v1

the first vector

v2

the second vector

Returns:

the dot product

Variables

@:implx:Float

x component, also accessable via subscript [0]

@:imply:Float

y component, also accessable via subscript [1]

@:implz:Float

z component, also accessable via subscript [2]

Methods

@:impl@:op(A + B)inlineadd(rhs:Vec3):Vec3

Overload + operator to add vectors

Parameters:

rhs

the other vector

Returns:

elementwise sum

@:implinlineassign(v:Vec3):Void

Set x y z components of this vector from another vector

Parameters:

v

the vector to copy from

@:implinlinecopy():Vec3

Duplicate a vector

Returns:

a new vector that equals to this vector

@:impl@:arrayAccessinlineget(i:Int):Float

Get vector x/y/z component via subscript operator [0] [1] [2]

Parameters:

i

the index

@:implinlinelen():Float

Compute the length (magnitude, l2-norm) of the vector

Returns:

the length

@:implinlinelen2():Float

Compute the square of the length of the vector

Returns:

length^2

@:impl@:op(A * B)inlinemul(rhs:Vec3):Vec3

Overload * operator to multiply vectors elementwise

Parameters:

rhs

the other vector

Returns:

hadamard product

@:impl@:op(A * B)inlinemulf(rhs:Float):Vec3

Overload * operator to multiply vector by a scalar

Parameters:

rhs

the scalar

Returns:

scaled vector

@:implinlinenormalize():Void

Normalize the vector to unit vector in-place

@:implinlinescale(s:Float):Void

Scale the vector in place

Parameters:

s

the scaling factor

@:impl@:arrayAccessinlineset(i:Int, v:Float):Float

Set vector x/y/z component via subscript operator [0] [1] [2]

Parameters:

i

the index

v

the value to write

@:impl@:op(A - B)inlinesub(rhs:Vec3):Vec3

Overload - operator to subtract vectors

Parameters:

rhs

the other vector

Returns:

elementwise difference