* Scales the components of a p5.Vector object so * that its magnitude is 1. * * The static version of `normalize()`, as in `p5.Vector.normalize(v)`, * returns a new p5.Vector object and doesn't change * the original. * * @retu
()
| 1656 | * } |
| 1657 | */ |
| 1658 | normalize() { |
| 1659 | const len = this.mag(); |
| 1660 | // here we multiply by the reciprocal instead of calling 'div()' |
| 1661 | // since div duplicates this zero check. |
| 1662 | if (len !== 0) this.mult(1 / len); |
| 1663 | return this; |
| 1664 | } |
| 1665 | |
| 1666 | /** |
| 1667 | * Limits a vector's magnitude to a maximum value. |
no test coverage detected