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

Gilles Sadowski commented on NUMBERS-163:
-----------------------------------------

{quote}[here|https://github.com/apache/commons-geometry/blob/master/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/RegionBSPTree2S.java#L173]
 [...] replace [...] {{Vector3D}} accumulator [...] with extended precision 
[...]
{quote}
As this is (conceptually) a ({{Vector3D}}) addition (to be carried by 3 
{{Summation}} instances), we should perhaps encapsulate the (extended 
precision) "implementation details" in a {{SumVector3D}} class (name TBD):
{code:java}
public class SumVector3D {
    private Summation x = Summation.zero();
    private Summation y = Summation.zero();
    private Summation z = Summation.zero();

    public SumVector3D() {}

    public void add(Vector3D v) {
        x = Summation.add(v.getX());
        // ...
    }

    public Vector3D get() {
        return Vector3D.of(x.getAsDouble(), y.getAsDouble(), z.getAsDouble());
    }
}
{code}

(Unrelated) nit: Variable 
[{{centroidVector}}|https://github.com/apache/commons-geometry/blob/master/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/RegionBSPTree2S.java#L175]
 should be declared inside the loop and "final".

> Summation and LinearCombination Accumulators
> --------------------------------------------
>
>                 Key: NUMBERS-163
>                 URL: https://issues.apache.org/jira/browse/NUMBERS-163
>             Project: Commons Numbers
>          Issue Type: New Feature
>            Reporter: Matt Juntunen
>            Priority: Major
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> It would be useful to have simple accumulator classes in {{Summation}} and 
> {{LinearCombination}} to perform extended precision operations on arbitrary 
> collections of values without requiring conversion to {{double[]}}. Ex:
> {code:java}
> Summation.Accumulator sum= Summation.accumulator(1d);
> sum.add(x)
>     .add(y)
>     .add(z)
>    .add(w);
> double sumResult = sum.get();
> LinearCombination.Accumulator comb = LinearCombination.accumulator(1d);
> comb.add(x, scale)
>     .add(y, scale)
>     .add(z, scale)
>     .add(w, scale);
> double combResult = comb.get();
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to