public void h3js_67() { decimal east = (-56.25m).DegreesToRadians(); decimal north = (-33.13755119234615m).DegreesToRadians(); decimal south = (-34.30714385628804m).DegreesToRadians(); decimal west = (-57.65625m).DegreesToRadians(); var testVerts = new[] { new GeoCoord(north, east), new GeoCoord(south, east), new GeoCoord(south, west), new GeoCoord(north, west), }; var testGeoFence = new GeoFence { NumVerts = 4, Verts = testVerts }; var testPolygon = new GeoPolygon { GeoFence = testGeoFence, NumHoles = 0 }; const int res = 7; var hexagons = testPolygon.Polyfill(res); int actualNumHexagons = Utility.CountActualHexagons(hexagons); Assert.AreEqual(4499, actualNumHexagons); }
public void PolyfillTransmeridianComplex() { // This polygon is "complex" in that it has > 4 vertices - this // tests for a bug that was taking the max and min longitude as // the bounds for transmeridian polygons var verts = new[] { new GeoCoord(0.1m, -Constants.H3.M_PI + 0.00001m), new GeoCoord(0.1m, Constants.H3.M_PI - 0.00001m), new GeoCoord(0.05m, Constants.H3.M_PI - 0.2m), new GeoCoord(-0.1m, Constants.H3.M_PI - 0.00001m), new GeoCoord(-0.1m, -Constants.H3.M_PI + 0.00001m), new GeoCoord(-0.05m, -Constants.H3.M_PI + 0.2m), }; var geofence = new GeoFence { NumVerts = 6, Verts = verts }; var polygon = new GeoPolygon { GeoFence = geofence, NumHoles = 0 }; var hexagons = polygon.Polyfill(4); int actualNumHexagons = Utility.CountActualHexagons(hexagons); Assert.AreEqual(1204, actualNumHexagons); }
public void PolyfillExact() { var somewhere = new GeoCoord(1, 2); var origin = somewhere.ToH3Index(9); var boundary = origin.ToGeoBoundary(); var verts = new List <GeoCoord>(); verts.AddRange(boundary.Verts.Take(boundary.NumVerts)); verts.Add(boundary.Verts[0]); var someGeofence = new GeoFence { NumVerts = boundary.NumVerts + 1, Verts = verts.ToArray() }; var someHexagon = new GeoPolygon { GeoFence = someGeofence, NumHoles = 0 }; var hexagons = someHexagon.Polyfill(9); var actualNumHexagons = Utility.CountActualHexagons(hexagons); Assert.AreEqual(1, actualNumHexagons); }
public void PolyfillEmpty() { var hexagons = emptyGeoPolygon.Polyfill(9); var actualNumHexagons = Utility.CountActualHexagons(hexagons); Assert.AreEqual(0, actualNumHexagons); }
public void PolyfillHole() { var hexagons = holeGeoPolygon.Polyfill(9); int actualNumHexagons = Utility.CountActualHexagons(hexagons); Assert.AreEqual(1214, actualNumHexagons); }
// https://github.com/uber/h3-js/issues/76#issuecomment-561204505 public void entireWorld() { // TODO: Fails for a single worldwide polygon var worldVerts = new List <GeoCoord> { new GeoCoord(-Constants.H3.M_PI_2, -Constants.H3.M_PI), new GeoCoord(Constants.H3.M_PI_2, -Constants.H3.M_PI), new GeoCoord(Constants.H3.M_PI_2, 0), new GeoCoord(-Constants.H3.M_PI_2, 0), }; var worldGeofence = new GeoFence { NumVerts = 4, Verts = worldVerts.ToArray() }; var worldGeoPolygon = new GeoPolygon { GeoFence = worldGeofence, NumHoles = 0 }; var worldVerts2 = new List <GeoCoord> { new GeoCoord(-Constants.H3.M_PI_2, 0), new GeoCoord(Constants.H3.M_PI_2, 0), new GeoCoord(Constants.H3.M_PI_2, -Constants.H3.M_PI), new GeoCoord(-Constants.H3.M_PI_2, -Constants.H3.M_PI), }; var worldGeofence2 = new GeoFence { NumVerts = 4, Verts = worldVerts2.ToArray() }; var worldGeoPolygon2 = new GeoPolygon { GeoFence = worldGeofence2, NumHoles = 0 }; for (int res = 0; res < 3; res++) { var polyfillOut = worldGeoPolygon.Polyfill(res); var actualNumHexagons = Utility.CountActualHexagons(polyfillOut); var polyfillOut2 = worldGeoPolygon2.Polyfill(res); var actualNumHexagons2 = Utility.CountActualHexagons(polyfillOut2); Assert.AreEqual(res.NumHexagons(), actualNumHexagons + actualNumHexagons2); // Sets should be disjoint foreach (var fill1 in polyfillOut) { if (fill1 == 0) { continue; } bool found = polyfillOut2.Any(fill2 => fill1 == fill2); Assert.IsFalse(found); } polyfillOut.Clear(); polyfillOut2.Clear(); } }
private static void fillIndex_assertions(H3Index h) { if (IsTransmeridianCell(h)) { // TODO: these do not work correctly return; } int currentRes = h.Resolution; // TODO: Not testing more than one depth because the assertions fail. for (int nextRes = currentRes; nextRes <= currentRes + 1; nextRes++) { var boundary = h.ToGeoBoundary(); var polygon = new GeoPolygon() { GeoFence = new GeoFence { NumVerts = boundary.NumVerts, Verts = boundary.Verts.ToArray() }, NumHoles = 0, Holes = new List <GeoFence>() }; var polyfillOut = polygon.Polyfill(nextRes); int polyfillCount = Utility.CountActualHexagons(polyfillOut); var children = h.ToChildren(nextRes); int h3ToChildrenCount = Utility.CountActualHexagons(children); polyfillOut = polyfillOut.Where(p => p != Constants.H3Index.H3_NULL).ToList(); polyfillOut.Sort(); children = children.Where(p => p != Constants.H3Index.H3_NULL).ToList(); children.Sort(); Assert.AreEqual(h3ToChildrenCount, polyfillCount, $"h: {h}\nnextRes: {nextRes}\ncurrentRes: {currentRes}"); bool match = true; for (int i = 0; i < children.Count; i++) { if (children[i] != polyfillOut[i]) { match = false; } } Assert.IsTrue(match); } }
public void PolyfillPentagon() { H3Index pentagon = new H3Index(9, 24, 0); var coord = pentagon.ToGeoCoord(); // Length of half an edge of the polygon, in radians decimal edgeLength2 = (0.001m).DegreesToRadians(); var boundingTopRight = coord .SetLatitude(coord.Latitude + edgeLength2) .SetLongitude(coord.Longitude + edgeLength2); var boundingTopLeft = coord .SetLatitude(coord.Latitude + edgeLength2) .SetLongitude(coord.Longitude - edgeLength2); var boundingBottomRight = coord .SetLatitude(coord.Latitude - edgeLength2) .SetLongitude(coord.Longitude + edgeLength2); var boundingBottomLeft = coord .SetLatitude(coord.Latitude - edgeLength2) .SetLongitude(coord.Longitude - edgeLength2); var verts = new[] { boundingBottomLeft, boundingTopLeft, boundingTopRight, boundingBottomRight }; var geofence = new GeoFence { Verts = verts, NumVerts = 4 }; var polygon = new GeoPolygon { GeoFence = geofence, NumHoles = 0 }; var hexagons = polygon.Polyfill(9); Assert.AreEqual(1, hexagons.Count); Assert.IsTrue(hexagons.First().IsPentagon()); }
public void h3_136() { var testVerts = new[] { new GeoCoord(0.10068990369902957m, 0.8920772174196191m), new GeoCoord(0.10032914690616246m, 0.8915914753447348m), new GeoCoord(0.10033349237998787m, 0.8915860128746426m), new GeoCoord(0.10069496685903621m, 0.8920742194546231m) }; var testGeoFence = new GeoFence { NumVerts = 4, Verts = testVerts }; var testPolygon = new GeoPolygon { GeoFence = testGeoFence, NumHoles = 0 }; const int res = 13; var hexagons = testPolygon.Polyfill(res); int actualNumHexagons = Utility.CountActualHexagons(hexagons); Assert.AreEqual(4353, actualNumHexagons); }
private static void DoPolyFill(GeoPolygon polygon, int resolution) { var cells = polygon.Polyfill(resolution); cells.Clear(); }
public void PolyfillTransmeridian() { var primeMeridianVerts = new[] { new GeoCoord(0.01m, 0.01m), new GeoCoord(0.01m, -0.01m), new GeoCoord(-0.01m, -0.01m), new GeoCoord(-0.01m, 0.01m) }; var primeMeridianGeofence = new GeoFence { NumVerts = 4, Verts = primeMeridianVerts }; var primeMeridianGeoPolygon = new GeoPolygon { GeoFence = primeMeridianGeofence, NumHoles = 0 }; var transMeridianVerts = new[] { new GeoCoord(0.01m, -Constants.H3.M_PI + 0.01m), new GeoCoord(0.01m, Constants.H3.M_PI - 0.01m), new GeoCoord(-0.01m, Constants.H3.M_PI - 0.01m), new GeoCoord(-0.01m, -Constants.H3.M_PI + 0.01m), }; var transMeridianGeofence = new GeoFence { NumVerts = 4, Verts = transMeridianVerts }; var transMeridianGeoPolygon = new GeoPolygon { GeoFence = transMeridianGeofence, NumHoles = 0 }; var transMeridianHoleVerts = new[] { new GeoCoord(0.005m, -Constants.H3.M_PI + 0.005m), new GeoCoord(0.005m, Constants.H3.M_PI - 0.005m), new GeoCoord(-0.005m, Constants.H3.M_PI - 0.005m), new GeoCoord(-0.005m, -Constants.H3.M_PI + 0.005m), }; var transMeridianHoleGeofence = new GeoFence { NumVerts = 4, Verts = transMeridianHoleVerts }; var transMeridianHoleGeoPolygon = new GeoPolygon { GeoFence = transMeridianGeofence, NumHoles = 1, Holes = new List <GeoFence> { transMeridianHoleGeofence } }; var transMeridianFilledHoleGeoPolygon = new GeoPolygon { GeoFence = transMeridianHoleGeofence, NumHoles = 0 }; int expectedSize = 4228; var hexagons = primeMeridianGeoPolygon.Polyfill(7); int actualNumHexagons = Utility.CountActualHexagons(hexagons); Assert.AreEqual(expectedSize, actualNumHexagons); // Transmeridian case // This doesn't exactly match the prime meridian count because of slight // differences in hex size and grid offset between the two cases expectedSize = 4238; var hexagonsTM = transMeridianGeoPolygon.Polyfill(7); actualNumHexagons = Utility.CountActualHexagons(hexagonsTM); Assert.AreEqual(expectedSize, actualNumHexagons); // Transmeridian filled hole case -- only needed for calculating hole size var hexagonsTMFH = transMeridianFilledHoleGeoPolygon.Polyfill(7); var actualNumHoleHexagons = Utility.CountActualHexagons(hexagonsTMFH); // Transmeridian hole case var hexagonsTMH = transMeridianHoleGeoPolygon.Polyfill(7); actualNumHexagons = Utility.CountActualHexagons(hexagonsTMH); Assert.AreEqual(expectedSize - actualNumHoleHexagons, actualNumHexagons); }