public Shape prune ( ) { Polygon result = new Polygon ( ) ; for ( int i = 0 ; i < getPointCount ( ) ; i ++ ) { int next = i + 1 >= getPointCount ( ) ? 0 : i + 1 ; int prev = i - 1 < 0 ? getPointCount ( ) - 1 : i - 1 ; float dx1 = getPoint ( i ) [ 0 ] - getPoint ( prev ) [ 0 ] ; float dy1 = getPoint ( i ) [ 1 ] - getPoint ( prev ) [ 1 ] ; float dx2 = getPoint ( next ) [ 0 ] - getPoint ( i ) [ 0 ] ; float dy2 = getPoint ( next ) [ 1 ] - getPoint ( i ) [ 1 ] ; float len1 = ( float ) Math . sqrt ( ( dx1 * dx1 ) + ( dy1 * dy1 ) ) ; float len2 = ( float ) Math . sqrt ( ( dx2 * dx2 ) + ( dy2 * dy2 ) ) ; dx1 /= len1 ; dy1 /= len1 ; dx2 /= len2 ; dy2 /= len2 ; if ( ( dx1 != dx2 ) || ( dy1 != dy2 ) ) { result . addPoint ( getPoint ( i ) [ 0 ] , getPoint ( i ) [ 1 ] ) ; } } return result ; }
Prune any required points in this shape