List<Rectangle2D.Double> rectangles = Arrays.asList( new Rectangle2D.Double(0d, 0d, 100d, 100d), new Rectangle2D.Double(100d, 0d, 100d, 100d), new Rectangle2D.Double(0d, 100d, 100d, 100d), new Rectangle2D.Double(100d, 100d, 100d, 100d)); Point2D.Double aPoint = new Point2D.Double(30d, 40d); for (Rectangle2D.Double rectangle:rectangles){ if (rectangle.contains(aPoint)){ System.out.println(rectangle + " has the point " + aPoint); } }
public Collection<T> findContains(Point2D.Double p) { HashSet<T> result = new HashSet<T>(); root.findContains(p, result); for (Map.Entry<T,Rectangle2D.Double> entry : outside.entrySet()) { if (entry.getValue().contains(p)) { result.add(entry.getKey()); } } return result; } public Collection<T> findIntersects(Rectangle2D r) {
public Collection<T> findInside(Rectangle2D.Double r) { HashSet<T> result = new HashSet<T>(); root.findInside(r, result); for (Map.Entry<T,Rectangle2D.Double> entry : outside.entrySet()) { if (r.contains(entry.getValue())) { result.add(entry.getKey()); } } return result; }
private boolean setCursorWhenContained(Cursor cursor, Rectangle2D.Double rectangle, Point point) { if (rectangle.contains(point)) { if (worldMapPane.getCursor() != cursor) { worldMapPane.setCursor(cursor); } return true; } return false; }
@Override public void panStarted(MouseEvent event) { super.panStarted(event); p0 = event.getPoint(); final Rectangle2D.Double intersectionRectangle = createIntersectionRectangle(); if (intersectionRectangle.contains(event.getPoint())) { regionSelectionInteractor.mousePressed(event); } }
/** * Tests if a point is contained in the connector. */ @Override public boolean contains(Point2D.Double p) { return getBounds().contains(p); }
@Override public boolean figureContains(Point2D.Double p) { if (getBounds().contains(p)) { return true; } return false; }
/** * Checks if a Point2D.Double is inside the figure. */ @Override public boolean contains(Point2D.Double p) { Rectangle2D.Double r = (Rectangle2D.Double) rectangle.clone(); double grow = AttributeKeys.getPerpendicularHitGrowth(this) + 1d; Geom.grow(r, grow, grow); return r.contains(p); }
@Override public void performPan(MouseEvent event) { final Rectangle2D.Double intersectionRectangle = createIntersectionRectangle(); if (intersectionRectangle.contains(p0)) { regionSelectionInteractor.mouseDragged(event); } else { super.performPan(event); } }
private boolean setCursorWhenContained(Cursor cursor, Rectangle2D.Double rectangle, Point point) { if (rectangle.contains(point)) { if (worldMapPane.getCursor() != cursor) { worldMapPane.setCursor(cursor); } return true; } return false; }
@Override public boolean figureContains(Point2D.Double p) { return bounds.contains(p); }
public boolean containsStop(com.conveyal.r5.api.util.Stop stop) { return super.contains(stop.lon, stop.lat); } }
public void mouseClicked(MouseEvent evt) { if (image != null) { double width = scale * imageWidth; double height = scale * imageHeight; double x = (getWidth() - width) / 2; double y = (getHeight() - height) / 2; Rectangle2D.Double bounds = new Rectangle2D.Double(x, y, width, height); if (bounds.contains(evt.getPoint()) { // You clicked me... } } }
public void add(T o, Rectangle2D.Double bounds) { if (root.bounds.contains(bounds)) { root.add(o, (Rectangle2D.Double) bounds.clone()); } else { outside.put(o, (Rectangle2D.Double) bounds.clone()); if (outside.size() > maxOutside) { reorganize(); } } } public void reorganize() {
@Nullable public Figure findChild(Point2D.Double p) { if (getBounds().contains(p)) { Figure found = null; for (Figure child : getChildrenFrontToBack()) { if (child.isVisible() && child.contains(p)) { return child; } } } return null; }
/** * Checks if a Point2D.Double is inside the figure. */ @Override public boolean figureContains(Point2D.Double p) { Rectangle2D.Double r = (Rectangle2D.Double) rectangle.clone(); double grow = AttributeKeys.getPerpendicularHitGrowth(this) + 1d; Geom.grow(r, grow, grow); return r.contains(p); }
@Override public boolean contains(Point2D.Double p) { if (getDrawingArea().contains(p)) { for (Figure child : getChildrenFrontToBack()) { if (child.isVisible() && child.contains(p)) return true; } return super.contains(p); } return false; } // ATTRIBUTES
@Override public void performPan(MouseEvent event) { final Rectangle2D.Double intersectionRectangle = createIntersectionRectangle(); if (intersectionRectangle.contains(p0)) { regionSelectionInteractor.mouseDragged(event); } else { super.performPan(event); } }
@Override public void panStarted(MouseEvent event) { super.panStarted(event); p0 = event.getPoint(); final Rectangle2D.Double intersectionRectangle = createIntersectionRectangle(); if (intersectionRectangle.contains(event.getPoint())) { regionSelectionInteractor.mousePressed(event); } }
public boolean containsStop(Stop stop) { return super.contains(stop.getLon(), stop.getLat()); } }