* Calculates the magnitude (length) of the vector. * * Use mag() to calculate the magnitude of a 2D vector * using components as in `mag(x, y)`. * * @return {Number} magnitude of the vector. * * @example * function setup() { * createCanvas(100, 100
()
| 1245 | * } |
| 1246 | */ |
| 1247 | mag() { |
| 1248 | let sum = 0; |
| 1249 | for (let i = 0; i < this.values.length; i++) { |
| 1250 | const component = this.values[i]; |
| 1251 | sum += component * component; |
| 1252 | } |
| 1253 | return Math.sqrt(sum); |
| 1254 | } |
| 1255 | |
| 1256 | /** |
| 1257 | * Calculates the magnitude (length) of the vector squared. |
no outgoing calls
no test coverage detected