public static Point2D intersect(Line2D.Double orig, Shape shape) { final Line2D.Double copy = new Line2D.Double(orig.x1, orig.y1, orig.x2, orig.y2); final boolean contains1 = shape.contains(copy.x1, copy.y1); final boolean contains2 = shape.contains(copy.x2, copy.y2); if (contains1 ^ contains2 == false) { // return new Point2D.Double(orig.x2, orig.y2); throw new IllegalArgumentException(); } while (true) { final double mx = (copy.x1 + copy.x2) / 2; final double my = (copy.y1 + copy.y2) / 2; final boolean containsMiddle = shape.contains(mx, my); if (contains1 == containsMiddle) { copy.x1 = mx; copy.y1 = my; } else { copy.x2 = mx; copy.y2 = my; } if (dist(copy) < 0.1) { if (contains1) { return new Point2D.Double(copy.x2, copy.y2); } if (contains2) { return new Point2D.Double(copy.x1, copy.y1); } throw new IllegalStateException(); } } }
static void shorten(CubicCurve2D.Double bez, Shape shape) { final boolean contains1 = shape.contains(bez.x1, bez.y1); final boolean contains2 = shape.contains(bez.x2, bez.y2); if (contains1 ^ contains2 == false) { throw new IllegalArgumentException(); } if (contains1 == false) { bez.setCurve(bez.x2, bez.y2, bez.ctrlx2, bez.ctrly2, bez.ctrlx1, bez.ctrly1, bez.x1, bez.y1); } assert shape.contains(bez.x1, bez.y1) && shape.contains(bez.x2, bez.y2) == false; final CubicCurve2D.Double left = new CubicCurve2D.Double(); final CubicCurve2D.Double right = new CubicCurve2D.Double(); subdivide(bez, left, right, 0.5); if (isCutting(left, shape) ^ isCutting(right, shape) == false) { throw new IllegalArgumentException(); } if (isCutting(left, shape)) { bez.setCurve(left); } else { bez.setCurve(right); } }
public boolean contains(double x, double y, double w, double h) { return shape.contains(x, y, w, h); }
public boolean contains(double x, double y, double w, double h) { return shape.contains(x, y, w, h); }
public boolean contains(double x, double y) { return shape.contains(x, y); }
public boolean contains(double x, double y) { return shape.contains(x, y); }
public boolean contains(Rectangle2D r) { return shape.contains(r); }
public boolean contains(Point2D p) { return shape.contains(p); }
public boolean contains(Point2D p) { return shape.contains((Point2D) p); }
public boolean contains(Rectangle2D r) { return shape.contains((Rectangle2D) r); }
public class RoundJTextField extends JTextField { private Shape shape; public RoundJTextField(int size) { super(size); setOpaque(false); // As suggested by @AVD in comment. } protected void paintComponent(Graphics g) { g.setColor(getBackground()); g.fillRoundRect(0, 0, getWidth()-1, getHeight()-1, 15, 15); super.paintComponent(g); } protected void paintBorder(Graphics g) { g.setColor(getForeground()); g.drawRoundRect(0, 0, getWidth()-1, getHeight()-1, 15, 15); } public boolean contains(int x, int y) { if (shape == null || !shape.getBounds().equals(getBounds())) { shape = new RoundRectangle2D.Float(0, 0, getWidth()-1, getHeight()-1, 15, 15); } return shape.contains(x, y); } }
/** Tests if a specified {@link Point2D} is inside the boundary of the <code>Shape</code>. */ public boolean contains(final Point2D p) { try { return shape.contains(inverseTransform(p, point)); } catch (NoninvertibleTransformException exception) { exceptionOccured(exception, "contains"); return false; } }
/** * Tests if the interior of the <code>Shape</code> entirely contains the specified <code> * Rectangle2D</code>. This method might conservatively return <code>false</code>. */ public boolean contains(final Rectangle2D r) { try { return shape.contains(XAffineTransform.inverseTransform(this, r, rectangle)); } catch (NoninvertibleTransformException exception) { exceptionOccured(exception, "contains"); return false; } }
@Override public void mouseMoved(MouseEvent e) { if (!styler.isToolTipsEnabled()) { // don't draw anything or all labels aready drawn return; } DataPoint newPoint = null; int x = e.getX(); int y = e.getY(); for (DataPoint dataPoint : dataPointList) { if (dataPoint.shape.contains(x, y)) { newPoint = dataPoint; break; } } if (newPoint != null) { // if the existing shown data point is already shown, abort if (dataPoint != null) { if (dataPoint.equals(newPoint)) { return; } } dataPoint = newPoint; e.getComponent().repaint(); // repaint the entire XChartPanel } // remove the popup shape else if (dataPoint != null) { dataPoint = null; e.getComponent().repaint(); // repaint the entire XChartPanel } }
getWidth(), getHeight()); return shape.contains(x, y);
expect(shape.contains((Point2D) null)).andReturn(false); expect(shape.contains((Rectangle2D) null)).andReturn(false); expect(shape.contains(0.0, 0.0)).andReturn(false); expect(shape.contains(0.0, 0.0, 0.0, 0.0)).andReturn(false); expect(shape.getBounds()).andReturn(null); expect(shape.getBounds2D()).andReturn(null);
/**Checks whether the specified coordinates are inside a on this ROI's shape boundaries.*/ public boolean contains(int x, int y) { if(shape==null) return false; return shape.contains(x-this.x, y-this.y); }
point2D.y = y; crsToGrid.inverseTransform(point2D, point2D); if (area == null || area.contains(point2D)) { coordinate.ordinates[xAxis] = point2D.x; coordinate.ordinates[yAxis] = point2D.y;
/** * Tests if a specified {@link Point2D} is inside the boundary of the * <code>Shape</code>. */ public boolean contains(final Point2D p) { try { return shape.contains(inverseTransform(p, point)); } catch (NoninvertibleTransformException exception) { exceptionOccured(exception, "contains"); return false; } }