Skip to content

Commit b5abddd

Browse files
committed
better checks for rotate (static function)
1 parent f25907b commit b5abddd

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/math/p5.Vector.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,18 +2162,17 @@ p5.Vector.mult = function mult(v, n, target) {
21622162
* @param {Number} angle
21632163
* @param {p5.Vector} [target] the vector to receive the result (Optional)
21642164
*/
2165-
21662165
p5.Vector.rotate = function rotate(v, a, target) {
2167-
if (!target) {
2166+
if (arguments.length === 2) {
21682167
target = v.copy();
2169-
if (arguments.length === 3) {
2170-
p5._friendlyError(
2171-
'The target parameter is undefined, it should be of type p5.Vector',
2172-
'p5.Vector.rotate'
2173-
);
2174-
}
2175-
} else {
2168+
} else if (target instanceof p5.Vector) {
21762169
target.set(v);
2170+
} else {
2171+
target = v.copy();
2172+
p5._friendlyError(
2173+
'The target parameter should be of type p5.Vector',
2174+
'p5.Vector.rotate'
2175+
);
21772176
}
21782177
target.rotate(a);
21792178
return target;

0 commit comments

Comments
 (0)