public void SignedAreaTest() { // arrange // create a closed polygon (first point is the same as the last) var points = new List <Coordinate>(); points.Add(new Coordinate() { X = 1, Y = 1 }); points.Add(new Coordinate() { X = 2, Y = 2 }); points.Add(new Coordinate() { X = 3, Y = 1 }); points.Add(new Coordinate() { X = 1, Y = 1 }); var polygon = new VTPolygon(points); // act var area = polygon.SignedArea(); // assert // polygon is defined clock-wise so area should be negative Assert.IsTrue(area == -1); }
public void TestCCWPolygon() { var coords = TestData.GetCCWPolygon(1); var poly = new VTPolygon(coords); // act var ccw = poly.IsCCW(); // assert Assert.IsTrue(poly.SignedArea() > 0); Assert.IsTrue(ccw); }
// docs for inner/outer rings https://www.mapbox.com/vector-tiles/specification/ public static List<List<List<Coordinate>>> Classify(List<List<Coordinate>> rings) { var polygons = new List<List<List<Coordinate>>>(); List<List<Coordinate>> newpoly = null; foreach (var ring in rings) { var poly = new VTPolygon(ring); if (poly.IsOuterRing()) { newpoly = new List<List<Coordinate>>() { ring }; polygons.Add(newpoly); } else { if (newpoly != null) { newpoly.Add(ring); } } } return polygons; }