comparison semiconginev2/core/vector.nim @ 1253:c4f98eb4bb05

fix: a few things
author sam <sam@basx.dev>
date Fri, 26 Jul 2024 23:39:24 +0700
parents 56781cc0fc7c
children b0f4c8ccd49a
comparison
equal deleted inserted replaced
1252:01e9f41d35b1 1253:c4f98eb4bb05
100 func To*[T](v: TVec1): auto = TVec1([T(v[0])]) 100 func To*[T](v: TVec1): auto = TVec1([T(v[0])])
101 func To*[T](v: TVec2): auto = TVec2([T(v[0]), T(v[1])]) 101 func To*[T](v: TVec2): auto = TVec2([T(v[0]), T(v[1])])
102 func To*[T](v: TVec3): auto = TVec3([T(v[0]), T(v[1]), T(v[2])]) 102 func To*[T](v: TVec3): auto = TVec3([T(v[0]), T(v[1]), T(v[2])])
103 func To*[T](v: TVec4): auto = TVec4([T(v[0]), T(v[1]), T(v[2]), T(v[3])]) 103 func To*[T](v: TVec4): auto = TVec4([T(v[0]), T(v[1]), T(v[2]), T(v[3])])
104 104
105 func toString[T: TVec](value: T): string = 105 func toVecString[T: TVec](value: T): string =
106 var items: seq[string] 106 var items: seq[string]
107 for item in value: 107 for item in value:
108 items.add(&"{item.float:.5f}") 108 items.add(&"{item.float:.5f}")
109 & "(" & join(items, " ") & ")" 109 & "(" & join(items, " ") & ")"
110 110
111 func `$`*(v: TVec1[SomeNumber]): string = toString[TVec1[SomeNumber]](v) 111 func `$`*(v: TVec1[SomeNumber]): string = toVecString[TVec1[SomeNumber]](v)
112 func `$`*(v: TVec2[SomeNumber]): string = toString[TVec2[SomeNumber]](v) 112 func `$`*(v: TVec2[SomeNumber]): string = toVecString[TVec2[SomeNumber]](v)
113 func `$`*(v: TVec3[SomeNumber]): string = toString[TVec3[SomeNumber]](v) 113 func `$`*(v: TVec3[SomeNumber]): string = toVecString[TVec3[SomeNumber]](v)
114 func `$`*(v: TVec4[SomeNumber]): string = toString[TVec4[SomeNumber]](v) 114 func `$`*(v: TVec4[SomeNumber]): string = toVecString[TVec4[SomeNumber]](v)
115 115
116 func Length*(vec: TVec1): auto = vec[0] 116 func Length*(vec: TVec1): auto = vec[0]
117 func Length*(vec: TVec2[SomeFloat]): auto = sqrt(vec[0] * vec[0] + vec[1] * vec[1]) 117 func Length*(vec: TVec2[SomeFloat]): auto = sqrt(vec[0] * vec[0] + vec[1] * vec[1])
118 func Length*(vec: TVec2[SomeInteger]): auto = sqrt(float(vec[0] * vec[0] + vec[1] * vec[1])) 118 func Length*(vec: TVec2[SomeInteger]): auto = sqrt(float(vec[0] * vec[0] + vec[1] * vec[1]))
119 func Length*(vec: TVec3[SomeFloat]): auto = sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]) 119 func Length*(vec: TVec3[SomeFloat]): auto = sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2])