View source on GitHub | See Demo | Toggle Types language heron:std:0.1; module heron:tests:0.1 { import heron:std.array:0.1; import heron:geometry.mesh:0.1; import heron:geometry.vector:0.1; ( -> 'a)function main() { simpleArrayTest(); simpleVectorTest(); } ( -> 'a)function simpleArrayTest() { var xs = [1, 11, 3]; print('Expect [1, 11, 3]'); print(xs); print('Expect 1, 11, 3'); for (var x in xs) print(x); print('Expect 1'); print(xs[0]); print('Expect 3'); print(xs.count); print('Expect 1'); print(xs.first); print('Expect 3'); print(xs.last); print('Expect 1'); print(xs.min); print('Expect 11'); print(xs.max); var ys = xs.mutable; ys[1] = 5; print('Expect 5'); print(ys[1]); print('Expect 1, 3, 11'); var zs = xs.sort; for (var z in zs) print(z); print('Expect 3'); print(xs.median); print('Expect 15'); print(xs.sum); print('Expect 5'); print(xs.average); } (Float3 -> 'a)function printVector(v) { var xs = [v.x, v.y, v.z]; print(xs); } ( -> 'a)function simpleVectorTest() { var v = vector(4, 3, 0); print('Expect 5'); print(v.length); print('Expect [4, 3, 0]'); print(v); var v1 = vector(1, 0, 0); var v2 = vector(0, 1, 0); print('Expect [0,0,1]'); print(v1.cross(v2)); print('Expect [1,1,0]'); var v3 = v1 + v2; print(v3); print('Expect [1,0,0]'); var v4 = v3 - v2; print(v4); print('Expect [20,15,0]'); var v5 = v * 5.0.vector; print(v5); print('Expect [1,1,0]'); print(v1 + v2); print('Expect [0.8, 0.6, 0]'); print(v.normal); } (Mesh Float -> Mesh)function colorModifier(g, amount: Float) = g.setVertexColors(g.uvBuffer.map(v => vector( sin(v.x * pi * 4f) / 2.0 + 0.5, sin(amount), cos(v.y * pi * 4f) / 2.0 + 0.5))); (Mesh Float -> Mesh)function pushModifer(g, amount: Float) = g.translate(g.normalBuffer.map(n => n * amount.vector)); (Mesh Float -> Mesh)function scaleModifier(g, amount: Float) = g.scale(amount.vector); ( -> Array<(Mesh Float -> Mesh)>)function modifiers() = [ scaleModifier, pushModifer, colorModifier ]; ( -> Array<Mesh>)function primitives() = [ sphere(), cylinder(), torus(), klein(), plane(), mobius(), tetrahedron, cube, octahedron, dodecahedron, icosahedron ]; }