aboutsummaryrefslogtreecommitdiff
path: root/examples/vectors/vectors.tm
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-03-05 18:20:54 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-03-05 18:20:54 -0500
commit147e0f0269440fce15d6b88a8a90627f3a3b2df2 (patch)
treebc33522ba71b5a2996fae22e102cce5046cf1333 /examples/vectors/vectors.tm
parent2c4324670ff569ede360d13875c5e4b5720a626d (diff)
Overhaul of constructors, making it more consistent and correct. Also
changed T(), T, T_t, T_s type names to T(), T$$info, T$$type, T$$struct for unambiguity
Diffstat (limited to 'examples/vectors/vectors.tm')
-rw-r--r--examples/vectors/vectors.tm11
1 files changed, 8 insertions, 3 deletions
diff --git a/examples/vectors/vectors.tm b/examples/vectors/vectors.tm
index b2533be4..c07880a5 100644
--- a/examples/vectors/vectors.tm
+++ b/examples/vectors/vectors.tm
@@ -83,11 +83,13 @@ struct IVec2(x,y:Int):
func divided_by(v:IVec2, divisor:Int->IVec2; inline):
return IVec2(v.x/divisor, v.y/divisor)
func length(v:IVec2->Num; inline):
- return Num.sqrt(v.x*v.x + v.y*v.y)
+ x := Num(v.x)
+ y := Num(v.y)
+ return Num.sqrt(x*x + y*y)
func dist(a,b:IVec2->Num; inline):
return a:minus(b):length()
func angle(v:IVec2->Num; inline):
- return Num.atan2(v.y, v.x)
+ return Num.atan2(Num(v.y), Num(v.x))
struct IVec3(x,y,z:Int):
ZERO := IVec3(0, 0, 0)
@@ -106,7 +108,10 @@ struct IVec3(x,y,z:Int):
func divided_by(v:IVec3, divisor:Int->IVec3; inline):
return IVec3(v.x/divisor, v.y/divisor, v.z/divisor)
func length(v:IVec3->Num; inline):
- return Num.sqrt(v.x*v.x + v.y*v.y + v.z*v.z)
+ x := Num(v.x)
+ y := Num(v.y)
+ z := Num(v.z)
+ return Num.sqrt(x*x + y*y + z*z)
func dist(a,b:IVec3->Num; inline):
return a:minus(b):length()