()
| 213 | } |
| 214 | |
| 215 | func (point Vector) Unit() Vector { |
| 216 | l := point.Magnitude() |
| 217 | if l < 1e-8 || l == 1 { |
| 218 | // If it's 0, then don't modify the vector |
| 219 | return point |
| 220 | } |
| 221 | point.X, point.Y = point.X/l, point.Y/l |
| 222 | return point |
| 223 | } |
| 224 | |
| 225 | func (point Vector) IsZero() bool { |
| 226 | return point.X == 0 && point.Y == 0 |