[ 
https://issues.apache.org/jira/browse/GEOMETRY-10?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Matt Juntunen updated GEOMETRY-10:
----------------------------------
    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:
{code:java}
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);
}{code}
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

  was:
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:
{code:java}
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);
}{code}
We'll need to verify that this won't introduce any floating point accuracy 
issues.


> Reuse Normalized Vectors
> ------------------------
>
>                 Key: GEOMETRY-10
>                 URL: https://issues.apache.org/jira/browse/GEOMETRY-10
>             Project: Apache Commons Geometry
>          Issue Type: Improvement
>            Reporter: Matt Juntunen
>            Priority: Minor
>
> 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:
> {code:java}
> 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);
> }{code}
> 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



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to