Returns true if the Double value difference is minor to 1e-12. - Java java.lang

Java examples for java.lang:Math Algorithm

Description

Returns true if the Double value difference is minor to 1e-12.

Demo Code


import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;

public class Main{
    public static void main(String[] argv) throws Exception{
        double pointA = 2.45678;
        double pointB = 2.45678;
        System.out.println(comparePoints(pointA,pointB));
    }/*from   w w w  . ja  v a 2  s.  co  m*/
    private static final double EPS = 1e-12;
    /**
     * Returns true if the difference is minor to 1e-12.
     * @param pointA a point
     * @param pointB a point
     * @return true if pointA equal to pointB
     */
    public static boolean comparePoints(Double pointA, Double pointB) {
        if (Math.abs(pointA.getX() - pointB.getX()) < EPS) {
            if (Math.abs(pointA.getY() - pointB.getY()) < EPS) {
                return true;
            }
        }

        return false;
    }
}

Related Tutorials