MCPcopy Index your code
hub / github.com/processing/p5.js / limit

Method limit

src/math/p5.Vector.js:1746–1753  ·  view source on GitHub ↗

* Limits a vector's magnitude to a maximum value. * * The static version of `limit()`, as in `p5.Vector.limit(v, 5)`, returns a * new p5.Vector object and doesn't change the * original. * * @param {Number} max maximum magnitude for the vector. * @ch

(max)

Source from the content-addressed store, hash-verified

1744 * }
1745 */
1746 limit(max) {
1747 const mSq = this.magSq();
1748 if (mSq > max * max) {
1749 this.div(Math.sqrt(mSq)) //normalize it
1750 .mult(max);
1751 }
1752 return this;
1753 }
1754
1755 /**
1756 * Sets a vector's magnitude to a given value.

Callers 5

updateMethod · 0.80
seekMethod · 0.80
separateMethod · 0.80
alignMethod · 0.80
p5.Vector.jsFile · 0.80

Calls 6

magSqMethod · 0.95
divMethod · 0.95
_friendlyErrorMethod · 0.95
multMethod · 0.45
copyMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected