You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Matt Juntunen (JIRA)" <ji...@apache.org> on 2018/12/15 20:53:00 UTC

[jira] [Created] (GEOMETRY-26) Vector safeNormalize()

Matt Juntunen created GEOMETRY-26:
-------------------------------------

             Summary: Vector safeNormalize()
                 Key: GEOMETRY-26
                 URL: https://issues.apache.org/jira/browse/GEOMETRY-26
             Project: Apache Commons Geometry
          Issue Type: Wish
            Reporter: Matt Juntunen


I propose adding a {{safeNormalize}} method to the {{Vector}} classes that will return null instead throwing an exception when attempting to normalize. The rationale for this is that
in some algorithms, different actions may need to be taken depending on whether or not a vector can be normalized. It is inefficient to calculate the norm, determine if it is valid (zero, NaN, or infinite), and then calculate it again in the {{normalize}} method to perform the normalization. One approach to avoid this is to simply call {{normalize}} and then catch any exceptions that are thrown on failure (this is what {{QuaternionRotation.getAxis()}} does). However, I think having a null check will produce cleaner code.



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