Java Code Examples for java.awt.geom.Path2D#WIND_NON_ZERO

The following examples show how to use java.awt.geom.Path2D#WIND_NON_ZERO . 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: AccuracyTest.java    From pumpernickel with MIT License 6 votes vote down vote up
private GeneralPath getShape(int index) {
	Random r = new Random(index * 100000);
	GeneralPath path = new GeneralPath(
			r.nextBoolean() ? Path2D.WIND_EVEN_ODD : Path2D.WIND_NON_ZERO);
	path.moveTo(r.nextFloat() * 100, r.nextFloat() * 100);
	for (int a = 0; a < 3; a++) {
		int k;
		if (type.getSelectedIndex() == 0) {
			k = r.nextInt(3);
		} else {
			k = type.getSelectedIndex() - 1;
		}

		if (k == 0) {
			path.lineTo(r.nextFloat() * 100, r.nextFloat() * 100);
		} else if (k == 1) {
			path.quadTo(r.nextFloat() * 100, r.nextFloat() * 100,
					r.nextFloat() * 100, r.nextFloat() * 100);
		} else {
			path.curveTo(r.nextFloat() * 100, r.nextFloat() * 100,
					r.nextFloat() * 100, r.nextFloat() * 100,
					r.nextFloat() * 100, r.nextFloat() * 100);
		}
	}
	return path;
}
 
Example 2
Source File: Path.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
private static int getWindingRule(FillRule fillRule) {
	switch (fillRule) {
	case EVEN_ODD:
		return Path2D.WIND_EVEN_ODD;
	case NON_ZERO:
		return Path2D.WIND_NON_ZERO;
	}

	throw new IllegalArgumentException("unknown fill rule:" + fillRule);
}
 
Example 3
Source File: DiamondsTransition2D.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Transition2DInstruction[] getInstructions(float progress,
                                                 Dimension size) {

    GeneralPath clipping = new GeneralPath(Path2D.WIND_NON_ZERO);

    float dx = size.width / 2.0f;
    float dy = size.height / 2.0f;
    while (dx > 0 + diamondSize) {
        dx -= diamondSize;
    }
    while (dy > 0 + diamondSize) {
        dy -= diamondSize;
    }

    int ctr = 0;
    progress = progress / 2.0f;
    for (float y = -dy; y < size.height + diamondSize; y += diamondSize / 2) {
        float z = 0;
        if (ctr % 2 == 0) {
            z = diamondSize / 2.0f;
        }

        for (float x = -dx; x < size.width + diamondSize; x += diamondSize) {
            clipping.moveTo(x + z, y - diamondSize * progress);
            clipping.lineTo(x + diamondSize * progress + z, y);
            clipping.lineTo(x + z, y + diamondSize * progress);
            clipping.lineTo(x - diamondSize * progress + z, y);
            clipping.lineTo(x + z, y - diamondSize * progress);
            clipping.closePath();
        }
        ctr++;
    }

    return new Transition2DInstruction[]{
            new ImageInstruction(true),
            new ImageInstruction(false, null, clipping)
    };
}
 
Example 4
Source File: BpmnJsonConverter.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private Path2D.Double createGatewayShape(double x, double y, double width, double height) {
    double middleX = x + (width / 2);
    double middleY = y + (height / 2);

    Path2D.Double gatewayShape = new Path2D.Double(Path2D.WIND_NON_ZERO, 4);
    gatewayShape.moveTo(x, middleY);
    gatewayShape.lineTo(middleX, y);
    gatewayShape.lineTo(x + width, middleY);
    gatewayShape.lineTo(middleX, y + height);
    gatewayShape.closePath();
    return gatewayShape;
}
 
Example 5
Source File: DiamondsTransition2D.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
public Transition2DInstruction[] getInstructions(float progress,
		Dimension size) {

	GeneralPath clipping = new GeneralPath(Path2D.WIND_NON_ZERO);

	float dx = size.width / 2f;
	float dy = size.height / 2f;
	while (dx > 0 + diamondSize)
		dx -= diamondSize;
	while (dy > 0 + diamondSize)
		dy -= diamondSize;

	int ctr = 0;
	progress = progress / 2f;
	for (float y = -dy; y < size.height + diamondSize; y += diamondSize / 2) {
		float z = 0;
		if (ctr % 2 == 0)
			z = diamondSize / 2f;

		for (float x = -dx; x < size.width + diamondSize; x += diamondSize) {
			clipping.moveTo(x + z, y - diamondSize * progress);
			clipping.lineTo(x + diamondSize * progress + z, y);
			clipping.lineTo(x + z, y + diamondSize * progress);
			clipping.lineTo(x - diamondSize * progress + z, y);
			clipping.lineTo(x + z, y - diamondSize * progress);
			clipping.closePath();
		}
		ctr++;
	}

	return new Transition2DInstruction[] { new ImageInstruction(true),
			new ImageInstruction(false, null, clipping) };
}
 
Example 6
Source File: DmnJsonConverterUtil.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public static Shape getLineShape(java.awt.geom.Line2D line2D) {
    Path2D line = new Path2D.Double(Path2D.WIND_NON_ZERO, 4);
    line.moveTo(line2D.getX1(), line2D.getY1());
    line.lineTo(line2D.getX2(), line2D.getY2());
    line.lineTo(line2D.getX2() + lineWidth, line2D.getY2() + lineWidth);
    line.closePath();
    return line;
}
 
Example 7
Source File: BpmnJsonConverter.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected Shape getLineShape(java.awt.geom.Line2D line2D) {
    Path2D line = new Path2D.Double(Path2D.WIND_NON_ZERO, 4);
    line.moveTo(line2D.getX1(), line2D.getY1());
    line.lineTo(line2D.getX2(), line2D.getY2());
    line.lineTo(line2D.getX2() + lineWidth, line2D.getY2() + lineWidth);
    line.closePath();
    return line;
}
 
Example 8
Source File: DuctusRenderingEngine.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public FillAdapter() {
    // Ductus only supplies float coordinates so
    // Path2D.Double is not necessary here.
    path = new Path2D.Float(Path2D.WIND_NON_ZERO);
}
 
Example 9
Source File: SWT2AWT.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Converts an SWT {@link PathData} into an equivalent AWT
 * {@link PathIterator}.
 * 
 * @param pathData
 *            the {@link PathData} to convert.
 * @param windingRule
 *            the winding rule to use when constructing the
 *            {@link PathIterator}, i.e. one of {@link SWT#FILL_WINDING} or
 *            {@link SWT#FILL_EVEN_ODD}.
 * @return a new {@link PathIterator} representing the same path
 */
public static PathIterator toAWTPathIterator(PathData pathData, int windingRule) {
	if (windingRule != SWT.FILL_WINDING && windingRule != SWT.FILL_EVEN_ODD) {
		throw new IllegalArgumentException(
				"Unsupported winding rule. Must be one of SWT.FILL_WINDING or SWT.FILL_EVEN_ODD");
	}
	Path2D.Double path = new Path2D.Double(
			windingRule == SWT.FILL_EVEN_ODD ? Path2D.WIND_EVEN_ODD : Path2D.WIND_NON_ZERO);
	int j = 0;
	byte[] types = pathData.types;
	float[] points = pathData.points;
	double x, y, x2, y2, x3, y3;
	for (int i = 0; i < types.length; i++) {

		switch (types[i]) {
		case SWT.PATH_MOVE_TO:
			x = points[j++];
			y = points[j++];
			path.moveTo(x, y);
			break;
		case SWT.PATH_LINE_TO:
			x = points[j++];
			y = points[j++];
			path.lineTo(x, y);
			break;
		case SWT.PATH_QUAD_TO:
			x = points[j++];
			y = points[j++];
			x2 = points[j++];
			y2 = points[j++];
			path.quadTo(x, y, x2, y2);
			break;
		case SWT.PATH_CUBIC_TO:
			x = points[j++];
			y = points[j++];
			x2 = points[j++];
			y2 = points[j++];
			x3 = points[j++];
			y3 = points[j++];
			path.curveTo(x, y, x2, y2, x3, y3);
			break;
		case SWT.PATH_CLOSE:
			path.closePath();
			break;
		default:
			break;
		}
	}
	return path.getPathIterator(null);
}
 
Example 10
Source File: RawRatioDataViewForShrimp.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
/**
     *
     * @param g2d
     */
    @Override
    public void paint(Graphics2D g2d) {
        super.paint(g2d);

//        if (isNotShownDueToBelowDetectionFlag()) {
//            setBackground(ReduxConstants.palePinkBelowDetection);
//            g2d.drawString("BELOW DETECTION", 25, 25);
//        }
//
//        if (!isNotShownDueToBelowDetectionFlag()) {
//            for (int i = 0; i < myOnPeakData.length; i++) {
//                Shape rawRatioPoint = new java.awt.geom.Ellipse2D.Double( //
//                        mapX(myOnPeakNormalizedAquireTimes[i]), mapY(myOnPeakData[i]), 1, 1);
//                g2d.setPaint(determineDataColor(i, Color.black));
//
//                g2d.draw(rawRatioPoint);
//            }
//        }
        Path2D pointTrace = new Path2D.Double(Path2D.WIND_NON_ZERO);
        pointTrace.moveTo(mapX(myOnPeakNormalizedAquireTimes[0]), mapY(myOnPeakData[0]));
        for (int i = 0; i < myOnPeakData.length; i++) {
            // line tracing through points
            pointTrace.lineTo(mapX(myOnPeakNormalizedAquireTimes[i]), mapY(myOnPeakData[i]));
            g2d.setStroke(new BasicStroke(0.5f));
            g2d.setPaint(determineDataColor(i, Color.GRAY));
            g2d.draw(pointTrace);

            Shape intensity = new java.awt.geom.Ellipse2D.Double( //
                    mapX(myOnPeakNormalizedAquireTimes[i]) - 1, mapY(myOnPeakData[i]) - 1, 2, 2);
            g2d.setStroke(new BasicStroke(1.5f));
            g2d.setPaint(determineDataColor(i, Color.black));
            g2d.draw(intensity);

            // uncertainty
            Shape plusMinusOneSigma = new Line2D.Double(//
                    mapX(myOnPeakNormalizedAquireTimes[i]),// 
                    mapY(myOnPeakData[i] - myOnPeakOneSigmas[i]),//
                    mapX(myOnPeakNormalizedAquireTimes[i]),// 
                    mapY(myOnPeakData[i] + myOnPeakOneSigmas[i]));
            g2d.setStroke(new BasicStroke(1.0f));
            g2d.draw(plusMinusOneSigma);

            // tips of uncertainty
            Shape plusOneSigmaTip = new Line2D.Double(//
                    mapX(myOnPeakNormalizedAquireTimes[i]) - 1,// 
                    mapY(myOnPeakData[i] + myOnPeakOneSigmas[i]),//
                    mapX(myOnPeakNormalizedAquireTimes[i]) + 1,// 
                    mapY(myOnPeakData[i] + myOnPeakOneSigmas[i]));

            Shape minusOneSigmaTip = new Line2D.Double(//
                    mapX(myOnPeakNormalizedAquireTimes[i]) - 1,// 
                    mapY(myOnPeakData[i] - myOnPeakOneSigmas[i]),//
                    mapX(myOnPeakNormalizedAquireTimes[i]) + 1,// 
                    mapY(myOnPeakData[i] - myOnPeakOneSigmas[i]));

            g2d.setStroke(new BasicStroke(1.0f));
            g2d.draw(plusOneSigmaTip);
            g2d.draw(minusOneSigmaTip);

        }
    }
 
Example 11
Source File: DuctusRenderingEngine.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public FillAdapter() {
    // Ductus only supplies float coordinates so
    // Path2D.Double is not necessary here.
    path = new Path2D.Float(Path2D.WIND_NON_ZERO);
}
 
Example 12
Source File: BrushStroke.java    From pumpernickel with MIT License 4 votes vote down vote up
public Shape createStrokedShape(Shape p) {
	if (thinStrokes == null) {
		thinStrokes = new BasicStroke[100];
		for (int a = 0; a < thinStrokes.length; a++) {
			float f = .15f + (2.05f - .15f) * (a) / (thinStrokes.length);
			thinStrokes[a] = new BasicStroke(f, BasicStroke.CAP_BUTT,
					BasicStroke.JOIN_BEVEL, 10);
		}
	}

	GeneralPath path = new GeneralPath();

	Random r = new Random(randomSeed);

	float h = thickness * thickness;
	int thicknessMax = Math.min(thinStrokes.length,
			(int) (thinStrokes.length * h + thinStrokes.length * .2f));
	int thicknessMin = (int) (thinStrokes.length * h / 2f);

	GeneralPath thisLayer = new GeneralPath(Path2D.WIND_NON_ZERO);
	GeneralPathWriter writer = new GeneralPathWriter(thisLayer);
	for (int a = 0; a < layers; a++) {
		writer.reset();
		float k1 = a * width / (layers - 1f);
		float k2 = k1 - width / 2;
		InsetPathWriter insetWriter;
		if (k2 > 0) {
			insetWriter = new InsetPathWriter(writer, Math.abs(k2), theta);
		} else {
			insetWriter = new InsetPathWriter(writer, Math.abs(k2),
					(float) (Math.PI + theta));
		}
		insetWriter.write(p);
		MeasuredShape[] measuredLayers = MeasuredShape
				.getSubpaths(thisLayer);

		float minStreakDistance = (4 + 10 * thickness) / 1f;
		float maxStreakDistance = (40 + 10 * thickness) / 1f;
		float k3 = Math.abs(k2);
		float minGapDistance = (4 + 10 * k3) / 1f;
		float maxGapDistance = (40 + 10 * k3) / 1f;

		for (int b = 0; b < measuredLayers.length; b++) {
			r.setSeed(randomSeed + 1000 * a + 10000 * b);

			float x = 0;
			if (a != layers / 2) {
				float k4 = Math.abs(k2 / width);
				x = (maxGapDistance - minGapDistance) * r.nextFloat()
						+ k4 * (.3f * r.nextFloat() + .7f) * minGapDistance;
			}

			boolean first = true;
			while (x < measuredLayers[b].getOriginalDistance()) {
				float streakDistance = minStreakDistance
						+ (maxStreakDistance - minStreakDistance)
								* r.nextFloat();
				float gapDistance;
				if (first) {
					first = false;
					gapDistance = (.2f + .8f * r.nextFloat())
							* minGapDistance
							+ (maxGapDistance - minGapDistance)
									* r.nextFloat();
				} else {
					gapDistance = minGapDistance
							+ (maxGapDistance - minGapDistance)
									* r.nextFloat();
				}

				if (x + streakDistance > measuredLayers[b]
						.getOriginalDistance()) {
					float z = 0;
					if (a != layers / 2)
						z = (maxGapDistance - minGapDistance)
								* r.nextFloat();
					streakDistance = measuredLayers[b].getOriginalDistance()
							- x - z;
				}
				if (streakDistance > 0) {
					GeneralPath p2 = measuredLayers[b].getShape(
							x / measuredLayers[b].getClosedDistance(),
							streakDistance / measuredLayers[b]
									.getClosedDistance());
					path.append(
							thinStrokes[r
									.nextInt(thicknessMax - thicknessMin)
									+ thicknessMin].createStrokedShape(p2),
							false);
				}

				x = x + (streakDistance + gapDistance);
			}
		}
	}
	return path;
}
 
Example 13
Source File: DuctusRenderingEngine.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public FillAdapter() {
    // Ductus only supplies float coordinates so
    // Path2D.Double is not necessary here.
    path = new Path2D.Float(Path2D.WIND_NON_ZERO);
}
 
Example 14
Source File: DuctusRenderingEngine.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public FillAdapter() {
    // Ductus only supplies float coordinates so
    // Path2D.Double is not necessary here.
    path = new Path2D.Float(Path2D.WIND_NON_ZERO);
}
 
Example 15
Source File: DuctusRenderingEngine.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public FillAdapter() {
    // Ductus only supplies float coordinates so
    // Path2D.Double is not necessary here.
    path = new Path2D.Float(Path2D.WIND_NON_ZERO);
}
 
Example 16
Source File: DuctusRenderingEngine.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public FillAdapter() {
    // Ductus only supplies float coordinates so
    // Path2D.Double is not necessary here.
    path = new Path2D.Float(Path2D.WIND_NON_ZERO);
}
 
Example 17
Source File: ConcordiaLine.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @param aspectRatio
 * @param minX
 * @param minY
 * @param maxX
 * @param maxY
 */
public void calcLowerUnctEnvelopeTW(double aspectRatio, double minX, double minY, double maxX, double maxY) {

    // parameters represent viewport
    constructLowerEnvelopeAtRightEnd(startSeg, aspectRatio, minX, minY, maxX, maxY);
    constructLowerEnvelopeAtLeftEnd(endSeg, aspectRatio, minX, minY, maxX, maxY);

    lowerUnctEnvelope = new Path2D.Double (Path2D.WIND_NON_ZERO);

    // start at top right of concordia
    lowerUnctEnvelope.moveTo(
            (float) mapX(startSeg.minX()),
            (float) mapY(startSeg.minY()));

    ParametricCurveSegmentI myWorkingSeg = startLowerUncertSeg;

    // decide whether to include lower right corner of viewport
    if (myWorkingSeg != null) {
        if (myWorkingSeg.minPlusSigmaY(aspectRatio) > startSeg.minY()) {
            lowerUnctEnvelope.lineTo(
                    (float) mapX(maxX),
                    (float) mapY(minY));
        }
    }

    while (myWorkingSeg != null) {
        // check for out of bounds
        double tempX = myWorkingSeg.minPlusSigmaX(aspectRatio);
        double tempY = myWorkingSeg.minPlusSigmaY(aspectRatio);
        double tempXc = myWorkingSeg.controlLowerX(aspectRatio);
        double tempYc = myWorkingSeg.controlLowerY(aspectRatio);
        double tempXl = myWorkingSeg.maxPlusSigmaX(aspectRatio);
        double tempYl = myWorkingSeg.maxPlusSigmaY(aspectRatio);

        lowerUnctEnvelope.lineTo(
                (float) mapX(tempX),
                (float) mapY(tempY));

        if (pointInViewPort(tempX, tempY, minX, minY, maxX, maxY) //
                ||//
                ((determineAxisIntersectedByLowerEnvelopeRight(maxX, maxY, tempXl, tempYl, tempX, tempY) == 1) //
                && pointInViewPort(tempXl, tempYl, minX, minY, maxX, maxY))) {

            lowerUnctEnvelope.curveTo(//
                    (float) mapX(tempX),
                    (float) mapY(tempY),
                    (float) mapX(tempXc),
                    (float) mapY(tempYc),
                    (float) mapX(tempXl),
                    (float) mapY(tempYl));
        } else if ((tempX < maxX) && (tempY > minY) && !pointInViewPort(tempX, tempY, minX, minY, maxX, maxY)//
                && (!pointInViewPort(tempXl, tempYl, minX, minY, maxX, maxY))) { //
            if (determineAxisIntersectedByConcordiaLeft(minX, minY) == -1) {
                lowerUnctEnvelope.lineTo(
                        (float) mapX(tempXl),
                        (float) mapY(tempYl));
            }
            lowerUnctEnvelope.lineTo(
                    (float) mapX(minX),
                    (float) mapY(maxY));
            // get rid of the rest
            while (myWorkingSeg.getRightSeg() != null) {
                myWorkingSeg = myWorkingSeg.getRightSeg();
            }

        }
        myWorkingSeg = myWorkingSeg.getRightSeg();
    }
}
 
Example 18
Source File: DuctusRenderingEngine.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public FillAdapter() {
    // Ductus only supplies float coordinates so
    // Path2D.Double is not necessary here.
    path = new Path2D.Float(Path2D.WIND_NON_ZERO);
}
 
Example 19
Source File: DuctusRenderingEngine.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public FillAdapter() {
    // Ductus only supplies float coordinates so
    // Path2D.Double is not necessary here.
    path = new Path2D.Float(Path2D.WIND_NON_ZERO);
}
 
Example 20
Source File: MeasuredShape.java    From pumpernickel with MIT License 3 votes vote down vote up
/**
 * Trace the shape.
 * 
 * @param position
 *            a fraction from zero to one indicating where to start tracing
 * @param length
 *            a fraction from negative one to one indicating how much to
 *            trace. If this value is negative then the shape will be traced
 *            backwards.
 * @return a new path
 */
public GeneralPath getShape(float position, float length) {
	GeneralPath dest = new GeneralPath(Path2D.WIND_NON_ZERO);
	PathWriter w = new GeneralPathWriter(dest);
	writeShape(position, length, w, true);
	return dest;
}