private Shape [ ] combine ( Shape target , Shape other , boolean subtract ) { if ( subtract ) { ArrayList shapes = new ArrayList ( ) ; ArrayList used = new ArrayList ( ) ; // remove any points that are contianed in the shape we're removing, these // are implicitly used for ( int i = 0 ; i < target . getPointCount ( ) ; i ++ ) { float [ ] point = target . getPoint ( i ) ; if ( other . contains ( point [ 0 ] , point [ 1 ] ) ) { used . add ( new Vector2f ( point [ 0 ] , point [ 1 ] ) ) ; if ( listener != null ) { listener . pointExcluded ( point [ 0 ] , point [ 1 ] ) ; } } } for ( int i = 0 ; i < target . getPointCount ( ) ; i ++ ) { float [ ] point = target . getPoint ( i ) ; Vector2f pt = new Vector2f ( point [ 0 ] , point [ 1 ] ) ; if ( ! used . contains ( pt ) ) { Shape result = combineSingle ( target , other , true , i ) ; shapes . add ( result ) ; for ( int j = 0 ; j < result . getPointCount ( ) ; j ++ ) { float [ ] kpoint = result . getPoint ( j ) ; Vector2f kpt = new Vector2f ( kpoint [ 0 ] , kpoint [ 1 ] ) ; used . add ( kpt ) ; } } } return ( Shape [ ] ) shapes . toArray ( new Shape [ 0 ] ) ; } else { for ( int i = 0 ; i < target . getPointCount ( ) ; i ++ ) { if ( ! other . contains ( target . getPoint ( i ) [ 0 ] , target . getPoint ( i ) [ 1 ] ) ) { if ( ! other . hasVertex ( target . getPoint ( i ) [ 0 ] , target . getPoint ( i ) [ 1 ] ) ) { Shape shape = combineSingle ( target , other , false , i ) ; return new Shape [ ] { shape } ; } } } return new Shape [ ] { other } ; } }
Perform the combination