* @param {p5.Vector} v vector to divide the components of the original vector by. * @chainable
(args)
| 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. |
no test coverage detected