Skip to content

Commit a224a2f

Browse files
committed
they're baaaaaack #257
1 parent 176a58b commit a224a2f

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

core/src/processing/core/PVector.java

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
/*
44
Part of the Processing project - http://processing.org
55
6+
Copyright (c) 2012-15 The Processing Foundation
7+
Copyright (c) 2008-12 Ben Fry and Casey Reas
68
Copyright (c) 2008 Dan Shiffman
7-
Copyright (c) 2008-10 Ben Fry and Casey Reas
89
910
This library is free software; you can redistribute it and/or
1011
modify it under the terms of the GNU Lesser General Public
@@ -68,12 +69,6 @@
6869
* @webref math
6970
*/
7071
public class PVector implements Serializable {
71-
72-
/**
73-
* Generated 2010-09-14 by jdf
74-
*/
75-
private static final long serialVersionUID = -6717872085945400694L;
76-
7772
/**
7873
* ( begin auto-generated from PVector_x.xml )
7974
*
@@ -165,45 +160,49 @@ public PVector(float x, float y) {
165160
* @param z the z component of the vector
166161
* @brief Set the components of the vector
167162
*/
168-
public void set(float x, float y, float z) {
163+
public PVector set(float x, float y, float z) {
169164
this.x = x;
170165
this.y = y;
171166
this.z = z;
167+
return this;
172168
}
173169

174170

175171
/**
176172
* @param x the x component of the vector
177173
* @param y the y component of the vector
178174
*/
179-
public void set(float x, float y) {
175+
public PVector set(float x, float y) {
180176
this.x = x;
181177
this.y = y;
178+
return this;
182179
}
183180

184181

185182
/**
186183
* @param v any variable of type PVector
187184
*/
188-
public void set(PVector v) {
185+
public PVector set(PVector v) {
189186
x = v.x;
190187
y = v.y;
191188
z = v.z;
189+
return this;
192190
}
193191

194192

195193
/**
196194
* Set the x, y (and maybe z) coordinates using a float[] array as the source.
197195
* @param source array to copy from
198196
*/
199-
public void set(float[] source) {
197+
public PVector set(float[] source) {
200198
if (source.length >= 2) {
201199
x = source[0];
202200
y = source[1];
203201
}
204202
if (source.length >= 3) {
205203
z = source[2];
206204
}
205+
return this;
207206
}
208207

209208

@@ -453,10 +452,11 @@ public float magSq() {
453452
* @param v the vector to be added
454453
* @brief Adds x, y, and z components to a vector, one vector to another, or two independent vectors
455454
*/
456-
public void add(PVector v) {
455+
public PVector add(PVector v) {
457456
x += v.x;
458457
y += v.y;
459458
z += v.z;
459+
return this;
460460
}
461461

462462

@@ -465,10 +465,11 @@ public void add(PVector v) {
465465
* @param y y component of the vector
466466
* @param z z component of the vector
467467
*/
468-
public void add(float x, float y, float z) {
468+
public PVector add(float x, float y, float z) {
469469
this.x += x;
470470
this.y += y;
471471
this.z += z;
472+
return this;
472473
}
473474

474475

@@ -512,10 +513,11 @@ static public PVector add(PVector v1, PVector v2, PVector target) {
512513
* @param v any variable of type PVector
513514
* @brief Subtract x, y, and z components from a vector, one vector from another, or two independent vectors
514515
*/
515-
public void sub(PVector v) {
516+
public PVector sub(PVector v) {
516517
x -= v.x;
517518
y -= v.y;
518519
z -= v.z;
520+
return this;
519521
}
520522

521523

@@ -524,10 +526,11 @@ public void sub(PVector v) {
524526
* @param y the y component of the vector
525527
* @param z the z component of the vector
526528
*/
527-
public void sub(float x, float y, float z) {
529+
public PVector sub(float x, float y, float z) {
528530
this.x -= x;
529531
this.y -= y;
530532
this.z -= z;
533+
return this;
531534
}
532535

533536

@@ -568,10 +571,11 @@ static public PVector sub(PVector v1, PVector v2, PVector target) {
568571
* @brief Multiply a vector by a scalar
569572
* @param n the number to multiply with the vector
570573
*/
571-
public void mult(float n) {
574+
public PVector mult(float n) {
572575
x *= n;
573576
y *= n;
574577
z *= n;
578+
return this;
575579
}
576580

577581

@@ -609,10 +613,11 @@ static public PVector mult(PVector v, float n, PVector target) {
609613
* @brief Divide a vector by a scalar
610614
* @param n the number by which to divide the vector
611615
*/
612-
public void div(float n) {
616+
public PVector div(float n) {
613617
x /= n;
614618
y /= n;
615619
z /= n;
620+
return this;
616621
}
617622

618623

@@ -776,11 +781,12 @@ static public PVector cross(PVector v1, PVector v2, PVector target) {
776781
* @usage web_application
777782
* @brief Normalize the vector to a length of 1
778783
*/
779-
public void normalize() {
784+
public PVector normalize() {
780785
float m = mag();
781786
if (m != 0 && m != 1) {
782787
div(m);
783788
}
789+
return this;
784790
}
785791

786792

@@ -814,11 +820,12 @@ public PVector normalize(PVector target) {
814820
* @param max the maximum magnitude for the vector
815821
* @brief Limit the magnitude of the vector
816822
*/
817-
public void limit(float max) {
823+
public PVector limit(float max) {
818824
if (magSq() > max*max) {
819825
normalize();
820826
mult(max);
821827
}
828+
return this;
822829
}
823830

824831

@@ -834,9 +841,10 @@ public void limit(float max) {
834841
* @param len the new length for this vector
835842
* @brief Set the magnitude of the vector
836843
*/
837-
public void setMag(float len) {
844+
public PVector setMag(float len) {
838845
normalize();
839846
mult(len);
847+
return this;
840848
}
841849

842850

@@ -889,11 +897,12 @@ public float heading2D() {
889897
* @brief Rotate the vector by an angle (2D only)
890898
* @param theta the angle of rotation
891899
*/
892-
public void rotate(float theta) {
900+
public PVector rotate(float theta) {
893901
float temp = x;
894902
// Might need to check for rounding errors like with angleBetween function?
895903
x = x*PApplet.cos(theta) - y*PApplet.sin(theta);
896904
y = temp*PApplet.sin(theta) + y*PApplet.cos(theta);
905+
return this;
897906
}
898907

899908

@@ -911,10 +920,11 @@ public void rotate(float theta) {
911920
* @param amt The amount of interpolation; some value between 0.0 (old vector) and 1.0 (new vector). 0.1 is very near the new vector. 0.5 is halfway in between.
912921
* @see PApplet#lerp(float, float, float)
913922
*/
914-
public void lerp(PVector v, float amt) {
923+
public PVector lerp(PVector v, float amt) {
915924
x = PApplet.lerp(x, v.x, amt);
916925
y = PApplet.lerp(y, v.y, amt);
917926
z = PApplet.lerp(z, v.z, amt);
927+
return this;
918928
}
919929

920930

@@ -936,10 +946,11 @@ public static PVector lerp(PVector v1, PVector v2, float amt) {
936946
* @param y the y component to lerp to
937947
* @param z the z component to lerp to
938948
*/
939-
public void lerp(float x, float y, float z, float amt) {
949+
public PVector lerp(float x, float y, float z, float amt) {
940950
this.x = PApplet.lerp(this.x, x, amt);
941951
this.y = PApplet.lerp(this.y, y, amt);
942952
this.z = PApplet.lerp(this.z, z, amt);
953+
return this;
943954
}
944955

945956

0 commit comments

Comments
 (0)