Skip to content

Commit

Permalink
sync with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
planetis-m committed Jun 13, 2024
1 parent f0977e8 commit 8762516
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/raymath.nim
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,18 @@ func distanceSqr*(v1, v2: Vector2): float32 {.inline.} =
## Calculate square distance between two vectors
result = (v1.x - v2.x) * (v1.x - v2.x) + (v1.y - v2.y) * (v1.y - v2.y)

func angle*(v1: Vector2; v2: Vector2): float32 {.inline.} =
func angle*(v1, v2: Vector2): float32 {.inline.} =
## Calculate angle between two vectors
## NOTE: Angle is calculated from origin point (0, 0)
let dot = v1.x*v2.x + v1.y*v2.y
let det = v1.x*v2.y - v1.y*v2.x
result = -arctan2(det, dot)
result = arctan2(det, dot)

func lineAngle*(start, `end`: Vector2): float32 {.inline.} =
## Calculate angle defined by a two vectors line
## NOTE: Parameters need to be normalized
result = arctan2(`end`.y - start.y, `end`.x - start.x)
# TODO: Currently angles move clockwise, determine if this is wanted behavior
result = -arctan2(`end`.y - start.y, `end`.x - start.x)

func scale*(v: Vector2; scale: float32): Vector2 {.inline.} =
## Scale vector (multiply by value)
Expand Down

0 comments on commit 8762516

Please sign in to comment.