better
This commit is contained in:
parent
35c99e641f
commit
2ddcdc4dc6
1 changed files with 30 additions and 48 deletions
|
@ -152,20 +152,16 @@ proc inRect*(v: Vec2, a: Vec2, b: Vec2): bool {.inline.} =
|
||||||
v.x > min.x and v.x < max.x and v.y > min.y and v.y < max.y
|
v.x > min.x and v.x < max.x and v.y > min.y and v.y < max.y
|
||||||
|
|
||||||
proc `[]`*(a: Vec2, i: int): float32 =
|
proc `[]`*(a: Vec2, i: int): float32 =
|
||||||
if i < 0 or i > 1:
|
case i
|
||||||
raise newException(IndexDefect, "Vec2 index out of bounds")
|
of 0: a.x
|
||||||
if i == 0:
|
of 1: a.y
|
||||||
a.x
|
else: raise newException(IndexDefect, "Index not in 0 .. 1")
|
||||||
else:
|
|
||||||
a.y
|
|
||||||
|
|
||||||
proc `[]=`*(a: var Vec2, i: int, b: float32) =
|
proc `[]=`*(a: var Vec2, i: int, b: float32) =
|
||||||
if i < 0 or i > 1:
|
case i
|
||||||
raise newException(IndexDefect, "Vec2 index out of bounds")
|
of 0: a.x = b
|
||||||
if i == 0:
|
of 1: a.y = b
|
||||||
a.x = b
|
else: raise newException(IndexDefect, "Index not in 0 .. 1")
|
||||||
else:
|
|
||||||
a.y = b
|
|
||||||
|
|
||||||
proc randVec2*(r: var Rand): Vec2 =
|
proc randVec2*(r: var Rand): Vec2 =
|
||||||
let a = r.rand(PI * 2)
|
let a = r.rand(PI * 2)
|
||||||
|
@ -329,24 +325,18 @@ proc angleBetween*(a, b: Vec3): float32 =
|
||||||
arccos(dot)
|
arccos(dot)
|
||||||
|
|
||||||
proc `[]`*(a: Vec3, i: int): float32 =
|
proc `[]`*(a: Vec3, i: int): float32 =
|
||||||
if i < 0 or i > 2:
|
case i
|
||||||
raise newException(IndexDefect, "Vec3 index out of bounds")
|
of 0: a.x
|
||||||
if i == 0:
|
of 1: a.y
|
||||||
a.x
|
of 2: a.z
|
||||||
elif i == 1:
|
else: raise newException(IndexDefect, "Index not in 0 .. 2")
|
||||||
a.y
|
|
||||||
else:
|
|
||||||
a.z
|
|
||||||
|
|
||||||
proc `[]=`*(a: var Vec3, i: int, b: float32) =
|
proc `[]=`*(a: var Vec3, i: int, b: float32) =
|
||||||
if i < 0 or i > 2:
|
case i
|
||||||
raise newException(IndexDefect, "Vec3 index out of bounds")
|
of 0: a.x = b
|
||||||
if i == 0:
|
of 1: a.y = b
|
||||||
a.x = b
|
of 2: a.z = b
|
||||||
elif i == 1:
|
else: raise newException(IndexDefect, "Index not in 0 .. 2")
|
||||||
a.y = b
|
|
||||||
else:
|
|
||||||
a.z = b
|
|
||||||
|
|
||||||
proc xy*(a: Vec3): Vec2 {.inline.} =
|
proc xy*(a: Vec3): Vec2 {.inline.} =
|
||||||
vec2(a.x, a.y)
|
vec2(a.x, a.y)
|
||||||
|
@ -479,28 +469,20 @@ proc hash*(a: Vec4): Hash {.inline.} =
|
||||||
hash((a.x, a.y, a.z, a.w))
|
hash((a.x, a.y, a.z, a.w))
|
||||||
|
|
||||||
proc `[]`*(a: Vec4, i: int): float32 =
|
proc `[]`*(a: Vec4, i: int): float32 =
|
||||||
if i < 0 or i > 3:
|
case i
|
||||||
raise newException(IndexDefect, "Vec4 index out of bounds")
|
of 0: a.x
|
||||||
if i == 0:
|
of 1: a.y
|
||||||
a.x
|
of 2: a.z
|
||||||
elif i == 1:
|
of 3: a.w
|
||||||
a.y
|
else: raise newException(IndexDefect, "Index not in 0 .. 3")
|
||||||
elif i == 2:
|
|
||||||
a.z
|
|
||||||
else:
|
|
||||||
a.w
|
|
||||||
|
|
||||||
proc `[]=`*(a: var Vec4, i: int, b: float32) =
|
proc `[]=`*(a: var Vec4, i: int, b: float32) =
|
||||||
if i < 0 or i > 3:
|
case i
|
||||||
raise newException(IndexDefect, "Vec4 index out of bounds")
|
of 0: a.x = b
|
||||||
if i == 0:
|
of 1: a.y = b
|
||||||
a.x = b
|
of 2: a.z = b
|
||||||
elif i == 1:
|
of 3: a.w = b
|
||||||
a.y = b
|
else: raise newException(IndexDefect, "Index not in 0 .. 3")
|
||||||
elif i == 2:
|
|
||||||
a.z = b
|
|
||||||
else:
|
|
||||||
a.w = b
|
|
||||||
|
|
||||||
proc lerp*(a: Vec4, b: Vec4, v: float32): Vec4 =
|
proc lerp*(a: Vec4, b: Vec4, v: float32): Vec4 =
|
||||||
a * (1.0 - v) + b * v
|
a * (1.0 - v) + b * v
|
||||||
|
|
Loading…
Reference in a new issue