Class ShapeChecker

java.lang.Object
imagingbook.common.geometry.shape.ShapeChecker

public class ShapeChecker extends Object
Used to check if AWT shapes produced by ShapeProducer.getShape() match the underlying curve (Primitive2d). This is mainly used to test if generated shapes (to be drawn to the screen) are sufficiently accurate.
See Also:
  • Constructor Details

    • ShapeChecker

      public ShapeChecker(double tolerance)
      Constructor.
      Parameters:
      tolerance - maximum deviation between curve and shape
    • ShapeChecker

      public ShapeChecker()
      Constructor.
  • Method Details

    • check

      public boolean check(Primitive2d curve, Shape shape)
      Checks if all points of the specified AWT Shape are sufficiently close to the Primitive2d instance specified in the constructor. This is typically used to test if a shape produced by ShapeProducer.getShape() coincides with this curve. Only the discrete sample points produced by ShapePointIterator are checked, not the points on connecting polygon segments. Typical usage example:
       GeometricCircle circle = ... ; // implements ShapeProducer and Curve2d
       Shape shape = circle.getShape();
       boolean ok = new ShapeChecker().checkShape(circle, shape);
      Parameters:
      curve - a Primitive2d instance
      shape - the AWT shape to check
      Returns:
      true if all points of the shape are closer to the curve than tolerance