org.hermit.geometry
Class MathTools

java.lang.Object
  extended by org.hermit.geometry.MathTools

public class MathTools
extends java.lang.Object

Mathematical utilities for geometric calculations.

This package provides mathematical comparisons which ignore the lowest bits of the provided values. This is useful when comparing values which should be equal, except for floating-point representability and rounding.


Constructor Summary
MathTools()
           
 
Method Summary
static boolean eq(double a, double b)
          Determine whether two values are equal to within the current precision.
static boolean lt(double a, double b)
          Determine whether a value is less than another to within the current precision.
static double round(double val)
          Return the given value rounded according to the current precision.
static void setPrecision(double val)
          Set the precision for calculations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MathTools

public MathTools()
Method Detail

setPrecision

public static final void setPrecision(double val)
Set the precision for calculations. The precision is given as a scaling factor; values are scaled by this value and rounded to 1.

Parameters:
val - The precision as a scaling factor.

round

public static final double round(double val)
Return the given value rounded according to the current precision.

Parameters:
val - The value to round.
Returns:
The rounded value.

eq

public static final boolean eq(double a,
                               double b)
Determine whether two values are equal to within the current precision.

Parameters:
a - One value to compare.
b - The other value to compare.
Returns:
True if the values do not differ within the current precision.

lt

public static final boolean lt(double a,
                               double b)
Determine whether a value is less than another to within the current precision.

Parameters:
a - One value to compare.
b - The other value to compare.
Returns:
True if a < b by at least the current precision.