Skip to content

Commit

Permalink
fixes treeform#72 by removing the faulty vec2 proc and making the vec…
Browse files Browse the repository at this point in the history
…3 angle proc work for vec2
  • Loading branch information
lilkeet committed Jun 24, 2024
1 parent 7282ae1 commit 90a390c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/vmath.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1573,12 +1573,16 @@ proc angle*[T](a: GVec2[T]): T =
## Angle of a Vec2.
arctan2(a.y, a.x)

proc angle*[T](a, b: GVec2[T]): T =
## Angle between 2 Vec2.
fixAngle(arctan2(a.y - b.y, a.x - b.x))

proc angle*[T](a, b: GVec3[T]): T =
## Angle between 2 Vec3.
proc angle*[T](a, b: GVec2[T]|GVec3[T]): T =
## Angle between 2 Vec2 or Vec3.
runnableExamples:
assert angle(vec2(0.0, 1.0), vec2(1.0, 0.0)).toDegrees() == 90.0
assert angle(vec2(0.0, 1.0), vec2(-1.0, 0.0)).toDegrees() == 90.0
assert angle(vec2(0.0, 1.0), vec2(0.0, -1.0)).toDegrees() == 180.0

assert angle(vec3(0.0, 1.0, 0.0), vec3(1.0, 0.0, 0.0)).toDegrees() == 90.0
assert angle(vec3(0.0, 1.0, 0.0), vec3(-1.0, 0.0, 0.0)).toDegrees() == 90.0
assert angle(vec3(0.0, 1.0, 0.0), vec3(0.0, -1.0, 0.0)).toDegrees() == 180.0
var dot = dot(a, b)
dot = dot / (a.length * b.length)
arccos(dot)
Expand Down

0 comments on commit 90a390c

Please sign in to comment.