Example usage for java.awt.geom GeneralPath getWindingRule

List of usage examples for java.awt.geom GeneralPath getWindingRule

Introduction

In this page you can find the example usage for java.awt.geom GeneralPath getWindingRule.

Prototype

public final synchronized int getWindingRule() 

Source Link

Document

Returns the fill style winding rule.

Usage

From source file:Main.java

/**
 * 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.//from   www  . j av  a 2  s. c om
 */
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;
}