Java Code Examples for java.awt.geom.Path2D#getBounds2D()

The following examples show how to use java.awt.geom.Path2D#getBounds2D() . 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: Path2DCopyConstructor.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
static void testGetBounds(Path2D pathA, Path2D pathB) {
    final Rectangle rA = pathA.getBounds();
    final Rectangle rB = pathB.getBounds();

    if (!rA.equals(rB)) {
        throw new IllegalStateException("Bounds are not equals [" + rA
            + "|" + rB + "] !");
    }
    final Rectangle2D r2dA = pathA.getBounds2D();
    final Rectangle2D r2dB = pathB.getBounds2D();

    if (!equalsRectangle2D(r2dA, r2dB)) {
        throw new IllegalStateException("Bounds2D are not equals ["
            + r2dA + "|" + r2dB + "] !");
    }
    log("testGetBounds: passed.");
}
 
Example 2
Source File: Path2DCopyConstructor.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static void testGetBounds(Path2D pathA, Path2D pathB) {
    final Rectangle rA = pathA.getBounds();
    final Rectangle rB = pathB.getBounds();

    if (!rA.equals(rB)) {
        throw new IllegalStateException("Bounds are not equals [" + rA
            + "|" + rB + "] !");
    }
    final Rectangle2D r2dA = pathA.getBounds2D();
    final Rectangle2D r2dB = pathB.getBounds2D();

    if (!equalsRectangle2D(r2dA, r2dB)) {
        throw new IllegalStateException("Bounds2D are not equals ["
            + r2dA + "|" + r2dB + "] !");
    }
    log("testGetBounds: passed.");
}
 
Example 3
Source File: Path2DCopyConstructor.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static void testGetBounds(Path2D pathA, Path2D pathB) {
    final Rectangle rA = pathA.getBounds();
    final Rectangle rB = pathB.getBounds();

    if (!rA.equals(rB)) {
        throw new IllegalStateException("Bounds are not equals [" + rA
            + "|" + rB + "] !");
    }
    final Rectangle2D r2dA = pathA.getBounds2D();
    final Rectangle2D r2dB = pathB.getBounds2D();

    if (!equalsRectangle2D(r2dA, r2dB)) {
        throw new IllegalStateException("Bounds2D are not equals ["
            + r2dA + "|" + r2dB + "] !");
    }
    log("testGetBounds: passed.");
}
 
Example 4
Source File: Path2DCopyConstructor.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static void testGetBounds(Path2D pathA, Path2D pathB) {
    final Rectangle rA = pathA.getBounds();
    final Rectangle rB = pathB.getBounds();

    if (!rA.equals(rB)) {
        throw new IllegalStateException("Bounds are not equals [" + rA
            + "|" + rB + "] !");
    }
    final Rectangle2D r2dA = pathA.getBounds2D();
    final Rectangle2D r2dB = pathB.getBounds2D();

    if (!equalsRectangle2D(r2dA, r2dB)) {
        throw new IllegalStateException("Bounds2D are not equals ["
            + r2dA + "|" + r2dB + "] !");
    }
    log("testGetBounds: passed.");
}
 
Example 5
Source File: Path2DCopyConstructor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static void testGetBounds(Path2D pathA, Path2D pathB) {
    final Rectangle rA = pathA.getBounds();
    final Rectangle rB = pathB.getBounds();

    if (!rA.equals(rB)) {
        throw new IllegalStateException("Bounds are not equals [" + rA
            + "|" + rB + "] !");
    }
    final Rectangle2D r2dA = pathA.getBounds2D();
    final Rectangle2D r2dB = pathB.getBounds2D();

    if (!equalsRectangle2D(r2dA, r2dB)) {
        throw new IllegalStateException("Bounds2D are not equals ["
            + r2dA + "|" + r2dB + "] !");
    }
    log("testGetBounds: passed.");
}
 
Example 6
Source File: Path2DCopyConstructor.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static void testGetBounds(Path2D pathA, Path2D pathB) {
    final Rectangle rA = pathA.getBounds();
    final Rectangle rB = pathB.getBounds();

    if (!rA.equals(rB)) {
        throw new IllegalStateException("Bounds are not equals [" + rA
            + "|" + rB + "] !");
    }
    final Rectangle2D r2dA = pathA.getBounds2D();
    final Rectangle2D r2dB = pathB.getBounds2D();

    if (!equalsRectangle2D(r2dA, r2dB)) {
        throw new IllegalStateException("Bounds2D are not equals ["
            + r2dA + "|" + r2dB + "] !");
    }
    log("testGetBounds: passed.");
}
 
Example 7
Source File: Path2DCopyConstructor.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void testGetBounds(Path2D pathA, Path2D pathB) {
    final Rectangle rA = pathA.getBounds();
    final Rectangle rB = pathB.getBounds();

    if (!rA.equals(rB)) {
        throw new IllegalStateException("Bounds are not equals [" + rA
            + "|" + rB + "] !");
    }
    final Rectangle2D r2dA = pathA.getBounds2D();
    final Rectangle2D r2dB = pathB.getBounds2D();

    if (!equalsRectangle2D(r2dA, r2dB)) {
        throw new IllegalStateException("Bounds2D are not equals ["
            + r2dA + "|" + r2dB + "] !");
    }
    log("testGetBounds: passed.");
}
 
Example 8
Source File: Path2DCopyConstructor.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static void testGetBounds(Path2D pathA, Path2D pathB) {
    final Rectangle rA = pathA.getBounds();
    final Rectangle rB = pathB.getBounds();

    if (!rA.equals(rB)) {
        throw new IllegalStateException("Bounds are not equals [" + rA
            + "|" + rB + "] !");
    }
    final Rectangle2D r2dA = pathA.getBounds2D();
    final Rectangle2D r2dB = pathB.getBounds2D();

    if (!equalsRectangle2D(r2dA, r2dB)) {
        throw new IllegalStateException("Bounds2D are not equals ["
            + r2dA + "|" + r2dB + "] !");
    }
    log("testGetBounds: passed.");
}
 
Example 9
Source File: Path2DCopyConstructor.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
static void testGetBounds(Path2D pathA, Path2D pathB) {
    final Rectangle rA = pathA.getBounds();
    final Rectangle rB = pathB.getBounds();

    if (!rA.equals(rB)) {
        throw new IllegalStateException("Bounds are not equals [" + rA
            + "|" + rB + "] !");
    }
    final Rectangle2D r2dA = pathA.getBounds2D();
    final Rectangle2D r2dB = pathB.getBounds2D();

    if (!equalsRectangle2D(r2dA, r2dB)) {
        throw new IllegalStateException("Bounds2D are not equals ["
            + r2dA + "|" + r2dB + "] !");
    }
    log("testGetBounds: passed.");
}
 
Example 10
Source File: ProjectMetagonEditGrammarIconImage.java    From Forsythia with GNU General Public License v3.0 5 votes vote down vote up
ProjectMetagonEditGrammarIconImage(ProjectMetagon pm,int span){
super(span,span,BufferedImage.TYPE_INT_RGB);
//init image
Path2D path=pm.getImagePath();
Graphics2D g=createGraphics();
g.setRenderingHints(UI.RENDERING_HINTS);
//fill background
g.setColor(UI.ELEMENTMENU_ICONBACKGROUND);
g.fillRect(0,0,span,span);
//glean metrics and transform
Rectangle2D pbounds=path.getBounds2D();
double pw=pbounds.getWidth(),ph=pbounds.getHeight(),scale;
int maxpolygonimagespan=span-(UI.ELEMENTMENU_ICONGEOMETRYINSET*2);
scale=(pw>ph)?maxpolygonimagespan/pw:maxpolygonimagespan/ph;
AffineTransform t=new AffineTransform();
t.scale(scale,-scale);//note y flip
double 
  xoffset=-pbounds.getMinX()+(((span-(pw*scale))/2)/scale),
  yoffset=-pbounds.getMaxY()-(((span-(ph*scale))/2)/scale);
t.translate(xoffset,yoffset);
g.transform(t);
//fill metagon
//use color to distinguish protojig counts
int pjcount=pm.getJigCount();
if(pjcount<UI.GRAMMAR_EDITOR_METAGON_ICONS_FILLCOLOR.length)
  g.setColor(UI.GRAMMAR_EDITOR_METAGON_ICONS_FILLCOLOR[pjcount]);
else
  g.setColor(UI.GRAMMAR_EDITOR_METAGON_ICONS_FILLCOLOR[UI.GRAMMAR_EDITOR_METAGON_ICONS_FILLCOLOR.length-1]);
g.fill(path);
//stroke it
g.setColor(UI.ELEMENTMENU_ICON_STROKE);
g.setStroke(new BasicStroke(
  (float)(UI.ELEMENTMENU_ICONPATHSTROKETHICKNESS/scale),
  BasicStroke.CAP_SQUARE,
  BasicStroke.JOIN_ROUND,
  0,null,0));
g.draw(path);}
 
Example 11
Source File: StructureMapLayer.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a path shape on the map.
 * @param g2d the graphics2D context.
 * @param color the color to display the path shape.
 */
private void drawPathShape(Path2D pathShape, Graphics2D g2d, Color color) {

    // Save original graphics transforms.
    AffineTransform saveTransform = g2d.getTransform();

    // Determine bounds.
    Rectangle2D bounds = pathShape.getBounds2D();

    // Determine transform information.
    double boundsPosX = bounds.getX() * scale;
    double boundsPosY = bounds.getY() * scale;
    double centerX = bounds.getWidth() * scale / 2D;
    double centerY = bounds.getHeight() * scale / 2D;
    double translationX = (-1D * bounds.getCenterX() * scale) - centerX - boundsPosX;
    double translationY = (-1D * bounds.getCenterY() * scale) - centerY - boundsPosY;
    double facingRadian = Math.PI;

    // Apply graphic transforms for path shape.
    AffineTransform newTransform = new AffineTransform();
    newTransform.translate(translationX, translationY);
    newTransform.rotate(facingRadian, centerX + boundsPosX, centerY + boundsPosY);

    // Draw filled path shape.
    newTransform.scale(scale, scale);
    g2d.transform(newTransform);
    g2d.setColor(color);
    g2d.fill(pathShape);

    // Restore original graphic transforms.
    g2d.setTransform(saveTransform);
}
 
Example 12
Source File: LocalAreaUtil.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the bounding rectangle around a local bounded object with facing.
 * 
 * @param object the local bounded object.
 * @return bounding rectangle.
 */
public static Rectangle2D getBoundingRectangle(LocalBoundedObject object) {

	Rectangle2D rect = new Rectangle2D.Double(object.getXLocation() - (object.getWidth() / 2D),
			object.getYLocation() - (object.getLength() / 2D), object.getWidth(), object.getLength());
	Path2D path = getPathFromRectangleRotation(rect, object.getFacing());

	return path.getBounds2D();
}
 
Example 13
Source File: BblToRegion.java    From data-polygamy with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void readBblData(FSDataInputStream fis) throws IOException {
    
    try {
        BufferedReader buff = new BufferedReader(new InputStreamReader(fis));
        String line = buff.readLine();
        
        ArrayList<Double> xPoints = new ArrayList<Double>();
        ArrayList<Double> yPoints = new ArrayList<Double>();
        
        while (line != null) {
            String region = line.trim();
            buff.readLine();
            Integer nbPoints = Integer.parseInt(buff.readLine());
            
            xPoints = new ArrayList<Double>(nbPoints);
            yPoints = new ArrayList<Double>(nbPoints);
            for (int i = 0; i < nbPoints; i++) {
                String[] points = buff.readLine().split(" ");
                xPoints.add(Double.parseDouble(points[0]));
                yPoints.add(Double.parseDouble(points[1]));
            }
            
            // creating polygon
            Path2D polygon = new Path2D.Double();
            polygon.moveTo(xPoints.get(0), yPoints.get(0));
            for (int i = 1; i < xPoints.size(); ++i) {
                polygon.lineTo(xPoints.get(i), yPoints.get(i));
            }
            polygon.closePath();
            
            Rectangle2D rect = polygon.getBounds2D();
            double x = rect.getCenterX();
            double y = rect.getCenterY();
            
            int r = grid.getRegion(x, y);
            if(r != -1) {
                bblRegions.put(Long.parseLong(region), regionNames.get(r));
            }
            
            line = buff.readLine();
        }
        
        buff.close();
        
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        fis.close();
    }
}
 
Example 14
Source File: BlockToNbhd.java    From data-polygamy with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void readBlockData(FSDataInputStream fis) throws IOException {
    
    int id = 0;
    
    try {
        BufferedReader buff = new BufferedReader(new InputStreamReader(fis));
        String line = buff.readLine();
        
        ArrayList<Double> xPoints = new ArrayList<Double>();
        ArrayList<Double> yPoints = new ArrayList<Double>();
        
        while (line != null) {
            buff.readLine();
            Integer nbPoints = Integer.parseInt(buff.readLine());
            
            xPoints = new ArrayList<Double>(nbPoints);
            yPoints = new ArrayList<Double>(nbPoints);
            for (int i = 0; i < nbPoints; i++) {
                String[] points = buff.readLine().split(" ");
                xPoints.add(Double.parseDouble(points[0]));
                yPoints.add(Double.parseDouble(points[1]));
            }
            
            // creating polygon
            Path2D polygon = new Path2D.Double();
            polygon.moveTo(xPoints.get(0), yPoints.get(0));
            for (int i = 1; i < xPoints.size(); ++i) {
                polygon.lineTo(xPoints.get(i), yPoints.get(i));
            }
            polygon.closePath();
            
            Rectangle2D rect = polygon.getBounds2D();
            double x = rect.getCenterX();
            double y = rect.getCenterY();
            
            int r = grid.getRegion(x, y);
            if(r != -1) {
                blockRegions.put(id, nbhdRegionNames.get(r));
            }
            
            id++;
            line = buff.readLine();
        }
        
        buff.close();
        
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        fis.close();
    }
}
 
Example 15
Source File: LocalAreaUtil.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
	 * Checks if a path collides with an existing building, construction site, or
	 * vehicle at a location.
	 * 
	 * @param object      the object being checked (may be null if no object).
	 * @param path        the path to check.
	 * @param coordinates the global coordinate location to check.
	 * @param useCache    true if caching should be used.
	 * @return true if path doesn't collide with anything.
	 */
	private static boolean isPathCollisionFree(Object object, Path2D path, Coordinates coordinates, boolean useCache) {

		boolean result = true;

		// Check if obstacle area has been cached for this coordinate location if using
		// cache.
		boolean cached = false;
		Area obstacleArea = null;
		if (useCache && obstacleAreaCache.containsKey(coordinates)) {
			if (marsClock == null)
				marsClock = Simulation.instance().getMasterClock().getMarsClock();
			String currentTimestamp = marsClock.getDateTimeStamp();
			String cachedTimestamp = obstacleAreaTimestamps.get(coordinates);
			if (currentTimestamp.equals(cachedTimestamp)) {
				cached = true;
				obstacleArea = obstacleAreaCache.get(coordinates);
			}
		}

		if (!cached) {
			// Add all obstacle areas at location together to create a total obstacle area.
			Iterator<LocalBoundedObject> i = getAllLocalBoundedObjectsAtLocation(coordinates).iterator();
			while (i.hasNext()) {
				LocalBoundedObject lbo = i.next();
				if (lbo != object) {
					Rectangle2D objectRect = new Rectangle2D.Double(lbo.getXLocation() - (lbo.getWidth() / 2D),
							lbo.getYLocation() - (lbo.getLength() / 2D), lbo.getWidth(), lbo.getLength());
					Path2D objectPath = getPathFromRectangleRotation(objectRect, lbo.getFacing());
					Area objectArea = new Area(objectPath);
					if (obstacleArea == null) {
						obstacleArea = objectArea;
					} else {
						obstacleArea.add(objectArea);
					}
				}
			}
		}

		if (obstacleArea != null) {
			// Check for intersection of obstacle and path bounding rectangles first
			// (faster).
			Rectangle2D pathBounds = path.getBounds2D();
			Rectangle2D obstacleBounds = obstacleArea.getBounds2D();
			if (pathBounds.intersects(obstacleBounds)) {
				// If rectangles intersect, check for collision of path and obstacle areas
				// (slower).
				Area pathArea = new Area(path);
				result = !doAreasCollide(pathArea, obstacleArea);
			}
		}

		// Store cached obstacle area for location with current timestamp if needed.
		if (useCache && !cached && (obstacleArea != null)) {
			obstacleAreaCache.put(coordinates, obstacleArea);
//			String currentTimestamp = marsClock.getDateTimeStamp();
			obstacleAreaTimestamps.put(coordinates, marsClock.getDateTimeStamp());
		}

		return result;
	}