You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gilles (JIRA)" <ji...@apache.org> on 2018/09/06 12:42:00 UTC
[jira] [Commented] (GEOMETRY-10) Reuse Normalized Vectors
[ https://issues.apache.org/jira/browse/GEOMETRY-10?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16605723#comment-16605723 ]
Gilles commented on GEOMETRY-10:
--------------------------------
Implementation of {{normalize()}} in the description does not take [infinities into account|https://git1-us-west.apache.org/repos/asf?p=commons-math.git;a=blob;f=src/main/java/org/apache/commons/math4/util/MathArrays.java;h=0f7046ee0bf83073c18a2928752e6d21c4cf7152;hb=HEAD#l958].
bq. We'll need to verify that this won't introduce any floating point accuracy issues.
Perhaps this [implementation|https://git1-us-west.apache.org/repos/asf?p=commons-numbers.git;a=blob;f=commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/SafeNorm.java;h=a04fb4d1a5aef78fb4b10eb8d4d9dea5cff03780;hb=HEAD] should be used (?).
> 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.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)