From 57ad916ab10e7150231870e8d80793c6349c34af Mon Sep 17 00:00:00 2001 From: lilkeet Date: Mon, 24 Jun 2024 01:55:34 -0500 Subject: [PATCH] fixes #73 by removing the faulty vec2 proc and making the vec3 angle proc work for vec2 --- src/vmath.nim | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/vmath.nim b/src/vmath.nim index b1bb102..46d913a 100644 --- a/src/vmath.nim +++ b/src/vmath.nim @@ -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: 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 -proc angle*[T](a, b: GVec3[T]): T = - ## Angle between 2 Vec3. + 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)