splitToIslands() {
        let polygons = this.toArray();      // split into array of one-loop polygons
        /* Sort polygons by area in descending order */
        polygons.sort((polygon1, polygon2) => polygon2.area() - polygon1.area());
        /* define orientation of the island by orientation of the first polygon in array */
        let orientation = [...polygons[0].faces][0].orientation();
        /* Create output array from polygons with same orientation as a first polygon (array of islands) */
        let newPolygons = polygons.filter(polygon => [...polygon.faces][0].orientation() === orientation);
        for (let polygon of polygons) {
            let face = [...polygon.faces][0];
            if (face.orientation() === orientation) continue;  // skip same orientation
            /* Proceed with opposite orientation */
            /* Look if any of island polygons contains tested polygon as a hole */
            for (let islandPolygon of newPolygons) {
                if (face.shapes.every(shape => islandPolygon.contains(shape))) {
                    islandPolygon.addFace(face.shapes);      // add polygon as a hole in islandPolygon
                    break;
                }
            }
        }
        // TODO: assert if not all polygons added into output
        return newPolygons;
    }
/**
     * Split polygon into array of polygons, where each polygon is an island with all
     * hole that it contains
     * @returns {Flatten.Polygon[]}
     */
Split polygon into array of polygons, where each polygon is an island with all
hole that it contains
@returns {Flatten.Polygon[]}
Split polygon into array of polygons where each polygon is an island with all hole that it contains @returns { Flatten . Polygon [] }
splitToIslands() {
        let polygons = this.toArray();      
        polygons.sort((polygon1, polygon2) => polygon2.area() - polygon1.area());
        let orientation = [...polygons[0].faces][0].orientation();
        let newPolygons = polygons.filter(polygon => [...polygon.faces][0].orientation() === orientation);
        for (let polygon of polygons) {
            let face = [...polygon.faces][0];
            if (face.orientation() === orientation) continue;  
            for (let islandPolygon of newPolygons) {
                if (face.shapes.every(shape => islandPolygon.contains(shape))) {
                    islandPolygon.addFace(face.shapes);      
                    break;
                }
            }
        }
        return newPolygons;
    }
splitToIslands ( ) { let polygons = this . toArray ( ) ; polygons . sort ( ( polygon1 , polygon2 ) => polygon2 . area ( ) - polygon1 . area ( ) ) ; let orientation = [ ... polygons [ 0 ] . faces ] [ 0 ] . orientation ( ) ; let newPolygons = polygons . filter ( polygon => [ ... polygon . faces ] [ 0 ] . orientation ( ) === orientation ) ; for ( let polygon of polygons ) { let face = [ ... polygon . faces ] [ 0 ] ; if ( face . orientation ( ) === orientation ) continue ; for ( let islandPolygon of newPolygons ) { if ( face . shapes . every ( shape => islandPolygon . contains ( shape ) ) ) { islandPolygon . addFace ( face . shapes ) ; break ; } } } return newPolygons ; }
Split polygon into array of polygons, where each polygon is an island with all
 hole that it contains
 @returns {Flatten.Polygon[]}
Split polygon into array of polygons where each polygon is an island with all hole that it contains @returns { Flatten . Polygon [] }
// split into array of one-loop polygons /* Sort polygons by area in descending order */ /* define orientation of the island by orientation of the first polygon in array */ /* Create output array from polygons with same orientation as a first polygon (array of islands) */ // skip same orientation /* Proceed with opposite orientation */ /* Look if any of island polygons contains tested polygon as a hole */ // add polygon as a hole in islandPolygon // TODO: assert if not all polygons added into output