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

Matt Juntunen commented on NUMBERS-90:
--------------------------------------

These classes are meant to replace the usage of {{tolerance}} values in 
commons-geometry. When users create instances of classes like {{Plane}} and 
{{Line}}, they currently pass in a tolerance double value that essentially 
defines the "thickness" of the hyperplane. For example, if the distance of a 
point from the hyperplane is less than the tolerance, then the point belongs to 
the hyperplane. The value is also used in various other floating point 
comparisons and is exactly like the absolute epsilon in the 
{{EpsilonDoublePrecisionContext}} class in this PR. I wanted to move away from 
passing raw double values as tolerances in commons-geometry and instead use 
classes so that 1) we could avoid all of the duplication of expressions such as 
{{if (Math.abs(a - b) <= tolerance)\{ ... }}} and 2) so that the library could 
be extended later with other floating point comparison strategies. Users could 
then choose the comparison strategy that works best for the types of numbers 
used in their applications.

So, all of this to say, these classes can't be internal. Users will need to 
create instances of them to pass to other commons-geometry types.
{quote}Assuming you have two *very* large cubes next to each other, how do 
define whether they have a common face?
{quote}
The logic is the same for any size of cubes. In order to help avoid floating 
point comparison issues, users need to choose an appropriate tolerance value 
(current behavior) or precision context (after this PR and GEOMETRY-11) for 
their particular application.

> DoublePrecisionContext
> ----------------------
>
>                 Key: NUMBERS-90
>                 URL: https://issues.apache.org/jira/browse/NUMBERS-90
>             Project: Commons Numbers
>          Issue Type: New Feature
>            Reporter: Matt Juntunen
>            Priority: Blocker
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> We should add a new class to commons-numbers-core that encapsulates 
> configurable strategies for comparing doubles. This is required for 
> GEOMETRY-11. Here is what I'm picturing:
> {code:java}
> // abstract class for the general concept of comparisons
> public abstract class DoublePrecisionContext implements Comparator<Double> {
>     public abstract boolean equals(double a, double b);
>     public int compare(double a, double b) { /* ... */ }
>     public int compare(Double a, Double b) { /* ... */ }
> }
> // ...
> // concrete class implementing a specific strategy
> public class EpsilonUlpDoublePrecisionContext extends DoublePrecisionContext {
>     public EpsilonUlpDoublePrecisionContext(double eps, double maxUlps) { /* 
> ... */ }
>     @Override
>     public boolean equals(double a, double b) { /* ... */ }
> } {code}
> Pull request: https://github.com/apache/commons-numbers/pull/28



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

Reply via email to