class Vector3
class Vector3
lib/geometry/vector3.tya:2
Vector3 provides the geometry/Vector3 standard library API.
Source
# Vector3 provides the geometry/Vector3 standard library API.
class Vector3
# Vector3.x stores instance state.
# @type Int
x: 0
# Vector3.y stores instance state.
# @type Int
y: 0
# Vector3.z stores instance state.
# @type Int
z: 0
# Vector3.initialize provides the geometry/Vector3 standard library operation.
# @param x Int x value.
# @param y Int y value.
# @param z Int z value.
# @return Self the initialized object.
initialize: x = 0, y = 0, z = 0 ->
self.x = self.number(x, "x")
self.y = self.number(y, "y")
self.z = self.number(z, "z")
# Vector3.abs provides the geometry/Vector3 standard library operation.
# @param value String value value.
# @return Any the resulting value.
abs: value ->
if value < 0
return 0 - value
value
# Vector3.add provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @return Any the resulting value.
add: a, b = nil ->
if b == nil
b = a
a = self
self.expect(a, "a")
self.expect(b, "b")
Vector3(a.x + b.x, a.y + b.y, a.z + b.z)
# Vector3.cross provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @return Any the resulting value.
cross: a, b = nil ->
if b == nil
b = a
a = self
self.expect(a, "a")
self.expect(b, "b")
Vector3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x)
# Vector3.distance provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @return Any the resulting value.
distance: a, b = nil ->
if b == nil
b = a
a = self
math_sqrt(self.distance_squared(a, b))
# Vector3.distance_squared provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @return Any the resulting value.
distance_squared: a, b = nil ->
if b == nil
b = a
a = self
self.length_squared(self.sub(a, b))
# Vector3.div provides the geometry/Vector3 standard library operation.
# @param v Any v value.
# @param k Any k value.
# @return Any the resulting value.
div: v, k = nil ->
if k == nil
k = v
v = self
self.expect(v, "v")
self.number(k, "k")
if k == 0
raise error("geometry.Vector3.div: divide by zero")
Vector3(v.x / k, v.y / k, v.z / k)
# Vector3.dot provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @return Any the resulting value.
dot: a, b = nil ->
if b == nil
b = a
a = self
self.expect(a, "a")
self.expect(b, "b")
a.x * b.x + a.y * b.y + a.z * b.z
# Vector3.equal? provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @return Boolean whether the condition is true.
equal?: a, b = nil ->
if b == nil
b = a
a = self
a.class == Vector3 and b.class == Vector3 and a.x == b.x and a.y == b.y and a.z == b.z
# Vector3.expect provides the geometry/Vector3 standard library operation.
# @param value String value value.
# @param name String name value.
# @return Any the resulting value.
expect: value, name ->
if value.class != Vector3
raise error("geometry.Vector3: " + name + " must be a Vector3")
# Vector3.from_array provides the geometry/Vector3 standard library operation.
# @param values Array values value.
# @return Array the resulting value.
from_array: values ->
if values.class != Array or values.len() != 3
raise error("geometry.Vector3.from_array: expected three-number array")
Vector3(values[0], values[1], values[2])
# Vector3.length provides the geometry/Vector3 standard library operation.
# @param v Any v value.
# @return Any the resulting value.
length: v = nil ->
if v == nil
v = self
math_sqrt(self.length_squared(v))
# Vector3.length_squared provides the geometry/Vector3 standard library operation.
# @param v Any v value.
# @return Any the resulting value.
length_squared: v = nil ->
if v == nil
v = self
self.expect(v, "v")
self.dot(v, v)
# Vector3.lerp provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @param t Any t value.
# @return Any the resulting value.
lerp: a, b, t ->
self.expect(a, "a")
self.expect(b, "b")
self.number(t, "t")
Vector3(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t)
# Vector3.nearly_equal? provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @param epsilon Any epsilon value.
# @return Boolean whether the condition is true.
nearly_equal?: a, b, epsilon = nil ->
if epsilon == nil
epsilon = b
b = a
a = self
self.expect(a, "a")
self.expect(b, "b")
if epsilon < 0
raise error("geometry.Vector3.nearly_equal?: epsilon must be non-negative")
self.abs(a.x - b.x) <= epsilon and self.abs(a.y - b.y) <= epsilon and self.abs(a.z - b.z) <= epsilon
# Vector3.new provides the geometry/Vector3 standard library operation.
# @param x Int x value.
# @param y Int y value.
# @param z Int z value.
# @return Self the resulting value.
new: x, y, z ->
Vector3(x, y, z)
# Vector3.normalize provides the geometry/Vector3 standard library operation.
# @param v Any v value.
# @return String the resulting value.
normalize: v = nil ->
if v == nil
v = self
geometry_len = self.length(v)
if geometry_len == 0
return self.zero()
self.div(v, geometry_len)
# Vector3.number provides the geometry/Vector3 standard library operation.
# @param value String value value.
# @param name String name value.
# @return Any the resulting value.
number: value, name ->
if value.class != Number
raise error("geometry.Vector3: " + name + " must be a number")
value
# Vector3.one provides the geometry/Vector3 standard library operation.
# @return Any the resulting value.
one: ->
Vector3(1, 1, 1)
# Vector3.scale provides the geometry/Vector3 standard library operation.
# @param v Any v value.
# @param k Any k value.
# @return Any the resulting value.
scale: v, k = nil ->
if k == nil
k = v
v = self
self.expect(v, "v")
self.number(k, "k")
Vector3(v.x * k, v.y * k, v.z * k)
# Vector3.sub provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @return Any the resulting value.
sub: a, b = nil ->
if b == nil
b = a
a = self
self.expect(a, "a")
self.expect(b, "b")
Vector3(a.x - b.x, a.y - b.y, a.z - b.z)
# Vector3.to_array provides the geometry/Vector3 standard library operation.
# @param v Any v value.
# @return Array the resulting value.
to_array: v = nil ->
if v == nil
v = self
self.expect(v, "v")
[v.x, v.y, v.z]
# Vector3.zero provides the geometry/Vector3 standard library operation.
# @return Any the resulting value.
zero: ->
Vector3(0, 0, 0)
Instance Variables
x
Vector3.x
lib/geometry/vector3.tya:5
Vector3.x stores instance state.
Source
# Vector3.x stores instance state.
# @type Int
x: 0
y
Vector3.y
lib/geometry/vector3.tya:9
Vector3.y stores instance state.
Source
# Vector3.y stores instance state.
# @type Int
y: 0
z
Vector3.z
lib/geometry/vector3.tya:13
Vector3.z stores instance state.
Source
# Vector3.z stores instance state.
# @type Int
z: 0
Methods
abs
Vector3.abs(value)
lib/geometry/vector3.tya:28
Vector3.abs provides the geometry/Vector3 standard library operation.
Source
# Vector3.abs provides the geometry/Vector3 standard library operation.
# @param value String value value.
# @return Any the resulting value.
abs: value ->
if value < 0
return 0 - value
value
add
Vector3.add(a, b = nil)
lib/geometry/vector3.tya:37
Vector3.add provides the geometry/Vector3 standard library operation.
Source
# Vector3.add provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @return Any the resulting value.
add: a, b = nil ->
if b == nil
b = a
a = self
self.expect(a, "a")
self.expect(b, "b")
Vector3(a.x + b.x, a.y + b.y, a.z + b.z)
cross
Vector3.cross(a, b = nil)
lib/geometry/vector3.tya:49
Vector3.cross provides the geometry/Vector3 standard library operation.
Source
# Vector3.cross provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @return Any the resulting value.
cross: a, b = nil ->
if b == nil
b = a
a = self
self.expect(a, "a")
self.expect(b, "b")
Vector3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x)
distance
Vector3.distance(a, b = nil)
lib/geometry/vector3.tya:61
Vector3.distance provides the geometry/Vector3 standard library operation.
Source
# Vector3.distance provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @return Any the resulting value.
distance: a, b = nil ->
if b == nil
b = a
a = self
math_sqrt(self.distance_squared(a, b))
distance_squared
Vector3.distance_squared(a, b = nil)
lib/geometry/vector3.tya:71
Vector3.distance_squared provides the geometry/Vector3 standard library operation.
Source
# Vector3.distance_squared provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @return Any the resulting value.
distance_squared: a, b = nil ->
if b == nil
b = a
a = self
self.length_squared(self.sub(a, b))
div
Vector3.div(v, k = nil)
lib/geometry/vector3.tya:81
Vector3.div provides the geometry/Vector3 standard library operation.
Source
# Vector3.div provides the geometry/Vector3 standard library operation.
# @param v Any v value.
# @param k Any k value.
# @return Any the resulting value.
div: v, k = nil ->
if k == nil
k = v
v = self
self.expect(v, "v")
self.number(k, "k")
if k == 0
raise error("geometry.Vector3.div: divide by zero")
Vector3(v.x / k, v.y / k, v.z / k)
dot
Vector3.dot(a, b = nil)
lib/geometry/vector3.tya:95
Vector3.dot provides the geometry/Vector3 standard library operation.
Source
# Vector3.dot provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @return Any the resulting value.
dot: a, b = nil ->
if b == nil
b = a
a = self
self.expect(a, "a")
self.expect(b, "b")
a.x * b.x + a.y * b.y + a.z * b.z
equal?
Vector3.equal?(a, b = nil)
lib/geometry/vector3.tya:107
Vector3.equal? provides the geometry/Vector3 standard library operation.
Source
# Vector3.equal? provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @return Boolean whether the condition is true.
equal?: a, b = nil ->
if b == nil
b = a
a = self
a.class == Vector3 and b.class == Vector3 and a.x == b.x and a.y == b.y and a.z == b.z
expect
Vector3.expect(value, name)
lib/geometry/vector3.tya:117
Vector3.expect provides the geometry/Vector3 standard library operation.
Source
# Vector3.expect provides the geometry/Vector3 standard library operation.
# @param value String value value.
# @param name String name value.
# @return Any the resulting value.
expect: value, name ->
if value.class != Vector3
raise error("geometry.Vector3: " + name + " must be a Vector3")
from_array
Vector3.from_array(values)
lib/geometry/vector3.tya:124
Vector3.from_array provides the geometry/Vector3 standard library operation.
Source
# Vector3.from_array provides the geometry/Vector3 standard library operation.
# @param values Array values value.
# @return Array the resulting value.
from_array: values ->
if values.class != Array or values.len() != 3
raise error("geometry.Vector3.from_array: expected three-number array")
Vector3(values[0], values[1], values[2])
initialize
Vector3.initialize(x = 0, y = 0, z = 0)
lib/geometry/vector3.tya:20
Vector3.initialize provides the geometry/Vector3 standard library operation.
Source
# Vector3.initialize provides the geometry/Vector3 standard library operation.
# @param x Int x value.
# @param y Int y value.
# @param z Int z value.
# @return Self the initialized object.
initialize: x = 0, y = 0, z = 0 ->
self.x = self.number(x, "x")
self.y = self.number(y, "y")
self.z = self.number(z, "z")
length
Vector3.length(v = nil)
lib/geometry/vector3.tya:132
Vector3.length provides the geometry/Vector3 standard library operation.
Source
# Vector3.length provides the geometry/Vector3 standard library operation.
# @param v Any v value.
# @return Any the resulting value.
length: v = nil ->
if v == nil
v = self
math_sqrt(self.length_squared(v))
length_squared
Vector3.length_squared(v = nil)
lib/geometry/vector3.tya:140
Vector3.length_squared provides the geometry/Vector3 standard library operation.
Source
# Vector3.length_squared provides the geometry/Vector3 standard library operation.
# @param v Any v value.
# @return Any the resulting value.
length_squared: v = nil ->
if v == nil
v = self
self.expect(v, "v")
self.dot(v, v)
lerp
Vector3.lerp(a, b, t)
lib/geometry/vector3.tya:151
Vector3.lerp provides the geometry/Vector3 standard library operation.
Source
# Vector3.lerp provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @param t Any t value.
# @return Any the resulting value.
lerp: a, b, t ->
self.expect(a, "a")
self.expect(b, "b")
self.number(t, "t")
Vector3(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t)
nearly_equal?
Vector3.nearly_equal?(a, b, epsilon = nil)
lib/geometry/vector3.tya:162
Vector3.nearly_equal? provides the geometry/Vector3 standard library operation.
Source
# Vector3.nearly_equal? provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @param epsilon Any epsilon value.
# @return Boolean whether the condition is true.
nearly_equal?: a, b, epsilon = nil ->
if epsilon == nil
epsilon = b
b = a
a = self
self.expect(a, "a")
self.expect(b, "b")
if epsilon < 0
raise error("geometry.Vector3.nearly_equal?: epsilon must be non-negative")
self.abs(a.x - b.x) <= epsilon and self.abs(a.y - b.y) <= epsilon and self.abs(a.z - b.z) <= epsilon
new
Vector3.new(x, y, z)
lib/geometry/vector3.tya:178
Vector3.new provides the geometry/Vector3 standard library operation.
Source
# Vector3.new provides the geometry/Vector3 standard library operation.
# @param x Int x value.
# @param y Int y value.
# @param z Int z value.
# @return Self the resulting value.
new: x, y, z ->
Vector3(x, y, z)
normalize
Vector3.normalize(v = nil)
lib/geometry/vector3.tya:184
Vector3.normalize provides the geometry/Vector3 standard library operation.
Source
# Vector3.normalize provides the geometry/Vector3 standard library operation.
# @param v Any v value.
# @return String the resulting value.
normalize: v = nil ->
if v == nil
v = self
geometry_len = self.length(v)
if geometry_len == 0
return self.zero()
self.div(v, geometry_len)
number
Vector3.number(value, name)
lib/geometry/vector3.tya:196
Vector3.number provides the geometry/Vector3 standard library operation.
Source
# Vector3.number provides the geometry/Vector3 standard library operation.
# @param value String value value.
# @param name String name value.
# @return Any the resulting value.
number: value, name ->
if value.class != Number
raise error("geometry.Vector3: " + name + " must be a number")
value
one
Vector3.one()
lib/geometry/vector3.tya:203
Vector3.one provides the geometry/Vector3 standard library operation.
Source
# Vector3.one provides the geometry/Vector3 standard library operation.
# @return Any the resulting value.
one: ->
Vector3(1, 1, 1)
scale
Vector3.scale(v, k = nil)
lib/geometry/vector3.tya:210
Vector3.scale provides the geometry/Vector3 standard library operation.
Source
# Vector3.scale provides the geometry/Vector3 standard library operation.
# @param v Any v value.
# @param k Any k value.
# @return Any the resulting value.
scale: v, k = nil ->
if k == nil
k = v
v = self
self.expect(v, "v")
self.number(k, "k")
Vector3(v.x * k, v.y * k, v.z * k)
sub
Vector3.sub(a, b = nil)
lib/geometry/vector3.tya:222
Vector3.sub provides the geometry/Vector3 standard library operation.
Source
# Vector3.sub provides the geometry/Vector3 standard library operation.
# @param a Int a value.
# @param b Int b value.
# @return Any the resulting value.
sub: a, b = nil ->
if b == nil
b = a
a = self
self.expect(a, "a")
self.expect(b, "b")
Vector3(a.x - b.x, a.y - b.y, a.z - b.z)
to_array
Vector3.to_array(v = nil)
lib/geometry/vector3.tya:233
Vector3.to_array provides the geometry/Vector3 standard library operation.
Source
# Vector3.to_array provides the geometry/Vector3 standard library operation.
# @param v Any v value.
# @return Array the resulting value.
to_array: v = nil ->
if v == nil
v = self
self.expect(v, "v")
[v.x, v.y, v.z]
zero
Vector3.zero()
lib/geometry/vector3.tya:241
Vector3.zero provides the geometry/Vector3 standard library operation.
Source
# Vector3.zero provides the geometry/Vector3 standard library operation.
# @return Any the resulting value.
zero: ->
Vector3(0, 0, 0)