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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

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

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/GEOMETRY-26?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16764432#comment-16764432 ]

Matt Juntunen commented on GEOMETRY-26:

{quote}Side note: In "Commons Math", the angle is computed in either of two ways depending on the value of "w" (numerical stability IIUC). Could you please have a look?
I don't think this applies in our situtation. The old code had the concept of a {{RotationConvention}} which we've discarded.

{quote}IMHO, it's up to the caller to keep track of the context and _not_ call normalize if it would fail.
Ok, I can go with that. I'm going to close this issue, then.


> Vector safeNormalize()
> ----------------------
>                 Key: GEOMETRY-26
>                 URL: https://issues.apache.org/jira/browse/GEOMETRY-26
>             Project: Apache Commons Geometry
>          Issue Type: Wish
>            Reporter: Matt Juntunen
>            Priority: Minor
> 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