Example usage for java.awt.geom QuadCurve2D contains

List of usage examples for java.awt.geom QuadCurve2D contains

Introduction

In this page you can find the example usage for java.awt.geom QuadCurve2D contains.

Prototype

public boolean contains(double x, double y) 

Source Link

Usage

From source file:com.cburch.draw.shapes.Curve.java

@Override
public boolean contains(Location loc, boolean assumeFilled) {
    Object type = getPaintType();
    if (assumeFilled && type == DrawAttr.PAINT_STROKE) {
        type = DrawAttr.PAINT_STROKE_FILL;
    }/*from   ww  w  . ja va2  s . com*/
    if (type != DrawAttr.PAINT_FILL) {
        int stroke = getStrokeWidth();
        double[] q = toArray(loc);
        double[] p0 = toArray(this.p0);
        double[] p1 = toArray(this.p1);
        double[] p2 = toArray(this.p2);
        double[] p = CurveUtil.findNearestPoint(q, p0, p1, p2);
        if (p == null)
            return false;

        int thr;
        if (type == DrawAttr.PAINT_STROKE) {
            thr = Math.max(Line.ON_LINE_THRESH, stroke / 2);
        } else {
            thr = stroke / 2;
        }
        if (LineUtil.distanceSquared(p[0], p[1], q[0], q[1]) < thr * thr) {
            return true;
        }
    }
    if (type != DrawAttr.PAINT_STROKE) {
        QuadCurve2D curve = getCurve(null);
        if (curve.contains(loc.getX(), loc.getY())) {
            return true;
        }
    }
    return false;
}