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

Method div

src/math/p5.Vector.js:1176–1214  ·  view source on GitHub ↗

* @param {p5.Vector} v vector to divide the components of the original vector by. * @chainable

(args)

Source from the content-addressed store, hash-verified

1174 * @chainable
1175 */
1176 div(args) {
1177 const minDimension = prioritizeSmallerDimension(this.dimensions, args);
1178
1179 if (Array.isArray(args)) {
1180 for (let i = 0; i < minDimension; i++) {
1181 if ((typeof args[i] !== 'number' || args[i] === 0)) {
1182 if (!this.friendlyErrorsDisabled()) {
1183 console.warn(
1184 'p5.Vector.prototype.div',
1185 'Arguments contain components that are 0'
1186 );
1187 }
1188 return this;
1189 }
1190 }
1191 } else if(typeof args !== 'number' || args === 0) {
1192 if (!this.friendlyErrorsDisabled()) {
1193 console.warn(
1194 'p5.Vector.prototype.div',
1195 'Arguments contain components that are 0'
1196 );
1197 }
1198 return this;
1199 }
1200
1201 shrinkToDimension(this.values, minDimension);
1202
1203 if(Array.isArray(args)){
1204 for (let i = 0; i < this.values.length; i++) {
1205 this.values[i] /= args[i];
1206 }
1207 } else {
1208 for (let i = 0; i < this.values.length; i++) {
1209 this.values[i] /= args;
1210 }
1211 }
1212
1213 return this;
1214 }
1215
1216 /**
1217 * Calculates the magnitude (length) of the vector.

Callers 11

limitMethod · 0.95
drawFunction · 0.80
mover.jsFile · 0.80
separateMethod · 0.80
alignMethod · 0.80
cohesionMethod · 0.80
applyForceMethod · 0.80
p5.Vector.jsFile · 0.80
initGlobalStrandsAPIFunction · 0.80
averageNormalsMethod · 0.80
averagePoleNormalsMethod · 0.80

Calls 6

_friendlyErrorMethod · 0.95
shrinkToDimensionFunction · 0.85
copyMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected