Java examples for 2D Graphics:Rectangle
snug Fit Rectangle2D
import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import org.apache.log4j.*; public class Main{ public static boolean snugFit(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)); }//from w ww . j a va 2s . c o m 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); } }