return a polygon for the waypoints
198331
def polygon(self, done=None):
        ''''''
        indexes = self.view_indexes(done)
        points = []
        for idx in indexes:
            w = self.wp(idx)
            points.append((w.x, w.y))
        return points
1255609
def draw_polygon(
            self,
            *pts,
            close_path=True,
            stroke=None,
            stroke_width=1,
            stroke_dash=None,
            fill=None
            ) -> None:
        """"""
        c = self.c
        c.save()
        c.new_path()
        for x,y in zip(*[iter(pts)]*2):
            c.line_to(x, y)
        if close_path:
            c.close_path()
        self._fill_and_stroke(stroke, stroke_width, stroke_dash, fill)
        c.restore()
97952
def get_shapely(self):
        
        if self.shapely == None:
            from shapely.geometry import Polygon as shPolygon
            self.shapely = shPolygon(self.points[:, :2]) # z=0 projection!
        return self.shapely
843351
function polygonAt(polygon, i){
    var s = polygon.length;
    return polygon[i < 0 ? i % s + s : i % s];
}
1176524
def draw_polygon(
            self,
            *pts,
            close_path:bool=True,
            stroke:Color=None,
            stroke_width:float=1,
            stroke_dash:typing.Sequence=None,
            fill:Color=None
            ) -> None:
        """"""
        pass
807590
def to_polygon(self):
        
        x,y = self.corners.T
        vertices = PixCoord(x=x, y=y)
        return PolygonPixelRegion(vertices=vertices, meta=self.meta,
                                  visual=self.visual)
429836
def to_s
      result = "Waypoint \n"
      result << "\tName: #{name}\n"
      result << "\tLatitude: #{lat} \n"
      result << "\tLongitude: #{lon} \n"
      result << "\tElevation: #{elevation}\n "
      result << "\tTime: #{time}\n"
      SUB_ELEMENTS.each do |sub_element_attribute|
        val = send(sub_element_attribute)
        result << "\t#{sub_element_attribute}: #{val}\n" unless val.nil?
      end
      result
    end
311785
def path_valid(self):
        
        valid = [i is not None for i in self.polygons_closed]
        valid = np.array(valid, dtype=np.bool)
        return valid
435907
public static Polygon getTilePolygon (
        MisoSceneMetrics metrics, int x, int y)
    {
        return getFootprintPolygon(metrics, x, y, 1, 1);
    }
303177
function(orthobasis) {
            var EPS = 1e-5;
            var cags = [];
            this.polygons.filter(function(p) {
                    // only return polys in plane, others may disturb result
                    return p.plane.normal.minus(orthobasis.plane.normal).lengthSquared() < EPS*EPS;
                })
                .map(function(polygon) {
                    var cag = polygon.projectToOrthoNormalBasis(orthobasis);
                    if (cag.sides.length > 0) {
                        cags.push(cag);
                    }
            });
            var result = new CAG().union(cags);
            return result;
        }
883408
def distancePointToPolygon(point, polygon, perpendicular=False):
    """"""
    p = point
    s = polygon
    minDist = None
    for i in range(0, len(s) - 1):
        dist = distancePointToLine(p, s[i], s[i + 1], perpendicular)
        if dist == INVALID_DISTANCE and perpendicular and i != 0:
            # distance to inner corner
            dist = distance(point, s[i])
        if dist != INVALID_DISTANCE:
            if minDist is None or dist < minDist:
                minDist = dist
    if minDist is not None:
        return minDist
    else:
        return INVALID_DISTANCE
1233998
def geojson(self, feature_id):
        """"""
        lat, lon = self.lat_lon
        return {
            'type': 'Feature',
            'id': feature_id,
            'geometry': {
                'type': 'Point',
                'coordinates': (lon, lat),
            },
        }
1374966
def get_catalogue_bounding_polygon(catalogue):
    '''
    
    '''
    upper_lon = np.max(catalogue.data['longitude'])
    upper_lat = np.max(catalogue.data['latitude'])
    lower_lon = np.min(catalogue.data['longitude'])
    lower_lat = np.min(catalogue.data['latitude'])

    return Polygon([Point(lower_lon, upper_lat), Point(upper_lon, upper_lat),
                    Point(upper_lon, lower_lat), Point(lower_lon, lower_lat)])
1324338
def grid_coords_from_corners(upper_left_corner, lower_right_corner, size):
    '''  '''
    assert upper_left_corner.wkt == lower_right_corner.wkt
    geotransform = np.array([upper_left_corner.lon, -(upper_left_corner.lon - lower_right_corner.lon) / float(size[1]), 0,
                            upper_left_corner.lat, 0, -(upper_left_corner.lat - lower_right_corner.lat) / float(size[0])])
    return GridCoordinates(geotransform=geotransform,
                               wkt=upper_left_corner.wkt,
                               y_size=size[0],
                               x_size=size[1])
72645
public static List<WayDataBlock> toWayDataBlockList(Geometry geometry) {
        List<WayDataBlock> res = new ArrayList<>();
        if (geometry instanceof MultiPolygon) {
            MultiPolygon mp = (MultiPolygon) geometry;
            for (int i = 0; i < mp.getNumGeometries(); i++) {
                Polygon p = (Polygon) mp.getGeometryN(i);
                List<Integer> outer = toCoordinateList(p.getExteriorRing());
                if (outer.size() / 2 > 0) {
                    List<List<Integer>> inner = new ArrayList<>();
                    for (int j = 0; j < p.getNumInteriorRing(); j++) {
                        List<Integer> innr = toCoordinateList(p.getInteriorRingN(j));
                        if (innr.size() / 2 > 0) {
                            inner.add(innr);
                        }
                    }
                    res.add(new WayDataBlock(outer, inner));
                }
            }
        } else if (geometry instanceof Polygon) {
            Polygon p = (Polygon) geometry;
            List<Integer> outer = toCoordinateList(p.getExteriorRing());
            if (outer.size() / 2 > 0) {
                List<List<Integer>> inner = new ArrayList<>();
                for (int i = 0; i < p.getNumInteriorRing(); i++) {
                    List<Integer> innr = toCoordinateList(p.getInteriorRingN(i));
                    if (innr.size() / 2 > 0) {
                        inner.add(innr);
                    }
                }
                res.add(new WayDataBlock(outer, inner));
            }
        } else if (geometry instanceof MultiLineString) {
            MultiLineString ml = (MultiLineString) geometry;
            for (int i = 0; i < ml.getNumGeometries(); i++) {
                LineString l = (LineString) ml.getGeometryN(i);
                List<Integer> outer = toCoordinateList(l);
                if (outer.size() / 2 > 0) {
                    res.add(new WayDataBlock(outer, null));
                }
            }
        } else if (geometry instanceof LinearRing || geometry instanceof LineString) {
            List<Integer> outer = toCoordinateList(geometry);
            if (outer.size() / 2 > 0) {
                res.add(new WayDataBlock(outer, null));
            }
        } else if (geometry instanceof GeometryCollection) {
            GeometryCollection gc = (GeometryCollection) geometry;
            for (int i = 0; i < gc.getNumGeometries(); i++) {
                List<WayDataBlock> recursiveResult = toWayDataBlockList(gc.getGeometryN(i));
                for (WayDataBlock wayDataBlock : recursiveResult) {
                    List<Integer> outer = wayDataBlock.getOuterWay();
                    if (outer.size() / 2 > 0) {
                        res.add(wayDataBlock);
                    }
                }
            }
        }

        return res;
    }
671118
def polygon_generator(data, scale, style, permutation=None):
    """"""

    # We'll project the coordinates inside this function to prevent
    # passing around permutation more than necessary
    project = functools.partial(project_point, permutation=permutation)

    if isinstance(data, dict):
        data_gen = data.items()
    else:
        # Only works with style == 'h'
        data_gen = data

    for key, value in data_gen:
        if value is None:
            continue
        i = key[0]
        j = key[1]
        k = scale - i - j
        if style == 'h':
            vertices = hexagon_coordinates(i, j, k)
            yield (map(project, vertices), value)
        elif style == 'd':
            # Upright triangles
            if (i <= scale) and (j <= scale) and (k >= 0):
                vertices = triangle_coordinates(i, j, k)
                yield (map(project, vertices), value)
            # Upside-down triangles
            if (i < scale) and (j < scale) and (k >= 1):
                vertices = alt_triangle_coordinates(i, j, k)
                value = blend_value(data, i, j, k)
                yield (map(project, vertices), value)
        elif style == 't':
            # Upright triangles
            if (i < scale) and (j < scale) and (k > 0):
                vertices = triangle_coordinates(i, j, k)
                value = blend_value(data, i, j, k)
                yield (map(project, vertices), value)
            # If not on the boundary add the upside-down triangle
            if (i < scale) and (j < scale) and (k > 1):
                vertices = alt_triangle_coordinates(i, j, k)
                value = alt_blend_value(data, i, j, k)
                yield (map(project, vertices), value)
936262
function polygonMakeCCW(polygon){
    var br = 0,
        v = polygon;

    // find bottom right point
    for (var i = 1; i < polygon.length; ++i) {
        if (v[i][1] < v[br][1] || (v[i][1] === v[br][1] && v[i][0] > v[br][0])) {
            br = i;
        }
    }

    // reverse poly if clockwise
    if (!isLeft(polygonAt(polygon, br - 1), polygonAt(polygon, br), polygonAt(polygon, br + 1))) {
        polygonReverse(polygon);
        return true;
    } else {
        return false;
    }
}