public Shape [ ] subtract ( Shape target , Shape missing ) { target = target . transform ( new Transform ( ) ) ; missing = missing . transform ( new Transform ( ) ) ; int count = 0 ; for ( int i = 0 ; i < target . getPointCount ( ) ; i ++ ) { if ( missing . contains ( target . getPoint ( i ) [ 0 ] , target . getPoint ( i ) [ 1 ] ) ) { count ++ ; } } if ( count == target . getPointCount ( ) ) { return new Shape [ 0 ] ; } if ( ! target . intersects ( missing ) ) { return new Shape [ ] { target } ; } int found = 0 ; for ( int i = 0 ; i < missing . getPointCount ( ) ; i ++ ) { if ( target . contains ( missing . getPoint ( i ) [ 0 ] , missing . getPoint ( i ) [ 1 ] ) ) { if ( ! onPath ( target , missing . getPoint ( i ) [ 0 ] , missing . getPoint ( i ) [ 1 ] ) ) { found ++ ; } } } for ( int i = 0 ; i < target . getPointCount ( ) ; i ++ ) { if ( missing . contains ( target . getPoint ( i ) [ 0 ] , target . getPoint ( i ) [ 1 ] ) ) { if ( ! onPath ( missing , target . getPoint ( i ) [ 0 ] , target . getPoint ( i ) [ 1 ] ) ) { found ++ ; } } } if ( found < 1 ) { return new Shape [ ] { target } ; } return combine ( target , missing , true ) ; }
Subtract one shape from another - note this is experimental and doesn t currently handle islands