/** * Returns an integer {@link Rectangle}that completely encloses the <code>Shape</code>. Note * that there is no guarantee that the returned <code>Rectangle</code> is the smallest bounding * box that encloses the <code>Shape</code>, only that the <code>Shape</code> lies entirely * within the indicated <code>Rectangle</code>. The returned <code>Rectangle</code> might also * fail to completely enclose the <code>Shape</code> if the <code>Shape</code> overflows the * limited range of the integer data type. The <code>getBounds2D</code> method generally returns * a tighter bounding box due to its greater flexibility in representation. * * @return an integer <code>Rectangle</code> that completely encloses the <code>Shape</code>. * @see #getBounds2D */ public Rectangle getBounds() { Rectangle2D env = getBounds2D(); return new Rectangle( (int) Math.round(env.getMinX()), (int) Math.round(env.getMinY()), (int) Math.ceil(env.getWidth()), (int) Math.ceil(env.getHeight())); }
Rectangle2D bounds = shape.getBounds2D(); return bounds.getWidth() < lineWidth || bounds.getHeight() < lineWidth;
labelCache.put(shape.getBounds2D());
public void testPolygonShape() throws TransformException, FactoryException { GeometryFactory geomFac = new GeometryFactory(); Polygon polygon = makeSamplePolygon(geomFac, 0, 0); LiteShape2 lineShape = new LiteShape2( polygon, ProjectiveTransform.create(new AffineTransform()), new Decimator(ProjectiveTransform.create(new AffineTransform())), false); assertFalse(lineShape.contains(0, 0)); assertTrue(lineShape.contains(100, 100)); assertFalse(lineShape.contains(50, 50, 10, 10)); assertTrue(lineShape.contains(100, 100, 10, 10)); assertTrue(lineShape.contains(new java.awt.Point(70, 90))); assertFalse(lineShape.contains(new java.awt.geom.Rectangle2D.Float(50, 50, 10, 10))); assertTrue(lineShape.getBounds2D().equals(new Rectangle2D.Double(60, 70, 70, 50))); assertTrue(lineShape.getBounds().equals(new java.awt.Rectangle(60, 70, 70, 50))); assertTrue(lineShape.intersects(0, 0, 100, 100)); assertTrue(lineShape.intersects(new Rectangle2D.Double(0, 0, 100, 100))); assertFalse(lineShape.intersects(55, 55, 3, 100)); assertFalse(lineShape.intersects(new Rectangle2D.Double(55, 55, 3, 100))); }
public void testLineShape2() throws TransformException, FactoryException { GeometryFactory geomFac = new GeometryFactory(); LineString lineString = makeSampleLineString(geomFac, 0, 0); MathTransform transform = ProjectiveTransform.create(new AffineTransform()); Decimator decimator = new Decimator(transform); LiteShape2 lineShape = new LiteShape2(lineString, transform, decimator, false); assertFalse(lineShape.contains(0, 0)); assertTrue(lineShape.contains(60, 60)); assertFalse(lineShape.contains(50, 50, 10, 10)); assertTrue(lineShape.contains(new java.awt.Point(60, 60))); assertFalse(lineShape.contains(new java.awt.geom.Rectangle2D.Float(50, 50, 10, 10))); assertTrue(lineShape.getBounds2D().equals(new Rectangle2D.Double(50, 50, 80, 250))); assertTrue(lineShape.getBounds().equals(new java.awt.Rectangle(50, 50, 80, 250))); assertTrue(lineShape.intersects(0, 0, 100, 100)); assertTrue(lineShape.intersects(new Rectangle2D.Double(0, 0, 100, 100))); assertFalse(lineShape.intersects(55, 55, 3, 100)); assertFalse(lineShape.intersects(new Rectangle2D.Double(55, 55, 3, 100))); }
/** * Returns an integer {@link Rectangle}that completely encloses the * <code>Shape</code>. Note that there is no guarantee that the returned * <code>Rectangle</code> is the smallest bounding box that encloses the * <code>Shape</code>, only that the <code>Shape</code> lies entirely * within the indicated <code>Rectangle</code>. The returned * <code>Rectangle</code> might also fail to completely enclose the * <code>Shape</code> if the <code>Shape</code> overflows the limited * range of the integer data type. The <code>getBounds2D</code> method * generally returns a tighter bounding box due to its greater flexibility * in representation. * * @return an integer <code>Rectangle</code> that completely encloses the * <code>Shape</code>. * * @see #getBounds2D */ public Rectangle getBounds() { Rectangle2D env = getBounds2D(); return new Rectangle((int) Math.round(env.getMinX()), (int) Math.round(env.getMinY()), (int) Math.ceil(env.getWidth()), (int) Math.ceil(env.getHeight())); }
labelCache.put(shape.getBounds2D());