Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Done
-
None
-
None
-
None
Description
The Vector.normalize() method is used quite frequently. We currently always return a new instance with each method call, but we should be able to reuse the current instance if it is already normalized.
Ex:
public Vector3D normalize() { final double normSq = getNormSq(); if (normSq == 1.0) { return this; } else if (normSq == 0.0) { throw new IllegalStateException(ZERO_NORM_MSG); } return scalarMultiply(1 / Math.sqrt(normSq); }
We'll need to verify that this won't introduce any floating point accuracy issues.
Pull request: https://github.com/apache/commons-geometry/pull/10