Java Code Examples for java.awt.geom.GeneralPath#transform()

The following examples show how to use java.awt.geom.GeneralPath#transform() . 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: ShipNeedle.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
@Override
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea,
                          Point2D rotate, double angle) {

    GeneralPath shape = new GeneralPath();
    shape.append(new Arc2D.Double(-9.0, -7.0, 10, 14, 0.0, 25.5,
            Arc2D.OPEN), true);
    shape.append(new Arc2D.Double(0.0, -7.0, 10, 14, 154.5, 25.5,
            Arc2D.OPEN), true);
    shape.closePath();
    getTransform().setToTranslation(plotArea.getMinX(), plotArea.getMaxY());
    getTransform().scale(plotArea.getWidth(), plotArea.getHeight() / 3);
    shape.transform(getTransform());

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        shape.transform(getTransform());
    }

    defaultDisplay(g2, shape);
}
 
Example 2
Source File: StandardGlyphVector.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 3
Source File: StandardGlyphVector.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 4
Source File: StandardGlyphVector.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 5
Source File: GUIHex.java    From Rails with GNU General Public License v2.0 6 votes vote down vote up
private GeneralPath getInnerHexagon(GeneralPath hexagon, HexPoint center) {
    //inner hexagons are drawn outlined (not filled)
    //for this draw, the stroke width is half the scale reduction
    //the scale factor is multiplied by the average of hex width / height in order
    //to get a good estimate for which for stroke width the hex borders are touched
    //by the stroke

    AffineTransform at =
            AffineTransform.getScaleInstance(getHexDrawScale(), getHexDrawScale());
    GeneralPath innerHexagon = (GeneralPath) hexagon.createTransformedShape(at);

    // Translate innerHexagon to make it concentric.
    Rectangle2D innerBounds = innerHexagon.getBounds2D();
    HexPoint innerCenter = new HexPoint(
            innerBounds.getX() + innerBounds.getWidth() / 2.0,
            innerBounds.getY() + innerBounds.getHeight() / 2.0
    );
    HexPoint difference = HexPoint.difference(center, innerCenter);

    at = AffineTransform.getTranslateInstance(difference.getX(), difference.getY());
    innerHexagon.transform(at);

    return innerHexagon;
}
 
Example 6
Source File: MinMaxCategoryRenderer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an icon.
 *
 * @param shape  the shape.
 * @param fillPaint  the fill paint.
 * @param outlinePaint  the outline paint.
 *
 * @return The icon.
 */
private Icon getIcon(Shape shape, final Paint fillPaint,
                    final Paint outlinePaint) {

  final int width = shape.getBounds().width;
  final int height = shape.getBounds().height;
  final GeneralPath path = new GeneralPath(shape);
  return new Icon() {
      public void paintIcon(Component c, Graphics g, int x, int y) {
          Graphics2D g2 = (Graphics2D) g;
          path.transform(AffineTransform.getTranslateInstance(x, y));
          if (fillPaint != null) {
              g2.setPaint(fillPaint);
              g2.fill(path);
          }
          if (outlinePaint != null) {
              g2.setPaint(outlinePaint);
              g2.draw(path);
          }
          path.transform(AffineTransform.getTranslateInstance(-x, -y));
    }

    public int getIconWidth() {
        return width;
    }

    public int getIconHeight() {
        return height;
    }

  };
}
 
Example 7
Source File: BorderRenderer.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Shape getBorderRightShape() {
  if ( borderShapeRight != null ) {
    return borderShapeRight;
  }

  final StaticBoxLayoutProperties sblp = this.staticBoxLayoutProperties;
  final long halfBorderWidth = sblp.getBorderRight() / 2;
  final long x = this.x;
  final long y = this.y;
  final long w = this.width;
  final long h = this.height;

  final Border border = boxDefinition.getBorder();
  final long topRightWidth = border.getTopRight().getWidth();
  final long topRightHeight = border.getTopRight().getHeight();
  final long bottomRightWidth = border.getBottomRight().getWidth();
  final long bottomRightHeight = border.getBottomRight().getHeight();

  if ( topRightWidth == 0 && bottomRightWidth == 0 && topRightHeight == 0 && bottomRightHeight == 0 ) {
    // Make a square corner
    final double lineX = StrictGeomUtility.toExternalValue( x + w - halfBorderWidth );
    final double lineY1 = StrictGeomUtility.toExternalValue( y );
    final double lineY2 = StrictGeomUtility.toExternalValue( y + h );
    borderShapeRight = new Line2D.Double( lineX, lineY1, lineX, lineY2 );
    return borderShapeRight;
  }

  // Make a rounded corner
  final GeneralPath generalPath = new GeneralPath( GeneralPath.WIND_NON_ZERO, 20 );
  generalPath.append( configureArc( x + w - 2 * topRightWidth, y, 2 * topRightWidth, 2 * topRightHeight, 45, -45,
      Arc2D.OPEN ), true );
  generalPath.lineTo( (float) ( x + w ), (float) ( y + h - bottomRightHeight ) ); // 4
  generalPath.append( configureArc( x + w - 2 * bottomRightWidth, y + h - 2 * bottomRightHeight,
      2 * bottomRightWidth, 2 * bottomRightHeight, 0, -45, Arc2D.OPEN ), true );
  generalPath.transform( BorderRenderer.scaleInstance );
  borderShapeRight = generalPath;
  return generalPath;
}
 
Example 8
Source File: MinMaxCategoryRenderer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an icon from a shape.
 *
 * @param shape  the shape.
 * @param fill  the fill flag.
 * @param outline  the outline flag.
 *
 * @return The icon.
 */
private Icon getIcon(Shape shape, final boolean fill,
        final boolean outline) {
    final int width = shape.getBounds().width;
    final int height = shape.getBounds().height;
    final GeneralPath path = new GeneralPath(shape);
    return new Icon() {
        public void paintIcon(Component c, Graphics g, int x, int y) {
            Graphics2D g2 = (Graphics2D) g;
            path.transform(AffineTransform.getTranslateInstance(x, y));
            if (fill) {
                g2.fill(path);
            }
            if (outline) {
                g2.draw(path);
            }
            path.transform(AffineTransform.getTranslateInstance(-x, -y));
        }

        public int getIconWidth() {
            return width;
        }

        public int getIconHeight() {
            return height;
        }
    };
}
 
Example 9
Source File: TextLine.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Shape getOutline(AffineTransform tx) {

        GeneralPath dstShape = new GeneralPath(GeneralPath.WIND_NON_ZERO);

        for (int i=0, n = 0; i < fComponents.length; i++, n += 2) {
            TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];

            dstShape.append(tlc.getOutline(locs[n], locs[n+1]), false);
        }

        if (tx != null) {
            dstShape.transform(tx);
        }
        return dstShape;
    }
 
Example 10
Source File: NestWorldMapPane.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void drawGeoBoundaryPath(final Graphics2D g2d, final GeneralPath[] boundaryPaths,
                                 final Color fillColor, final Color borderColor) {
    final AffineTransform transform = layerCanvas.getViewport().getModelToViewTransform();
    for (GeneralPath boundaryPath : boundaryPaths) {
        boundaryPath.transform(transform);
        g2d.setColor(fillColor);
        g2d.fill(boundaryPath);
        g2d.setColor(borderColor);
        g2d.draw(boundaryPath);
    }
}
 
Example 11
Source File: TextLine.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public Shape getOutline(AffineTransform tx) {

        GeneralPath dstShape = new GeneralPath(GeneralPath.WIND_NON_ZERO);

        for (int i=0, n = 0; i < fComponents.length; i++, n += 2) {
            TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];

            dstShape.append(tlc.getOutline(locs[n], locs[n+1]), false);
        }

        if (tx != null) {
            dstShape.transform(tx);
        }
        return dstShape;
    }
 
Example 12
Source File: TextLine.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public Shape getOutline(AffineTransform tx) {

        GeneralPath dstShape = new GeneralPath(GeneralPath.WIND_NON_ZERO);

        for (int i=0, n = 0; i < fComponents.length; i++, n += 2) {
            TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];

            dstShape.append(tlc.getOutline(locs[n], locs[n+1]), false);
        }

        if (tx != null) {
            dstShape.transform(tx);
        }
        return dstShape;
    }
 
Example 13
Source File: StarsTransition2D.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
protected static void fit(GeneralPath p, float length, float centerX, float centerY, GeneralPath path, Dimension size, float progress) {
    Rectangle2D r = p.getBounds2D();
    AffineTransform t = new AffineTransform();
    t.translate(-r.getX() - r.getWidth() / 2, -r.getY() - r.getHeight() / 2);
    t.rotate((1 - progress) * 1);
    double scaleProgress = Math.pow(progress, 3) * 0.75f;
    t.scale(length / r.getWidth() * (0.02 + 1.8 * scaleProgress), length / r
            .getWidth() * (0.02 + 1.8 * scaleProgress));
    p.transform(t);

    if (progress > 1) {
        progress = 1;
    }
    if (progress < 0) {
        progress = 0;
    }
    Point2D endPoint = ShapeUtils.getPoint(path, 1);
    Point2D startPoint = ShapeUtils.getPoint(path, progress);
    Rectangle2D pathBounds = ShapeBounds.getBounds(path);
    AffineTransform pathTransform = RectangularTransform.create(
            pathBounds,
            new Rectangle2D.Float(0, 0, size.width + 100, size.height)
    );
    pathTransform.transform(endPoint, endPoint);
    pathTransform.transform(startPoint, startPoint);
    r = p.getBounds();
    t.setToTranslation(-r.getCenterX() + centerX - endPoint.getX() + startPoint.getX(),
            -r.getCenterY() + centerY - endPoint.getY() + startPoint.getY());

    p.transform(t);
}
 
Example 14
Source File: MinMaxCategoryRenderer.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns an icon from a shape.
 *
 * @param shape  the shape.
 * @param fill  the fill flag.
 * @param outline  the outline flag.
 *
 * @return The icon.
 */
private Icon getIcon(Shape shape, final boolean fill,
        final boolean outline) {
    final int width = shape.getBounds().width;
    final int height = shape.getBounds().height;
    final GeneralPath path = new GeneralPath(shape);
    return new Icon() {
        @Override
        public void paintIcon(Component c, Graphics g, int x, int y) {
            Graphics2D g2 = (Graphics2D) g;
            path.transform(AffineTransform.getTranslateInstance(x, y));
            if (fill) {
                g2.fill(path);
            }
            if (outline) {
                g2.draw(path);
            }
            path.transform(AffineTransform.getTranslateInstance(-x, -y));
        }

        @Override
        public int getIconWidth() {
            return width;
        }

        @Override
        public int getIconHeight() {
            return height;
        }
    };
}
 
Example 15
Source File: StandardGlyphVector.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
void appendGlyphOutline(int glyphID, GeneralPath result, float x, float y) {
    // !!! fontStrike needs a method for this.  For that matter, GeneralPath does.
    GeneralPath gp = null;
    if (sgv.invdtx == null) {
        gp = strike.getGlyphOutline(glyphID, x + dx, y + dy);
    } else {
        gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        gp.transform(AffineTransform.getTranslateInstance(x + dx, y + dy));
    }
    PathIterator iterator = gp.getPathIterator(null);
    result.append(iterator, false);
}
 
Example 16
Source File: StandardGlyphVector.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
void appendGlyphOutline(int glyphID, GeneralPath result, float x, float y) {
    // !!! fontStrike needs a method for this.  For that matter, GeneralPath does.
    GeneralPath gp = null;
    if (sgv.invdtx == null) {
        gp = strike.getGlyphOutline(glyphID, x + dx, y + dy);
    } else {
        gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        gp.transform(AffineTransform.getTranslateInstance(x + dx, y + dy));
    }
    PathIterator iterator = gp.getPathIterator(null);
    result.append(iterator, false);
}
 
Example 17
Source File: VisualizeKMLJointProb.java    From beast-mcmc with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void paintComponent(Graphics g) {

        System.out.println("entering paintComponent()");

        computeScales();

        Graphics2D g2d = (Graphics2D) g;

        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        g2d.setStroke(new BasicStroke(1.5f));

        int sx1 = probs.x(start.getX());
        int sy1 = probs.y(start.getY());
        int sx2 = probs.x(B.getX());
        int sy2 = probs.y(B.getY());
        int t = 49;

        AffineTransform transform = getFullTransform();

        double maxProb = 0.0;
        double[][] p = new double[probs.latticeWidth][probs.latticeHeight];
        for (int i = 0; i < probs.latticeWidth; i++) {
            for (int j = 0; j < probs.latticeHeight; j++) {

                p[i][j] = probs.p(sx1, sy1, i, j, t) * probs.p(sx2, sy2, i, j, t);
                if (p[i][j] > maxProb) maxProb = p[i][j];
            }
        }

        System.out.println("Painting lattice probs");
        for (int i = 0; i < probs.latticeWidth; i++) {
            for (int j = 0; j < probs.latticeHeight; j++) {

                p[i][j] /= maxProb;

                Rectangle2D rect = new Rectangle2D.Double(i * probs.dx + probs.minx, j * probs.dy + probs.miny, probs.dx, probs.dy);

                g.setColor(cf.getColor((float) p[i][j]));
                g2d.fill(transform.createTransformedShape(rect));
                g.setColor(Color.black);
                g2d.draw(transform.createTransformedShape(rect));
            }
        }

        System.out.println("Painting shapes");
        for (Shape s : shapes) {
            System.out.print(".");
            System.out.flush();
            GeneralPath path = new GeneralPath(s);
            path.transform(transform);
            g2d.setPaint(Color.BLACK);
            g2d.fill(path);
        }

        g2d.setColor(Color.yellow);
        SpaceTime.paintDot(new SpaceTime(0, start), 4, transform, g2d);
        SpaceTime.paintDot(new SpaceTime(0, B), 4, transform, g2d);

    }
 
Example 18
Source File: ArrowIcon.java    From pumpernickel with MIT License 4 votes vote down vote up
/**
 * Creates an arrow.
 * 
 * @param direction
 *            one of the SwingConstants NORTH, SOUTH, EAST or WEST.
 * @param w
 *            the width of the arrow.
 * @param h
 *            the height of the arrow.
 * @return an arrow.
 */
public static GeneralPath createArrow(int direction, int w, int h) {
	GeneralPath p = new GeneralPath();

	float width = (direction == EAST || direction == WEST) ? w : h;
	float height = (direction == EAST || direction == WEST) ? h : w;
	p.moveTo(0, height / 2 - height / 6);
	p.lineTo(width / 2, height / 2 - height / 6);
	p.lineTo(width / 2, 0);
	p.lineTo(width, height / 2);
	p.lineTo(width / 2, height);
	p.lineTo(width / 2, height / 2 + height / 6);
	p.lineTo(0, height / 2 + height / 6);

	if (direction == EAST) {
		return p;
	} else if (direction == WEST) {
		AffineTransform horizontalFlip = new AffineTransform();
		horizontalFlip.translate(width, 0);
		horizontalFlip.scale(-1, 1);
		p.transform(horizontalFlip);
		return p;
	} else if (direction == NORTH) {
		AffineTransform rotateCounterclockwise = new AffineTransform();
		rotateCounterclockwise.translate(0, width);
		rotateCounterclockwise.rotate(-Math.PI / 2);
		p.transform(rotateCounterclockwise);
		return p;
	} else if (direction == SOUTH) {
		AffineTransform rotateClockwise = new AffineTransform();
		rotateClockwise.translate(height, 0);
		rotateClockwise.rotate(Math.PI / 2);
		p.transform(rotateClockwise);
		return p;
	}

	throw new IllegalArgumentException(
			"direction ("
					+ direction
					+ ") must be one of the SwingConstants: NORTH, SOUTH, EAST or WEST.");
}
 
Example 19
Source File: StarsTransition2D.java    From pumpernickel with MIT License 4 votes vote down vote up
@Override
public Shape[] getShapes(float progress, Dimension size) {
	progress = 1 - progress;

	GeneralPath star1 = new GeneralPath(star[8]);
	GeneralPath star2 = new GeneralPath(star[5]);
	GeneralPath star3 = new GeneralPath(star[8]);
	GeneralPath star4 = new GeneralPath(star[5]);
	GeneralPath star5 = new GeneralPath(star[7]);
	GeneralPath star6 = new GeneralPath(star[5]);
	GeneralPath star7 = new GeneralPath(star[8]);
	GeneralPath star8 = new GeneralPath(star[6]);

	Random random = new Random(2);

	star1.transform(AffineTransform.getRotateInstance(random.nextDouble()));
	star2.transform(AffineTransform.getRotateInstance(random.nextDouble()));
	star3.transform(AffineTransform.getRotateInstance(random.nextDouble()));
	star4.transform(AffineTransform.getRotateInstance(random.nextDouble()));
	star5.transform(AffineTransform.getRotateInstance(random.nextDouble()));
	star6.transform(AffineTransform.getRotateInstance(random.nextDouble()));
	star7.transform(AffineTransform.getRotateInstance(random.nextDouble()));
	star8.transform(AffineTransform.getRotateInstance(random.nextDouble()));

	float big = (Math.min(size.width, size.height)) * .7f;
	float base1 = (float) (Math.pow(progress, 2.2) * .5f + 0f / 8f * .3f);
	float base2 = (float) (Math.pow(progress, 2.2) * .5f + 1f / 8f * .3f);
	float base3 = (float) (Math.pow(progress, 2.2) * .5f + 2f / 8f * .3f);
	float base4 = (float) (Math.pow(progress, 2.2) * .5f + 3f / 8f * .3f);
	float base5 = (float) (Math.pow(progress, 2.2) * .5f + 4f / 8f * .3f);
	float base6 = (float) (Math.pow(progress, 2.2) * .5f + 5f / 8f * .3f);
	float base7 = (float) (Math.pow(progress, 2.2) * .5f + 6f / 8f * .3f);
	float base8 = (float) (Math.pow(progress, 2.2) * .5f + 7f / 8f * .3f);
	float progress1 = (progress - base1) / (1 - base1);
	float progress2 = (progress - base2) / (1 - base2);
	float progress3 = (progress - base3) / (1 - base3);
	float progress4 = (progress - base4) / (1 - base4);
	float progress5 = (progress - base5) / (1 - base5);
	float progress6 = (progress - base6) / (1 - base6);
	float progress7 = (progress - base7) / (1 - base7);
	float progress8 = (progress - base8) / (1 - base8);
	List<GeneralPath> v = new ArrayList<GeneralPath>();

	if (progress1 > 0) {
		fit(star1, big, size.width * 2f / 3f, size.height * 3f / 4f,
				paths[0], size, progress1 * 2);
		v.add(star1);
	}
	if (progress2 > 0) {
		fit(star2, big, size.width * 7f / 8f, size.height * 1f / 5f,
				paths[1], size, progress2 * 2);
		v.add(star2);
	}
	if (progress3 > 0) {
		fit(star3, big, size.width * 1f / 6f, size.height * 2.2f / 5f,
				paths[2], size, progress3 * 2);
		v.add(star3);
	}
	if (progress4 > 0) {
		fit(star4, big, size.width * 3.1f / 6f, size.height * 1.2f / 5f,
				paths[0], size, progress4 * 2);
		v.add(star4);
	}
	if (progress5 > 0) {
		fit(star5, big, size.width * 1.9f / 6f, size.height * 4.2f / 5f,
				paths[1], size, progress5 * 2);
		v.add(star5);
	}
	if (progress6 > 0) {
		fit(star6, big, size.width * 13f / 15f, size.height * 4.3f / 5f,
				paths[2], size, progress6 * 2);
		v.add(star6);
	}
	if (progress7 > 0) {
		fit(star7, big, size.width * 2f / 5f, size.height * 2.4f / 5f,
				paths[0], size, progress7 * 2);
		v.add(star7);
	}
	if (progress8 > 0) {
		fit(star8, big, size.width * 3f / 6f, size.height * 2f / 5f,
				paths[2], size, progress8 * 2);
		v.add(star8);
	}

	Shape[] shapes = v.toArray(new Shape[v.size()]);
	if (type == LEFT) {
		AffineTransform flipHorizontal = TransformUtils
				.createAffineTransform(0, 0, 0, size.height, size.width, 0,
						size.width, 0, size.width, size.height, 0, 0);
		for (int a = 0; a < shapes.length; a++) {
			if (shapes[a] instanceof GeneralPath) {
				((GeneralPath) shapes[a]).transform(flipHorizontal);
			} else {
				shapes[a] = flipHorizontal
						.createTransformedShape(shapes[a]);
			}
		}
	}
	return shapes;
}
 
Example 20
Source File: TransformTest.java    From pumpernickel with MIT License 4 votes vote down vote up
@Override
public void doTest() {
	int failures = 0;
	int additions = ((Number) TransformTest.this.additions.getValue())
			.intValue();
	try {
		long[] time = new long[((Number) repeat.getValue()).intValue()];
		for (int a = 0; a < time.length; a++) {
			time[a] = System.currentTimeMillis();
			AreaX sum = new AreaX();
			for (int b = 0; b < additions; b++) {
				if (cancelled)
					return;

				float percent = ((float) a) / ((float) time.length);
				percent = percent + 1f / (time.length) * (b) / (additions);
				progress.setValue((int) (percent * (progress.getMaximum() - progress
						.getMinimum())) + progress.getMinimum());

				AreaX newGuy = new AreaX(getShape(a * time.length + b));
				AffineTransform t = getTransform(a * time.length + b);
				newGuy.transform(t);
				sum.add(newGuy);
			}
			time[a] = System.currentTimeMillis() - time[a];

			clear(image1);
			clear(image2);

			Rectangle rect = sum.getBounds().getBounds();
			RectangularTransform overall = new RectangularTransform(rect,
					new Rectangle(0, 0, image1.getWidth(),
							image1.getHeight()));

			Graphics2D g = image1.createGraphics();
			g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
					RenderingHints.VALUE_ANTIALIAS_ON);
			g.transform(overall.createAffineTransform());
			g.setColor(Color.black);
			for (int b = 0; b < additions; b++) {
				GeneralPath mini = getShape(a * time.length + b);
				mini.transform(getTransform(a * time.length + b));
				g.fill(mini);
			}
			g.dispose();

			g = image2.createGraphics();
			g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
					RenderingHints.VALUE_ANTIALIAS_ON);
			g.transform(overall.createAffineTransform());
			g.setColor(Color.black);
			g.fill(sum);
			g.dispose();

			if (equals(image1, image2, printStream) == false) {
				failures++;
				printStream.println("failed for a = " + a + " (repeat = "
						+ repeat.getValue() + ", additions = " + additions
						+ ")");
			}

		}
		Arrays.sort(time);
		printStream
				.println("Median time: " + time[time.length / 2] + " ms");
	} finally {
		if (cancelled) {
			printStream.println("cancelled");
		} else {
			printStream.println("failures: " + failures);
		}
	}
}