toxiclibs 0.4.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (404) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +16 -0
  3. data/.mvn/extensions.xml +8 -0
  4. data/.mvn/wrapper/maven-wrapper.properties +1 -0
  5. data/.travis.yml +23 -0
  6. data/CHANGELOG.md +7 -0
  7. data/COPYING.md +14 -0
  8. data/Gemfile +10 -0
  9. data/LICENSE +675 -0
  10. data/README.md +9 -7
  11. data/Rakefile +25 -81
  12. data/examples/README.md +5 -0
  13. data/examples/attract_repel/attract_repel.rb +30 -0
  14. data/examples/attract_repel/attractor.rb +23 -0
  15. data/examples/attract_repel/particle.rb +27 -0
  16. data/examples/data/ReplicaBold.ttf +0 -0
  17. data/examples/data/ti_yong.png +0 -0
  18. data/examples/force_directed/cluster.rb +76 -0
  19. data/examples/force_directed/force_directed_graph.rb +92 -0
  20. data/examples/force_directed/node.rb +26 -0
  21. data/examples/gray_scott_image.rb +74 -0
  22. data/examples/gray_scott_tone_map.rb +77 -0
  23. data/examples/implicit.rb +139 -0
  24. data/examples/inflate_mesh.rb +89 -0
  25. data/examples/model_align.rb +43 -0
  26. data/examples/physics_type.rb +77 -0
  27. data/examples/povmesh/data/mask.jpg +0 -0
  28. data/examples/povmesh/ftest.rb +59 -0
  29. data/examples/povmesh/mesh_align.rb +47 -0
  30. data/examples/povmesh/tentacle.rb +71 -0
  31. data/examples/simple_cluster/cluster.rb +47 -0
  32. data/examples/simple_cluster/node.rb +27 -0
  33. data/examples/simple_cluster/simple_cluster.rb +60 -0
  34. data/examples/soft_body/blanket.rb +45 -0
  35. data/examples/soft_body/connection.rb +16 -0
  36. data/examples/soft_body/particle.rb +22 -0
  37. data/examples/soft_body/soft_body_square_adapted.rb +55 -0
  38. data/examples/spherical_harmonics_mesh.rb +50 -0
  39. data/examples/test_rect.rb +32 -0
  40. data/lib/toxiclibs.jar +0 -0
  41. data/lib/toxiclibs.rb +72 -22
  42. data/lib/toxiclibs/version.rb +1 -1
  43. data/pom.rb +63 -0
  44. data/pom.xml +124 -0
  45. data/src/com/toxi/net/ClientListener.java +41 -0
  46. data/src/com/toxi/net/ServerListener.java +70 -0
  47. data/src/com/toxi/net/ServerListenerAdapter.java +47 -0
  48. data/src/com/toxi/net/ServerState.java +18 -0
  49. data/src/com/toxi/net/UDPConnection.java +66 -0
  50. data/src/com/toxi/net/UDPSyncClient.java +81 -0
  51. data/src/com/toxi/net/UDPSyncServer.java +450 -0
  52. data/src/com/toxi/nio/UDPClient.java +121 -0
  53. data/src/com/toxi/nio/UDPClientState.java +32 -0
  54. data/src/com/toxi/nio/UDPServer.java +129 -0
  55. data/src/toxi/audio/AudioBuffer.java +229 -0
  56. data/src/toxi/audio/AudioSource.java +288 -0
  57. data/src/toxi/audio/DecompressInputStream.java +159 -0
  58. data/src/toxi/audio/IIRFilter.java +197 -0
  59. data/src/toxi/audio/JOALUtil.java +388 -0
  60. data/src/toxi/audio/MultiTimbralManager.java +162 -0
  61. data/src/toxi/audio/SoundListener.java +154 -0
  62. data/src/toxi/audio/SynthUtil.java +109 -0
  63. data/src/toxi/color/AccessCriteria.java +114 -0
  64. data/src/toxi/color/AlphaAccessor.java +67 -0
  65. data/src/toxi/color/CMYKAccessor.java +122 -0
  66. data/src/toxi/color/CMYKDistanceProxy.java +40 -0
  67. data/src/toxi/color/ColorGradient.java +260 -0
  68. data/src/toxi/color/ColorList.java +699 -0
  69. data/src/toxi/color/ColorRange.java +671 -0
  70. data/src/toxi/color/ColorTheme.java +163 -0
  71. data/src/toxi/color/DistanceProxy.java +44 -0
  72. data/src/toxi/color/HSVAccessor.java +113 -0
  73. data/src/toxi/color/HSVDistanceProxy.java +40 -0
  74. data/src/toxi/color/HistEntry.java +85 -0
  75. data/src/toxi/color/Histogram.java +185 -0
  76. data/src/toxi/color/Hue.java +249 -0
  77. data/src/toxi/color/LuminanceAccessor.java +78 -0
  78. data/src/toxi/color/NamedColor.java +935 -0
  79. data/src/toxi/color/ProximityComparator.java +70 -0
  80. data/src/toxi/color/RGBAccessor.java +113 -0
  81. data/src/toxi/color/RGBDistanceProxy.java +41 -0
  82. data/src/toxi/color/ReadonlyTColor.java +296 -0
  83. data/src/toxi/color/TColor.java +1677 -0
  84. data/src/toxi/color/TColorAdapter.java +68 -0
  85. data/src/toxi/color/ToneMap.java +218 -0
  86. data/src/toxi/color/theory/AnalogousStrategy.java +140 -0
  87. data/src/toxi/color/theory/ColorTheoryRegistry.java +139 -0
  88. data/src/toxi/color/theory/ColorTheoryStrategy.java +56 -0
  89. data/src/toxi/color/theory/ComplementaryStrategy.java +111 -0
  90. data/src/toxi/color/theory/CompoundTheoryStrategy.java +143 -0
  91. data/src/toxi/color/theory/LeftSplitComplementaryStrategy.java +82 -0
  92. data/src/toxi/color/theory/MonochromeTheoryStrategy.java +103 -0
  93. data/src/toxi/color/theory/RightSplitComplementaryStrategy.java +82 -0
  94. data/src/toxi/color/theory/SingleComplementStrategy.java +76 -0
  95. data/src/toxi/color/theory/SplitComplementaryStrategy.java +77 -0
  96. data/src/toxi/color/theory/TetradTheoryStrategy.java +114 -0
  97. data/src/toxi/color/theory/TriadTheoryStrategy.java +77 -0
  98. data/src/toxi/data/csv/CSVAdapter.java +74 -0
  99. data/src/toxi/data/csv/CSVFieldMapper.java +212 -0
  100. data/src/toxi/data/csv/CSVListener.java +61 -0
  101. data/src/toxi/data/csv/CSVParser.java +202 -0
  102. data/src/toxi/data/feeds/AtomAuthor.java +49 -0
  103. data/src/toxi/data/feeds/AtomContent.java +50 -0
  104. data/src/toxi/data/feeds/AtomEntry.java +111 -0
  105. data/src/toxi/data/feeds/AtomFeed.java +129 -0
  106. data/src/toxi/data/feeds/AtomLink.java +62 -0
  107. data/src/toxi/data/feeds/RSSChannel.java +88 -0
  108. data/src/toxi/data/feeds/RSSEnclosure.java +60 -0
  109. data/src/toxi/data/feeds/RSSFeed.java +99 -0
  110. data/src/toxi/data/feeds/RSSItem.java +104 -0
  111. data/src/toxi/data/feeds/util/EntityStripper.java +2480 -0
  112. data/src/toxi/data/feeds/util/Iso8601DateAdapter.java +101 -0
  113. data/src/toxi/data/feeds/util/Rfc822DateAdapter.java +93 -0
  114. data/src/toxi/geom/AABB.java +658 -0
  115. data/src/toxi/geom/Axis3D.java +116 -0
  116. data/src/toxi/geom/AxisAlignedCylinder.java +163 -0
  117. data/src/toxi/geom/BernsteinPolynomial.java +94 -0
  118. data/src/toxi/geom/BezierCurve2D.java +159 -0
  119. data/src/toxi/geom/BezierCurve3D.java +148 -0
  120. data/src/toxi/geom/BooleanShapeBuilder.java +185 -0
  121. data/src/toxi/geom/BoxIntersector.java +52 -0
  122. data/src/toxi/geom/Circle.java +230 -0
  123. data/src/toxi/geom/CircleIntersector.java +85 -0
  124. data/src/toxi/geom/Cone.java +150 -0
  125. data/src/toxi/geom/ConvexPolygonClipper.java +136 -0
  126. data/src/toxi/geom/CoordinateExtractor.java +16 -0
  127. data/src/toxi/geom/Ellipse.java +250 -0
  128. data/src/toxi/geom/GMatrix.java +2599 -0
  129. data/src/toxi/geom/GVector.java +833 -0
  130. data/src/toxi/geom/GlobalGridTesselator.java +54 -0
  131. data/src/toxi/geom/GridTesselator.java +108 -0
  132. data/src/toxi/geom/Intersector2D.java +49 -0
  133. data/src/toxi/geom/Intersector3D.java +51 -0
  134. data/src/toxi/geom/IsectData2D.java +103 -0
  135. data/src/toxi/geom/IsectData3D.java +103 -0
  136. data/src/toxi/geom/Line2D.java +534 -0
  137. data/src/toxi/geom/Line3D.java +471 -0
  138. data/src/toxi/geom/LineStrip2D.java +430 -0
  139. data/src/toxi/geom/LineStrip3D.java +230 -0
  140. data/src/toxi/geom/LocalGridTesselator.java +57 -0
  141. data/src/toxi/geom/Matrix3d.java +3048 -0
  142. data/src/toxi/geom/Matrix4f.java +3446 -0
  143. data/src/toxi/geom/Matrix4x4.java +1076 -0
  144. data/src/toxi/geom/MatrixSizeException.java +58 -0
  145. data/src/toxi/geom/OctreeVisitor.java +44 -0
  146. data/src/toxi/geom/Origin3D.java +148 -0
  147. data/src/toxi/geom/Plane.java +293 -0
  148. data/src/toxi/geom/PlaneIntersector.java +57 -0
  149. data/src/toxi/geom/PointCloud3D.java +253 -0
  150. data/src/toxi/geom/PointOctree.java +502 -0
  151. data/src/toxi/geom/PointQuadtree.java +375 -0
  152. data/src/toxi/geom/Polygon2D.java +1038 -0
  153. data/src/toxi/geom/PolygonClipper2D.java +45 -0
  154. data/src/toxi/geom/PolygonTesselator.java +20 -0
  155. data/src/toxi/geom/QuadtreeVisitor.java +44 -0
  156. data/src/toxi/geom/Quaternion.java +641 -0
  157. data/src/toxi/geom/Ray2D.java +146 -0
  158. data/src/toxi/geom/Ray3D.java +150 -0
  159. data/src/toxi/geom/Ray3DIntersector.java +75 -0
  160. data/src/toxi/geom/ReadonlyVec2D.java +575 -0
  161. data/src/toxi/geom/ReadonlyVec3D.java +628 -0
  162. data/src/toxi/geom/ReadonlyVec4D.java +431 -0
  163. data/src/toxi/geom/Rect.java +720 -0
  164. data/src/toxi/geom/Reflector3D.java +58 -0
  165. data/src/toxi/geom/Shape2D.java +94 -0
  166. data/src/toxi/geom/Shape3D.java +42 -0
  167. data/src/toxi/geom/SingularMatrixException.java +57 -0
  168. data/src/toxi/geom/SpatialBins.java +182 -0
  169. data/src/toxi/geom/SpatialIndex.java +61 -0
  170. data/src/toxi/geom/Sphere.java +224 -0
  171. data/src/toxi/geom/SphereIntersectorReflector.java +196 -0
  172. data/src/toxi/geom/Spline2D.java +349 -0
  173. data/src/toxi/geom/Spline3D.java +351 -0
  174. data/src/toxi/geom/SutherlandHodgemanClipper.java +151 -0
  175. data/src/toxi/geom/Triangle2D.java +422 -0
  176. data/src/toxi/geom/Triangle3D.java +456 -0
  177. data/src/toxi/geom/TriangleIntersector.java +105 -0
  178. data/src/toxi/geom/Vec2D.java +1328 -0
  179. data/src/toxi/geom/Vec3D.java +1832 -0
  180. data/src/toxi/geom/Vec4D.java +985 -0
  181. data/src/toxi/geom/VecMathUtil.java +100 -0
  182. data/src/toxi/geom/XAxisCylinder.java +64 -0
  183. data/src/toxi/geom/YAxisCylinder.java +65 -0
  184. data/src/toxi/geom/ZAxisCylinder.java +64 -0
  185. data/src/toxi/geom/mesh/BezierPatch.java +200 -0
  186. data/src/toxi/geom/mesh/BoxSelector.java +62 -0
  187. data/src/toxi/geom/mesh/DefaultSTLColorModel.java +67 -0
  188. data/src/toxi/geom/mesh/DefaultSelector.java +50 -0
  189. data/src/toxi/geom/mesh/Face.java +176 -0
  190. data/src/toxi/geom/mesh/LaplacianSmooth.java +80 -0
  191. data/src/toxi/geom/mesh/MaterialiseSTLColorModel.java +150 -0
  192. data/src/toxi/geom/mesh/Mesh3D.java +224 -0
  193. data/src/toxi/geom/mesh/MeshIntersector.java +91 -0
  194. data/src/toxi/geom/mesh/OBJWriter.java +194 -0
  195. data/src/toxi/geom/mesh/PLYWriter.java +167 -0
  196. data/src/toxi/geom/mesh/PlaneSelector.java +90 -0
  197. data/src/toxi/geom/mesh/STLColorModel.java +54 -0
  198. data/src/toxi/geom/mesh/STLReader.java +185 -0
  199. data/src/toxi/geom/mesh/STLWriter.java +323 -0
  200. data/src/toxi/geom/mesh/SphereFunction.java +156 -0
  201. data/src/toxi/geom/mesh/SphericalHarmonics.java +110 -0
  202. data/src/toxi/geom/mesh/SuperEllipsoid.java +110 -0
  203. data/src/toxi/geom/mesh/SurfaceFunction.java +75 -0
  204. data/src/toxi/geom/mesh/SurfaceMeshBuilder.java +149 -0
  205. data/src/toxi/geom/mesh/Terrain.java +451 -0
  206. data/src/toxi/geom/mesh/TriangleMesh.java +1201 -0
  207. data/src/toxi/geom/mesh/Vertex.java +78 -0
  208. data/src/toxi/geom/mesh/VertexSelector.java +193 -0
  209. data/src/toxi/geom/mesh/WEFace.java +100 -0
  210. data/src/toxi/geom/mesh/WEMeshFilterStrategy.java +51 -0
  211. data/src/toxi/geom/mesh/WETriangleMesh.java +761 -0
  212. data/src/toxi/geom/mesh/WEVertex.java +134 -0
  213. data/src/toxi/geom/mesh/WingedEdge.java +115 -0
  214. data/src/toxi/geom/mesh/subdiv/CentroidSubdiv.java +37 -0
  215. data/src/toxi/geom/mesh/subdiv/DisplacementSubdivision.java +85 -0
  216. data/src/toxi/geom/mesh/subdiv/DualDisplacementSubdivision.java +94 -0
  217. data/src/toxi/geom/mesh/subdiv/DualSubdivision.java +49 -0
  218. data/src/toxi/geom/mesh/subdiv/EdgeLengthComparator.java +50 -0
  219. data/src/toxi/geom/mesh/subdiv/FaceCountComparator.java +51 -0
  220. data/src/toxi/geom/mesh/subdiv/MidpointDisplacementSubdivision.java +80 -0
  221. data/src/toxi/geom/mesh/subdiv/MidpointSubdiv.java +42 -0
  222. data/src/toxi/geom/mesh/subdiv/MidpointSubdivision.java +48 -0
  223. data/src/toxi/geom/mesh/subdiv/NewSubdivStrategy.java +23 -0
  224. data/src/toxi/geom/mesh/subdiv/NormalDisplacementSubdivision.java +74 -0
  225. data/src/toxi/geom/mesh/subdiv/SubdivisionStrategy.java +83 -0
  226. data/src/toxi/geom/mesh/subdiv/TriSubdivision.java +51 -0
  227. data/src/toxi/geom/mesh2d/DelaunayTriangle.java +222 -0
  228. data/src/toxi/geom/mesh2d/DelaunayTriangulation.java +327 -0
  229. data/src/toxi/geom/mesh2d/DelaunayVertex.java +560 -0
  230. data/src/toxi/geom/mesh2d/Voronoi.java +149 -0
  231. data/src/toxi/geom/nurbs/BasicNurbsCurve.java +210 -0
  232. data/src/toxi/geom/nurbs/BasicNurbsSurface.java +233 -0
  233. data/src/toxi/geom/nurbs/ControlNet.java +148 -0
  234. data/src/toxi/geom/nurbs/CurveCreator.java +112 -0
  235. data/src/toxi/geom/nurbs/CurveUtils.java +259 -0
  236. data/src/toxi/geom/nurbs/InterpolationException.java +65 -0
  237. data/src/toxi/geom/nurbs/KnotVector.java +333 -0
  238. data/src/toxi/geom/nurbs/NurbsCreator.java +815 -0
  239. data/src/toxi/geom/nurbs/NurbsCurve.java +120 -0
  240. data/src/toxi/geom/nurbs/NurbsMeshCreator.java +145 -0
  241. data/src/toxi/geom/nurbs/NurbsSurface.java +147 -0
  242. data/src/toxi/image/util/Filter8bit.java +331 -0
  243. data/src/toxi/image/util/TiledFrameExporter.java +162 -0
  244. data/src/toxi/math/BezierInterpolation.java +102 -0
  245. data/src/toxi/math/CircularInterpolation.java +88 -0
  246. data/src/toxi/math/CosineInterpolation.java +51 -0
  247. data/src/toxi/math/DecimatedInterpolation.java +77 -0
  248. data/src/toxi/math/ExponentialInterpolation.java +68 -0
  249. data/src/toxi/math/InterpolateStrategy.java +60 -0
  250. data/src/toxi/math/Interpolation2D.java +93 -0
  251. data/src/toxi/math/LinearInterpolation.java +46 -0
  252. data/src/toxi/math/MathUtils.java +990 -0
  253. data/src/toxi/math/NonLinearScaleMap.java +101 -0
  254. data/src/toxi/math/ScaleMap.java +183 -0
  255. data/src/toxi/math/SigmoidInterpolation.java +78 -0
  256. data/src/toxi/math/SinCosLUT.java +141 -0
  257. data/src/toxi/math/ThresholdInterpolation.java +58 -0
  258. data/src/toxi/math/ZoomLensInterpolation.java +126 -0
  259. data/src/toxi/math/conversion/UnitTranslator.java +161 -0
  260. data/src/toxi/math/noise/PerlinNoise.java +281 -0
  261. data/src/toxi/math/noise/SimplexNoise.java +542 -0
  262. data/src/toxi/math/waves/AMFMSineWave.java +143 -0
  263. data/src/toxi/math/waves/AbstractWave.java +248 -0
  264. data/src/toxi/math/waves/ConstantWave.java +48 -0
  265. data/src/toxi/math/waves/FMHarmonicSquareWave.java +155 -0
  266. data/src/toxi/math/waves/FMSawtoothWave.java +144 -0
  267. data/src/toxi/math/waves/FMSineWave.java +142 -0
  268. data/src/toxi/math/waves/FMSquareWave.java +143 -0
  269. data/src/toxi/math/waves/FMTriangleWave.java +126 -0
  270. data/src/toxi/math/waves/SineWave.java +81 -0
  271. data/src/toxi/math/waves/Wave2D.java +68 -0
  272. data/src/toxi/math/waves/WaveState.java +69 -0
  273. data/src/toxi/music/scale/AbstractScale.java +117 -0
  274. data/src/toxi/music/scale/GenericScale.java +66 -0
  275. data/src/toxi/music/scale/MajorScale.java +41 -0
  276. data/src/toxi/newmesh/AttributedEdge.java +106 -0
  277. data/src/toxi/newmesh/AttributedFace.java +63 -0
  278. data/src/toxi/newmesh/IndexedTriangleMesh.java +809 -0
  279. data/src/toxi/newmesh/MeshAttributeCompiler.java +45 -0
  280. data/src/toxi/newmesh/MeshFaceNormalCompiler.java +52 -0
  281. data/src/toxi/newmesh/MeshUVCompiler.java +52 -0
  282. data/src/toxi/newmesh/MeshVertexColorCompiler.java +49 -0
  283. data/src/toxi/newmesh/MeshVertexCompiler.java +54 -0
  284. data/src/toxi/newmesh/MeshVertexNormalCompiler.java +55 -0
  285. data/src/toxi/newmesh/SpatialIndex.java +78 -0
  286. data/src/toxi/physics2d/ParticlePath2D.java +100 -0
  287. data/src/toxi/physics2d/ParticleString2D.java +184 -0
  288. data/src/toxi/physics2d/PullBackSpring2D.java +51 -0
  289. data/src/toxi/physics2d/VerletConstrainedSpring2D.java +89 -0
  290. data/src/toxi/physics2d/VerletMinDistanceSpring2D.java +57 -0
  291. data/src/toxi/physics2d/VerletParticle2D.java +457 -0
  292. data/src/toxi/physics2d/VerletPhysics2D.java +448 -0
  293. data/src/toxi/physics2d/VerletSpring2D.java +181 -0
  294. data/src/toxi/physics2d/behaviors/AttractionBehavior2D.java +212 -0
  295. data/src/toxi/physics2d/behaviors/ConstantForceBehavior2D.java +112 -0
  296. data/src/toxi/physics2d/behaviors/GravityBehavior2D.java +61 -0
  297. data/src/toxi/physics2d/behaviors/ParticleBehavior2D.java +66 -0
  298. data/src/toxi/physics2d/constraints/AngularConstraint.java +83 -0
  299. data/src/toxi/physics2d/constraints/AxisConstraint.java +71 -0
  300. data/src/toxi/physics2d/constraints/CircularConstraint.java +69 -0
  301. data/src/toxi/physics2d/constraints/MaxConstraint.java +66 -0
  302. data/src/toxi/physics2d/constraints/MinConstraint.java +66 -0
  303. data/src/toxi/physics2d/constraints/ParticleConstraint2D.java +47 -0
  304. data/src/toxi/physics2d/constraints/PolygonConstraint.java +93 -0
  305. data/src/toxi/physics2d/constraints/RectConstraint.java +114 -0
  306. data/src/toxi/physics3d/ParticlePath3D.java +100 -0
  307. data/src/toxi/physics3d/ParticleString3D.java +184 -0
  308. data/src/toxi/physics3d/PullBackSpring3D.java +50 -0
  309. data/src/toxi/physics3d/VerletConstrainedSpring3D.java +88 -0
  310. data/src/toxi/physics3d/VerletMinDistanceSpring3D.java +56 -0
  311. data/src/toxi/physics3d/VerletParticle3D.java +385 -0
  312. data/src/toxi/physics3d/VerletPhysics3D.java +417 -0
  313. data/src/toxi/physics3d/VerletSpring3D.java +180 -0
  314. data/src/toxi/physics3d/behaviors/AttractionBehavior3D.java +182 -0
  315. data/src/toxi/physics3d/behaviors/ConstantForceBehavior3D.java +92 -0
  316. data/src/toxi/physics3d/behaviors/GravityBehavior3D.java +61 -0
  317. data/src/toxi/physics3d/behaviors/ParticleBehavior3D.java +52 -0
  318. data/src/toxi/physics3d/constraints/AxisConstraint.java +68 -0
  319. data/src/toxi/physics3d/constraints/BoxConstraint.java +121 -0
  320. data/src/toxi/physics3d/constraints/CylinderConstraint.java +87 -0
  321. data/src/toxi/physics3d/constraints/MaxConstraint.java +65 -0
  322. data/src/toxi/physics3d/constraints/MinConstraint.java +65 -0
  323. data/src/toxi/physics3d/constraints/ParticleConstraint3D.java +49 -0
  324. data/src/toxi/physics3d/constraints/PlaneConstraint.java +78 -0
  325. data/src/toxi/physics3d/constraints/SoftBoxConstraint.java +87 -0
  326. data/src/toxi/physics3d/constraints/SphereConstraint.java +108 -0
  327. data/src/toxi/processing/ArrowModifier.java +116 -0
  328. data/src/toxi/processing/DashedLineModifier.java +48 -0
  329. data/src/toxi/processing/DeltaOrientationMapper.java +57 -0
  330. data/src/toxi/processing/Line2DRenderModifier.java +18 -0
  331. data/src/toxi/processing/MeshToVBO.java +127 -0
  332. data/src/toxi/processing/NormalMapper.java +18 -0
  333. data/src/toxi/processing/POVInterface.java +121 -0
  334. data/src/toxi/processing/POVMesh.java +219 -0
  335. data/src/toxi/processing/POVWriter.java +460 -0
  336. data/src/toxi/processing/RCOpaque.java +77 -0
  337. data/src/toxi/processing/RCTransp.java +78 -0
  338. data/src/toxi/processing/TextureBuilder.java +232 -0
  339. data/src/toxi/processing/Textures.java +110 -0
  340. data/src/toxi/processing/ToxiclibsSupport.java +1239 -0
  341. data/src/toxi/processing/Tracing.java +25 -0
  342. data/src/toxi/processing/XYZNormalMapper.java +30 -0
  343. data/src/toxi/sim/automata/CAMatrix.java +297 -0
  344. data/src/toxi/sim/automata/CARule.java +76 -0
  345. data/src/toxi/sim/automata/CARule2D.java +354 -0
  346. data/src/toxi/sim/automata/CAWolfram1D.java +309 -0
  347. data/src/toxi/sim/automata/EvolvableMatrix.java +61 -0
  348. data/src/toxi/sim/automata/MatrixEvolver.java +42 -0
  349. data/src/toxi/sim/dla/BottomUpOrder.java +76 -0
  350. data/src/toxi/sim/dla/DLA.java +497 -0
  351. data/src/toxi/sim/dla/DLAConfiguration.java +364 -0
  352. data/src/toxi/sim/dla/DLAEventAdapter.java +64 -0
  353. data/src/toxi/sim/dla/DLAEventListener.java +57 -0
  354. data/src/toxi/sim/dla/DLAGuideLines.java +219 -0
  355. data/src/toxi/sim/dla/DLAParticle.java +102 -0
  356. data/src/toxi/sim/dla/DLASegment.java +88 -0
  357. data/src/toxi/sim/dla/PipelineOrder.java +50 -0
  358. data/src/toxi/sim/dla/RadialDistanceOrder.java +92 -0
  359. data/src/toxi/sim/erosion/ErosionFunction.java +122 -0
  360. data/src/toxi/sim/erosion/TalusAngleErosion.java +145 -0
  361. data/src/toxi/sim/erosion/ThermalErosion.java +75 -0
  362. data/src/toxi/sim/fluids/FluidSolver2D.java +762 -0
  363. data/src/toxi/sim/fluids/FluidSolver3D.java +326 -0
  364. data/src/toxi/sim/grayscott/GrayScott.java +469 -0
  365. data/src/toxi/util/DateUtils.java +141 -0
  366. data/src/toxi/util/FileSequenceDescriptor.java +181 -0
  367. data/src/toxi/util/FileUtils.java +467 -0
  368. data/src/toxi/util/datatypes/ArraySet.java +128 -0
  369. data/src/toxi/util/datatypes/ArrayUtil.java +404 -0
  370. data/src/toxi/util/datatypes/BiasedDoubleRange.java +141 -0
  371. data/src/toxi/util/datatypes/BiasedFloatRange.java +141 -0
  372. data/src/toxi/util/datatypes/BiasedIntegerRange.java +141 -0
  373. data/src/toxi/util/datatypes/DoubleRange.java +251 -0
  374. data/src/toxi/util/datatypes/FloatRange.java +251 -0
  375. data/src/toxi/util/datatypes/GenericSet.java +215 -0
  376. data/src/toxi/util/datatypes/IntegerRange.java +247 -0
  377. data/src/toxi/util/datatypes/IntegerSet.java +149 -0
  378. data/src/toxi/util/datatypes/ItemIndex.java +72 -0
  379. data/src/toxi/util/datatypes/SingletonRegistry.java +91 -0
  380. data/src/toxi/util/datatypes/TypedProperties.java +291 -0
  381. data/src/toxi/util/datatypes/UndirectedGraph.java +134 -0
  382. data/src/toxi/util/datatypes/UniqueItemIndex.java +223 -0
  383. data/src/toxi/util/datatypes/WeightedRandomEntry.java +76 -0
  384. data/src/toxi/util/datatypes/WeightedRandomSet.java +125 -0
  385. data/src/toxi/util/events/EventDispatcher.java +86 -0
  386. data/src/toxi/volume/AdditiveBrush.java +19 -0
  387. data/src/toxi/volume/ArrayIsoSurface.java +297 -0
  388. data/src/toxi/volume/BoxBrush.java +100 -0
  389. data/src/toxi/volume/BrushMode.java +16 -0
  390. data/src/toxi/volume/HashIsoSurface.java +354 -0
  391. data/src/toxi/volume/IsoSurface.java +59 -0
  392. data/src/toxi/volume/MarchingCubesIndex.java +312 -0
  393. data/src/toxi/volume/MeshLatticeBuilder.java +358 -0
  394. data/src/toxi/volume/MeshVoxelizer.java +216 -0
  395. data/src/toxi/volume/MultiplyBrush.java +20 -0
  396. data/src/toxi/volume/PeakBrush.java +21 -0
  397. data/src/toxi/volume/ReplaceBrush.java +19 -0
  398. data/src/toxi/volume/RoundBrush.java +113 -0
  399. data/src/toxi/volume/VolumetricBrush.java +160 -0
  400. data/src/toxi/volume/VolumetricHashMap.java +179 -0
  401. data/src/toxi/volume/VolumetricSpace.java +195 -0
  402. data/src/toxi/volume/VolumetricSpaceArray.java +214 -0
  403. data/toxiclibs.gemspec +28 -0
  404. metadata +442 -31
@@ -0,0 +1,1832 @@
1
+ /*
2
+ * __ .__ .__ ._____.
3
+ * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4
+ * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5
+ * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6
+ * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7
+ * \/ \/ \/ \/
8
+ *
9
+ * Copyright (c) 2006-2011 Karsten Schmidt
10
+ *
11
+ * This library is free software; you can redistribute it and/or
12
+ * modify it under the terms of the GNU Lesser General Public
13
+ * License as published by the Free Software Foundation; either
14
+ * version 2.1 of the License, or (at your option) any later version.
15
+ *
16
+ * http://creativecommons.org/licenses/LGPL/2.1/
17
+ *
18
+ * This library is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21
+ * Lesser General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU Lesser General Public
24
+ * License along with this library; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26
+ */
27
+
28
+ package toxi.geom;
29
+
30
+ import java.util.Random;
31
+
32
+ import javax.xml.bind.annotation.XmlAttribute;
33
+
34
+ import toxi.math.InterpolateStrategy;
35
+ import toxi.math.MathUtils;
36
+ import toxi.math.ScaleMap;
37
+
38
+ /**
39
+ * Comprehensive 3D vector class with additional basic intersection and
40
+ * collision detection features.
41
+ */
42
+ public class Vec3D implements Comparable<ReadonlyVec3D>, ReadonlyVec3D {
43
+
44
+ /**
45
+ *
46
+ */
47
+ public static enum Axis {
48
+
49
+ /**
50
+ *
51
+ */
52
+ X(Vec3D.X_AXIS),
53
+
54
+ /**
55
+ *
56
+ */
57
+ Y(Vec3D.Y_AXIS),
58
+
59
+ /**
60
+ *
61
+ */
62
+ Z(Vec3D.Z_AXIS);
63
+
64
+ private final ReadonlyVec3D vector;
65
+
66
+ private Axis(ReadonlyVec3D v) {
67
+ this.vector = v;
68
+ }
69
+
70
+ /**
71
+ *
72
+ * @return
73
+ */
74
+ public ReadonlyVec3D getVector() {
75
+ return vector;
76
+ }
77
+ }
78
+
79
+ /** Defines positive X axis. */
80
+ public static final ReadonlyVec3D X_AXIS = new Vec3D(1, 0, 0);
81
+
82
+ /** Defines positive Y axis. */
83
+ public static final ReadonlyVec3D Y_AXIS = new Vec3D(0, 1, 0);
84
+
85
+ /** Defines positive Z axis. */
86
+ public static final ReadonlyVec3D Z_AXIS = new Vec3D(0, 0, 1);
87
+
88
+ /** Defines the zero vector. */
89
+ public static final ReadonlyVec3D ZERO = new Vec3D();;
90
+
91
+ /**
92
+ * Defines vector with all coords set to Float.MIN_VALUE. Useful for
93
+ * bounding box operations.
94
+ */
95
+ public static final ReadonlyVec3D MIN_VALUE = new Vec3D(Float.MIN_VALUE,
96
+ Float.MIN_VALUE, Float.MIN_VALUE);
97
+
98
+ /**
99
+ * Defines vector with all coords set to Float.MAX_VALUE. Useful for
100
+ * bounding box operations.
101
+ */
102
+ public static final ReadonlyVec3D MAX_VALUE = new Vec3D(Float.MAX_VALUE,
103
+ Float.MAX_VALUE, Float.MAX_VALUE);
104
+
105
+ /**
106
+ *
107
+ */
108
+ public static final ReadonlyVec3D NEG_MAX_VALUE = new Vec3D(
109
+ -Float.MAX_VALUE, -Float.MAX_VALUE, -Float.MAX_VALUE);
110
+
111
+ /**
112
+ * Creates a new vector from the given angle in the XY plane. The Z
113
+ * component of the vector will be zero.
114
+ *
115
+ * The resulting vector for theta=0 is equal to the positive X axis.
116
+ *
117
+ * @param theta
118
+ * the theta
119
+ *
120
+ * @return new vector in the XY plane
121
+ */
122
+ public static final Vec3D fromXYTheta(float theta) {
123
+ return new Vec3D((float) Math.cos(theta), (float) Math.sin(theta), 0);
124
+ }
125
+
126
+ /**
127
+ * Creates a new vector from the given angle in the XZ plane. The Y
128
+ * component of the vector will be zero.
129
+ *
130
+ * The resulting vector for theta=0 is equal to the positive X axis.
131
+ *
132
+ * @param theta
133
+ * the theta
134
+ *
135
+ * @return new vector in the XZ plane
136
+ */
137
+ public static final Vec3D fromXZTheta(float theta) {
138
+ return new Vec3D((float) Math.cos(theta), 0, (float) Math.sin(theta));
139
+ }
140
+
141
+ /**
142
+ * Creates a new vector from the given angle in the YZ plane. The X
143
+ * component of the vector will be zero.
144
+ *
145
+ * The resulting vector for theta=0 is equal to the positive Y axis.
146
+ *
147
+ * @param theta
148
+ * the theta
149
+ *
150
+ * @return new vector in the YZ plane
151
+ */
152
+ public static final Vec3D fromYZTheta(float theta) {
153
+ return new Vec3D(0, (float) Math.cos(theta), (float) Math.sin(theta));
154
+ }
155
+
156
+ /**
157
+ * Constructs a new vector consisting of the largest components of both
158
+ * vectors.
159
+ *
160
+ * @param b
161
+ * the b
162
+ * @param a
163
+ * the a
164
+ *
165
+ * @return result as new vector
166
+ */
167
+ public static final Vec3D max(ReadonlyVec3D a, ReadonlyVec3D b) {
168
+ return new Vec3D(MathUtils.max(a.x(), b.x()), MathUtils.max(a.y(),
169
+ b.y()), MathUtils.max(a.z(), b.z()));
170
+ }
171
+
172
+ /**
173
+ * Constructs a new vector consisting of the smallest components of both
174
+ * vectors.
175
+ *
176
+ * @param b
177
+ * comparing vector
178
+ * @param a
179
+ * the a
180
+ *
181
+ * @return result as new vector
182
+ */
183
+ public static final Vec3D min(ReadonlyVec3D a, ReadonlyVec3D b) {
184
+ return new Vec3D(MathUtils.min(a.x(), b.x()), MathUtils.min(a.y(),
185
+ b.y()), MathUtils.min(a.z(), b.z()));
186
+ }
187
+
188
+ /**
189
+ * Static factory method. Creates a new random unit vector using the Random
190
+ * implementation set as default for the {@link MathUtils} class.
191
+ *
192
+ * @return a new random normalized unit vector.
193
+ */
194
+ public static final Vec3D randomVector() {
195
+ return randomVector(MathUtils.RND);
196
+ }
197
+
198
+ /**
199
+ * Static factory method. Creates a new random unit vector using the given
200
+ * Random generator instance. I recommend to have a look at the
201
+ * https://uncommons-maths.dev.java.net library for a good choice of
202
+ * reliable and high quality random number generators.
203
+ *
204
+ * @param rnd
205
+ * the rnd
206
+ *
207
+ * @return a new random normalized unit vector.
208
+ */
209
+ public static final Vec3D randomVector(Random rnd) {
210
+ Vec3D v = new Vec3D(rnd.nextFloat() * 2 - 1, rnd.nextFloat() * 2 - 1,
211
+ rnd.nextFloat() * 2 - 1);
212
+ return v.normalize();
213
+ }
214
+
215
+ /** X coordinate. */
216
+ @XmlAttribute(required = true)
217
+ public float x;
218
+
219
+ /** Y coordinate. */
220
+ @XmlAttribute(required = true)
221
+ public float y;
222
+
223
+ /** Z coordinate. */
224
+ @XmlAttribute(required = true)
225
+ public float z;
226
+
227
+ /**
228
+ * Creates a new zero vector.
229
+ */
230
+ public Vec3D() {
231
+ }
232
+
233
+ /**
234
+ * Creates a new vector with the given coordinates.
235
+ *
236
+ * @param x
237
+ * the x
238
+ * @param y
239
+ * the y
240
+ * @param z
241
+ * the z
242
+ */
243
+ public Vec3D(float x, float y, float z) {
244
+ this.x = x;
245
+ this.y = y;
246
+ this.z = z;
247
+ }
248
+
249
+ /**
250
+ *
251
+ * @param v
252
+ */
253
+ public Vec3D(float[] v) {
254
+ this.x = v[0];
255
+ this.y = v[1];
256
+ this.z = v[2];
257
+ }
258
+
259
+ /**
260
+ * Creates a new vector with the coordinates of the given vector.
261
+ *
262
+ * @param v
263
+ * vector to be copied
264
+ */
265
+ public Vec3D(ReadonlyVec3D v) {
266
+ this.x = v.x();
267
+ this.y = v.y();
268
+ this.z = v.z();
269
+ }
270
+
271
+ /**
272
+ * Abs.
273
+ *
274
+ * @return the vec3 d
275
+ */
276
+ public final Vec3D abs() {
277
+ x = MathUtils.abs(x);
278
+ y = MathUtils.abs(y);
279
+ z = MathUtils.abs(z);
280
+ return this;
281
+ }
282
+
283
+ @Override
284
+ public final Vec3D add(float a, float b, float c) {
285
+ return new Vec3D(x + a, y + b, z + c);
286
+ }
287
+
288
+ /**
289
+ *
290
+ * @param v
291
+ * @return
292
+ */
293
+ @Override
294
+ public Vec3D add(ReadonlyVec3D v) {
295
+ return new Vec3D(x + v.x(), y + v.y(), z + v.z());
296
+ }
297
+
298
+ @Override
299
+ public final Vec3D add(Vec3D v) {
300
+ return new Vec3D(x + v.x, y + v.y, z + v.z);
301
+ }
302
+
303
+ /**
304
+ * Adds vector {a,b,c} and overrides coordinates with result.
305
+ *
306
+ * @param a
307
+ * X coordinate
308
+ * @param b
309
+ * Y coordinate
310
+ * @param c
311
+ * Z coordinate
312
+ *
313
+ * @return itself
314
+ */
315
+ public final Vec3D addSelf(float a, float b, float c) {
316
+ x += a;
317
+ y += b;
318
+ z += c;
319
+ return this;
320
+ }
321
+
322
+ /**
323
+ *
324
+ * @param v
325
+ * @return
326
+ */
327
+ public final Vec3D addSelf(ReadonlyVec3D v) {
328
+ x += v.x();
329
+ y += v.y();
330
+ z += v.z();
331
+ return this;
332
+ }
333
+
334
+ /**
335
+ * Adds vector v and overrides coordinates with result.
336
+ *
337
+ * @param v
338
+ * vector to add
339
+ *
340
+ * @return itself
341
+ */
342
+ public final Vec3D addSelf(Vec3D v) {
343
+ x += v.x;
344
+ y += v.y;
345
+ z += v.z;
346
+ return this;
347
+ }
348
+
349
+ @Override
350
+ public final float angleBetween(ReadonlyVec3D v) {
351
+ return (float) Math.acos(dot(v));
352
+ }
353
+
354
+ @Override
355
+ public final float angleBetween(ReadonlyVec3D v, boolean forceNormalize) {
356
+ float theta;
357
+ if (forceNormalize) {
358
+ theta = getNormalized().dot(v.getNormalized());
359
+ } else {
360
+ theta = dot(v);
361
+ }
362
+ return (float) Math.acos(theta);
363
+ }
364
+
365
+ /**
366
+ * Sets all vector components to 0.
367
+ *
368
+ * @return itself
369
+ */
370
+ public final ReadonlyVec3D clear() {
371
+ x = y = z = 0;
372
+ return this;
373
+ }
374
+
375
+ @Override
376
+ public int compareTo(ReadonlyVec3D o) {
377
+ if (this.equals(o)) {
378
+ return 0;
379
+ }
380
+ int result = (this.magSquared() < o.magSquared()) ? -1 : 1;
381
+ return result;
382
+ }
383
+
384
+ /**
385
+ * Forcefully fits the vector in the given AABB.
386
+ *
387
+ * @param box
388
+ * the box
389
+ *
390
+ * @return itself
391
+ */
392
+ public Vec3D constrain(AABB box) {
393
+ return constrain(box.getMin(), box.getMax());
394
+ }
395
+
396
+ /**
397
+ * Forcefully fits the vector in the given AABB specified by the 2 given
398
+ * points.
399
+ *
400
+ * @param min
401
+ * @param max
402
+ * @return itself
403
+ */
404
+ public Vec3D constrain(Vec3D min, Vec3D max) {
405
+ x = MathUtils.clip(x, min.x, max.x);
406
+ y = MathUtils.clip(y, min.y, max.y);
407
+ z = MathUtils.clip(z, min.z, max.z);
408
+ return this;
409
+ }
410
+
411
+ @Override
412
+ public Vec3D copy() {
413
+ return new Vec3D(this);
414
+ }
415
+
416
+ @Override
417
+ public final Vec3D cross(ReadonlyVec3D v) {
418
+ return new Vec3D(y * v.z() - v.y() * z, z * v.x() - v.z() * x, x
419
+ * v.y() - v.x() * y);
420
+ }
421
+
422
+ /**
423
+ *
424
+ * @param v
425
+ * @return
426
+ */
427
+ public final Vec3D cross(Vec3D v) {
428
+ return new Vec3D(y * v.z - v.y * z, z * v.x - v.z * x, x * v.y - v.x
429
+ * y);
430
+ }
431
+
432
+ @Override
433
+ public final Vec3D crossInto(ReadonlyVec3D v, Vec3D result) {
434
+ final float vx = v.x();
435
+ final float vy = v.y();
436
+ final float vz = v.z();
437
+ result.x = y * vz - vy * z;
438
+ result.y = z * vx - vz * x;
439
+ result.z = x * vy - vx * y;
440
+ return result;
441
+ }
442
+
443
+ /**
444
+ * Calculates cross-product with vector v. The resulting vector is
445
+ * perpendicular to both the current and supplied vector and overrides the
446
+ * current.
447
+ *
448
+ * @param v
449
+ * the v
450
+ *
451
+ * @return itself
452
+ */
453
+ public final Vec3D crossSelf(Vec3D v) {
454
+ final float cx = y * v.z - v.y * z;
455
+ final float cy = z * v.x - v.z * x;
456
+ z = x * v.y - v.x * y;
457
+ y = cy;
458
+ x = cx;
459
+ return this;
460
+ }
461
+
462
+ @Override
463
+ public final float distanceTo(ReadonlyVec3D v) {
464
+ if (v != null) {
465
+ final float dx = x - v.x();
466
+ final float dy = y - v.y();
467
+ final float dz = z - v.z();
468
+ return (float) Math.sqrt(dx * dx + dy * dy + dz * dz);
469
+ } else {
470
+ return Float.NaN;
471
+ }
472
+ }
473
+
474
+ @Override
475
+ public final float distanceToSquared(ReadonlyVec3D v) {
476
+ if (v != null) {
477
+ final float dx = x - v.x();
478
+ final float dy = y - v.y();
479
+ final float dz = z - v.z();
480
+ return dx * dx + dy * dy + dz * dz;
481
+ } else {
482
+ return Float.NaN;
483
+ }
484
+ }
485
+
486
+ @Override
487
+ public final float dot(ReadonlyVec3D v) {
488
+ return x * v.x() + y * v.y() + z * v.z();
489
+ }
490
+
491
+ /**
492
+ *
493
+ * @param v
494
+ * @return
495
+ */
496
+ public final float dot(Vec3D v) {
497
+ return x * v.x + y * v.y + z * v.z;
498
+ }
499
+
500
+ /**
501
+ * Returns true if the Object v is of type ReadonlyVec3D and all of the data
502
+ * members of v are equal to the corresponding data members in this vector.
503
+ *
504
+ * @param v
505
+ * the Object with which the comparison is made
506
+ * @return true or false
507
+ */
508
+ @Override
509
+ public boolean equals(Object v) {
510
+ if (v instanceof ReadonlyVec3D) {
511
+ ReadonlyVec3D vv = (ReadonlyVec3D) v;
512
+ if (!((Float)x).equals(vv.x())){
513
+ return false;
514
+ }
515
+ if (!((Float)y).equals(vv.y())){
516
+ return false;
517
+ }
518
+ return ((Float)z).equals(vv.z());
519
+ }
520
+ return false;
521
+ }
522
+
523
+ /**
524
+ * Returns a hash code value based on the data values in this object. Two
525
+ * different Vec3D objects with identical data values (i.e., Vec3D.equals
526
+ * returns true) will return the same hash code value. Two objects with
527
+ * different data members may return the same hash value, although this is
528
+ * not likely.
529
+ *
530
+ * @return the integer hash code value
531
+ */
532
+
533
+ @Override
534
+ public int hashCode() {
535
+ int hash = 7;
536
+ hash = 19 * hash + Float.floatToIntBits(this.x);
537
+ hash = 19 * hash + Float.floatToIntBits(this.y);
538
+ hash = 19 * hash + Float.floatToIntBits(this.z);
539
+ return hash;
540
+ }
541
+
542
+ /**
543
+ * Returns true if the Object v is of type ReadonlyVec3D and all of the data
544
+ * members of v are equal to the corresponding data members in this vector.
545
+ *
546
+ * @param v
547
+ * the vector with which the comparison is made
548
+ * @return true or false
549
+ */
550
+ public boolean equals(ReadonlyVec3D v) {
551
+ if (!((Float) x).equals(v.x())) {
552
+ return false;
553
+ }
554
+ if (!((Float) y).equals(v.y())) {
555
+ return false;
556
+ }
557
+ return ((Float) z).equals(v.z());
558
+ }
559
+
560
+ @Override
561
+ public boolean equalsWithTolerance(ReadonlyVec3D v, float tolerance) {
562
+ if (v instanceof ReadonlyVec3D) {
563
+ float diff = x - v.x();
564
+ if (Float.isNaN(diff)) {
565
+ return false;
566
+ }
567
+ if ((diff < 0 ? -diff : diff) > tolerance) {
568
+ return false;
569
+ }
570
+ diff = y - v.y();
571
+ if (Float.isNaN(diff)) {
572
+ return false;
573
+ }
574
+ if ((diff < 0 ? -diff : diff) > tolerance) {
575
+ return false;
576
+ }
577
+ diff = z - v.z();
578
+ if (Float.isNaN(diff)) {
579
+ return false;
580
+ }
581
+ return ((diff < 0 ? -diff : diff) < tolerance);
582
+ }
583
+ return false;
584
+ }
585
+
586
+ /**
587
+ * Replaces the vector components with integer values of their current
588
+ * values.
589
+ *
590
+ * @return itself
591
+ */
592
+ public final Vec3D floor() {
593
+ x = MathUtils.floor(x);
594
+ y = MathUtils.floor(y);
595
+ z = MathUtils.floor(z);
596
+ return this;
597
+ }
598
+
599
+ /**
600
+ * Replaces the vector components with the fractional part of their current
601
+ * values.
602
+ *
603
+ * @return itself
604
+ */
605
+ public final Vec3D frac() {
606
+ x -= MathUtils.floor(x);
607
+ y -= MathUtils.floor(y);
608
+ z -= MathUtils.floor(z);
609
+ return this;
610
+ }
611
+
612
+ @Override
613
+ public final Vec3D getAbs() {
614
+ return new Vec3D(this).abs();
615
+ }
616
+
617
+ @Override
618
+ public Vec3D getCartesian() {
619
+ return copy().toCartesian();
620
+ }
621
+
622
+ /**
623
+ * Identifies the closest cartesian axis to this vector. If at leat two
624
+ * vector components are equal, no unique decision can be made and the
625
+ * method returns null.
626
+ *
627
+ * @return Axis enum or null
628
+ */
629
+ @Override
630
+ public final Axis getClosestAxis() {
631
+ float ax = MathUtils.abs(x);
632
+ float ay = MathUtils.abs(y);
633
+ float az = MathUtils.abs(z);
634
+ if (ax > ay && ax > az) {
635
+ return Axis.X;
636
+ }
637
+ if (ay > ax && ay > az) {
638
+ return Axis.Y;
639
+ }
640
+ if (az > ax && az > ay) {
641
+ return Axis.Z;
642
+ }
643
+ return null;
644
+ }
645
+
646
+ /**
647
+ *
648
+ * @param id
649
+ * @return
650
+ */
651
+ @Override
652
+ public final float getComponent(Axis id) {
653
+ switch (id) {
654
+ case X:
655
+ return x;
656
+ case Y:
657
+ return y;
658
+ case Z:
659
+ return z;
660
+ }
661
+ throw new IllegalArgumentException();
662
+ }
663
+
664
+ /**
665
+ *
666
+ * @param id
667
+ * @return
668
+ */
669
+ @Override
670
+ public final float getComponent(int id) {
671
+ switch (id) {
672
+ case 0:
673
+ return x;
674
+ case 1:
675
+ return y;
676
+ case 2:
677
+ return z;
678
+ }
679
+ throw new IllegalArgumentException("index must be 0, 1 or 2");
680
+ }
681
+
682
+ /*
683
+ * (non-Javadoc)
684
+ *
685
+ * @see toxi.geom.ReadonlyVec3D#getConstrained(toxi.geom.AABB)
686
+ */
687
+ @Override
688
+ public final Vec3D getConstrained(AABB box) {
689
+ return new Vec3D(this).constrain(box);
690
+ }
691
+
692
+ /*
693
+ * (non-Javadoc)
694
+ *
695
+ * @see toxi.geom.ReadonlyVec3D#getFloored()
696
+ */
697
+ @Override
698
+ public final Vec3D getFloored() {
699
+ return new Vec3D(this).floor();
700
+ }
701
+
702
+ /*
703
+ * (non-Javadoc)
704
+ *
705
+ * @see toxi.geom.ReadonlyVec3D#getFrac()
706
+ */
707
+ @Override
708
+ public final Vec3D getFrac() {
709
+ return new Vec3D(this).frac();
710
+ }
711
+
712
+ /*
713
+ * (non-Javadoc)
714
+ *
715
+ * @see toxi.geom.ReadonlyVec3D#getInverted()
716
+ */
717
+ @Override
718
+ public final Vec3D getInverted() {
719
+ return new Vec3D(-x, -y, -z);
720
+ }
721
+
722
+ /*
723
+ * (non-Javadoc)
724
+ *
725
+ * @see toxi.geom.ReadonlyVec3D#getLimited(float)
726
+ */
727
+ @Override
728
+ public final Vec3D getLimited(float lim) {
729
+ if (magSquared() > lim * lim) {
730
+ return getNormalizedTo(lim);
731
+ }
732
+ return new Vec3D(this);
733
+ }
734
+
735
+ @Override
736
+ public Vec3D getMapped(ScaleMap map) {
737
+ return new Vec3D((float) map.getClippedValueFor(x),
738
+ (float) map.getClippedValueFor(y),
739
+ (float) map.getClippedValueFor(z));
740
+ }
741
+
742
+ /*
743
+ * (non-Javadoc)
744
+ *
745
+ * @see toxi.geom.ReadonlyVec3D#getNormalized()
746
+ */
747
+ @Override
748
+ public final Vec3D getNormalized() {
749
+ return new Vec3D(this).normalize();
750
+ }
751
+
752
+ /*
753
+ * (non-Javadoc)
754
+ *
755
+ * @see toxi.geom.ReadonlyVec3D#getNormalizedTo(float)
756
+ */
757
+ @Override
758
+ public final Vec3D getNormalizedTo(float len) {
759
+ return new Vec3D(this).normalizeTo(len);
760
+ }
761
+
762
+ /*
763
+ * (non-Javadoc)
764
+ *
765
+ * @see toxi.geom.ReadonlyVec3D#getReciprocal()
766
+ */
767
+ @Override
768
+ public final Vec3D getReciprocal() {
769
+ return copy().reciprocal();
770
+ }
771
+
772
+ /**
773
+ *
774
+ * @param normal
775
+ * @return
776
+ */
777
+ @Override
778
+ public final Vec3D getReflected(ReadonlyVec3D normal) {
779
+ return copy().reflect(normal);
780
+ }
781
+
782
+ /*
783
+ * (non-Javadoc)
784
+ *
785
+ * @see toxi.geom.ReadonlyVec3D#getRotatedAroundAxis(toxi.geom.Vec3D, float)
786
+ */
787
+ @Override
788
+ public final Vec3D getRotatedAroundAxis(ReadonlyVec3D axis, float theta) {
789
+ return new Vec3D(this).rotateAroundAxis(axis, theta);
790
+ }
791
+
792
+ /*
793
+ * (non-Javadoc)
794
+ *
795
+ * @see toxi.geom.ReadonlyVec3D#getRotatedX(float)
796
+ */
797
+ @Override
798
+ public final Vec3D getRotatedX(float theta) {
799
+ return new Vec3D(this).rotateX(theta);
800
+ }
801
+
802
+ /*
803
+ * (non-Javadoc)
804
+ *
805
+ * @see toxi.geom.ReadonlyVec3D#getRotatedY(float)
806
+ */
807
+ @Override
808
+ public final Vec3D getRotatedY(float theta) {
809
+ return new Vec3D(this).rotateY(theta);
810
+ }
811
+
812
+ /*
813
+ * (non-Javadoc)
814
+ *
815
+ * @see toxi.geom.ReadonlyVec3D#getRotatedZ(float)
816
+ */
817
+ @Override
818
+ public final Vec3D getRotatedZ(float theta) {
819
+ return new Vec3D(this).rotateZ(theta);
820
+ }
821
+
822
+ @Override
823
+ public Vec3D getRoundedTo(float prec) {
824
+ return copy().roundTo(prec);
825
+ }
826
+
827
+ /*
828
+ * (non-Javadoc)
829
+ *
830
+ * @see toxi.geom.ReadonlyVec3D#getSignum()
831
+ */
832
+ @Override
833
+ public final Vec3D getSignum() {
834
+ return new Vec3D(this).signum();
835
+ }
836
+
837
+ @Override
838
+ public Vec3D getSpherical() {
839
+ return copy().toSpherical();
840
+ }
841
+
842
+ /*
843
+ * (non-Javadoc)
844
+ *
845
+ * @see toxi.geom.ReadonlyVec3D#headingXY()
846
+ */
847
+ @Override
848
+ public final float headingXY() {
849
+ return (float) Math.atan2(y, x);
850
+ }
851
+
852
+ /*
853
+ * (non-Javadoc)
854
+ *
855
+ * @see toxi.geom.ReadonlyVec3D#headingXZ()
856
+ */
857
+ @Override
858
+ public final float headingXZ() {
859
+ return (float) Math.atan2(z, x);
860
+ }
861
+
862
+ /*
863
+ * (non-Javadoc)
864
+ *
865
+ * @see toxi.geom.ReadonlyVec3D#headingYZ()
866
+ */
867
+ @Override
868
+ public final float headingYZ() {
869
+ return (float) Math.atan2(y, z);
870
+ }
871
+
872
+ /**
873
+ *
874
+ * @return
875
+ */
876
+ public ReadonlyVec3D immutable() {
877
+ return this;
878
+ }
879
+
880
+ @Override
881
+ public final Vec3D interpolateTo(ReadonlyVec3D v, float f) {
882
+ return new Vec3D(x + (v.x() - x) * f, y + (v.y() - y) * f, z
883
+ + (v.z() - z) * f);
884
+ }
885
+
886
+ @Override
887
+ public final Vec3D interpolateTo(ReadonlyVec3D v, float f,
888
+ InterpolateStrategy s) {
889
+ return new Vec3D(s.interpolate(x, v.x(), f),
890
+ s.interpolate(y, v.y(), f), s.interpolate(z, v.z(), f));
891
+ }
892
+
893
+ /**
894
+ *
895
+ * @param v
896
+ * @param f
897
+ * @return
898
+ */
899
+ public final Vec3D interpolateTo(Vec3D v, float f) {
900
+ return new Vec3D(x + (v.x - x) * f, y + (v.y - y) * f, z + (v.z - z)
901
+ * f);
902
+ }
903
+
904
+ /**
905
+ *
906
+ * @param v
907
+ * @param f
908
+ * @param s
909
+ * @return
910
+ */
911
+ public final Vec3D interpolateTo(Vec3D v, float f, InterpolateStrategy s) {
912
+ return new Vec3D(s.interpolate(x, v.x, f), s.interpolate(y, v.y, f),
913
+ s.interpolate(z, v.z, f));
914
+ }
915
+
916
+ /**
917
+ * Interpolates the vector towards the given target vector, using linear
918
+ * interpolation.
919
+ *
920
+ * @param v
921
+ * target vector
922
+ * @param f
923
+ * interpolation factor (should be in the range 0..1)
924
+ *
925
+ * @return itself, result overrides current vector
926
+ */
927
+ public final Vec3D interpolateToSelf(ReadonlyVec3D v, float f) {
928
+ x += (v.x() - x) * f;
929
+ y += (v.y() - y) * f;
930
+ z += (v.z() - z) * f;
931
+ return this;
932
+ }
933
+
934
+ /**
935
+ * Interpolates the vector towards the given target vector, using the given
936
+ * {@link InterpolateStrategy}.
937
+ *
938
+ * @param v
939
+ * target vector
940
+ * @param f
941
+ * interpolation factor (should be in the range 0..1)
942
+ * @param s
943
+ * InterpolateStrategy instance
944
+ *
945
+ * @return itself, result overrides current vector
946
+ */
947
+ public final Vec3D interpolateToSelf(ReadonlyVec3D v, float f,
948
+ InterpolateStrategy s) {
949
+ x = s.interpolate(x, v.x(), f);
950
+ y = s.interpolate(y, v.y(), f);
951
+ z = s.interpolate(z, v.z(), f);
952
+ return this;
953
+ }
954
+
955
+ /**
956
+ * Scales vector uniformly by factor -1 ( v = -v ), overrides coordinates
957
+ * with result.
958
+ *
959
+ * @return itself
960
+ */
961
+ public final Vec3D invert() {
962
+ x *= -1;
963
+ y *= -1;
964
+ z *= -1;
965
+ return this;
966
+ }
967
+
968
+ /*
969
+ * (non-Javadoc)
970
+ *
971
+ * @see toxi.geom.ReadonlyVec3D#isInAABB(toxi.geom.AABB)
972
+ */
973
+ @Override
974
+ public boolean isInAABB(AABB box) {
975
+ final Vec3D min = box.getMin();
976
+ final Vec3D max = box.getMax();
977
+ if (x < min.x || x > max.x) {
978
+ return false;
979
+ }
980
+ if (y < min.y || y > max.y) {
981
+ return false;
982
+ }
983
+ return (z > min.z || z < max.z);
984
+ }
985
+
986
+ @Override
987
+ public boolean isInAABB(Vec3D boxOrigin, Vec3D boxExtent) {
988
+ float w = boxExtent.x;
989
+ if (x < boxOrigin.x - w || x > boxOrigin.x + w) {
990
+ return false;
991
+ }
992
+ w = boxExtent.y;
993
+ if (y < boxOrigin.y - w || y > boxOrigin.y + w) {
994
+ return false;
995
+ }
996
+ w = boxExtent.z;
997
+ return (z >= boxOrigin.z - w && z <= boxOrigin.z + w);
998
+ }
999
+
1000
+ @Override
1001
+ public final boolean isMajorAxis(float tol) {
1002
+ float ax = MathUtils.abs(x);
1003
+ float ay = MathUtils.abs(y);
1004
+ float az = MathUtils.abs(z);
1005
+ float itol = 1 - tol;
1006
+ if (ax > itol) {
1007
+ if (ay < tol) {
1008
+ return (az < tol);
1009
+ }
1010
+ } else if (ay > itol) {
1011
+ if (ax < tol) {
1012
+ return (az < tol);
1013
+ }
1014
+ } else if (az > itol) {
1015
+ if (ax < tol) {
1016
+ return (ay < tol);
1017
+ }
1018
+ }
1019
+ return false;
1020
+ }
1021
+
1022
+ @Override
1023
+ public final boolean isZeroVector() {
1024
+ return MathUtils.abs(x) < MathUtils.EPS
1025
+ && MathUtils.abs(y) < MathUtils.EPS
1026
+ && MathUtils.abs(z) < MathUtils.EPS;
1027
+ }
1028
+
1029
+ /**
1030
+ * Add random jitter to the vector in the range -j ... +j using the default
1031
+ * {@link Random} generator of {@link MathUtils}.
1032
+ *
1033
+ * @param j
1034
+ * the j
1035
+ *
1036
+ * @return the vec3 d
1037
+ */
1038
+ public final Vec3D jitter(float j) {
1039
+ return jitter(j, j, j);
1040
+ }
1041
+
1042
+ /**
1043
+ * Adds random jitter to the vector in the range -j ... +j using the default
1044
+ * {@link Random} generator of {@link MathUtils}.
1045
+ *
1046
+ * @param jx
1047
+ * maximum x jitter
1048
+ * @param jy
1049
+ * maximum y jitter
1050
+ * @param jz
1051
+ * maximum z jitter
1052
+ *
1053
+ * @return itself
1054
+ */
1055
+ public final Vec3D jitter(float jx, float jy, float jz) {
1056
+ x += MathUtils.normalizedRandom() * jx;
1057
+ y += MathUtils.normalizedRandom() * jy;
1058
+ z += MathUtils.normalizedRandom() * jz;
1059
+ return this;
1060
+ }
1061
+
1062
+ /**
1063
+ *
1064
+ * @param rnd
1065
+ * @param j
1066
+ * @return
1067
+ */
1068
+ public final Vec3D jitter(Random rnd, float j) {
1069
+ return jitter(rnd, j, j, j);
1070
+ }
1071
+
1072
+ /**
1073
+ *
1074
+ * @param rnd
1075
+ * @param jx
1076
+ * @param jy
1077
+ * @param jz
1078
+ * @return
1079
+ */
1080
+ public final Vec3D jitter(Random rnd, float jx, float jy, float jz) {
1081
+ x += MathUtils.normalizedRandom(rnd) * jx;
1082
+ y += MathUtils.normalizedRandom(rnd) * jy;
1083
+ z += MathUtils.normalizedRandom(rnd) * jz;
1084
+ return this;
1085
+ }
1086
+
1087
+ /**
1088
+ *
1089
+ * @param rnd
1090
+ * @param jitterVec
1091
+ * @return
1092
+ */
1093
+ public final Vec3D jitter(Random rnd, Vec3D jitterVec) {
1094
+ return jitter(rnd, jitterVec.x, jitterVec.y, jitterVec.z);
1095
+ }
1096
+
1097
+ /**
1098
+ * Adds random jitter to the vector in the range defined by the given vector
1099
+ * components and using the default {@link Random} generator of
1100
+ * {@link MathUtils}.
1101
+ *
1102
+ * @param jitterVec
1103
+ * the jitter vec
1104
+ *
1105
+ * @return itself
1106
+ */
1107
+ public final Vec3D jitter(Vec3D jitterVec) {
1108
+ return jitter(jitterVec.x, jitterVec.y, jitterVec.z);
1109
+ }
1110
+
1111
+ /**
1112
+ * Limits the vector's magnitude to the length given.
1113
+ *
1114
+ * @param lim
1115
+ * new maximum magnitude
1116
+ *
1117
+ * @return itself
1118
+ */
1119
+ public final Vec3D limit(float lim) {
1120
+ if (magSquared() > lim * lim) {
1121
+ return normalize().scaleSelf(lim);
1122
+ }
1123
+ return this;
1124
+ }
1125
+
1126
+ @Override
1127
+ public final float magnitude() {
1128
+ return (float) Math.sqrt(x * x + y * y + z * z);
1129
+ }
1130
+
1131
+ @Override
1132
+ public final float magSquared() {
1133
+ return x * x + y * y + z * z;
1134
+ }
1135
+
1136
+ /**
1137
+ * Max self.
1138
+ *
1139
+ * @param b
1140
+ * the b
1141
+ *
1142
+ * @return the vec3 d
1143
+ */
1144
+ public final Vec3D maxSelf(ReadonlyVec3D b) {
1145
+ x = MathUtils.max(x, b.x());
1146
+ y = MathUtils.max(y, b.y());
1147
+ z = MathUtils.max(z, b.z());
1148
+ return this;
1149
+ }
1150
+
1151
+ /**
1152
+ * Min self.
1153
+ *
1154
+ * @param b
1155
+ * the b
1156
+ *
1157
+ * @return the vec3 d
1158
+ */
1159
+ public final Vec3D minSelf(ReadonlyVec3D b) {
1160
+ x = MathUtils.min(x, b.x());
1161
+ y = MathUtils.min(y, b.y());
1162
+ z = MathUtils.min(z, b.z());
1163
+ return this;
1164
+ }
1165
+
1166
+ /**
1167
+ * Applies a uniform modulo operation to the vector, using the same base for
1168
+ * all components.
1169
+ *
1170
+ * @param base
1171
+ * the base
1172
+ *
1173
+ * @return itself
1174
+ */
1175
+ public final Vec3D modSelf(float base) {
1176
+ x %= base;
1177
+ y %= base;
1178
+ z %= base;
1179
+ return this;
1180
+ }
1181
+
1182
+ /**
1183
+ * Calculates modulo operation for each vector component separately.
1184
+ *
1185
+ * @param bx
1186
+ * the bx
1187
+ * @param by
1188
+ * the by
1189
+ * @param bz
1190
+ * the bz
1191
+ *
1192
+ * @return itself
1193
+ */
1194
+
1195
+ public final Vec3D modSelf(float bx, float by, float bz) {
1196
+ x %= bx;
1197
+ y %= by;
1198
+ z %= bz;
1199
+ return this;
1200
+ }
1201
+
1202
+ /**
1203
+ * Normalizes the vector so that its magnitude = 1.
1204
+ *
1205
+ * @return itself
1206
+ */
1207
+ public final Vec3D normalize() {
1208
+ float mag = (float) Math.sqrt(x * x + y * y + z * z);
1209
+ if (mag > 0) {
1210
+ mag = 1f / mag;
1211
+ x *= mag;
1212
+ y *= mag;
1213
+ z *= mag;
1214
+ }
1215
+ return this;
1216
+ }
1217
+
1218
+ /**
1219
+ * Normalizes the vector to the given length.
1220
+ *
1221
+ * @param len
1222
+ * desired length
1223
+ * @return itself
1224
+ */
1225
+ public final Vec3D normalizeTo(float len) {
1226
+ float mag = (float) Math.sqrt(x * x + y * y + z * z);
1227
+ if (mag > 0) {
1228
+ mag = len / mag;
1229
+ x *= mag;
1230
+ y *= mag;
1231
+ z *= mag;
1232
+ }
1233
+ return this;
1234
+ }
1235
+
1236
+ /**
1237
+ * Replaces the vector components with their multiplicative inverse.
1238
+ *
1239
+ * @return itself
1240
+ */
1241
+ public final Vec3D reciprocal() {
1242
+ x = 1f / x;
1243
+ y = 1f / y;
1244
+ z = 1f / z;
1245
+ return this;
1246
+ }
1247
+
1248
+ /**
1249
+ *
1250
+ * @param normal
1251
+ * @return
1252
+ */
1253
+ public final Vec3D reflect(ReadonlyVec3D normal) {
1254
+ return set(normal.scale(this.dot(normal) * 2).subSelf(this));
1255
+ }
1256
+
1257
+ /**
1258
+ * Rotates the vector around the giving axis.
1259
+ *
1260
+ * @param axis
1261
+ * rotation axis vector
1262
+ * @param theta
1263
+ * rotation angle (in radians)
1264
+ *
1265
+ * @return itself
1266
+ */
1267
+ public final Vec3D rotateAroundAxis(ReadonlyVec3D axis, float theta) {
1268
+ final float ax = axis.x();
1269
+ final float ay = axis.y();
1270
+ final float az = axis.z();
1271
+ final float ux = ax * x;
1272
+ final float uy = ax * y;
1273
+ final float uz = ax * z;
1274
+ final float vx = ay * x;
1275
+ final float vy = ay * y;
1276
+ final float vz = ay * z;
1277
+ final float wx = az * x;
1278
+ final float wy = az * y;
1279
+ final float wz = az * z;
1280
+ final double si = Math.sin(theta);
1281
+ final double co = Math.cos(theta);
1282
+ float xx = (float) (ax * (ux + vy + wz)
1283
+ + (x * (ay * ay + az * az) - ax * (vy + wz)) * co + (-wy + vz)
1284
+ * si);
1285
+ float yy = (float) (ay * (ux + vy + wz)
1286
+ + (y * (ax * ax + az * az) - ay * (ux + wz)) * co + (wx - uz)
1287
+ * si);
1288
+ float zz = (float) (az * (ux + vy + wz)
1289
+ + (z * (ax * ax + ay * ay) - az * (ux + vy)) * co + (-vx + uy)
1290
+ * si);
1291
+ x = xx;
1292
+ y = yy;
1293
+ z = zz;
1294
+ return this;
1295
+ }
1296
+
1297
+ /**
1298
+ * Rotates the vector by the given angle around the X axis.
1299
+ *
1300
+ * @param theta
1301
+ * the theta
1302
+ *
1303
+ * @return itself
1304
+ */
1305
+ public final Vec3D rotateX(float theta) {
1306
+ final float co = (float) Math.cos(theta);
1307
+ final float si = (float) Math.sin(theta);
1308
+ final float zz = co * z - si * y;
1309
+ y = si * z + co * y;
1310
+ z = zz;
1311
+ return this;
1312
+ }
1313
+
1314
+ /**
1315
+ * Rotates the vector by the given angle around the Y axis.
1316
+ *
1317
+ * @param theta
1318
+ * the theta
1319
+ *
1320
+ * @return itself
1321
+ */
1322
+ public final Vec3D rotateY(float theta) {
1323
+ final float co = (float) Math.cos(theta);
1324
+ final float si = (float) Math.sin(theta);
1325
+ final float xx = co * x - si * z;
1326
+ z = si * x + co * z;
1327
+ x = xx;
1328
+ return this;
1329
+ }
1330
+
1331
+ /**
1332
+ * Rotates the vector by the given angle around the Z axis.
1333
+ *
1334
+ * @param theta
1335
+ * the theta
1336
+ *
1337
+ * @return itself
1338
+ */
1339
+ public final Vec3D rotateZ(float theta) {
1340
+ final float co = (float) Math.cos(theta);
1341
+ final float si = (float) Math.sin(theta);
1342
+ final float xx = co * x - si * y;
1343
+ y = si * x + co * y;
1344
+ x = xx;
1345
+ return this;
1346
+ }
1347
+
1348
+ /**
1349
+ *
1350
+ * @param prec
1351
+ * @return
1352
+ */
1353
+ public Vec3D roundTo(float prec) {
1354
+ x = MathUtils.roundTo(x, prec);
1355
+ y = MathUtils.roundTo(y, prec);
1356
+ z = MathUtils.roundTo(z, prec);
1357
+ return this;
1358
+ }
1359
+
1360
+ @Override
1361
+ public Vec3D scale(float s) {
1362
+ return new Vec3D(x * s, y * s, z * s);
1363
+ }
1364
+
1365
+ @Override
1366
+ public Vec3D scale(float a, float b, float c) {
1367
+ return new Vec3D(x * a, y * b, z * c);
1368
+ }
1369
+
1370
+ @Override
1371
+ public Vec3D scale(ReadonlyVec3D s) {
1372
+ return new Vec3D(x * s.x(), y * s.y(), z * s.z());
1373
+ }
1374
+
1375
+ /**
1376
+ *
1377
+ * @param s
1378
+ * @return
1379
+ */
1380
+ public Vec3D scale(Vec3D s) {
1381
+ return new Vec3D(x * s.x, y * s.y, z * s.z);
1382
+ }
1383
+
1384
+ /**
1385
+ * Scales vector uniformly and overrides coordinates with result.
1386
+ *
1387
+ * @param s
1388
+ * scale factor
1389
+ *
1390
+ * @return itself
1391
+ */
1392
+ public Vec3D scaleSelf(float s) {
1393
+ x *= s;
1394
+ y *= s;
1395
+ z *= s;
1396
+ return this;
1397
+ }
1398
+
1399
+ /**
1400
+ * Scales vector non-uniformly by vector {a,b,c} and overrides coordinates
1401
+ * with result.
1402
+ *
1403
+ * @param a
1404
+ * scale factor for X coordinate
1405
+ * @param b
1406
+ * scale factor for Y coordinate
1407
+ * @param c
1408
+ * scale factor for Z coordinate
1409
+ *
1410
+ * @return itself
1411
+ */
1412
+ public Vec3D scaleSelf(float a, float b, float c) {
1413
+ x *= a;
1414
+ y *= b;
1415
+ z *= c;
1416
+ return this;
1417
+ }
1418
+
1419
+ /**
1420
+ *
1421
+ * @param s
1422
+ * @return
1423
+ */
1424
+ public Vec3D scaleSelf(ReadonlyVec3D s) {
1425
+ x *= s.x();
1426
+ y *= s.y();
1427
+ z *= s.z();
1428
+ return this;
1429
+ }
1430
+
1431
+ /**
1432
+ * Scales vector non-uniformly by vector v and overrides coordinates with
1433
+ * result.
1434
+ *
1435
+ * @param s
1436
+ * scale vector
1437
+ *
1438
+ * @return itself
1439
+ */
1440
+
1441
+ public Vec3D scaleSelf(Vec3D s) {
1442
+ x *= s.x;
1443
+ y *= s.y;
1444
+ z *= s.z;
1445
+ return this;
1446
+ }
1447
+
1448
+ /**
1449
+ * Overrides coordinates with the given values.
1450
+ *
1451
+ * @param x
1452
+ * the x
1453
+ * @param y
1454
+ * the y
1455
+ * @param z
1456
+ * the z
1457
+ *
1458
+ * @return itself
1459
+ */
1460
+ public Vec3D set(float x, float y, float z) {
1461
+ this.x = x;
1462
+ this.y = y;
1463
+ this.z = z;
1464
+ return this;
1465
+ }
1466
+
1467
+ /**
1468
+ *
1469
+ * @param v
1470
+ * @return
1471
+ */
1472
+ public Vec3D set(ReadonlyVec3D v) {
1473
+ x = v.x();
1474
+ y = v.y();
1475
+ z = v.z();
1476
+ return this;
1477
+ }
1478
+
1479
+ /**
1480
+ * Overrides coordinates with the ones of the given vector.
1481
+ *
1482
+ * @param v
1483
+ * vector to be copied
1484
+ *
1485
+ * @return itself
1486
+ */
1487
+ public Vec3D set(Vec3D v) {
1488
+ x = v.x;
1489
+ y = v.y;
1490
+ z = v.z;
1491
+ return this;
1492
+ }
1493
+
1494
+ /**
1495
+ *
1496
+ * @param id
1497
+ * @param val
1498
+ * @return
1499
+ */
1500
+ public final Vec3D setComponent(Axis id, float val) {
1501
+ switch (id) {
1502
+ case X:
1503
+ x = val;
1504
+ break;
1505
+ case Y:
1506
+ y = val;
1507
+ break;
1508
+ case Z:
1509
+ z = val;
1510
+ break;
1511
+ }
1512
+ return this;
1513
+ }
1514
+
1515
+ /**
1516
+ *
1517
+ * @param id
1518
+ * @param val
1519
+ * @return
1520
+ */
1521
+ public final Vec3D setComponent(int id, float val) {
1522
+ switch (id) {
1523
+ case 0:
1524
+ x = val;
1525
+ break;
1526
+ case 1:
1527
+ y = val;
1528
+ break;
1529
+ case 2:
1530
+ z = val;
1531
+ break;
1532
+ }
1533
+ return this;
1534
+ }
1535
+
1536
+ /**
1537
+ *
1538
+ * @param x
1539
+ * @return
1540
+ */
1541
+ public Vec3D setX(float x) {
1542
+ this.x = x;
1543
+ return this;
1544
+ }
1545
+
1546
+ /**
1547
+ * Overrides XY coordinates with the ones of the given 2D vector.
1548
+ *
1549
+ * @param v
1550
+ * 2D vector
1551
+ *
1552
+ * @return itself
1553
+ */
1554
+ public Vec3D setXY(Vec2D v) {
1555
+ x = v.x;
1556
+ y = v.y;
1557
+ return this;
1558
+ }
1559
+
1560
+ /**
1561
+ *
1562
+ * @param y
1563
+ * @return
1564
+ */
1565
+ public Vec3D setY(float y) {
1566
+ this.y = y;
1567
+ return this;
1568
+ }
1569
+
1570
+ /**
1571
+ *
1572
+ * @param z
1573
+ * @return
1574
+ */
1575
+ public Vec3D setZ(float z) {
1576
+ this.z = z;
1577
+ return this;
1578
+ }
1579
+
1580
+ /**
1581
+ *
1582
+ * @param iterations
1583
+ * @return
1584
+ */
1585
+ public Vec3D shuffle(int iterations) {
1586
+ float t;
1587
+ for (int i = 0; i < iterations; i++) {
1588
+ switch (MathUtils.random(3)) {
1589
+ case 0:
1590
+ t = x;
1591
+ x = y;
1592
+ y = t;
1593
+ break;
1594
+ case 1:
1595
+ t = x;
1596
+ x = z;
1597
+ z = t;
1598
+ break;
1599
+ case 2:
1600
+ t = y;
1601
+ y = z;
1602
+ z = t;
1603
+ break;
1604
+ }
1605
+ }
1606
+ return this;
1607
+ }
1608
+
1609
+ /**
1610
+ * Replaces all vector components with the signum of their original values.
1611
+ * In other words if a components value was negative its new value will be
1612
+ * -1, if zero => 0, if positive => +1
1613
+ *
1614
+ * @return itself
1615
+ */
1616
+ public Vec3D signum() {
1617
+ x = (x < 0 ? -1 : x == 0 ? 0 : 1);
1618
+ y = (y < 0 ? -1 : y == 0 ? 0 : 1);
1619
+ z = (z < 0 ? -1 : z == 0 ? 0 : 1);
1620
+ return this;
1621
+ }
1622
+
1623
+ /**
1624
+ * Rounds the vector to the closest major axis. Assumes the vector is
1625
+ * normalized.
1626
+ *
1627
+ * @return itself
1628
+ */
1629
+ public final Vec3D snapToAxis() {
1630
+ if (MathUtils.abs(x) < 0.5f) {
1631
+ x = 0;
1632
+ } else {
1633
+ x = x < 0 ? -1 : 1;
1634
+ y = z = 0;
1635
+ }
1636
+ if (MathUtils.abs(y) < 0.5f) {
1637
+ y = 0;
1638
+ } else {
1639
+ y = y < 0 ? -1 : 1;
1640
+ x = z = 0;
1641
+ }
1642
+ if (MathUtils.abs(z) < 0.5f) {
1643
+ z = 0;
1644
+ } else {
1645
+ z = z < 0 ? -1 : 1;
1646
+ x = y = 0;
1647
+ }
1648
+ return this;
1649
+ }
1650
+
1651
+ @Override
1652
+ public final Vec3D sub(float a, float b, float c) {
1653
+ return new Vec3D(x - a, y - b, z - c);
1654
+ }
1655
+
1656
+ @Override
1657
+ public final Vec3D sub(ReadonlyVec3D v) {
1658
+ return new Vec3D(x - v.x(), y - v.y(), z - v.z());
1659
+ }
1660
+
1661
+ /**
1662
+ *
1663
+ * @param v
1664
+ * @return
1665
+ */
1666
+ public final Vec3D sub(Vec3D v) {
1667
+ return new Vec3D(x - v.x, y - v.y, z - v.z);
1668
+ }
1669
+
1670
+ /**
1671
+ * Subtracts vector {a,b,c} and overrides coordinates with result.
1672
+ *
1673
+ * @param a
1674
+ * X coordinate
1675
+ * @param b
1676
+ * Y coordinate
1677
+ * @param c
1678
+ * Z coordinate
1679
+ *
1680
+ * @return itself
1681
+ */
1682
+ public final Vec3D subSelf(float a, float b, float c) {
1683
+ x -= a;
1684
+ y -= b;
1685
+ z -= c;
1686
+ return this;
1687
+ }
1688
+
1689
+ /**
1690
+ *
1691
+ * @param v
1692
+ * @return
1693
+ */
1694
+ public final Vec3D subSelf(ReadonlyVec3D v) {
1695
+ x -= v.x();
1696
+ y -= v.y();
1697
+ z -= v.z();
1698
+ return this;
1699
+ }
1700
+
1701
+ /**
1702
+ * Subtracts vector v and overrides coordinates with result.
1703
+ *
1704
+ * @param v
1705
+ * vector to be subtracted
1706
+ *
1707
+ * @return itself
1708
+ */
1709
+ public final Vec3D subSelf(Vec3D v) {
1710
+ x -= v.x;
1711
+ y -= v.y;
1712
+ z -= v.z;
1713
+ return this;
1714
+ }
1715
+
1716
+ @Override
1717
+ public final Vec2D to2DXY() {
1718
+ return new Vec2D(x, y);
1719
+ }
1720
+
1721
+ @Override
1722
+ public final Vec2D to2DXZ() {
1723
+ return new Vec2D(x, z);
1724
+ }
1725
+
1726
+ @Override
1727
+ public final Vec2D to2DYZ() {
1728
+ return new Vec2D(y, z);
1729
+ }
1730
+
1731
+ @Override
1732
+ public Vec4D to4D() {
1733
+ return new Vec4D(x, y, z, 1);
1734
+ }
1735
+
1736
+ @Override
1737
+ public Vec4D to4D(float w) {
1738
+ return new Vec4D(x, y, z, w);
1739
+ }
1740
+
1741
+ /**
1742
+ *
1743
+ * @return
1744
+ */
1745
+ @Override
1746
+ public float[] toArray() {
1747
+ return new float[] {
1748
+ x, y, z
1749
+ };
1750
+ }
1751
+
1752
+ /**
1753
+ *
1754
+ * @param w
1755
+ * @return
1756
+ */
1757
+ @Override
1758
+ public float[] toArray4(float w) {
1759
+ return new float[] {
1760
+ x, y, z, w
1761
+ };
1762
+ }
1763
+
1764
+ /**
1765
+ *
1766
+ * @return
1767
+ */
1768
+ public final Vec3D toCartesian() {
1769
+ final float a = (float) (x * Math.cos(z));
1770
+ final float xx = (float) (a * Math.cos(y));
1771
+ final float yy = (float) (x * Math.sin(z));
1772
+ final float zz = (float) (a * Math.sin(y));
1773
+ x = xx;
1774
+ y = yy;
1775
+ z = zz;
1776
+ return this;
1777
+ }
1778
+
1779
+ /**
1780
+ *
1781
+ * @return
1782
+ */
1783
+ public final Vec3D toSpherical() {
1784
+ final float xx = Math.abs(x) <= MathUtils.EPS ? MathUtils.EPS : x;
1785
+ final float zz = z;
1786
+
1787
+ final float radius = (float) Math.sqrt((xx * xx) + (y * y) + (zz * zz));
1788
+ z = (float) Math.asin(y / radius);
1789
+ y = (float) Math.atan(zz / xx) + (xx < 0.0 ? MathUtils.PI : 0);
1790
+ x = radius;
1791
+ return this;
1792
+ }
1793
+
1794
+ /**
1795
+ *
1796
+ * @return
1797
+ */
1798
+ @Override
1799
+ public String toString() {
1800
+ final StringBuffer sb = new StringBuffer(48);
1801
+ sb.append("{x:").append(x).append(", y:").append(y).append(", z:")
1802
+ .append(z).append("}");
1803
+ return sb.toString();
1804
+ }
1805
+
1806
+ /**
1807
+ *
1808
+ * @return
1809
+ */
1810
+ @Override
1811
+ public final float x() {
1812
+ return x;
1813
+ }
1814
+
1815
+ /**
1816
+ *
1817
+ * @return
1818
+ */
1819
+ @Override
1820
+ public final float y() {
1821
+ return y;
1822
+ }
1823
+
1824
+ /**
1825
+ *
1826
+ * @return
1827
+ */
1828
+ @Override
1829
+ public final float z() {
1830
+ return z;
1831
+ }
1832
+ }