Java Code Examples for java.awt.geom.Area#isEmpty()
The following examples show how to use
java.awt.geom.Area#isEmpty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SWTGraphics2D.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * Returns <code>true</code> if the rectangle (in device space) intersects * with the shape (the interior, if <code>onStroke</code> is false, * otherwise the stroked outline of the shape). * * @param rect a rectangle (in device space). * @param s the shape. * @param onStroke test the stroked outline only? * * @return A boolean. */ @Override public boolean hit(Rectangle rect, Shape s, boolean onStroke) { AffineTransform transform = getTransform(); Shape ts; if (onStroke) { Stroke stroke = getStroke(); ts = transform.createTransformedShape(stroke.createStrokedShape(s)); } else { ts = transform.createTransformedShape(s); } if (!rect.getBounds2D().intersects(ts.getBounds2D())) { return false; } Area a1 = new Area(rect); Area a2 = new Area(ts); a1.intersect(a2); return !a1.isEmpty(); }
Example 2
Source File: TimeSeriesAssistantPage_ReprojectingSources.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
private boolean productsIntersect(Product timeSeriesSourceProduct, Product collocationProduct) { if (collocationProduct.getGeoCoding() == null) { return false; } final GeoCoding geoCoding = collocationProduct.getGeoCoding(); if (geoCoding.canGetGeoPos() && geoCoding.canGetPixelPos() && ((geoCoding instanceof CrsGeoCoding)||(geoCoding instanceof MapGeoCoding))) { final GeneralPath[] sourcePaths = ProductUtils.createGeoBoundaryPaths(timeSeriesSourceProduct); final GeneralPath[] collocationPaths = ProductUtils.createGeoBoundaryPaths(collocationProduct); for (GeneralPath sourcePath : sourcePaths) { for (GeneralPath collocationPath : collocationPaths) { final Area sourceArea = new Area(sourcePath); final Area collocationArea = new Area(collocationPath); collocationArea.intersect(sourceArea); if (!collocationArea.isEmpty()) { return true; } } } } return false; }
Example 3
Source File: TileBoundsRTree.java From render with GNU General Public License v2.0 | 6 votes |
/** * @param tile core tile for comparison. * @param intersectingTiles list of tiles that intersect with the core tile. * * @return true if the core tile is completely obscured by other tiles; otherwise false. * Assumes tiles with lexicographically greater tileId values are drawn on top. */ private static boolean isCompletelyObscured(final TileBounds tile, final List<TileBounds> intersectingTiles) { final String tileId = tile.getTileId(); final Area tileArea = new Area(new Rectangle2D.Double(tile.getMinX(), tile.getMinY(), tile.getDeltaX(), tile.getDeltaY())); for (final TileBounds intersectingTile : intersectingTiles) { if (tileId.compareTo(intersectingTile.getTileId()) < 0) { tileArea.subtract(new Area( new Rectangle2D.Double( intersectingTile.getMinX(), intersectingTile.getMinY(), intersectingTile.getDeltaX(), intersectingTile.getDeltaY()))); } } return tileArea.isEmpty(); }
Example 4
Source File: FXGraphics2D.java From ECG-Viewer with GNU General Public License v2.0 | 6 votes |
/** * Returns {@code true} if the rectangle (in device space) intersects * with the shape (the interior, if {@code onStroke} is false, * otherwise the stroked outline of the shape). * * @param rect a rectangle (in device space). * @param s the shape. * @param onStroke test the stroked outline only? * * @return A boolean. */ @Override public boolean hit(Rectangle rect, Shape s, boolean onStroke) { Shape ts; if (onStroke) { ts = this.transform.createTransformedShape( this.stroke.createStrokedShape(s)); } else { ts = this.transform.createTransformedShape(s); } if (!rect.getBounds2D().intersects(ts.getBounds2D())) { return false; } Area a1 = new Area(rect); Area a2 = new Area(ts); a1.intersect(a2); return !a1.isEmpty(); }
Example 5
Source File: SWTGraphics2D.java From ECG-Viewer with GNU General Public License v2.0 | 6 votes |
/** * Returns <code>true</code> if the rectangle (in device space) intersects * with the shape (the interior, if <code>onStroke</code> is false, * otherwise the stroked outline of the shape). * * @param rect a rectangle (in device space). * @param s the shape. * @param onStroke test the stroked outline only? * * @return A boolean. */ @Override public boolean hit(Rectangle rect, Shape s, boolean onStroke) { AffineTransform transform = getTransform(); Shape ts; if (onStroke) { Stroke stroke = getStroke(); ts = transform.createTransformedShape(stroke.createStrokedShape(s)); } else { ts = transform.createTransformedShape(s); } if (!rect.getBounds2D().intersects(ts.getBounds2D())) { return false; } Area a1 = new Area(rect); Area a2 = new Area(ts); a1.intersect(a2); return !a1.isEmpty(); }
Example 6
Source File: AreaList.java From TrakEM2 with GNU General Public License v3.0 | 6 votes |
@Override public void exportXML(final StringBuilder sb_body, final String indent, final XMLOptions options) { sb_body.append(indent).append("<t2_area_list\n"); final String in = indent + "\t"; super.exportXML(sb_body, in, options); sb_body.append(in).append("fill_paint=\"").append(fill_paint).append("\"\n"); final String[] RGB = Utils.getHexRGBColor(color); sb_body.append(in).append("style=\"stroke:none;fill-opacity:").append(alpha).append(";fill:#").append(RGB[0]).append(RGB[1]).append(RGB[2]).append(";\"\n"); sb_body.append(indent).append(">\n"); for (final Map.Entry<Long,Area> entry : ht_areas.entrySet()) { final Area area = entry.getValue(); if (null == area || area.isEmpty()) continue; sb_body.append(in).append("<t2_area layer_id=\"").append(entry.getKey()).append("\">\n"); exportArea(sb_body, in + "\t", area); sb_body.append(in).append("</t2_area>\n"); } super.restXML(sb_body, in, options); sb_body.append(indent).append("</t2_area_list>\n"); }
Example 7
Source File: FXGraphics2D.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Returns {@code true} if the rectangle (in device space) intersects * with the shape (the interior, if {@code onStroke} is false, * otherwise the stroked outline of the shape). * * @param rect a rectangle (in device space). * @param s the shape. * @param onStroke test the stroked outline only? * * @return A boolean. */ @Override public boolean hit(Rectangle rect, Shape s, boolean onStroke) { Shape ts; if (onStroke) { ts = this.transform.createTransformedShape( this.stroke.createStrokedShape(s)); } else { ts = this.transform.createTransformedShape(s); } if (!rect.getBounds2D().intersects(ts.getBounds2D())) { return false; } Area a1 = new Area(rect); Area a2 = new Area(ts); a1.intersect(a2); return !a1.isEmpty(); }
Example 8
Source File: FXGraphics2D.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Returns {@code true} if the rectangle (in device space) intersects * with the shape (the interior, if {@code onStroke} is false, * otherwise the stroked outline of the shape). * * @param rect a rectangle (in device space). * @param s the shape. * @param onStroke test the stroked outline only? * * @return A boolean. */ @Override public boolean hit(Rectangle rect, Shape s, boolean onStroke) { Shape ts; if (onStroke) { ts = this.transform.createTransformedShape( this.stroke.createStrokedShape(s)); } else { ts = this.transform.createTransformedShape(s); } if (!rect.getBounds2D().intersects(ts.getBounds2D())) { return false; } Area a1 = new Area(rect); Area a2 = new Area(ts); a1.intersect(a2); return !a1.isEmpty(); }
Example 9
Source File: SVGGraphics2D.java From jfreesvg with GNU General Public License v3.0 | 6 votes |
/** * Returns {@code true} if the rectangle (in device space) intersects * with the shape (the interior, if {@code onStroke} is {@code false}, * otherwise the stroked outline of the shape). * * @param rect a rectangle (in device space). * @param s the shape. * @param onStroke test the stroked outline only? * * @return A boolean. */ @Override public boolean hit(Rectangle rect, Shape s, boolean onStroke) { Shape ts; if (onStroke) { ts = this.transform.createTransformedShape( this.stroke.createStrokedShape(s)); } else { ts = this.transform.createTransformedShape(s); } if (!rect.getBounds2D().intersects(ts.getBounds2D())) { return false; } Area a1 = new Area(rect); Area a2 = new Area(ts); a1.intersect(a2); return !a1.isEmpty(); }
Example 10
Source File: SWTGraphics2D.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * Returns <code>true</code> if the rectangle (in device space) intersects * with the shape (the interior, if <code>onStroke</code> is false, * otherwise the stroked outline of the shape). * * @param rect a rectangle (in device space). * @param s the shape. * @param onStroke test the stroked outline only? * * @return A boolean. */ @Override public boolean hit(Rectangle rect, Shape s, boolean onStroke) { AffineTransform transform = getTransform(); Shape ts; if (onStroke) { Stroke stroke = getStroke(); ts = transform.createTransformedShape(stroke.createStrokedShape(s)); } else { ts = transform.createTransformedShape(s); } if (!rect.getBounds2D().intersects(ts.getBounds2D())) { return false; } Area a1 = new Area(rect); Area a2 = new Area(ts); a1.intersect(a2); return !a1.isEmpty(); }
Example 11
Source File: FXGraphics2D.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * Returns {@code true} if the rectangle (in device space) intersects * with the shape (the interior, if {@code onStroke} is false, * otherwise the stroked outline of the shape). * * @param rect a rectangle (in device space). * @param s the shape. * @param onStroke test the stroked outline only? * * @return A boolean. */ @Override public boolean hit(Rectangle rect, Shape s, boolean onStroke) { Shape ts; if (onStroke) { ts = this.transform.createTransformedShape( this.stroke.createStrokedShape(s)); } else { ts = this.transform.createTransformedShape(s); } if (!rect.getBounds2D().intersects(ts.getBounds2D())) { return false; } Area a1 = new Area(rect); Area a2 = new Area(ts); a1.intersect(a2); return !a1.isEmpty(); }
Example 12
Source File: CmmnJsonConverter.java From flowable-engine with Apache License 2.0 | 5 votes |
protected Collection<java.awt.geom.Point2D> getIntersections(java.awt.geom.Line2D line, Area shape) { Area intersectionArea = new Area(getLineShape(line)); intersectionArea.intersect(shape); if (!intersectionArea.isEmpty()) { Rectangle2D bounds2D = intersectionArea.getBounds2D(); HashSet<java.awt.geom.Point2D> intersections = new HashSet<>(2); intersections.add(new java.awt.geom.Point2D.Double(bounds2D.getX(), bounds2D.getY())); return intersections; } return Collections.EMPTY_SET; }
Example 13
Source File: DmnJsonConverterUtil.java From flowable-engine with Apache License 2.0 | 5 votes |
public static Collection<Point2D> getIntersections(java.awt.geom.Line2D line, Area shape) { Area intersectionArea = new Area(getLineShape(line)); intersectionArea.intersect(shape); if (!intersectionArea.isEmpty()) { Rectangle2D bounds2D = intersectionArea.getBounds2D(); HashSet<Point2D> intersections = new HashSet<>(1); intersections.add(new java.awt.geom.Point2D.Double(bounds2D.getX(), bounds2D.getY())); return intersections; } return Collections.EMPTY_SET; }
Example 14
Source File: ShapeTransform.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Clips the given shape to the given bounds. If the shape is a Line2D, manual clipping is performed, as the built in * Area does not handle lines. * * @param s * the shape to be clipped * @param bounds * the bounds to which the shape should be clipped * @return the clipped shape. */ public static Shape performCliping( final Shape s, final Rectangle2D bounds ) { if ( s instanceof Line2D ) { final Line2D line = (Line2D) s; final Point2D[] clipped = getClipped( line.getX1(), line.getY1(), line.getX2(), line.getY2(), -DELTA, DELTA + bounds.getWidth(), -DELTA, DELTA + bounds.getHeight() ); if ( clipped == null ) { return new GeneralPath(); } return new Line2D.Float( clipped[0], clipped[1] ); } final Rectangle2D boundsCorrected = bounds.getBounds2D(); boundsCorrected.setRect( -DELTA, -DELTA, DELTA + boundsCorrected.getWidth(), DELTA + boundsCorrected.getHeight() ); final Area a = new Area( boundsCorrected ); if ( a.isEmpty() ) { // don't clip ... Area does not like lines // operations with lines always result in an empty Bounds:(0,0,0,0) area return new GeneralPath(); } final Area clipArea = new Area( s ); a.intersect( clipArea ); return a; }
Example 15
Source File: AbstractShapeTransition2D.java From pumpernickel with MIT License | 5 votes |
/** Determine if a particular scaling ratio works */ private boolean isOK(Area shape, Rectangle2D shapeBounds, Rectangle2D bounds, float ratio) { Area area = new Area(shape); area.transform(AffineTransform.getScaleInstance(ratio, ratio)); Rectangle2D r = ShapeBounds.getBounds(area); area.transform(AffineTransform.getTranslateInstance(-r.getCenterX() + bounds.getCenterX(), -r.getCenterY() + bounds.getCenterY())); Area boundsArea = new Area(bounds); boundsArea.subtract(area); return boundsArea.isEmpty(); }
Example 16
Source File: LocalAreaUtil.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Checks if two areas collide. * * @param area1 the first area. * @param area2 the second area. * @return true if areas collide. */ private static boolean doAreasCollide(Area area1, Area area2) { Area collide = new Area(area1); collide.intersect(area2); return !collide.isEmpty(); }
Example 17
Source File: RegionManager.java From NovaGuilds with GNU General Public License v3.0 | 5 votes |
/** * Checks WorldGuard validity if possible * * @param selection region selection * @return true if valid */ private boolean checkWorldGuardValidity(RegionSelection selection) { if(!plugin.getDependencyManager().isEnabled(Dependency.WORLDGUARD)) { return true; } WorldGuardPlugin worldGuard = plugin.getDependencyManager().get(Dependency.WORLDGUARD, WorldGuardPlugin.class); Area selectionArea = new Area(new Rectangle( selection.getCorner(selection.getCorner(0).getBlockX() < selection.getCorner(1).getBlockX() ? 0 : 1).getBlockX(), selection.getCorner(selection.getCorner(0).getBlockZ() < selection.getCorner(1).getBlockZ() ? 0 : 1).getBlockZ(), selection.getWidth(), selection.getLength()) ); for(ProtectedRegion region : worldGuard.getRegionManager(selection.getWorld()).getRegions().values()) { if(region.getFlag((Flag) RegionManager.WORLDGUARD_FLAG) == StateFlag.State.ALLOW) { continue; } Area regionArea = RegionUtils.toArea(region); regionArea.intersect(selectionArea); if(!regionArea.isEmpty()) { return false; } } return true; }
Example 18
Source File: ShapeCollider.java From salty-engine with Apache License 2.0 | 5 votes |
@Override public CollisionDetectionResult checkCollision(final GameObject object1, final GameObject object2) { final Collider otherCollider = getOtherCollider(object1.getCollider(), object2.getCollider()); final GameObject otherGameObject = object1.getCollider() == otherCollider ? object1 : object2; final Area collisionArea = new Area(shape); switch (otherCollider.getType()) { case HITBOX_COLLIDER: collisionArea.intersect(new Area(otherGameObject.getHitbox().getTransform().getRect())); return new CollisionDetectionResult(!collisionArea.isEmpty(), new Transform(shape.getBounds()).getRelation(otherGameObject.getHitbox().getTransform())); case CIRCLE_COLLIDER: final CircleCollider collider = (CircleCollider) otherCollider; final Transform hitbox = collider.getHitbox(); collisionArea.intersect(new Area(new Ellipse2D.Float(hitbox.getX(), hitbox.getY(), hitbox.getWidth(), hitbox.getHeight()))); return new CollisionDetectionResult(!collisionArea.isEmpty(), new Transform(shape.getBounds()).getRelation(otherGameObject.getHitbox().getTransform())); case SHAPE_COLLIDER: final ShapeCollider shapeCollider = (ShapeCollider) otherCollider; collisionArea.intersect(new Area(shapeCollider.shape)); return new CollisionDetectionResult(!collisionArea.isEmpty(), new Transform(shape.getBounds()).getRelation(new Transform(shapeCollider.shape.getBounds()))); } return new CollisionDetectionResult(false, Directions.Direction.EMPTY); }
Example 19
Source File: AbstractShapeTransition2D.java From Pixelitor with GNU General Public License v3.0 | 5 votes |
/** * Determine if a particular scaling ratio works */ private static boolean isOK(Area shape, Rectangle2D bounds, float ratio) { Area area = new Area(shape); area.transform(AffineTransform.getScaleInstance(ratio, ratio)); Rectangle2D r = ShapeBounds.getBounds(area); area.transform(AffineTransform.getTranslateInstance( -r.getCenterX() + bounds.getCenterX(), -r.getCenterY() + bounds.getCenterY())); Area boundsArea = new Area(bounds); boundsArea.subtract(area); return boundsArea.isEmpty(); }
Example 20
Source File: NestWorldMapPane.java From snap-desktop with GNU General Public License v3.0 | 4 votes |
public static GeneralPath[] assemblePathList(GeoPos[] geoPoints) { final GeneralPath path = new GeneralPath(GeneralPath.WIND_NON_ZERO, geoPoints.length + 8); final ArrayList<GeneralPath> pathList = new ArrayList<>(16); if (geoPoints.length > 1) { double lon, lat; double minLon = 0, maxLon = 0; boolean first = true; for (GeoPos gp : geoPoints) { lon = gp.getLon(); lat = gp.getLat(); if (first) { minLon = lon; maxLon = lon; path.moveTo(lon, lat); first = false; } if (lon < minLon) { minLon = lon; } if (lon > maxLon) { maxLon = lon; } path.lineTo(lon, lat); } //path.closePath(); int runIndexMin = (int) Math.floor((minLon + 180) / 360); int runIndexMax = (int) Math.floor((maxLon + 180) / 360); if (runIndexMin == 0 && runIndexMax == 0) { // the path is completely within [-180, 180] longitude pathList.add(path); return pathList.toArray(new GeneralPath[pathList.size()]); } final Area pathArea = new Area(path); final GeneralPath pixelPath = new GeneralPath(GeneralPath.WIND_NON_ZERO); for (int k = runIndexMin; k <= runIndexMax; k++) { final Area currentArea = new Area(new Rectangle2D.Float(k * 360.0f - 180.0f, -90.0f, 360.0f, 180.0f)); currentArea.intersect(pathArea); if (!currentArea.isEmpty()) { pathList.add(areaToPath(currentArea, -k * 360.0, pixelPath)); } } } return pathList.toArray(new GeneralPath[pathList.size()]); }