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

The following examples show how to use java.awt.geom.GeneralPath#getWindingRule() . 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: ShapeUtilities.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Tests two polygons for equality.  If both are <code>null</code> this
 * method returns <code>true</code>.
 *
 * @param p1  path 1 (<code>null</code> permitted).
 * @param p2  path 2 (<code>null</code> permitted).
 *
 * @return A boolean.
 */
public static boolean equal(final GeneralPath p1, final GeneralPath p2) {
    if (p1 == null) {
        return (p2 == null);
    }
    if (p2 == null) {
        return false;
    }
    if (p1.getWindingRule() != p2.getWindingRule()) {
        return false;
    }
    PathIterator iterator1 = p1.getPathIterator(null);
    PathIterator iterator2 = p2.getPathIterator(null);
    double[] d1 = new double[6];
    double[] d2 = new double[6];
    boolean done = iterator1.isDone() && iterator2.isDone();
    while (!done) {
        if (iterator1.isDone() != iterator2.isDone()) {
            return false;
        }
        int seg1 = iterator1.currentSegment(d1);
        int seg2 = iterator2.currentSegment(d2);
        if (seg1 != seg2) {
            return false;
        }
        if (!Arrays.equals(d1, d2)) {
            return false;
        }
        iterator1.next();
        iterator2.next();
        done = iterator1.isDone() && iterator2.isDone();
    }
    return true;
}
 
Example 2
Source File: Cardumen_009_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Converts a path from Java2D space to data space.
 *
 * @param path  the path (<code>null</code> not permitted).
 * @param dataArea  the data area.
 * @param dataset  the dataset which can be used to find the appropriate
 *         axes.
 *
 * @return A path in data space.
 */
private GeneralPath convertToDataSpace(GeneralPath path,
        Rectangle2D dataArea, XYDataset dataset) {
    GeneralPath result = new GeneralPath(path.getWindingRule());
    int datasetIndex = indexOf(dataset);
    ValueAxis xAxis = getDomainAxisForDataset(datasetIndex);
    ValueAxis yAxis = getRangeAxisForDataset(datasetIndex);
    RectangleEdge xAxisEdge = getDomainAxisEdge();
    RectangleEdge yAxisEdge = getRangeAxisEdge();
    double[] coords = new double[6];
    PathIterator iterator = path.getPathIterator(null);
    while (!iterator.isDone()) {
        int segType = iterator.currentSegment(coords);
        double xx = xAxis.java2DToValue(coords[0], dataArea, xAxisEdge);
        double yy = yAxis.java2DToValue(coords[1], dataArea, yAxisEdge);
        if (segType == PathIterator.SEG_MOVETO) {
            result.moveTo((float) xx, (float) yy);
        }
        else if (segType == PathIterator.SEG_LINETO) {
            result.lineTo((float) xx, (float) yy);
        }
        else if (segType == PathIterator.SEG_CLOSE) {
            result.closePath();
        }
        iterator.next();
    }
    return result;
}
 
Example 3
Source File: Cardumen_009_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Converts a path from Java2D space to data space.
 *
 * @param path  the path (<code>null</code> not permitted).
 * @param dataArea  the data area.
 * @param dataset  the dataset which can be used to find the appropriate
 *         axes.
 *
 * @return A path in data space.
 */
private GeneralPath convertToDataSpace(GeneralPath path,
        Rectangle2D dataArea, XYDataset dataset) {
    GeneralPath result = new GeneralPath(path.getWindingRule());
    int datasetIndex = indexOf(dataset);
    ValueAxis xAxis = getDomainAxisForDataset(datasetIndex);
    ValueAxis yAxis = getRangeAxisForDataset(datasetIndex);
    RectangleEdge xAxisEdge = getDomainAxisEdge();
    RectangleEdge yAxisEdge = getRangeAxisEdge();
    double[] coords = new double[6];
    PathIterator iterator = path.getPathIterator(null);
    while (!iterator.isDone()) {
        int segType = iterator.currentSegment(coords);
        double xx = xAxis.java2DToValue(coords[0], dataArea, xAxisEdge);
        double yy = yAxis.java2DToValue(coords[1], dataArea, yAxisEdge);
        if (segType == PathIterator.SEG_MOVETO) {
            result.moveTo((float) xx, (float) yy);
        }
        else if (segType == PathIterator.SEG_LINETO) {
            result.lineTo((float) xx, (float) yy);
        }
        else if (segType == PathIterator.SEG_CLOSE) {
            result.closePath();
        }
        iterator.next();
    }
    return result;
}
 
Example 4
Source File: Cardumen_0082_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Converts a path from Java2D space to data space.
 *
 * @param path  the path (<code>null</code> not permitted).
 * @param dataArea  the data area.
 * @param dataset  the dataset which can be used to find the appropriate
 *         axes.
 *
 * @return A path in data space.
 */
private GeneralPath convertToDataSpace(GeneralPath path,
        Rectangle2D dataArea, XYDataset dataset) {
    GeneralPath result = new GeneralPath(path.getWindingRule());
    int datasetIndex = indexOf(dataset);
    ValueAxis xAxis = getDomainAxisForDataset(datasetIndex);
    ValueAxis yAxis = getRangeAxisForDataset(datasetIndex);
    RectangleEdge xAxisEdge = getDomainAxisEdge();
    RectangleEdge yAxisEdge = getRangeAxisEdge();
    double[] coords = new double[6];
    PathIterator iterator = path.getPathIterator(null);
    while (!iterator.isDone()) {
        int segType = iterator.currentSegment(coords);
        double xx = xAxis.java2DToValue(coords[0], dataArea, xAxisEdge);
        double yy = yAxis.java2DToValue(coords[1], dataArea, yAxisEdge);
        if (segType == PathIterator.SEG_MOVETO) {
            result.moveTo((float) xx, (float) yy);
        }
        else if (segType == PathIterator.SEG_LINETO) {
            result.lineTo((float) xx, (float) yy);
        }
        else if (segType == PathIterator.SEG_CLOSE) {
            result.closePath();
        }
        iterator.next();
    }
    return result;
}
 
Example 5
Source File: Cardumen_0082_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Converts a path from Java2D space to data space.
 *
 * @param path  the path (<code>null</code> not permitted).
 * @param dataArea  the data area.
 * @param dataset  the dataset which can be used to find the appropriate
 *         axes.
 *
 * @return A path in data space.
 */
private GeneralPath convertToDataSpace(GeneralPath path,
        Rectangle2D dataArea, XYDataset dataset) {
    GeneralPath result = new GeneralPath(path.getWindingRule());
    int datasetIndex = indexOf(dataset);
    ValueAxis xAxis = getDomainAxisForDataset(datasetIndex);
    ValueAxis yAxis = getRangeAxisForDataset(datasetIndex);
    RectangleEdge xAxisEdge = getDomainAxisEdge();
    RectangleEdge yAxisEdge = getRangeAxisEdge();
    double[] coords = new double[6];
    PathIterator iterator = path.getPathIterator(null);
    while (!iterator.isDone()) {
        int segType = iterator.currentSegment(coords);
        double xx = xAxis.java2DToValue(coords[0], dataArea, xAxisEdge);
        double yy = yAxis.java2DToValue(coords[1], dataArea, yAxisEdge);
        if (segType == PathIterator.SEG_MOVETO) {
            result.moveTo((float) xx, (float) yy);
        }
        else if (segType == PathIterator.SEG_LINETO) {
            result.lineTo((float) xx, (float) yy);
        }
        else if (segType == PathIterator.SEG_CLOSE) {
            result.closePath();
        }
        iterator.next();
    }
    return result;
}
 
Example 6
Source File: Elixir_001_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Tests two polygons for equality.  If both are <code>null</code> this
 * method returns <code>true</code>.
 *
 * @param p1  path 1 (<code>null</code> permitted).
 * @param p2  path 2 (<code>null</code> permitted).
 *
 * @return A boolean.
 */
public static boolean equal(GeneralPath p1, GeneralPath p2) {
    if (p1 == null) {
        return (p2 == null);
    }
    if (p2 == null) {
        return false;
    }
    if (p1.getWindingRule() != p2.getWindingRule()) {
        return false;
    }
    PathIterator iterator1 = p1.getPathIterator(null);
    PathIterator iterator2 = p1.getPathIterator(null);
    double[] d1 = new double[6];
    double[] d2 = new double[6];
    boolean done = iterator1.isDone() && iterator2.isDone();
    while (!done) {
        if (iterator1.isDone() != iterator2.isDone()) {
            return false;
        }
        int seg1 = iterator1.currentSegment(d1);
        int seg2 = iterator2.currentSegment(d2);
        if (seg1 != seg2) {
            return false;
        }
        if (!Arrays.equals(d1, d2)) {
            return false;
        }
        iterator1.next();
        iterator2.next();
        done = iterator1.isDone() && iterator2.isDone();
    }
    return true;
}
 
Example 7
Source File: Elixir_001_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Tests two polygons for equality.  If both are <code>null</code> this
 * method returns <code>true</code>.
 *
 * @param p1  path 1 (<code>null</code> permitted).
 * @param p2  path 2 (<code>null</code> permitted).
 *
 * @return A boolean.
 */
public static boolean equal(GeneralPath p1, GeneralPath p2) {
    if (p1 == null) {
        return (p2 == null);
    }
    if (p2 == null) {
        return false;
    }
    if (p1.getWindingRule() != p2.getWindingRule()) {
        return false;
    }
    PathIterator iterator1 = p1.getPathIterator(null);
    PathIterator iterator2 = p2.getPathIterator(null);
    double[] d1 = new double[6];
    double[] d2 = new double[6];
    boolean done = iterator1.isDone() && iterator2.isDone();
    while (!done) {
        if (iterator1.isDone() != iterator2.isDone()) {
            return false;
        }
        int seg1 = iterator1.currentSegment(d1);
        int seg2 = iterator2.currentSegment(d2);
        if (seg1 != seg2) {
            return false;
        }
        if (!Arrays.equals(d1, d2)) {
            return false;
        }
        iterator1.next();
        iterator2.next();
        done = iterator1.isDone() && iterator2.isDone();
    }
    return true;
}
 
Example 8
Source File: Chart_11_ShapeUtilities_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Tests two polygons for equality.  If both are <code>null</code> this
 * method returns <code>true</code>.
 *
 * @param p1  path 1 (<code>null</code> permitted).
 * @param p2  path 2 (<code>null</code> permitted).
 *
 * @return A boolean.
 */
public static boolean equal(GeneralPath p1, GeneralPath p2) {
    if (p1 == null) {
        return (p2 == null);
    }
    if (p2 == null) {
        return false;
    }
    if (p1.getWindingRule() != p2.getWindingRule()) {
        return false;
    }
    PathIterator iterator1 = p1.getPathIterator(null);
    PathIterator iterator2 = p2.getPathIterator(null);
    double[] d1 = new double[6];
    double[] d2 = new double[6];
    boolean done = iterator1.isDone() && iterator2.isDone();
    while (!done) {
        if (iterator1.isDone() != iterator2.isDone()) {
            return false;
        }
        int seg1 = iterator1.currentSegment(d1);
        int seg2 = iterator2.currentSegment(d2);
        if (seg1 != seg2) {
            return false;
        }
        if (!Arrays.equals(d1, d2)) {
            return false;
        }
        iterator1.next();
        iterator2.next();
        done = iterator1.isDone() && iterator2.isDone();
    }
    return true;
}
 
Example 9
Source File: Chart_11_ShapeUtilities_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Tests two polygons for equality.  If both are <code>null</code> this
 * method returns <code>true</code>.
 *
 * @param p1  path 1 (<code>null</code> permitted).
 * @param p2  path 2 (<code>null</code> permitted).
 *
 * @return A boolean.
 */
public static boolean equal(GeneralPath p1, GeneralPath p2) {
    if (p1 == null) {
        return (p2 == null);
    }
    if (p2 == null) {
        return false;
    }
    if (p1.getWindingRule() != p2.getWindingRule()) {
        return false;
    }
    PathIterator iterator1 = p1.getPathIterator(null);
    PathIterator iterator2 = p1.getPathIterator(null);
    double[] d1 = new double[6];
    double[] d2 = new double[6];
    boolean done = iterator1.isDone() && iterator2.isDone();
    while (!done) {
        if (iterator1.isDone() != iterator2.isDone()) {
            return false;
        }
        int seg1 = iterator1.currentSegment(d1);
        int seg2 = iterator2.currentSegment(d2);
        if (seg1 != seg2) {
            return false;
        }
        if (!Arrays.equals(d1, d2)) {
            return false;
        }
        iterator1.next();
        iterator2.next();
        done = iterator1.isDone() && iterator2.isDone();
    }
    return true;
}
 
Example 10
Source File: ShapeUtilities.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests two polygons for equality.  If both are <code>null</code> this
 * method returns <code>true</code>.
 *
 * @param p1  path 1 (<code>null</code> permitted).
 * @param p2  path 2 (<code>null</code> permitted).
 *
 * @return A boolean.
 */
public static boolean equal(GeneralPath p1, GeneralPath p2) {
    if (p1 == null) {
        return (p2 == null);
    }
    if (p2 == null) {
        return false;
    }
    if (p1.getWindingRule() != p2.getWindingRule()) {
        return false;
    }
    PathIterator iterator1 = p1.getPathIterator(null);
    PathIterator iterator2 = p2.getPathIterator(null);
    double[] d1 = new double[6];
    double[] d2 = new double[6];
    boolean done = iterator1.isDone() && iterator2.isDone();
    while (!done) {
        if (iterator1.isDone() != iterator2.isDone()) {
            return false;
        }
        int seg1 = iterator1.currentSegment(d1);
        int seg2 = iterator2.currentSegment(d2);
        if (seg1 != seg2) {
            return false;
        }
        if (!Arrays.equals(d1, d2)) {
            return false;
        }
        iterator1.next();
        iterator2.next();
        done = iterator1.isDone() && iterator2.isDone();
    }
    return true;
}
 
Example 11
Source File: ShapeUtilities.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests two polygons for equality.  If both are <code>null</code> this
 * method returns <code>true</code>.
 *
 * @param p1  path 1 (<code>null</code> permitted).
 * @param p2  path 2 (<code>null</code> permitted).
 *
 * @return A boolean.
 */
public static boolean equal(GeneralPath p1, GeneralPath p2) {
    if (p1 == null) {
        return (p2 == null);
    }
    if (p2 == null) {
        return false;
    }
    if (p1.getWindingRule() != p2.getWindingRule()) {
        return false;
    }
    PathIterator iterator1 = p1.getPathIterator(null);
    PathIterator iterator2 = p1.getPathIterator(null);
    double[] d1 = new double[6];
    double[] d2 = new double[6];
    boolean done = iterator1.isDone() && iterator2.isDone();
    while (!done) {
        if (iterator1.isDone() != iterator2.isDone()) {
            return false;
        }
        int seg1 = iterator1.currentSegment(d1);
        int seg2 = iterator2.currentSegment(d2);
        if (seg1 != seg2) {
            return false;
        }
        if (!Arrays.equals(d1, d2)) {
            return false;
        }
        iterator1.next();
        iterator2.next();
        done = iterator1.isDone() && iterator2.isDone();
    }
    return true;
}
 
Example 12
Source File: SimplifyStroke.java    From han3_ji7_tsoo1_kian3 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 去掉該路徑的冗點。
 * 
 * @param generalPath
 *            路徑物件
 * @return 去掉冗點的結果
 */
public Shape createStrokedShape(GeneralPath generalPath)
{
	SimplifyAction simplifyAction = new SimplifyAction(
			generalPath.getWindingRule());
	PathTravel pathTravel = new PathTravel(simplifyAction);
	pathTravel.travelOn(generalPath);
	new ShapeAnalyst(simplifyAction.getCurrnetPath());
	return simplifyAction.getCurrnetPath();
}
 
Example 13
Source File: UnsharpenStroke.java    From han3_ji7_tsoo1_kian3 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 圓滑該路徑的頂點。
 * 
 * @param generalPath
 *            路徑物件
 * @return 圓滑後的結果
 */
public Shape createStrokedShape(GeneralPath generalPath)
{
	UnsharpenAction unsharpenAction = new UnsharpenAction(
			generalPath.getWindingRule());
	PathTravel pathTravel = new PathTravel(unsharpenAction);
	pathTravel.travelOn(generalPath);
	return unsharpenAction.getCurrnetPath();
}