propane 3.4.0-java → 3.7.0.pre-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -2
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +2 -2
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -2
  5. data/.travis.yml +2 -2
  6. data/CHANGELOG.md +12 -0
  7. data/Gemfile +2 -0
  8. data/README.md +17 -8
  9. data/Rakefile +10 -11
  10. data/bin/propane +3 -1
  11. data/lib/propane.rb +6 -4
  12. data/lib/propane/app.rb +20 -10
  13. data/lib/propane/creators/sketch_class.rb +7 -1
  14. data/lib/propane/creators/sketch_factory.rb +4 -2
  15. data/lib/propane/creators/sketch_writer.rb +1 -0
  16. data/lib/propane/helper_methods.rb +23 -24
  17. data/lib/propane/helpers/numeric.rb +2 -0
  18. data/lib/propane/helpers/version_error.rb +1 -0
  19. data/lib/propane/library.rb +5 -1
  20. data/lib/propane/library_loader.rb +2 -0
  21. data/lib/propane/native_folder.rb +10 -9
  22. data/lib/propane/native_loader.rb +3 -0
  23. data/lib/propane/runner.rb +14 -6
  24. data/lib/propane/version.rb +2 -1
  25. data/library/boids/boids.rb +21 -11
  26. data/library/color_group/color_group.rb +28 -0
  27. data/library/control_panel/control_panel.rb +8 -5
  28. data/library/dxf/dxf.rb +6 -0
  29. data/library/file_chooser/chooser.rb +10 -9
  30. data/library/file_chooser/file_chooser.rb +10 -9
  31. data/library/library_proxy/library_proxy.rb +2 -0
  32. data/library/net/net.rb +7 -0
  33. data/library/simplex_noise/simplex_noise.rb +2 -0
  34. data/library/slider/slider.rb +23 -22
  35. data/library/vector_utils/vector_utils.rb +4 -0
  36. data/library/video_event/video_event.rb +4 -1
  37. data/pom.rb +37 -36
  38. data/pom.xml +7 -7
  39. data/propane.gemspec +16 -12
  40. data/src/main/java/monkstone/ColorUtil.java +13 -1
  41. data/src/main/java/monkstone/MathToolModule.java +253 -203
  42. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  43. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  44. data/src/main/java/monkstone/filechooser/Chooser.java +2 -1
  45. data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
  46. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  47. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  48. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  49. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  50. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  51. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  52. data/src/main/java/monkstone/slider/WheelHandler.java +7 -6
  53. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  54. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  55. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +3 -3
  56. data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
  57. data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +11 -27
  58. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  59. data/src/main/java/processing/awt/PGraphicsJava2D.java +781 -285
  60. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  61. data/src/main/java/processing/awt/PShapeJava2D.java +56 -52
  62. data/src/main/java/processing/awt/PSurfaceAWT.java +309 -209
  63. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  64. data/src/main/java/processing/core/PApplet.java +4510 -4503
  65. data/src/main/java/processing/core/PConstants.java +477 -447
  66. data/src/main/java/processing/core/PFont.java +914 -880
  67. data/src/main/java/processing/core/PGraphics.java +193 -177
  68. data/src/main/java/processing/core/PImage.java +611 -309
  69. data/src/main/java/processing/core/PMatrix.java +172 -159
  70. data/src/main/java/processing/core/PMatrix2D.java +478 -415
  71. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  72. data/src/main/java/processing/core/PShape.java +2888 -2652
  73. data/src/main/java/processing/core/PShapeOBJ.java +97 -92
  74. data/src/main/java/processing/core/PShapeSVG.java +1705 -1490
  75. data/src/main/java/processing/core/PStyle.java +40 -37
  76. data/src/main/java/processing/core/PSurface.java +139 -97
  77. data/src/main/java/processing/core/PSurfaceNone.java +296 -218
  78. data/src/main/java/processing/core/PVector.java +997 -965
  79. data/src/main/java/processing/core/ThinkDifferent.java +15 -13
  80. data/src/main/java/processing/data/DoubleDict.java +756 -710
  81. data/src/main/java/processing/data/DoubleList.java +749 -696
  82. data/src/main/java/processing/data/FloatDict.java +748 -702
  83. data/src/main/java/processing/data/FloatList.java +751 -697
  84. data/src/main/java/processing/data/IntDict.java +720 -673
  85. data/src/main/java/processing/data/IntList.java +699 -633
  86. data/src/main/java/processing/data/JSONArray.java +931 -873
  87. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  88. data/src/main/java/processing/data/JSONTokener.java +351 -341
  89. data/src/main/java/processing/data/LongDict.java +710 -663
  90. data/src/main/java/processing/data/LongList.java +701 -635
  91. data/src/main/java/processing/data/Sort.java +37 -41
  92. data/src/main/java/processing/data/StringDict.java +525 -486
  93. data/src/main/java/processing/data/StringList.java +626 -580
  94. data/src/main/java/processing/data/Table.java +3690 -3510
  95. data/src/main/java/processing/data/TableRow.java +182 -183
  96. data/src/main/java/processing/data/XML.java +957 -883
  97. data/src/main/java/processing/dxf/RawDXF.java +404 -0
  98. data/src/main/java/processing/event/Event.java +87 -67
  99. data/src/main/java/processing/event/KeyEvent.java +48 -41
  100. data/src/main/java/processing/event/MouseEvent.java +88 -113
  101. data/src/main/java/processing/event/TouchEvent.java +10 -6
  102. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  103. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  104. data/src/main/java/processing/net/Client.java +744 -0
  105. data/src/main/java/processing/net/Server.java +388 -0
  106. data/src/main/java/processing/opengl/FontTexture.java +289 -270
  107. data/src/main/java/processing/opengl/FrameBuffer.java +386 -364
  108. data/src/main/java/processing/opengl/LinePath.java +547 -500
  109. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  110. data/src/main/java/processing/opengl/PGL.java +3047 -2914
  111. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  112. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  113. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  114. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  115. data/src/main/java/processing/opengl/PShader.java +1266 -1257
  116. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  117. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  118. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  119. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  120. data/test/create_test.rb +21 -20
  121. data/test/deglut_spec_test.rb +4 -2
  122. data/test/helper_methods_test.rb +49 -20
  123. data/test/math_tool_test.rb +39 -32
  124. data/test/native_folder.rb +47 -0
  125. data/test/respond_to_test.rb +3 -2
  126. data/test/sketches/key_event.rb +2 -2
  127. data/test/sketches/library/my_library/my_library.rb +3 -0
  128. data/test/test_helper.rb +2 -0
  129. data/test/vecmath_spec_test.rb +35 -22
  130. data/vendors/Rakefile +33 -62
  131. metadata +56 -48
  132. data/src/main/java/processing/core/util/image/ImageLoadFacade.java +0 -161
  133. data/src/main/java/processing/core/util/image/ImageSaveFacade.java +0 -169
  134. data/src/main/java/processing/core/util/image/constants/TifConstants.java +0 -45
  135. data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +0 -80
  136. data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +0 -73
  137. data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +0 -70
  138. data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +0 -132
  139. data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +0 -48
  140. data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +0 -45
  141. data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +0 -255
  142. data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +0 -98
  143. data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +0 -49
  144. data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +0 -48
  145. data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +0 -179
  146. data/src/main/java/processing/core/util/image/save/SaveImageException.java +0 -41
  147. data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +0 -198
  148. data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +0 -91
  149. data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +0 -57
  150. data/src/main/java/processing/core/util/io/InputFactory.java +0 -285
  151. data/src/main/java/processing/core/util/io/PathUtil.java +0 -109
  152. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  153. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  154. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  155. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1,3 +1,5 @@
1
+ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
1
3
  /*
2
4
  Part of the Processing project - http://processing.org
3
5
 
@@ -19,35 +21,33 @@
19
21
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
22
  Boston, MA 02111-1307 USA
21
23
  */
24
+
22
25
  package processing.core;
23
26
 
24
27
  import java.io.Serializable;
25
28
 
26
- import processing.core.PApplet;
27
- import processing.core.PConstants;
28
29
 
29
30
  /**
30
31
  * ( begin auto-generated from PVector.xml )
31
32
  *
32
- * A class to describe a two or three dimensional vector. This datatype stores
33
- * two or three variables that are commonly used as a position, velocity, and/or
34
- * acceleration. Technically, <em>position</em> is a point and <em>velocity</em>
35
- * and <em>acceleration</em> are vectors, but this is often simplified to
36
- * consider all three as vectors. For example, if you consider a rectangle
37
- * moving across the screen, at any given instant it has a position (the
38
- * object's location, expressed as a point.), a velocity (the rate at which the
39
- * object's position changes per time unit, expressed as a vector), and
40
- * acceleration (the rate at which the object's velocity changes per time unit,
41
- * expressed as a vector). Since vectors represent groupings of values, we
42
- * cannot simply use traditional addition/multiplication/etc. Instead, we'll
43
- * need to do some "vector" math, which is made easy by the methods inside the
44
- * <b>PVector</b>
45
- * class.<br />
46
- * <br />
33
+ * A class to describe a two or three dimensional vector. This datatype
34
+ * stores two or three variables that are commonly used as a position,
35
+ * velocity, and/or acceleration. Technically, <em>position</em> is a point
36
+ * and <em>velocity</em> and <em>acceleration</em> are vectors, but this is
37
+ * often simplified to consider all three as vectors. For example, if you
38
+ * consider a rectangle moving across the screen, at any given instant it
39
+ * has a position (the object's location, expressed as a point.), a
40
+ * velocity (the rate at which the object's position changes per time unit,
41
+ * expressed as a vector), and acceleration (the rate at which the object's
42
+ * velocity changes per time unit, expressed as a vector). Since vectors
43
+ * represent groupings of values, we cannot simply use traditional
44
+ * addition/multiplication/etc. Instead, we'll need to do some "vector"
45
+ * math, which is made easy by the methods inside the <b>PVector</b>
46
+ * class.
47
+ *
47
48
  * The methods for this class are extensive. For a complete list, visit the
48
49
  * <a
49
- * href="http://processing.googlecode.com/svn/trunk/processing/build/javadoc/core/">developer's
50
- * reference.</a>
50
+ * href="http://processing.googlecode.com/svn/trunk/processing/build/javadoc/core/">developer's reference.</a>
51
51
  *
52
52
  * ( end auto-generated )
53
53
  *
@@ -55,980 +55,1012 @@ import processing.core.PConstants;
55
55
  * <p>
56
56
  * The result of all functions are applied to the vector itself, with the
57
57
  * exception of cross(), which returns a new PVector (or writes to a specified
58
- * 'target' PVector). That is, add() will add the contents of one vector to this
59
- * one. Using add() with additional parameters allows you to put the result into
60
- * a new PVector. Functions that act on multiple vectors also include static
61
- * versions. Because creating new objects can be computationally expensive, most
62
- * functions include an optional 'target' PVector, so that a new PVector object
63
- * is not created with each operation.
58
+ * 'target' PVector). That is, add() will add the contents of one vector to
59
+ * this one. Using add() with additional parameters allows you to put the
60
+ * result into a new PVector. Functions that act on multiple vectors also
61
+ * include static versions. Because creating new objects can be computationally
62
+ * expensive, most functions include an optional 'target' PVector, so that a
63
+ * new PVector object is not created with each operation.
64
64
  * <p>
65
- * Initially based on the Vector3D class by
66
- * <a href="http://www.shiffman.net">Dan Shiffman</a>.
65
+ * Initially based on the Vector3D class by <a href="http://www.shiffman.net">Dan Shiffman</a>.
67
66
  *
68
67
  * @webref math
69
68
  */
70
69
  public class PVector implements Serializable {
71
-
72
- /**
73
- * ( begin auto-generated from PVector_x.xml )
74
- *
75
- * The x component of the vector. This field (variable) can be used to both
76
- * get and set the value (see above example.)
77
- *
78
- * ( end auto-generated )
79
- *
80
- * @webref pvector:field
81
- * @usage web_application
82
- * @brief The x component of the vector
83
- */
84
- public float x;
85
-
86
- /**
87
- * ( begin auto-generated from PVector_y.xml )
88
- *
89
- * The y component of the vector. This field (variable) can be used to both
90
- * get and set the value (see above example.)
91
- *
92
- * ( end auto-generated )
93
- *
94
- * @webref pvector:field
95
- * @usage web_application
96
- * @brief The y component of the vector
97
- */
98
- public float y;
99
-
100
- /**
101
- * ( begin auto-generated from PVector_z.xml )
102
- *
103
- * The z component of the vector. This field (variable) can be used to both
104
- * get and set the value (see above example.)
105
- *
106
- * ( end auto-generated )
107
- *
108
- * @webref pvector:field
109
- * @usage web_application
110
- * @brief The z component of the vector
111
- */
112
- public float z;
113
-
114
- /**
115
- * Array so that this can be temporarily used in an array context
116
- */
117
- transient protected float[] array;
118
-
119
- /**
120
- * Constructor for an empty vector: x, y, and z are set to 0.
121
- */
122
- public PVector() {
70
+ /**
71
+ * ( begin auto-generated from PVector_x.xml )
72
+ *
73
+ * The x component of the vector. This field (variable) can be used to both
74
+ * get and set the value (see above example.)
75
+ *
76
+ * ( end auto-generated )
77
+ *
78
+ * @webref pvector:field
79
+ * @usage web_application
80
+ * @brief The x component of the vector
81
+ */
82
+ public float x;
83
+
84
+ /**
85
+ * ( begin auto-generated from PVector_y.xml )
86
+ *
87
+ * The y component of the vector. This field (variable) can be used to both
88
+ * get and set the value (see above example.)
89
+ *
90
+ * ( end auto-generated )
91
+ *
92
+ * @webref pvector:field
93
+ * @usage web_application
94
+ * @brief The y component of the vector
95
+ */
96
+ public float y;
97
+
98
+ /**
99
+ * ( begin auto-generated from PVector_z.xml )
100
+ *
101
+ * The z component of the vector. This field (variable) can be used to both
102
+ * get and set the value (see above example.)
103
+ *
104
+ * ( end auto-generated )
105
+ *
106
+ * @webref pvector:field
107
+ * @usage web_application
108
+ * @brief The z component of the vector
109
+ */
110
+ public float z;
111
+
112
+ /** Array so that this can be temporarily used in an array context */
113
+ transient protected float[] array;
114
+
115
+
116
+ /**
117
+ * Constructor for an empty vector: x, y, and z are set to 0.
118
+ */
119
+ public PVector() {
120
+ }
121
+
122
+
123
+ /**
124
+ * Constructor for a 3D vector.
125
+ *
126
+ * @param x the x coordinate.
127
+ * @param y the y coordinate.
128
+ * @param z the z coordinate.
129
+ */
130
+ public PVector(float x, float y, float z) {
131
+ this.x = x;
132
+ this.y = y;
133
+ this.z = z;
134
+ }
135
+
136
+
137
+ /**
138
+ * Constructor for a 2D vector: z coordinate is set to 0.
139
+ */
140
+ public PVector(float x, float y) {
141
+ this.x = x;
142
+ this.y = y;
143
+ }
144
+
145
+
146
+ /**
147
+ * ( begin auto-generated from PVector_set.xml )
148
+ *
149
+ * Sets the x, y, and z component of the vector using two or three separate
150
+ * variables, the data from a PVector, or the values from a float array.
151
+ *
152
+ * ( end auto-generated )
153
+ *
154
+ * @webref pvector:method
155
+ * @param x the x component of the vector
156
+ * @param y the y component of the vector
157
+ * @param z the z component of the vector
158
+ * @brief Set the components of the vector
159
+ */
160
+ public PVector set(float x, float y, float z) {
161
+ this.x = x;
162
+ this.y = y;
163
+ this.z = z;
164
+ return this;
165
+ }
166
+
167
+
168
+ /**
169
+ * @param x the x component of the vector
170
+ * @param y the y component of the vector
171
+ */
172
+ public PVector set(float x, float y) {
173
+ this.x = x;
174
+ this.y = y;
175
+ this.z = 0;
176
+ return this;
177
+ }
178
+
179
+
180
+ /**
181
+ * @param v any variable of type PVector
182
+ */
183
+ public PVector set(PVector v) {
184
+ x = v.x;
185
+ y = v.y;
186
+ z = v.z;
187
+ return this;
188
+ }
189
+
190
+
191
+ /**
192
+ * Set the x, y (and maybe z) coordinates using a float[] array as the source.
193
+ * @param source array to copy from
194
+ */
195
+ public PVector set(float[] source) {
196
+ if (source.length >= 2) {
197
+ x = source[0];
198
+ y = source[1];
123
199
  }
124
-
125
- /**
126
- * Constructor for a 3D vector.
127
- *
128
- * @param x the x coordinate.
129
- * @param y the y coordinate.
130
- * @param z the z coordinate.
131
- */
132
- public PVector(float x, float y, float z) {
133
- this.x = x;
134
- this.y = y;
135
- this.z = z;
200
+ if (source.length >= 3) {
201
+ z = source[2];
202
+ } else {
203
+ z = 0;
136
204
  }
137
-
138
- /**
139
- * Constructor for a 2D vector: z coordinate is set to 0.
140
- */
141
- public PVector(float x, float y) {
142
- this.x = x;
143
- this.y = y;
205
+ return this;
206
+ }
207
+
208
+
209
+ /**
210
+ * ( begin auto-generated from PVector_random2D.xml )
211
+ *
212
+ * Make a new 2D unit vector with a random direction. If you pass in "this"
213
+ * as an argument, it will use the PApplet's random number generator. You can
214
+ * also pass in a target PVector to fill.
215
+ *
216
+ * @webref pvector:method
217
+ * @usage web_application
218
+ * @return the random PVector
219
+ * @brief Make a new 2D unit vector with a random direction.
220
+ * @see PVector#random3D()
221
+ */
222
+ static public PVector random2D() {
223
+ return random2D(null, null);
224
+ }
225
+
226
+
227
+ /**
228
+ * Make a new 2D unit vector with a random direction
229
+ * using Processing's current random number generator
230
+ * @param parent current PApplet instance
231
+ * @return the random PVector
232
+ */
233
+ static public PVector random2D(PApplet parent) {
234
+ return random2D(null, parent);
235
+ }
236
+
237
+ /**
238
+ * Set a 2D vector to a random unit vector with a random direction
239
+ * @param target the target vector (if null, a new vector will be created)
240
+ * @return the random PVector
241
+ */
242
+ static public PVector random2D(PVector target) {
243
+ return random2D(target, null);
244
+ }
245
+
246
+
247
+ /**
248
+ * Make a new 2D unit vector with a random direction. Pass in the parent
249
+ * PApplet if you want randomSeed() to work (and be predictable). Or leave
250
+ * it null and be... random.
251
+ * @return the random PVector
252
+ */
253
+ static public PVector random2D(PVector target, PApplet parent) {
254
+ return (parent == null) ?
255
+ fromAngle((float) (Math.random() * Math.PI*2), target) :
256
+ fromAngle(parent.random(PConstants.TAU), target);
257
+ }
258
+
259
+
260
+ /**
261
+ * ( begin auto-generated from PVector_random3D.xml )
262
+ *
263
+ * Make a new 3D unit vector with a random direction. If you pass in "this"
264
+ * as an argument, it will use the PApplet's random number generator. You can
265
+ * also pass in a target PVector to fill.
266
+ *
267
+ * @webref pvector:method
268
+ * @usage web_application
269
+ * @return the random PVector
270
+ * @brief Make a new 3D unit vector with a random direction.
271
+ * @see PVector#random2D()
272
+ */
273
+ static public PVector random3D() {
274
+ return random3D(null, null);
275
+ }
276
+
277
+
278
+ /**
279
+ * Make a new 3D unit vector with a random direction
280
+ * using Processing's current random number generator
281
+ * @param parent current PApplet instance
282
+ * @return the random PVector
283
+ */
284
+ static public PVector random3D(PApplet parent) {
285
+ return random3D(null, parent);
286
+ }
287
+
288
+
289
+ /**
290
+ * Set a 3D vector to a random unit vector with a random direction
291
+ * @param target the target vector (if null, a new vector will be created)
292
+ * @return the random PVector
293
+ */
294
+ static public PVector random3D(PVector target) {
295
+ return random3D(target, null);
296
+ }
297
+
298
+
299
+ /**
300
+ * Make a new 3D unit vector with a random direction
301
+ * @return the random PVector
302
+ */
303
+ static public PVector random3D(PVector target, PApplet parent) {
304
+ float angle;
305
+ float vz;
306
+ if (parent == null) {
307
+ angle = (float) (Math.random()*Math.PI*2);
308
+ vz = (float) (Math.random()*2-1);
309
+ } else {
310
+ angle = parent.random(PConstants.TWO_PI);
311
+ vz = parent.random(-1,1);
144
312
  }
145
-
146
- /**
147
- * ( begin auto-generated from PVector_set.xml )
148
- *
149
- * Sets the x, y, and z component of the vector using two or three separate
150
- * variables, the data from a PVector, or the values from a float array.
151
- *
152
- * ( end auto-generated )
153
- *
154
- * @webref pvector:method
155
- * @param x the x component of the vector
156
- * @param y the y component of the vector
157
- * @param z the z component of the vector
158
- * @brief Set the components of the vector
159
- */
160
- public PVector set(float x, float y, float z) {
161
- this.x = x;
162
- this.y = y;
163
- this.z = z;
164
- return this;
313
+ float vx = (float) (Math.sqrt(1-vz*vz)*Math.cos(angle));
314
+ float vy = (float) (Math.sqrt(1-vz*vz)*Math.sin(angle));
315
+ if (target == null) {
316
+ target = new PVector(vx, vy, vz);
317
+ //target.normalize(); // Should be unnecessary
318
+ } else {
319
+ target.set(vx,vy,vz);
165
320
  }
166
-
167
- /**
168
- * @param x the x component of the vector
169
- * @param y the y component of the vector
170
- */
171
- public PVector set(float x, float y) {
172
- this.x = x;
173
- this.y = y;
174
- this.z = 0;
175
- return this;
321
+ return target;
322
+ }
323
+
324
+
325
+ /**
326
+ * ( begin auto-generated from PVector_sub.xml )
327
+ *
328
+ * Make a new 2D unit vector from an angle.
329
+ *
330
+ * ( end auto-generated )
331
+ *
332
+ * @webref pvector:method
333
+ * @usage web_application
334
+ * @brief Make a new 2D unit vector from an angle
335
+ * @param angle the angle in radians
336
+ * @return the new unit PVector
337
+ */
338
+ static public PVector fromAngle(float angle) {
339
+ return fromAngle(angle,null);
340
+ }
341
+
342
+
343
+ /**
344
+ * Make a new 2D unit vector from an angle
345
+ *
346
+ * @param target the target vector (if null, a new vector will be created)
347
+ * @return the PVector
348
+ */
349
+ static public PVector fromAngle(float angle, PVector target) {
350
+ if (target == null) {
351
+ target = new PVector((float)Math.cos(angle),(float)Math.sin(angle),0);
352
+ } else {
353
+ target.set((float)Math.cos(angle),(float)Math.sin(angle),0);
176
354
  }
177
-
178
- /**
179
- * @param v any variable of type PVector
180
- */
181
- public PVector set(PVector v) {
182
- x = v.x;
183
- y = v.y;
184
- z = v.z;
185
- return this;
186
- }
187
-
188
- /**
189
- * Set the x, y (and maybe z) coordinates using a float[] array as the
190
- * source.
191
- *
192
- * @param source array to copy from
193
- */
194
- public PVector set(float[] source) {
195
- if (source.length >= 2) {
196
- x = source[0];
197
- y = source[1];
198
- }
199
- if (source.length >= 3) {
200
- z = source[2];
201
- } else {
202
- z = 0;
203
- }
204
- return this;
355
+ return target;
356
+ }
357
+
358
+
359
+ /**
360
+ * ( begin auto-generated from PVector_copy.xml )
361
+ *
362
+ * Gets a copy of the vector, returns a PVector object.
363
+ *
364
+ * ( end auto-generated )
365
+ *
366
+ * @webref pvector:method
367
+ * @usage web_application
368
+ * @brief Get a copy of the vector
369
+ */
370
+ public PVector copy() {
371
+ return new PVector(x, y, z);
372
+ }
373
+
374
+
375
+ @Deprecated
376
+ public PVector get() {
377
+ return copy();
378
+ }
379
+
380
+
381
+ /**
382
+ * @param target
383
+ */
384
+ public float[] get(float[] target) {
385
+ if (target == null) {
386
+ return new float[] { x, y, z };
205
387
  }
206
-
207
- /**
208
- * ( begin auto-generated from PVector_random2D.xml )
209
- *
210
- * Make a new 2D unit vector with a random direction. If you pass in "this"
211
- * as an argument, it will use the PApplet's random number generator. You
212
- * can also pass in a target PVector to fill.
213
- *
214
- * @webref pvector:method
215
- * @usage web_application
216
- * @return the random PVector
217
- * @brief Make a new 2D unit vector with a random direction.
218
- * @see PVector#random3D()
219
- */
220
- static public PVector random2D() {
221
- return random2D(null, null);
222
- }
223
-
224
- /**
225
- * Make a new 2D unit vector with a random direction using Processing's
226
- * current random number generator
227
- *
228
- * @param parent current PApplet instance
229
- * @return the random PVector
230
- */
231
- static public PVector random2D(PApplet parent) {
232
- return random2D(null, parent);
388
+ if (target.length >= 2) {
389
+ target[0] = x;
390
+ target[1] = y;
233
391
  }
234
-
235
- /**
236
- * Set a 2D vector to a random unit vector with a random direction
237
- *
238
- * @param target the target vector (if null, a new vector will be created)
239
- * @return the random PVector
240
- */
241
- static public PVector random2D(PVector target) {
242
- return random2D(target, null);
392
+ if (target.length >= 3) {
393
+ target[2] = z;
243
394
  }
244
-
245
- /**
246
- * Make a new 2D unit vector with a random direction. Pass in the parent
247
- * PApplet if you want randomSeed() to work (and be predictable). Or leave
248
- * it null and be... random.
249
- *
250
- * @return the random PVector
251
- */
252
- static public PVector random2D(PVector target, PApplet parent) {
253
- return (parent == null)
254
- ? fromAngle((float) (Math.random() * Math.PI * 2), target)
255
- : fromAngle(parent.random(PConstants.TAU), target);
395
+ return target;
396
+ }
397
+
398
+
399
+ /**
400
+ * ( begin auto-generated from PVector_mag.xml )
401
+ *
402
+ * Calculates the magnitude (length) of the vector and returns the result
403
+ * as a float (this is simply the equation <em>sqrt(x*x + y*y + z*z)</em>.)
404
+ *
405
+ * ( end auto-generated )
406
+ *
407
+ * @webref pvector:method
408
+ * @usage web_application
409
+ * @brief Calculate the magnitude of the vector
410
+ * @return magnitude (length) of the vector
411
+ * @see PVector#magSq()
412
+ */
413
+ public float mag() {
414
+ return (float) Math.sqrt(x*x + y*y + z*z);
415
+ }
416
+
417
+
418
+ /**
419
+ * ( begin auto-generated from PVector_mag.xml )
420
+ *
421
+ * Calculates the squared magnitude of the vector and returns the result
422
+ * as a float (this is simply the equation <em>(x*x + y*y + z*z)</em>.)
423
+ * Faster if the real length is not required in the
424
+ * case of comparing vectors, etc.
425
+ *
426
+ * ( end auto-generated )
427
+ *
428
+ * @webref pvector:method
429
+ * @usage web_application
430
+ * @brief Calculate the magnitude of the vector, squared
431
+ * @return squared magnitude of the vector
432
+ * @see PVector#mag()
433
+ */
434
+ public float magSq() {
435
+ return (x*x + y*y + z*z);
436
+ }
437
+
438
+
439
+ /**
440
+ * ( begin auto-generated from PVector_add.xml )
441
+ *
442
+ * Adds x, y, and z components to a vector, adds one vector to another, or
443
+ * adds two independent vectors together. The version of the method that
444
+ * adds two vectors together is a static method and returns a PVector, the
445
+ * others have no return value -- they act directly on the vector. See the
446
+ * examples for more context.
447
+ *
448
+ * ( end auto-generated )
449
+ *
450
+ * @webref pvector:method
451
+ * @usage web_application
452
+ * @param v the vector to be added
453
+ * @brief Adds x, y, and z components to a vector, one vector to another, or two independent vectors
454
+ */
455
+ public PVector add(PVector v) {
456
+ x += v.x;
457
+ y += v.y;
458
+ z += v.z;
459
+ return this;
460
+ }
461
+
462
+
463
+ /**
464
+ * @param x x component of the vector
465
+ * @param y y component of the vector
466
+ */
467
+ public PVector add(float x, float y) {
468
+ this.x += x;
469
+ this.y += y;
470
+ return this;
471
+ }
472
+
473
+
474
+ /**
475
+ * @param z z component of the vector
476
+ */
477
+ public PVector add(float x, float y, float z) {
478
+ this.x += x;
479
+ this.y += y;
480
+ this.z += z;
481
+ return this;
482
+ }
483
+
484
+
485
+ /**
486
+ * Add two vectors
487
+ * @param v1 a vector
488
+ * @param v2 another vector
489
+ */
490
+ static public PVector add(PVector v1, PVector v2) {
491
+ return add(v1, v2, null);
492
+ }
493
+
494
+
495
+ /**
496
+ * Add two vectors into a target vector
497
+ * @param target the target vector (if null, a new vector will be created)
498
+ */
499
+ static public PVector add(PVector v1, PVector v2, PVector target) {
500
+ if (target == null) {
501
+ target = new PVector(v1.x + v2.x,v1.y + v2.y, v1.z + v2.z);
502
+ } else {
503
+ target.set(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
256
504
  }
257
-
258
- /**
259
- * ( begin auto-generated from PVector_random3D.xml )
260
- *
261
- * Make a new 3D unit vector with a random direction. If you pass in "this"
262
- * as an argument, it will use the PApplet's random number generator. You
263
- * can also pass in a target PVector to fill.
264
- *
265
- * @webref pvector:method
266
- * @usage web_application
267
- * @return the random PVector
268
- * @brief Make a new 3D unit vector with a random direction.
269
- * @see PVector#random2D()
270
- */
271
- static public PVector random3D() {
272
- return random3D(null, null);
505
+ return target;
506
+ }
507
+
508
+
509
+ /**
510
+ * ( begin auto-generated from PVector_sub.xml )
511
+ *
512
+ * Subtracts x, y, and z components from a vector, subtracts one vector
513
+ * from another, or subtracts two independent vectors. The version of the
514
+ * method that subtracts two vectors is a static method and returns a
515
+ * PVector, the others have no return value -- they act directly on the
516
+ * vector. See the examples for more context.
517
+ *
518
+ * ( end auto-generated )
519
+ *
520
+ * @webref pvector:method
521
+ * @usage web_application
522
+ * @param v any variable of type PVector
523
+ * @brief Subtract x, y, and z components from a vector, one vector from another, or two independent vectors
524
+ */
525
+ public PVector sub(PVector v) {
526
+ x -= v.x;
527
+ y -= v.y;
528
+ z -= v.z;
529
+ return this;
530
+ }
531
+
532
+
533
+ /**
534
+ * @param x the x component of the vector
535
+ * @param y the y component of the vector
536
+ */
537
+ public PVector sub(float x, float y) {
538
+ this.x -= x;
539
+ this.y -= y;
540
+ return this;
541
+ }
542
+
543
+
544
+ /**
545
+ * @param z the z component of the vector
546
+ */
547
+ public PVector sub(float x, float y, float z) {
548
+ this.x -= x;
549
+ this.y -= y;
550
+ this.z -= z;
551
+ return this;
552
+ }
553
+
554
+
555
+ /**
556
+ * Subtract one vector from another
557
+ * @param v1 the x, y, and z components of a PVector object
558
+ * @param v2 the x, y, and z components of a PVector object
559
+ */
560
+ static public PVector sub(PVector v1, PVector v2) {
561
+ return sub(v1, v2, null);
562
+ }
563
+
564
+
565
+ /**
566
+ * Subtract one vector from another and store in another vector
567
+ * @param target PVector in which to store the result
568
+ */
569
+ static public PVector sub(PVector v1, PVector v2, PVector target) {
570
+ if (target == null) {
571
+ target = new PVector(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
572
+ } else {
573
+ target.set(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
273
574
  }
274
-
275
- /**
276
- * Make a new 3D unit vector with a random direction using Processing's
277
- * current random number generator
278
- *
279
- * @param parent current PApplet instance
280
- * @return the random PVector
281
- */
282
- static public PVector random3D(PApplet parent) {
283
- return random3D(null, parent);
575
+ return target;
576
+ }
577
+
578
+
579
+ /**
580
+ * ( begin auto-generated from PVector_mult.xml )
581
+ *
582
+ * Multiplies a vector by a scalar or multiplies one vector by another.
583
+ *
584
+ * ( end auto-generated )
585
+ *
586
+ * @webref pvector:method
587
+ * @usage web_application
588
+ * @brief Multiply a vector by a scalar
589
+ * @param n the number to multiply with the vector
590
+ */
591
+ public PVector mult(float n) {
592
+ x *= n;
593
+ y *= n;
594
+ z *= n;
595
+ return this;
596
+ }
597
+
598
+
599
+ /**
600
+ * @param v the vector to multiply by the scalar
601
+ */
602
+ static public PVector mult(PVector v, float n) {
603
+ return mult(v, n, null);
604
+ }
605
+
606
+
607
+ /**
608
+ * Multiply a vector by a scalar, and write the result into a target PVector.
609
+ * @param target PVector in which to store the result
610
+ */
611
+ static public PVector mult(PVector v, float n, PVector target) {
612
+ if (target == null) {
613
+ target = new PVector(v.x*n, v.y*n, v.z*n);
614
+ } else {
615
+ target.set(v.x*n, v.y*n, v.z*n);
284
616
  }
285
-
286
- /**
287
- * Set a 3D vector to a random unit vector with a random direction
288
- *
289
- * @param target the target vector (if null, a new vector will be created)
290
- * @return the random PVector
291
- */
292
- static public PVector random3D(PVector target) {
293
- return random3D(target, null);
617
+ return target;
618
+ }
619
+
620
+
621
+ /**
622
+ * ( begin auto-generated from PVector_div.xml )
623
+ *
624
+ * Divides a vector by a scalar or divides one vector by another.
625
+ *
626
+ * ( end auto-generated )
627
+ *
628
+ * @webref pvector:method
629
+ * @usage web_application
630
+ * @brief Divide a vector by a scalar
631
+ * @param n the number by which to divide the vector
632
+ */
633
+ public PVector div(float n) {
634
+ x /= n;
635
+ y /= n;
636
+ z /= n;
637
+ return this;
638
+ }
639
+
640
+
641
+ /**
642
+ * Divide a vector by a scalar and return the result in a new vector.
643
+ * @param v the vector to divide by the scalar
644
+ * @return a new vector that is v1 / n
645
+ */
646
+ static public PVector div(PVector v, float n) {
647
+ return div(v, n, null);
648
+ }
649
+
650
+
651
+ /**
652
+ * Divide a vector by a scalar and store the result in another vector.
653
+ * @param target PVector in which to store the result
654
+ */
655
+ static public PVector div(PVector v, float n, PVector target) {
656
+ if (target == null) {
657
+ target = new PVector(v.x/n, v.y/n, v.z/n);
658
+ } else {
659
+ target.set(v.x/n, v.y/n, v.z/n);
294
660
  }
295
-
296
- /**
297
- * Make a new 3D unit vector with a random direction
298
- *
299
- * @return the random PVector
300
- */
301
- static public PVector random3D(PVector target, PApplet parent) {
302
- float angle;
303
- float vz;
304
- if (parent == null) {
305
- angle = (float) (Math.random() * Math.PI * 2);
306
- vz = (float) (Math.random() * 2 - 1);
307
- } else {
308
- angle = parent.random(PConstants.TWO_PI);
309
- vz = parent.random(-1, 1);
310
- }
311
- float vx = (float) (Math.sqrt(1 - vz * vz) * Math.cos(angle));
312
- float vy = (float) (Math.sqrt(1 - vz * vz) * Math.sin(angle));
313
- if (target == null) {
314
- target = new PVector(vx, vy, vz);
315
- //target.normalize(); // Should be unnecessary
316
- } else {
317
- target.set(vx, vy, vz);
318
- }
319
- return target;
661
+ return target;
662
+ }
663
+
664
+
665
+ /**
666
+ * ( begin auto-generated from PVector_dist.xml )
667
+ *
668
+ * Calculates the Euclidean distance between two points (considering a
669
+ * point as a vector object).
670
+ *
671
+ * ( end auto-generated )
672
+ *
673
+ * @webref pvector:method
674
+ * @usage web_application
675
+ * @param v the x, y, and z coordinates of a PVector
676
+ * @brief Calculate the distance between two points
677
+ */
678
+ public float dist(PVector v) {
679
+ float dx = x - v.x;
680
+ float dy = y - v.y;
681
+ float dz = z - v.z;
682
+ return (float) Math.sqrt(dx*dx + dy*dy + dz*dz);
683
+ }
684
+
685
+
686
+ /**
687
+ * @param v1 any variable of type PVector
688
+ * @param v2 any variable of type PVector
689
+ * @return the Euclidean distance between v1 and v2
690
+ */
691
+ static public float dist(PVector v1, PVector v2) {
692
+ float dx = v1.x - v2.x;
693
+ float dy = v1.y - v2.y;
694
+ float dz = v1.z - v2.z;
695
+ return (float) Math.sqrt(dx*dx + dy*dy + dz*dz);
696
+ }
697
+
698
+
699
+ /**
700
+ * ( begin auto-generated from PVector_dot.xml )
701
+ *
702
+ * Calculates the dot product of two vectors.
703
+ *
704
+ * ( end auto-generated )
705
+ *
706
+ * @webref pvector:method
707
+ * @usage web_application
708
+ * @param v any variable of type PVector
709
+ * @return the dot product
710
+ * @brief Calculate the dot product of two vectors
711
+ */
712
+ public float dot(PVector v) {
713
+ return x*v.x + y*v.y + z*v.z;
714
+ }
715
+
716
+
717
+ /**
718
+ * @param x x component of the vector
719
+ * @param y y component of the vector
720
+ * @param z z component of the vector
721
+ */
722
+ public float dot(float x, float y, float z) {
723
+ return this.x*x + this.y*y + this.z*z;
724
+ }
725
+
726
+
727
+ /**
728
+ * @param v1 any variable of type PVector
729
+ * @param v2 any variable of type PVector
730
+ */
731
+ static public float dot(PVector v1, PVector v2) {
732
+ return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
733
+ }
734
+
735
+
736
+ /**
737
+ * ( begin auto-generated from PVector_cross.xml )
738
+ *
739
+ * Calculates and returns a vector composed of the cross product between
740
+ * two vectors.
741
+ *
742
+ * ( end auto-generated )
743
+ *
744
+ * @webref pvector:method
745
+ * @param v the vector to calculate the cross product
746
+ * @brief Calculate and return the cross product
747
+ */
748
+ public PVector cross(PVector v) {
749
+ return cross(v, null);
750
+ }
751
+
752
+
753
+ /**
754
+ * @param v any variable of type PVector
755
+ * @param target PVector to store the result
756
+ */
757
+ public PVector cross(PVector v, PVector target) {
758
+ float crossX = y * v.z - v.y * z;
759
+ float crossY = z * v.x - v.z * x;
760
+ float crossZ = x * v.y - v.x * y;
761
+
762
+ if (target == null) {
763
+ target = new PVector(crossX, crossY, crossZ);
764
+ } else {
765
+ target.set(crossX, crossY, crossZ);
320
766
  }
321
-
322
- /**
323
- * ( begin auto-generated from PVector_sub.xml )
324
- *
325
- * Make a new 2D unit vector from an angle.
326
- *
327
- * ( end auto-generated )
328
- *
329
- * @webref pvector:method
330
- * @usage web_application
331
- * @brief Make a new 2D unit vector from an angle
332
- * @param angle the angle in radians
333
- * @return the new unit PVector
334
- */
335
- static public PVector fromAngle(float angle) {
336
- return fromAngle(angle, null);
767
+ return target;
768
+ }
769
+
770
+
771
+ /**
772
+ * @param v1 any variable of type PVector
773
+ * @param v2 any variable of type PVector
774
+ * @param target PVector to store the result
775
+ */
776
+ static public PVector cross(PVector v1, PVector v2, PVector target) {
777
+ float crossX = v1.y * v2.z - v2.y * v1.z;
778
+ float crossY = v1.z * v2.x - v2.z * v1.x;
779
+ float crossZ = v1.x * v2.y - v2.x * v1.y;
780
+
781
+ if (target == null) {
782
+ target = new PVector(crossX, crossY, crossZ);
783
+ } else {
784
+ target.set(crossX, crossY, crossZ);
337
785
  }
338
-
339
- /**
340
- * Make a new 2D unit vector from an angle
341
- *
342
- * @param target the target vector (if null, a new vector will be created)
343
- * @return the PVector
344
- */
345
- static public PVector fromAngle(float angle, PVector target) {
346
- if (target == null) {
347
- target = new PVector((float) Math.cos(angle), (float) Math.sin(angle), 0);
348
- } else {
349
- target.set((float) Math.cos(angle), (float) Math.sin(angle), 0);
350
- }
351
- return target;
786
+ return target;
787
+ }
788
+
789
+
790
+ /**
791
+ * ( begin auto-generated from PVector_normalize.xml )
792
+ *
793
+ * Normalize the vector to length 1 (make it a unit vector).
794
+ *
795
+ * ( end auto-generated )
796
+ *
797
+ * @webref pvector:method
798
+ * @usage web_application
799
+ * @brief Normalize the vector to a length of 1
800
+ */
801
+ public PVector normalize() {
802
+ float m = mag();
803
+ if (m != 0 && m != 1) {
804
+ div(m);
352
805
  }
806
+ return this;
807
+ }
353
808
 
354
- /**
355
- * ( begin auto-generated from PVector_copy.xml )
356
- *
357
- * Gets a copy of the vector, returns a PVector object.
358
- *
359
- * ( end auto-generated )
360
- *
361
- * @webref pvector:method
362
- * @usage web_application
363
- * @brief Get a copy of the vector
364
- */
365
- public PVector copy() {
366
- return new PVector(x, y, z);
367
- }
368
809
 
369
- @Deprecated
370
- public PVector get() {
371
- return copy();
810
+ /**
811
+ * @param target Set to null to create a new vector
812
+ * @return a new vector (if target was null), or target
813
+ */
814
+ public PVector normalize(PVector target) {
815
+ if (target == null) {
816
+ target = new PVector();
372
817
  }
373
-
374
- /**
375
- * @param target
376
- */
377
- public float[] get(float[] target) {
378
- if (target == null) {
379
- return new float[]{x, y, z};
380
- }
381
- if (target.length >= 2) {
382
- target[0] = x;
383
- target[1] = y;
384
- }
385
- if (target.length >= 3) {
386
- target[2] = z;
387
- }
388
- return target;
818
+ float m = mag();
819
+ if (m > 0) {
820
+ target.set(x/m, y/m, z/m);
821
+ } else {
822
+ target.set(x, y, z);
389
823
  }
390
-
391
- /**
392
- * ( begin auto-generated from PVector_mag.xml )
393
- *
394
- * Calculates the magnitude (length) of the vector and returns the result as
395
- * a float (this is simply the equation <em>sqrt(x*x + y*y + z*z)</em>.)
396
- *
397
- * ( end auto-generated )
398
- *
399
- * @webref pvector:method
400
- * @usage web_application
401
- * @brief Calculate the magnitude of the vector
402
- * @return magnitude (length) of the vector
403
- * @see PVector#magSq()
404
- */
405
- public float mag() {
406
- return (float) Math.sqrt(x * x + y * y + z * z);
824
+ return target;
825
+ }
826
+
827
+
828
+ /**
829
+ * ( begin auto-generated from PVector_limit.xml )
830
+ *
831
+ * Limit the magnitude of this vector to the value used for the <b>max</b> parameter.
832
+ *
833
+ * ( end auto-generated )
834
+ *
835
+ * @webref pvector:method
836
+ * @usage web_application
837
+ * @param max the maximum magnitude for the vector
838
+ * @brief Limit the magnitude of the vector
839
+ */
840
+ public PVector limit(float max) {
841
+ if (magSq() > max*max) {
842
+ normalize();
843
+ mult(max);
407
844
  }
408
-
409
- /**
410
- * ( begin auto-generated from PVector_mag.xml )
411
- *
412
- * Calculates the squared magnitude of the vector and returns the result as
413
- * a float (this is simply the equation <em>(x*x + y*y + z*z)</em>.) Faster
414
- * if the real length is not required in the case of comparing vectors, etc.
415
- *
416
- * ( end auto-generated )
417
- *
418
- * @webref pvector:method
419
- * @usage web_application
420
- * @brief Calculate the magnitude of the vector, squared
421
- * @return squared magnitude of the vector
422
- * @see PVector#mag()
423
- */
424
- public float magSq() {
425
- return (x * x + y * y + z * z);
845
+ return this;
846
+ }
847
+
848
+
849
+ /**
850
+ * ( begin auto-generated from PVector_setMag.xml )
851
+ *
852
+ * Set the magnitude of this vector to the value used for the <b>len</b> parameter.
853
+ *
854
+ * ( end auto-generated )
855
+ *
856
+ * @webref pvector:method
857
+ * @usage web_application
858
+ * @param len the new length for this vector
859
+ * @brief Set the magnitude of the vector
860
+ */
861
+ public PVector setMag(float len) {
862
+ normalize();
863
+ mult(len);
864
+ return this;
865
+ }
866
+
867
+
868
+ /**
869
+ * Sets the magnitude of this vector, storing the result in another vector.
870
+ * @param target Set to null to create a new vector
871
+ * @param len the new length for the new vector
872
+ * @return a new vector (if target was null), or target
873
+ */
874
+ public PVector setMag(PVector target, float len) {
875
+ target = normalize(target);
876
+ target.mult(len);
877
+ return target;
878
+ }
879
+
880
+
881
+ /**
882
+ * ( begin auto-generated from PVector_setMag.xml )
883
+ *
884
+ * Calculate the angle of rotation for this vector (only 2D vectors)
885
+ *
886
+ * ( end auto-generated )
887
+ *
888
+ * @webref pvector:method
889
+ * @usage web_application
890
+ * @return the angle of rotation
891
+ * @brief Calculate the angle of rotation for this vector
892
+ */
893
+ public float heading() {
894
+ float angle = (float) Math.atan2(y, x);
895
+ return angle;
896
+ }
897
+
898
+
899
+ @Deprecated
900
+ public float heading2D() {
901
+ return heading();
902
+ }
903
+
904
+
905
+ /**
906
+ * ( begin auto-generated from PVector_rotate.xml )
907
+ *
908
+ * Rotate the vector by an angle (only 2D vectors), magnitude remains the same
909
+ *
910
+ * ( end auto-generated )
911
+ *
912
+ * @webref pvector:method
913
+ * @usage web_application
914
+ * @brief Rotate the vector by an angle (2D only)
915
+ * @param theta the angle of rotation
916
+ */
917
+ public PVector rotate(float theta) {
918
+ float temp = x;
919
+ // Might need to check for rounding errors like with angleBetween function?
920
+ x = x*PApplet.cos(theta) - y*PApplet.sin(theta);
921
+ y = temp*PApplet.sin(theta) + y*PApplet.cos(theta);
922
+ return this;
923
+ }
924
+
925
+
926
+ /**
927
+ * ( begin auto-generated from PVector_rotate.xml )
928
+ *
929
+ * Linear interpolate the vector to another vector
930
+ *
931
+ * ( end auto-generated )
932
+ *
933
+ * @webref pvector:method
934
+ * @usage web_application
935
+ * @brief Linear interpolate the vector to another vector
936
+ * @param v the vector to lerp to
937
+ * @param amt The amount of interpolation; some value between 0.0 (old vector) and 1.0 (new vector). 0.1 is very near the old vector; 0.5 is halfway in between.
938
+ * @see PApplet#lerp(float, float, float)
939
+ */
940
+ public PVector lerp(PVector v, float amt) {
941
+ x = PApplet.lerp(x, v.x, amt);
942
+ y = PApplet.lerp(y, v.y, amt);
943
+ z = PApplet.lerp(z, v.z, amt);
944
+ return this;
945
+ }
946
+
947
+
948
+ /**
949
+ * Linear interpolate between two vectors (returns a new PVector object)
950
+ * @param v1 the vector to start from
951
+ * @param v2 the vector to lerp to
952
+ * @param amt
953
+ * @return
954
+ */
955
+ public static PVector lerp(PVector v1, PVector v2, float amt) {
956
+ PVector v = v1.copy();
957
+ v.lerp(v2, amt);
958
+ return v;
959
+ }
960
+
961
+
962
+ /**
963
+ * Linear interpolate the vector to x,y,z values
964
+ * @param x the x component to lerp to
965
+ * @param y the y component to lerp to
966
+ * @param z the z component to lerp to
967
+ * @param amt
968
+ * @return
969
+ */
970
+ public PVector lerp(float x, float y, float z, float amt) {
971
+ this.x = PApplet.lerp(this.x, x, amt);
972
+ this.y = PApplet.lerp(this.y, y, amt);
973
+ this.z = PApplet.lerp(this.z, z, amt);
974
+ return this;
975
+ }
976
+
977
+
978
+ /**
979
+ * ( begin auto-generated from PVector_angleBetween.xml )
980
+ *
981
+ * Calculates and returns the angle (in radians) between two vectors.( end auto-generated )
982
+ *
983
+ *
984
+ * @return
985
+ * @webref pvector:method
986
+ * @usage web_application
987
+ * @param v1 the x, y, and z components of a PVector
988
+ * @param v2 the x, y, and z components of a PVector
989
+ * @brief Calculate and return the angle between two vectors
990
+ */
991
+ static public float angleBetween(PVector v1, PVector v2) {
992
+
993
+ // We get NaN if we pass in a zero vector which can cause problems
994
+ // Zero seems like a reasonable angle between a (0,0,0) vector and something else
995
+ if (v1.x == 0 && v1.y == 0 && v1.z == 0 ) return 0.0f;
996
+ if (v2.x == 0 && v2.y == 0 && v2.z == 0 ) return 0.0f;
997
+
998
+ double dot = v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
999
+ double v1mag = Math.sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z);
1000
+ double v2mag = Math.sqrt(v2.x * v2.x + v2.y * v2.y + v2.z * v2.z);
1001
+ // This should be a number between -1 and 1, since it's "normalized"
1002
+ double amt = dot / (v1mag * v2mag);
1003
+ // But if it's not due to rounding error, then we need to fix it
1004
+ // http://code.google.com/p/processing/issues/detail?id=340
1005
+ // Otherwise if outside the range, acos() will return NaN
1006
+ // http://www.cppreference.com/wiki/c/math/acos
1007
+ if (amt <= -1) {
1008
+ return PConstants.PI;
1009
+ } else if (amt >= 1) {
1010
+ // http://code.google.com/p/processing/issues/detail?id=435
1011
+ return 0;
426
1012
  }
427
-
428
- /**
429
- * ( begin auto-generated from PVector_add.xml )
430
- *
431
- * Adds x, y, and z components to a vector, adds one vector to another, or
432
- * adds two independent vectors together. The version of the method that
433
- * adds two vectors together is a static method and returns a PVector, the
434
- * others have no return value -- they act directly on the vector. See the
435
- * examples for more context.
436
- *
437
- * ( end auto-generated )
438
- *
439
- * @webref pvector:method
440
- * @usage web_application
441
- * @param v the vector to be added
442
- * @brief Adds x, y, and z components to a vector, one vector to another, or
443
- * two independent vectors
444
- */
445
- public PVector add(PVector v) {
446
- x += v.x;
447
- y += v.y;
448
- z += v.z;
449
- return this;
1013
+ return (float) Math.acos(amt);
1014
+ }
1015
+
1016
+
1017
+ @Override
1018
+ public String toString() {
1019
+ return "[ " + x + ", " + y + ", " + z + " ]";
1020
+ }
1021
+
1022
+
1023
+ /**
1024
+ * ( begin auto-generated from PVector_array.xml )
1025
+ *
1026
+ * Return a representation of this vector as a float array.This is only
1027
+ for temporary use. If used in any other fashion, the contents should be
1028
+ copied by using the <b>PVector.get()</b> method to copy into your own array.
1029
+ *
1030
+ * ( end auto-generated )
1031
+ *
1032
+ * @return
1033
+ * @webref pvector:method
1034
+ * @usage: web_application
1035
+ * @brief Return a representation of the vector as a float array
1036
+ */
1037
+ public float[] array() {
1038
+ if (array == null) {
1039
+ array = new float[3];
450
1040
  }
1041
+ array[0] = x;
1042
+ array[1] = y;
1043
+ array[2] = z;
1044
+ return array;
1045
+ }
451
1046
 
452
- /**
453
- * @param x x component of the vector
454
- * @param y y component of the vector
455
- */
456
- public PVector add(float x, float y) {
457
- this.x += x;
458
- this.y += y;
459
- return this;
460
- }
461
-
462
- /**
463
- * @param z z component of the vector
464
- */
465
- public PVector add(float x, float y, float z) {
466
- this.x += x;
467
- this.y += y;
468
- this.z += z;
469
- return this;
470
- }
471
-
472
- /**
473
- * Add two vectors
474
- *
475
- * @param v1 a vector
476
- * @param v2 another vector
477
- */
478
- static public PVector add(PVector v1, PVector v2) {
479
- return add(v1, v2, null);
480
- }
481
-
482
- /**
483
- * Add two vectors into a target vector
484
- *
485
- * @param target the target vector (if null, a new vector will be created)
486
- */
487
- static public PVector add(PVector v1, PVector v2, PVector target) {
488
- if (target == null) {
489
- target = new PVector(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
490
- } else {
491
- target.set(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
492
- }
493
- return target;
494
- }
495
-
496
- /**
497
- * ( begin auto-generated from PVector_sub.xml )
498
- *
499
- * Subtracts x, y, and z components from a vector, subtracts one vector from
500
- * another, or subtracts two independent vectors. The version of the method
501
- * that subtracts two vectors is a static method and returns a PVector, the
502
- * others have no return value -- they act directly on the vector. See the
503
- * examples for more context.
504
- *
505
- * ( end auto-generated )
506
- *
507
- * @webref pvector:method
508
- * @usage web_application
509
- * @param v any variable of type PVector
510
- * @brief Subtract x, y, and z components from a vector, one vector from
511
- * another, or two independent vectors
512
- */
513
- public PVector sub(PVector v) {
514
- x -= v.x;
515
- y -= v.y;
516
- z -= v.z;
517
- return this;
518
- }
519
-
520
- /**
521
- * @param x the x component of the vector
522
- * @param y the y component of the vector
523
- */
524
- public PVector sub(float x, float y) {
525
- this.x -= x;
526
- this.y -= y;
527
- return this;
528
- }
529
-
530
- /**
531
- * @param z the z component of the vector
532
- */
533
- public PVector sub(float x, float y, float z) {
534
- this.x -= x;
535
- this.y -= y;
536
- this.z -= z;
537
- return this;
538
- }
539
-
540
- /**
541
- * Subtract one vector from another
542
- *
543
- * @param v1 the x, y, and z components of a PVector object
544
- * @param v2 the x, y, and z components of a PVector object
545
- */
546
- static public PVector sub(PVector v1, PVector v2) {
547
- return sub(v1, v2, null);
548
- }
549
-
550
- /**
551
- * Subtract one vector from another and store in another vector
552
- *
553
- * @param target PVector in which to store the result
554
- */
555
- static public PVector sub(PVector v1, PVector v2, PVector target) {
556
- if (target == null) {
557
- target = new PVector(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
558
- } else {
559
- target.set(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
560
- }
561
- return target;
562
- }
563
-
564
- /**
565
- * ( begin auto-generated from PVector_mult.xml )
566
- *
567
- * Multiplies a vector by a scalar or multiplies one vector by another.
568
- *
569
- * ( end auto-generated )
570
- *
571
- * @webref pvector:method
572
- * @usage web_application
573
- * @brief Multiply a vector by a scalar
574
- * @param n the number to multiply with the vector
575
- */
576
- public PVector mult(float n) {
577
- x *= n;
578
- y *= n;
579
- z *= n;
580
- return this;
581
- }
582
-
583
- /**
584
- * @param v the vector to multiply by the scalar
585
- */
586
- static public PVector mult(PVector v, float n) {
587
- return mult(v, n, null);
588
- }
589
-
590
- /**
591
- * Multiply a vector by a scalar, and write the result into a target
592
- * PVector.
593
- *
594
- * @param target PVector in which to store the result
595
- */
596
- static public PVector mult(PVector v, float n, PVector target) {
597
- if (target == null) {
598
- target = new PVector(v.x * n, v.y * n, v.z * n);
599
- } else {
600
- target.set(v.x * n, v.y * n, v.z * n);
601
- }
602
- return target;
603
- }
604
-
605
- /**
606
- * ( begin auto-generated from PVector_div.xml )
607
- *
608
- * Divides a vector by a scalar or divides one vector by another.
609
- *
610
- * ( end auto-generated )
611
- *
612
- * @webref pvector:method
613
- * @usage web_application
614
- * @brief Divide a vector by a scalar
615
- * @param n the number by which to divide the vector
616
- */
617
- public PVector div(float n) {
618
- x /= n;
619
- y /= n;
620
- z /= n;
621
- return this;
622
- }
623
-
624
- /**
625
- * Divide a vector by a scalar and return the result in a new vector.
626
- *
627
- * @param v the vector to divide by the scalar
628
- * @return a new vector that is v1 / n
629
- */
630
- static public PVector div(PVector v, float n) {
631
- return div(v, n, null);
632
- }
633
-
634
- /**
635
- * Divide a vector by a scalar and store the result in another vector.
636
- *
637
- * @param target PVector in which to store the result
638
- */
639
- static public PVector div(PVector v, float n, PVector target) {
640
- if (target == null) {
641
- target = new PVector(v.x / n, v.y / n, v.z / n);
642
- } else {
643
- target.set(v.x / n, v.y / n, v.z / n);
644
- }
645
- return target;
646
- }
647
-
648
- /**
649
- * ( begin auto-generated from PVector_dist.xml )
650
- *
651
- * Calculates the Euclidean distance between two points (considering a point
652
- * as a vector object).
653
- *
654
- * ( end auto-generated )
655
- *
656
- * @webref pvector:method
657
- * @usage web_application
658
- * @param v the x, y, and z coordinates of a PVector
659
- * @brief Calculate the distance between two points
660
- */
661
- public float dist(PVector v) {
662
- float dx = x - v.x;
663
- float dy = y - v.y;
664
- float dz = z - v.z;
665
- return (float) Math.sqrt(dx * dx + dy * dy + dz * dz);
666
- }
667
-
668
- /**
669
- * @param v1 any variable of type PVector
670
- * @param v2 any variable of type PVector
671
- * @return the Euclidean distance between v1 and v2
672
- */
673
- static public float dist(PVector v1, PVector v2) {
674
- float dx = v1.x - v2.x;
675
- float dy = v1.y - v2.y;
676
- float dz = v1.z - v2.z;
677
- return (float) Math.sqrt(dx * dx + dy * dy + dz * dz);
678
- }
679
-
680
- /**
681
- * ( begin auto-generated from PVector_dot.xml )
682
- *
683
- * Calculates the dot product of two vectors.
684
- *
685
- * ( end auto-generated )
686
- *
687
- * @webref pvector:method
688
- * @usage web_application
689
- * @param v any variable of type PVector
690
- * @return the dot product
691
- * @brief Calculate the dot product of two vectors
692
- */
693
- public float dot(PVector v) {
694
- return x * v.x + y * v.y + z * v.z;
695
- }
696
-
697
- /**
698
- * @param x x component of the vector
699
- * @param y y component of the vector
700
- * @param z z component of the vector
701
- */
702
- public float dot(float x, float y, float z) {
703
- return this.x * x + this.y * y + this.z * z;
704
- }
705
-
706
- /**
707
- * @param v1 any variable of type PVector
708
- * @param v2 any variable of type PVector
709
- */
710
- static public float dot(PVector v1, PVector v2) {
711
- return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
712
- }
713
-
714
- /**
715
- * ( begin auto-generated from PVector_cross.xml )
716
- *
717
- * Calculates and returns a vector composed of the cross product between two
718
- * vectors.
719
- *
720
- * ( end auto-generated )
721
- *
722
- * @webref pvector:method
723
- * @param v the vector to calculate the cross product
724
- * @brief Calculate and return the cross product
725
- */
726
- public PVector cross(PVector v) {
727
- return cross(v, null);
728
- }
729
-
730
- /**
731
- * @param v any variable of type PVector
732
- * @param target PVector to store the result
733
- */
734
- public PVector cross(PVector v, PVector target) {
735
- float crossX = y * v.z - v.y * z;
736
- float crossY = z * v.x - v.z * x;
737
- float crossZ = x * v.y - v.x * y;
738
-
739
- if (target == null) {
740
- target = new PVector(crossX, crossY, crossZ);
741
- } else {
742
- target.set(crossX, crossY, crossZ);
743
- }
744
- return target;
745
- }
746
-
747
- /**
748
- * @param v1 any variable of type PVector
749
- * @param v2 any variable of type PVector
750
- * @param target PVector to store the result
751
- */
752
- static public PVector cross(PVector v1, PVector v2, PVector target) {
753
- float crossX = v1.y * v2.z - v2.y * v1.z;
754
- float crossY = v1.z * v2.x - v2.z * v1.x;
755
- float crossZ = v1.x * v2.y - v2.x * v1.y;
756
-
757
- if (target == null) {
758
- target = new PVector(crossX, crossY, crossZ);
759
- } else {
760
- target.set(crossX, crossY, crossZ);
761
- }
762
- return target;
763
- }
764
-
765
- /**
766
- * ( begin auto-generated from PVector_normalize.xml )
767
- *
768
- * Normalize the vector to length 1 (make it a unit vector).
769
- *
770
- * ( end auto-generated )
771
- *
772
- * @webref pvector:method
773
- * @usage web_application
774
- * @brief Normalize the vector to a length of 1
775
- */
776
- public PVector normalize() {
777
- float m = mag();
778
- if (m != 0 && m != 1) {
779
- div(m);
780
- }
781
- return this;
782
- }
783
-
784
- /**
785
- * @param target Set to null to create a new vector
786
- * @return a new vector (if target was null), or target
787
- */
788
- public PVector normalize(PVector target) {
789
- if (target == null) {
790
- target = new PVector();
791
- }
792
- float m = mag();
793
- if (m > 0) {
794
- target.set(x / m, y / m, z / m);
795
- } else {
796
- target.set(x, y, z);
797
- }
798
- return target;
799
- }
800
-
801
- /**
802
- * ( begin auto-generated from PVector_limit.xml )
803
- *
804
- * Limit the magnitude of this vector to the value used for the <b>max</b>
805
- * parameter.
806
- *
807
- * ( end auto-generated )
808
- *
809
- * @webref pvector:method
810
- * @usage web_application
811
- * @param max the maximum magnitude for the vector
812
- * @brief Limit the magnitude of the vector
813
- */
814
- public PVector limit(float max) {
815
- if (magSq() > max * max) {
816
- normalize();
817
- mult(max);
818
- }
819
- return this;
820
- }
821
-
822
- /**
823
- * ( begin auto-generated from PVector_setMag.xml )
824
- *
825
- * Set the magnitude of this vector to the value used for the <b>len</b>
826
- * parameter.
827
- *
828
- * ( end auto-generated )
829
- *
830
- * @webref pvector:method
831
- * @usage web_application
832
- * @param len the new length for this vector
833
- * @brief Set the magnitude of the vector
834
- */
835
- public PVector setMag(float len) {
836
- normalize();
837
- mult(len);
838
- return this;
839
- }
840
-
841
- /**
842
- * Sets the magnitude of this vector, storing the result in another vector.
843
- *
844
- * @param target Set to null to create a new vector
845
- * @param len the new length for the new vector
846
- * @return a new vector (if target was null), or target
847
- */
848
- public PVector setMag(PVector target, float len) {
849
- target = normalize(target);
850
- target.mult(len);
851
- return target;
852
- }
853
-
854
- /**
855
- * ( begin auto-generated from PVector_setMag.xml )
856
- *
857
- * Calculate the angle of rotation for this vector (only 2D vectors)
858
- *
859
- * ( end auto-generated )
860
- *
861
- * @webref pvector:method
862
- * @usage web_application
863
- * @return the angle of rotation
864
- * @brief Calculate the angle of rotation for this vector
865
- */
866
- public float heading() {
867
- float angle = (float) Math.atan2(y, x);
868
- return angle;
869
- }
870
-
871
- @Deprecated
872
- public float heading2D() {
873
- return heading();
874
- }
875
-
876
- /**
877
- * ( begin auto-generated from PVector_rotate.xml )
878
- *
879
- * Rotate the vector by an angle (only 2D vectors), magnitude remains the
880
- * same
881
- *
882
- * ( end auto-generated )
883
- *
884
- * @webref pvector:method
885
- * @usage web_application
886
- * @brief Rotate the vector by an angle (2D only)
887
- * @param theta the angle of rotation
888
- */
889
- public PVector rotate(float theta) {
890
- float temp = x;
891
- // Might need to check for rounding errors like with angleBetween function?
892
- x = x * PApplet.cos(theta) - y * PApplet.sin(theta);
893
- y = temp * PApplet.sin(theta) + y * PApplet.cos(theta);
894
- return this;
895
- }
896
-
897
- /**
898
- * ( begin auto-generated from PVector_rotate.xml )
899
- *
900
- * Linear interpolate the vector to another vector
901
- *
902
- * ( end auto-generated )
903
- *
904
- * @webref pvector:method
905
- * @usage web_application
906
- * @brief Linear interpolate the vector to another vector
907
- * @param v the vector to lerp to
908
- * @param amt The amount of interpolation; some value between 0.0 (old
909
- * vector) and 1.0 (new vector). 0.1 is very near the old vector; 0.5 is
910
- * halfway in between.
911
- * @see PApplet#lerp(float, float, float)
912
- */
913
- public PVector lerp(PVector v, float amt) {
914
- x = PApplet.lerp(x, v.x, amt);
915
- y = PApplet.lerp(y, v.y, amt);
916
- z = PApplet.lerp(z, v.z, amt);
917
- return this;
918
- }
919
-
920
- /**
921
- * Linear interpolate between two vectors (returns a new PVector object)
922
- *
923
- * @param v1 the vector to start from
924
- * @param v2 the vector to lerp to
925
- */
926
- public static PVector lerp(PVector v1, PVector v2, float amt) {
927
- PVector v = v1.copy();
928
- v.lerp(v2, amt);
929
- return v;
930
- }
931
-
932
- /**
933
- * Linear interpolate the vector to x,y,z values
934
- *
935
- * @param x the x component to lerp to
936
- * @param y the y component to lerp to
937
- * @param z the z component to lerp to
938
- */
939
- public PVector lerp(float x, float y, float z, float amt) {
940
- this.x = PApplet.lerp(this.x, x, amt);
941
- this.y = PApplet.lerp(this.y, y, amt);
942
- this.z = PApplet.lerp(this.z, z, amt);
943
- return this;
944
- }
945
-
946
- /**
947
- * ( begin auto-generated from PVector_angleBetween.xml )
948
- *
949
- * Calculates and returns the angle (in radians) between two vectors.
950
- *
951
- * ( end auto-generated )
952
- *
953
- * @webref pvector:method
954
- * @usage web_application
955
- * @param v1 the x, y, and z components of a PVector
956
- * @param v2 the x, y, and z components of a PVector
957
- * @brief Calculate and return the angle between two vectors
958
- */
959
- static public float angleBetween(PVector v1, PVector v2) {
960
-
961
- // We get NaN if we pass in a zero vector which can cause problems
962
- // Zero seems like a reasonable angle between a (0,0,0) vector and something else
963
- if (v1.x == 0 && v1.y == 0 && v1.z == 0) {
964
- return 0.0f;
965
- }
966
- if (v2.x == 0 && v2.y == 0 && v2.z == 0) {
967
- return 0.0f;
968
- }
969
-
970
- double dot = v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
971
- double v1mag = Math.sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z);
972
- double v2mag = Math.sqrt(v2.x * v2.x + v2.y * v2.y + v2.z * v2.z);
973
- // This should be a number between -1 and 1, since it's "normalized"
974
- double amt = dot / (v1mag * v2mag);
975
- // But if it's not due to rounding error, then we need to fix it
976
- // http://code.google.com/p/processing/issues/detail?id=340
977
- // Otherwise if outside the range, acos() will return NaN
978
- // http://www.cppreference.com/wiki/c/math/acos
979
- if (amt <= -1) {
980
- return PConstants.PI;
981
- } else if (amt >= 1) {
982
- // http://code.google.com/p/processing/issues/detail?id=435
983
- return 0;
984
- }
985
- return (float) Math.acos(amt);
986
- }
987
-
988
- @Override
989
- public String toString() {
990
- return "[ " + x + ", " + y + ", " + z + " ]";
991
- }
992
-
993
- /**
994
- * ( begin auto-generated from PVector_array.xml )
995
- *
996
- * Return a representation of this vector as a float array. This is only for
997
- * temporary use. If used in any other fashion, the contents should be
998
- * copied by using the <b>PVector.get()</b> method to copy into your own
999
- * array.
1000
- *
1001
- * ( end auto-generated )
1002
- *
1003
- * @webref pvector:method
1004
- * @usage: web_application
1005
- * @brief Return a representation of the vector as a float array
1006
- */
1007
- public float[] array() {
1008
- if (array == null) {
1009
- array = new float[3];
1010
- }
1011
- array[0] = x;
1012
- array[1] = y;
1013
- array[2] = z;
1014
- return array;
1015
- }
1016
-
1017
- @Override
1018
- public boolean equals(Object obj) {
1019
- if (!(obj instanceof PVector)) {
1020
- return false;
1021
- }
1022
- final PVector p = (PVector) obj;
1023
- return x == p.x && y == p.y && z == p.z;
1024
- }
1025
1047
 
1026
- @Override
1027
- public int hashCode() {
1028
- int result = 1;
1029
- result = 31 * result + Float.floatToIntBits(x);
1030
- result = 31 * result + Float.floatToIntBits(y);
1031
- result = 31 * result + Float.floatToIntBits(z);
1032
- return result;
1048
+ @Override
1049
+ public boolean equals(Object obj) {
1050
+ if (!(obj instanceof PVector)) {
1051
+ return false;
1033
1052
  }
1053
+ final PVector p = (PVector) obj;
1054
+ return x == p.x && y == p.y && z == p.z;
1055
+ }
1056
+
1057
+
1058
+ @Override
1059
+ public int hashCode() {
1060
+ int result = 1;
1061
+ result = 31 * result + Float.floatToIntBits(x);
1062
+ result = 31 * result + Float.floatToIntBits(y);
1063
+ result = 31 * result + Float.floatToIntBits(z);
1064
+ return result;
1065
+ }
1034
1066
  }