Java examples for 2D Graphics:Rectangle
nearly Equals Rectangle2D
import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import org.apache.log4j.*; public class Main{ public static void main(String[] argv) throws Exception{ double a = 2.45678; double b = 2.45678; double err = 2.45678; System.out.println(nearlyEquals(a,b,err)); }//www . jav a2 s . c om public static boolean nearlyEquals(double a, double b, double err) { return Math.abs(a - b) < err; } public static boolean nearlyEquals(Point2D a, Point2D b, double err) { return nearlyEquals(a.getX(), b.getX(), err) && nearlyEquals(a.getY(), b.getY(), err); } public static boolean nearlyEquals(Rectangle2D a, Rectangle2D b, double err) { return nearlyEquals(a.getX(), b.getX(), err) && nearlyEquals(a.getWidth(), b.getWidth(), err) && nearlyEquals(a.getY(), b.getY(), err) && nearlyEquals(a.getHeight(), b.getHeight(), err); } }