: bounds.getHeight()); double scale = size / shapeSize; TransformedShape ts = new TransformedShape(); ts.shape = shape; float dy = displacementY; if (baseRotation != 0) { ts.translate(x, y); ts.rotate(baseRotation); ts.translate(dx, dy); } else { ts.translate(x + dx, y + dy); ts.rotate(rotation); dx = (float) (bounds.getWidth() * scale * (0.5 - anchorPointX)); dy = (float) (bounds.getHeight() * scale * (anchorPointY - 0.5)); ts.translate(dx, dy); ts.scale(scale, -scale);
/** * Set the transform from a flat matrix. * * @param matrix The flat matrix. */ public void setTransform(final double[] matrix) { setTransform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]); }
/** Tests if the specified coordinates are inside the boundary of the <code>Shape</code>. */ public boolean contains(double x, double y) { point.x = x; point.y = y; return contains(point); }
/** Returns the 6 coefficients values. */ public void getMatrix(final float[] matrix, int offset) { matrix[offset] = (float) getScaleX(); // m00 matrix[++offset] = (float) getShearY(); // m10 matrix[++offset] = (float) getShearX(); // m01 matrix[++offset] = (float) getScaleY(); // m11 matrix[++offset] = (float) getTranslateX(); // m02 matrix[++offset] = (float) getTranslateY(); // m12 }
/** 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; } }
TransformedShape tss = new TransformedShape(); tss.shape = original; tss.setTransform( AffineTransform.getScaleInstance( width / bounds.getWidth(), height / bounds.getHeight()));
@Test public void testBounds() { GeneralPath gp = new GeneralPath(); gp.moveTo(0f, 0f); gp.lineTo(1, 0.3); gp.lineTo(0f, 0.6f); gp.closePath(); AffineTransform at = AffineTransform.getScaleInstance(1.5, 1.5); TransformedShape ts = new TransformedShape(gp, at); assertEquals(new Rectangle(0, 0, 2, 1), ts.getBounds()); } }
/** Apply a uniform scale. */ public void scale(final double s) { scale(s, s); }
@Override public Shape getShape(Graphics2D graphics, Expression symbolUrl, Feature feature) throws Exception { RenderableSVG svg = cache.getRenderableSVG(feature, symbolUrl, "image/svg"); if (svg == null) { return null; } Shape shape = getShape(svg.node); final Rectangle2D bounds = shape.getBounds2D(); double maxSize = Math.max(bounds.getWidth(), bounds.getHeight()); // flip and center the shape double scaleToOne = 1 / maxSize; final AffineTransform at = new AffineTransform(scaleToOne, 0, 0, -scaleToOne, -0.5, 0.5); TransformedShape ts = new TransformedShape(shape, at); return ts; }
/** * Tests if the interior of the <code>Shape</code> intersects the interior of a specified <code> * Rectangle2D</code>. This method might conservatively return <code>true</code>. */ public boolean intersects(final Rectangle2D r) { try { return shape.intersects(XAffineTransform.inverseTransform(this, r, rectangle)); } catch (NoninvertibleTransformException exception) { exceptionOccured(exception, "intersects"); return false; } }
/** * Returns the 6 coefficients values. */ public void getMatrix(final float[] matrix, int offset) { matrix[offset] = (float) getScaleX(); // m00 matrix[++offset] = (float) getShearY(); // m10 matrix[++offset] = (float) getShearX(); // m01 matrix[++offset] = (float) getScaleY(); // m11 matrix[++offset] = (float) getTranslateX(); // m02 matrix[++offset] = (float) getTranslateY(); // m12 }
TransformedShape tss = new TransformedShape(); tss.shape = original; tss.setTransform(AffineTransform.getScaleInstance(width / bounds.getWidth(), height / bounds.getHeight())); resized.setShape(tss); resized.setSize((int) height);
/** * 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; } }
/** * Apply a uniform scale. */ public void scale(final double s) { scale(s, s); }
result = new TransformedShape(result, transform);
/** * 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; } }
/** * Returns the 6 coefficients values. */ public void getMatrix(final float[] matrix, int offset) { matrix[offset] = (float) getScaleX(); // m00 matrix[++offset] = (float) getShearY(); // m10 matrix[++offset] = (float) getShearX(); // m01 matrix[++offset] = (float) getScaleY(); // m11 matrix[++offset] = (float) getTranslateX(); // m02 matrix[++offset] = (float) getTranslateY(); // m12 }
/** * Returns a shape that can be used to draw the mark at the x, y coordinates * with appropriated rotation and size (according to the current style) * * @param x the x coordinate where the mark will be drawn * @param y the y coordinate where the mark will be drawn * * @return a shape that can be used to draw the mark */ public Shape getTransformedShape(float x, float y) { if (shape != null) { Rectangle2D bounds = shape.getBounds2D(); double shapeSize = Math.max(bounds.getWidth(), bounds.getHeight()); double scale = size / shapeSize; TransformedShape ts = new TransformedShape(); ts.shape = shape; ts.translate(x, y); ts.rotate(rotation); ts.scale(scale, -scale); return ts; } else { return null; } }
/** Construct a transformed shape */ public TransformedShape(Shape shape, AffineTransform at) { this.shape = shape; setTransform(at); }
/** * 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; } }