Absolute value operations on vector classes - #2962
AfonsoDGBatista wants to merge 3 commits into
Conversation
Add methods to compute absolute values of Vector2f components.
Added methods to compute absolute values of vector components.
Added methods to compute absolute values of vector components.
| * @return a new Vector3f with non-negative components | ||
| */ | ||
| public Vector3f abs() { | ||
| return new Vector3f(Math.abs(x), Math.abs(y),Math.abs(z)); |
There was a problem hiding this comment.
Missing space after the comma between Math.abs(y) and Math.abs(z). The rest of this file (and the repo's documented style, Google style per CONTRIBUTING.md) uses a single space after argument commas.
| return new Vector3f(Math.abs(x), Math.abs(y),Math.abs(z)); | |
| return new Vector3f(Math.abs(x), Math.abs(y), Math.abs(z)); |
| * @return a new Vector4f with non-negative components | ||
| */ | ||
| public Vector4f abs() { | ||
| return new Vector4f(Math.abs(x), Math.abs(y),Math.abs(z),Math.abs(w)); |
There was a problem hiding this comment.
Same formatting issue as in Vector3f: missing space after the comma before Math.abs(z).
| return new Vector4f(Math.abs(x), Math.abs(y),Math.abs(z),Math.abs(w)); | |
| return new Vector4f(Math.abs(x), Math.abs(y), Math.abs(z), Math.abs(w)); |
| y = Math.abs(y); | ||
| z = Math.abs(z); | ||
| return this; | ||
| } |
There was a problem hiding this comment.
The six new public methods have no test coverage. jme3-core/src/test/java/com/jme3/math/Vector3fTest.java exercises essentially every other public method of Vector3f (including maxLocal, minLocal, negate), so abs()/absLocal() should get matching tests there. Worth asserting the edge cases the existing suite cares about: negative components, -0.0f (→ +0.0f), and NaN propagation. Vector2f/Vector4f have no test classes, so covering the Vector3f variants is the minimum.
jaime-jmebot
left a comment
There was a problem hiding this comment.
- The added logic is correct:
abs()/absLocal()follow the engine's...Localnaming, andMath.absmaps-0.0fto+0.0fand propagates NaN consistently with the rest ofcom.jme3.math. - Two formatting violations (missing space after a comma) in
Vector3f.abs()andVector4f.abs(); committable one-line fixes are posted inline. - No tests for the six new methods.
Vector3fTestis the established home for per-method vector tests and should be extended to cover the abs variants, including-0.0fand NaN inputs. - Per CONTRIBUTING.md, non-trivial additions are expected to start with a forum thread; link the discussion in the PR description if one exists.
Added abs and absLocal methods on Vector2f, Vector3f and Vector4f classes.