@Override public boolean contains(Point2D.Double p) { return Geom.lineContainsPoint( line.x1, line.y1, line.x2, line.y2, p.x, p.y, AttributeKeys.getStrokeTotalWidth(this)); }
/** * Returns the distance, that a Rectangle needs to grow (or shrink) to * draw (aka stroke) its shape as specified by the FILL_UNDER_STROKE and * STROKE_POSITION attributes of a figure. * The value returned is the number of units that need to be grown (or shrunk) * perpendicular to a stroke on an outline of the shape. */ public static double getPerpendicularDrawGrowth(Figure f) { double grow; double strokeWidth = AttributeKeys.getStrokeTotalWidth(f); switch (f.get(STROKE_PLACEMENT)) { case INSIDE: grow = strokeWidth / -2d; break; case OUTSIDE: grow = strokeWidth / 2d; break; case CENTER: default: grow = 0f; break; } return grow; }
@Override public Rectangle2D.Double getDrawingArea() { Rectangle2D rx = getTransformedShape().getBounds2D(); Rectangle2D.Double r = (rx instanceof Rectangle2D.Double) ? (Rectangle2D.Double) rx : new Rectangle2D.Double(rx.getX(), rx.getY(), rx.getWidth(), rx.getHeight()); if (get(TRANSFORM) == null) { double g = SVGAttributeKeys.getPerpendicularHitGrowth(this) * 2d + 1; Geom.grow(r, g, g); } else { double strokeTotalWidth = AttributeKeys.getStrokeTotalWidth(this); double width = strokeTotalWidth / 2d; width *= Math.max(get(TRANSFORM).getScaleX(), get(TRANSFORM).getScaleY()) + 1; Geom.grow(r, width, width); } return r; }
@Override public Rectangle2D.Double getDrawingArea() { Rectangle2D rx = getTransformedShape().getBounds2D(); Rectangle2D.Double r = (rx instanceof Rectangle2D.Double) ? (Rectangle2D.Double) rx : new Rectangle2D.Double(rx.getX(), rx.getY(), rx.getWidth(), rx.getHeight()); if (get(TRANSFORM) == null) { double g = ODGAttributeKeys.getPerpendicularHitGrowth(this) * 2; Geom.grow(r, g, g); } else { double strokeTotalWidth = AttributeKeys.getStrokeTotalWidth(this); double width = strokeTotalWidth / 2d; width *= Math.max(get(TRANSFORM).getScaleX(), get(TRANSFORM).getScaleY()); Geom.grow(r, width, width); } return r; }
@Override public Rectangle2D.Double getDrawingArea() { Rectangle2D rx = getTransformedShape().getBounds2D(); Rectangle2D.Double r = (rx instanceof Rectangle2D.Double) ? (Rectangle2D.Double) rx : new Rectangle2D.Double(rx.getX(), rx.getY(), rx.getWidth(), rx.getHeight()); if (get(TRANSFORM) == null) { double g = ODGAttributeKeys.getPerpendicularHitGrowth(this) * 2; Geom.grow(r, g, g); } else { double strokeTotalWidth = AttributeKeys.getStrokeTotalWidth(this); double width = strokeTotalWidth / 2d; if (get(STROKE_JOIN) == BasicStroke.JOIN_MITER) { width *= get(STROKE_MITER_LIMIT); } if (get(STROKE_CAP) != BasicStroke.CAP_BUTT) { width += strokeTotalWidth * 2; } width++; Geom.grow(r, width, width); } return r; }
@Override public Rectangle2D.Double getDrawingArea() { Rectangle2D rx = getTransformedShape().getBounds2D(); Rectangle2D.Double r = (rx instanceof Rectangle2D.Double) ? (Rectangle2D.Double) rx : new Rectangle2D.Double(rx.getX(), rx.getY(), rx.getWidth(), rx.getHeight()); if (get(TRANSFORM) == null) { double g = SVGAttributeKeys.getPerpendicularHitGrowth(this) * 2d + 1d; Geom.grow(r, g, g); } else { double strokeTotalWidth = AttributeKeys.getStrokeTotalWidth(this); double width = strokeTotalWidth / 2d; if (get(STROKE_JOIN) == BasicStroke.JOIN_MITER) { width *= get(STROKE_MITER_LIMIT); } if (get(STROKE_CAP) != BasicStroke.CAP_BUTT) { width += strokeTotalWidth * 2; } width++; Geom.grow(r, width, width); } return r; }
/** * Returns the distance, that a Rectangle needs to grow (or shrink) to * make hit detections on a shape as specified by the FILL_UNDER_STROKE and STROKE_POSITION * attributes of a figure. * The value returned is the number of units that need to be grown (or shrunk) * perpendicular to a stroke on an outline of the shape. */ public static double getPerpendicularHitGrowth(Figure f) { double grow; if (f.get(STROKE_COLOR) == null) { grow = getPerpendicularFillGrowth(f); } else { double strokeWidth = AttributeKeys.getStrokeTotalWidth(f); grow = getPerpendicularDrawGrowth(f) + strokeWidth / 2d; } return grow; } }
@Override protected void drawFill(Graphics2D g) { if (isClosed() || get(UNCLOSED_PATH_FILLED)) { double grow = AttributeKeys.getPerpendicularFillGrowth(this); if (grow == 0d) { g.fill(path); } else { GrowStroke gs = new GrowStroke(grow, AttributeKeys.getStrokeTotalWidth(this) * get(STROKE_MITER_LIMIT)); g.fill(gs.createStrokedShape(path)); } } }
@Override protected void drawFill(Graphics2D g) { Shape triangle = getBezierPath(); double grow = AttributeKeys.getPerpendicularFillGrowth(this); if (grow != 0d) { GrowStroke gs = new GrowStroke((float) grow, (float) (AttributeKeys.getStrokeTotalWidth(this) * get(STROKE_MITER_LIMIT)) ); triangle = gs.createStrokedShape(triangle); } g.fill(triangle); }
@Override protected void drawStroke(Graphics2D g) { Shape triangle = getBezierPath(); double grow = AttributeKeys.getPerpendicularDrawGrowth(this); if (grow != 0d) { GrowStroke gs = new GrowStroke((float) grow, (float) (AttributeKeys.getStrokeTotalWidth(this) * get(STROKE_MITER_LIMIT)) ); triangle = gs.createStrokedShape(triangle); } g.draw(triangle); } @Override
public Rectangle2D.Double getFigureDrawBounds() { double width = AttributeKeys.getStrokeTotalWidth(this) / 2d; if (get(STROKE_JOIN) == BasicStroke.JOIN_MITER) { width *= get(STROKE_MITER_LIMIT); } width++; Rectangle2D.Double r = getBounds(); Geom.grow(r, width, width); return r; }
@Override public Rectangle2D.Double getDrawingArea() { if (cachedDrawingArea == null) { double strokeTotalWidth = AttributeKeys.getStrokeTotalWidth(this); double width = strokeTotalWidth / 2d; if (get(STROKE_JOIN) == BasicStroke.JOIN_MITER) { width *= get(STROKE_MITER_LIMIT); } else if (get(STROKE_CAP) != BasicStroke.CAP_BUTT) { width += strokeTotalWidth * 2; } Path2D.Double gp = (Path2D.Double) getPath(); Rectangle2D strokeRect = new Rectangle2D.Double(0, 0, width, width); if (get(TRANSFORM) != null) { gp = (Path2D.Double) gp.clone(); gp.transform(get(TRANSFORM)); strokeRect = get(TRANSFORM).createTransformedShape(strokeRect).getBounds2D(); } Rectangle2D rx = gp.getBounds2D(); Rectangle2D.Double r = (rx instanceof Rectangle2D.Double) ? (Rectangle2D.Double) rx : new Rectangle2D.Double(rx.getX(), rx.getY(), rx.getWidth(), rx.getHeight()); Geom.grow(r, strokeRect.getWidth(), strokeRect.getHeight()); cachedDrawingArea = r; } return (Rectangle2D.Double) cachedDrawingArea.clone(); }
@Override protected void drawStroke(Graphics2D g) { if (isClosed()) { double grow = AttributeKeys.getPerpendicularDrawGrowth(this); if (grow == 0d) { g.draw(path); } else { GrowStroke gs = new GrowStroke(grow, AttributeKeys.getStrokeTotalWidth(this) * get(STROKE_MITER_LIMIT)); g.draw(gs.createStrokedShape(path)); } } else { g.draw(getCappedPath()); } drawCaps(g); }
protected Point2D.Double chop(Figure target, Point2D.Double from) { target = getConnectorTarget(target); Rectangle2D.Double r = target.getBounds(); if (target.get(STROKE_COLOR) != null) { double grow; switch (target.get(STROKE_PLACEMENT)) { case CENTER: default : grow = AttributeKeys.getStrokeTotalWidth(target) / 2d; break; case OUTSIDE : grow = AttributeKeys.getStrokeTotalWidth(target); break; case INSIDE : grow = 0d; break; } Geom.grow(r, grow, grow); } return Geom.angleToPoint(r, Geom.pointToAngle(r, from)); }
/** * Returns the distance, that a Rectangle needs to grow (or shrink) to * make hit detections on a shape as specified by the FILL_UNDER_STROKE and STROKE_POSITION * attributes of a figure. * The value returned is the number of units that need to be grown (or shrunk) * perpendicular to a stroke on an outline of the shape. */ public static double getPerpendicularHitGrowth(Figure f) { double grow; if (f.get(STROKE_COLOR) == null && f.get(STROKE_GRADIENT) == null) { grow = getPerpendicularFillGrowth(f); } else { double strokeWidth = AttributeKeys.getStrokeTotalWidth(f); grow = getPerpendicularDrawGrowth(f) + strokeWidth / 2d; } return grow; } }
@Override public Rectangle2D.Double getDrawingArea() { double strokeTotalWidth = AttributeKeys.getStrokeTotalWidth(this); double width = strokeTotalWidth / 2d; if (get(STROKE_JOIN) == BasicStroke.JOIN_MITER) { width *= get(STROKE_MITER_LIMIT); } else if (get(STROKE_CAP) != BasicStroke.CAP_BUTT) { width += strokeTotalWidth * 2; } width++; Rectangle2D.Double r = getBounds(); Geom.grow(r, width, width); return r; }
public Point2D.Double chop(Point2D.Double p) { Shape triangle = getBezierPath(); double grow = AttributeKeys.getPerpendicularHitGrowth(this); if (grow != 0d) { GrowStroke gs = new GrowStroke((float) grow, (float) (AttributeKeys.getStrokeTotalWidth(this) * get(STROKE_MITER_LIMIT)) ); triangle =gs.createStrokedShape(triangle); } return Geom.chop(triangle, p); } /**
/** * Checks if a Point2D.Double is inside the figure. */ @Override public boolean contains(Point2D.Double p) { Shape triangle = getBezierPath(); double grow = AttributeKeys.getPerpendicularHitGrowth(this); if (grow != 0d) { GrowStroke gs = new GrowStroke((float) grow, (float) (AttributeKeys.getStrokeTotalWidth(this) * get(STROKE_MITER_LIMIT)) ); triangle =gs.createStrokedShape(triangle); } return triangle.contains(p); } @Override
public Point2D.Double chop(Point2D.Double p) { if (isClosed()) { double grow = AttributeKeys.getPerpendicularHitGrowth(this); if (grow == 0d) { return path.chop(p); } else { GrowStroke gs = new GrowStroke(grow, AttributeKeys.getStrokeTotalWidth(this) * get(STROKE_MITER_LIMIT)); return Geom.chop(gs.createStrokedShape(path), p); } } else { return path.chop(p); } }
@Override public Rectangle2D.Double getDrawingArea() { if (cachedDrawingArea == null) { if (get(TRANSFORM) == null) { cachedDrawingArea = path.getBounds2D(); } else { BezierPath p2 = (BezierPath) path.clone(); p2.transform(get(TRANSFORM)); cachedDrawingArea = p2.getBounds2D(); } double strokeTotalWidth = AttributeKeys.getStrokeTotalWidth(this); double width = strokeTotalWidth / 2d; if (get(STROKE_JOIN) == BasicStroke.JOIN_MITER) { width *= get(STROKE_MITER_LIMIT); } else if (get(STROKE_CAP) != BasicStroke.CAP_BUTT) { width += strokeTotalWidth * 2; } Geom.grow(cachedDrawingArea, width, width); } return (Rectangle2D.Double) cachedDrawingArea.clone(); }