Skip to content

Commit

Permalink
Merge pull request #315 from dusk125/v2-divide-by-0
Browse files Browse the repository at this point in the history
Fix potential divide by 0 in vector2
  • Loading branch information
gen2brain committed Nov 16, 2023
2 parents 8c380e0 + a70feef commit f09d79e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion raylib/raymath.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ func Vector2Divide(v1, v2 Vector2) Vector2 {

// Vector2Normalize - Normalize provided vector
func Vector2Normalize(v Vector2) Vector2 {
return Vector2Scale(v, 1/Vector2Length(v))
if l := Vector2Length(v); l > 0 {
return Vector2Scale(v, 1/l)
}
return v
}

// Vector2Transform - Transforms a Vector2 by a given Matrix
Expand Down

0 comments on commit f09d79e

Please sign in to comment.