Skip to content

Commit 673a19e

Browse files
committed
add PVector.setHeading() for parity with p5.js (fixes #193)
1 parent 3ec2f28 commit 673a19e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

core/src/processing/core/PVector.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ static public PVector fromAngle(float angle, PVector target) {
345345

346346
/**
347347
*
348-
* Copies the components of the vector and returns the result as a <b>PVector</b>.
348+
* Copies the components of the vector and returns the result as a <b>PVector</b>.
349349
*
350350
*
351351
* @webref pvector:method
@@ -868,6 +868,14 @@ public float heading2D() {
868868
}
869869

870870

871+
public PVector setHeading(float angle) {
872+
float m = mag();
873+
x = m * Math.cos(a);
874+
y = m * Math.sin(a);
875+
return this;
876+
}
877+
878+
871879
/**
872880
*
873881
* Rotate the vector by an angle (only 2D vectors), magnitude remains the same

todo.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ X https://github.com/processing/processing4/pull/199
1818
X don't sort user's charset array when calling createFont()
1919
X https://github.com/processing/processing4/issues/197
2020
X https://github.com/processing/processing4/pull/198
21+
X add PVector.setHeading() for parity with p5.js
22+
X https://github.com/processing/processing4/issues/193
2123

2224

2325
earlier

0 commit comments

Comments
 (0)