public void normalizeMultiPolygonTwoHoles() { List <GeoCoord> verts = new List <GeoCoord> { new GeoCoord(0, 0), new GeoCoord(0, 0.4), new GeoCoord(0.4, 0.4), new GeoCoord(0.4, 0) }; LinkedGeo.LinkedGeoLoop outer = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(outer); createLinkedLoop(ref outer, verts, 4); List <GeoCoord> verts2 = new List <GeoCoord> { new GeoCoord(0.1, 0.1), new GeoCoord(0.2, 0.2), new GeoCoord(0.1, 0.2) }; LinkedGeo.LinkedGeoLoop inner1 = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(inner1); createLinkedLoop(ref inner1, verts2, 3); List <GeoCoord> verts3 = new List <GeoCoord> { new GeoCoord(0.2, 0.2), new GeoCoord(0.3, 0.3), new GeoCoord(0.2, 0.3) }; LinkedGeo.LinkedGeoLoop inner2 = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(inner2); createLinkedLoop(ref inner2, verts3, 3); LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon(); LinkedGeo.addLinkedLoop(ref polygon, ref inner2); LinkedGeo.addLinkedLoop(ref polygon, ref outer); LinkedGeo.addLinkedLoop(ref polygon, ref inner1); int result = LinkedGeo.normalizeMultiPolygon(ref polygon); Assert.True(result == LinkedGeo.NORMALIZATION_SUCCESS, "No error code returned"); Assert.True ( LinkedGeo.countLinkedPolygons(ref polygon) == 1, "Polygon count correct for 2 holes" ); Assert.True(polygon.first == outer, "Got expected outer loop"); Assert.True ( LinkedGeo.countLinkedLoops(ref polygon) == 3, "Loop count on first polygon correct" ); }
public void normalizeMultiPolygonSingle() { List <GeoCoord> verts = new List <GeoCoord> { new GeoCoord(0, 0), new GeoCoord(0, 1), new GeoCoord(1, 1) }; LinkedGeo.LinkedGeoLoop outer = new LinkedGeo.LinkedGeoLoop(); Assert.True(outer != null); createLinkedLoop(ref outer, verts, 3); LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon(); LinkedGeo.addLinkedLoop(ref polygon, ref outer); int result = LinkedGeo.normalizeMultiPolygon(ref polygon); Assert.True(result == LinkedGeo.NORMALIZATION_SUCCESS, "No error code returned"); Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 1, "Polygon count correct"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 1, "Loop count correct"); Assert.True(polygon.first == outer, "Got expected loop"); }
public void nestedDonut() { LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon(); // hollow 1-ring + hollow 3-ring around the same hex List <H3Index> set = new List <H3Index> { 0x89283082813ffff, 0x8928308281bffff, 0x8928308280bffff, 0x8928308280fffff, 0x89283082807ffff, 0x89283082817ffff, 0x8928308289bffff, 0x892830828d7ffff, 0x892830828c3ffff, 0x892830828cbffff, 0x89283082853ffff, 0x89283082843ffff, 0x8928308284fffff, 0x8928308287bffff, 0x89283082863ffff, 0x89283082867ffff, 0x8928308282bffff, 0x89283082823ffff, 0x89283082837ffff, 0x892830828afffff, 0x892830828a3ffff, 0x892830828b3ffff, 0x89283082887ffff, 0x89283082883ffff }; int numHexes = set.Count; Algos.h3SetToLinkedGeo(ref set, numHexes, ref polygon); // Note that the polygon order here is arbitrary, making this test // somewhat brittle, but it's difficult to assert correctness otherwise Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 2, "Polygon count correct"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 2, "Loop count on first polygon correct"); // Brittleness comes from hashing into buckets, so let's cover both bases. if (LinkedGeo.countLinkedCoords(ref polygon.first) == 42) { Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first) == 42, "Got expected big outer loop"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first.next) == 30, "Got expected big inner loop"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon.next) == 2, "Loop count on second polygon correct"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first) == 18, "Got expected outer loop"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first.next) == 6, "Got expected inner loop"); } else { Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first) == 18, "Got expected big outer loop"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first.next) == 6, "Got expected big inner loop"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon.next) == 2, "Loop count on second polygon correct"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first) == 42, "Got expected outer loop"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first.next) == 30, "Got expected inner loop"); } LinkedGeo.destroyLinkedPolygon(ref polygon); }
public void normalizeMultiPolygonNoOuterLoops() { GeoCoord[] verts1 = { new GeoCoord(0, 0), new GeoCoord(1, 1), new GeoCoord(0, 1) }; LinkedGeo.LinkedGeoLoop outer1 = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(outer1); createLinkedLoop(ref outer1, verts1.ToList(), 3); GeoCoord[] verts2 = { new GeoCoord(2, 2), new GeoCoord(3, 3), new GeoCoord(2, 3) }; LinkedGeo.LinkedGeoLoop outer2 = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(outer2); createLinkedLoop(ref outer2, verts2.ToList(), 3); LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon(); LinkedGeo.addLinkedLoop(ref polygon, ref outer1); LinkedGeo.addLinkedLoop(ref polygon, ref outer2); int result = LinkedGeo.normalizeMultiPolygon(ref polygon); Assert.True ( result == LinkedGeo.NORMALIZATION_ERR_UNASSIGNED_HOLES, "Expected error code returned" ); Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 1, "Polygon count correct"); Assert.True ( LinkedGeo.countLinkedLoops(ref polygon) == 0, "Loop count as expected with invalid input" ); }
public void normalizeMultiPolygonAlreadyNormalized() { GeoCoord[] verts1 = { new GeoCoord(0, 0), new GeoCoord(0, 1), new GeoCoord(1, 1) }; LinkedGeo.LinkedGeoLoop outer1 = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(outer1); createLinkedLoop(ref outer1, verts1.ToList(), 3); GeoCoord[] verts2 = { new GeoCoord(2, 2), new GeoCoord(2, 3), new GeoCoord(3, 3) }; LinkedGeo.LinkedGeoLoop outer2 = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(outer2); createLinkedLoop(ref outer2, verts2.ToList(), 3); LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon(); LinkedGeo.addLinkedLoop(ref polygon, ref outer1); LinkedGeo.LinkedGeoPolygon next = LinkedGeo.addNewLinkedPolygon(ref polygon); LinkedGeo.addLinkedLoop(ref next, ref outer2); // Should be a no-op int result = LinkedGeo.normalizeMultiPolygon(ref polygon); Assert.True(result == LinkedGeo.NORMALIZATION_ERR_MULTIPLE_POLYGONS, "Expected error code returned"); Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 2, "Polygon count correct"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 1, "Loop count on first polygon correct"); Assert.True(polygon.first == outer1, "Got expected outer loop"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon.next) == 1, "Loop count on second polygon correct"); Assert.True(polygon.next.first == outer2, "Got expected outer loop"); }
public void normalizeMultiPolygonTwoOuterLoops() { List <GeoCoord> verts1 = new List <GeoCoord> { new GeoCoord(0, 0), new GeoCoord(0, 1), new GeoCoord(1, 1) }; LinkedGeo.LinkedGeoLoop outer1 = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(outer1); createLinkedLoop(ref outer1, verts1, 3); List <GeoCoord> verts2 = new List <GeoCoord> { new GeoCoord(2, 2), new GeoCoord(2, 3), new GeoCoord(3, 3) }; LinkedGeo.LinkedGeoLoop outer2 = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(outer2); createLinkedLoop(ref outer2, verts2, 3); LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon(); LinkedGeo.addLinkedLoop(ref polygon, ref outer1); LinkedGeo.addLinkedLoop(ref polygon, ref outer2); int result = LinkedGeo.normalizeMultiPolygon(ref polygon); Assert.True(result == LinkedGeo.NORMALIZATION_SUCCESS, "No error code returned"); Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 2, "Polygon count correct"); Assert.True ( LinkedGeo.countLinkedLoops(ref polygon) == 1, "Loop count on first polygon correct" ); Assert.True ( LinkedGeo.countLinkedLoops(ref polygon.next) == 1, "Loop count on second polygon correct" ); }
public void nonContiguous2() { LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon(); List <H3Index> set = new List <H3Index> { 0x8928308291bffff, 0x89283082943ffff }; int numHexes = set.Count; Algos.h3SetToLinkedGeo(ref set, numHexes, ref polygon); Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 2, "2 polygons added"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 1, "1 loop on the first polygon"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first) == 6, "All coords for one hex added to first loop"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon.next) == 1, "Loop count on second polygon correct"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first) == 6, "All coords for one hex added to second polygon"); LinkedGeo.destroyLinkedPolygon(ref polygon); }
public void normalizeMultiPolygonOneHole() { List <GeoCoord> verts = new List <GeoCoord> { new GeoCoord(0, 0), new GeoCoord(0, 3), new GeoCoord(3, 3), new GeoCoord(3, 0) }; LinkedGeo.LinkedGeoLoop outer = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(outer); createLinkedLoop(ref outer, verts, 4); List <GeoCoord> verts2 = new List <GeoCoord> { new GeoCoord(1, 1), new GeoCoord(2, 2), new GeoCoord(1, 2) }; LinkedGeo.LinkedGeoLoop inner = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(inner); createLinkedLoop(ref inner, verts2, 3); LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon(); LinkedGeo.addLinkedLoop(ref polygon, ref inner); LinkedGeo.addLinkedLoop(ref polygon, ref outer); int result = LinkedGeo.normalizeMultiPolygon(ref polygon); Assert.True(result == LinkedGeo.NORMALIZATION_SUCCESS, "No error code returned"); Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 1, "Polygon count correct"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 2, "Loop count on first polygon correct"); Assert.True(polygon.first == outer, "Got expected outer loop"); Assert.True(polygon.first.next == inner, "Got expected inner loop"); }
public void createLinkedGeo() { LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon(); LinkedGeo.LinkedGeoLoop loop = new LinkedGeo.LinkedGeoLoop(); LinkedGeo.LinkedGeoCoord coord = new LinkedGeo.LinkedGeoCoord(); loop = LinkedGeo.addNewLinkedLoop(ref polygon); Assert.True(loop != null, "Loop created"); coord = LinkedGeo.addLinkedCoord(ref loop, ref vertex1); Assert.True(coord != null, "Coord created"); coord = LinkedGeo.addLinkedCoord(ref loop, ref vertex2); Assert.True(coord != null, "Coord created"); coord = LinkedGeo.addLinkedCoord(ref loop, ref vertex3); Assert.True(coord != null, "Coord created"); loop = LinkedGeo.addNewLinkedLoop(ref polygon); Assert.True(loop != null, "Loop createed"); coord = LinkedGeo.addLinkedCoord(ref loop, ref vertex2); Assert.True(coord != null, "Coord created"); coord = LinkedGeo.addLinkedCoord(ref loop, ref vertex4); Assert.True(coord != null, "Coord created"); Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 1, "Polygon count correct"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 2, "Loop count correct"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first) == 3, "Coord count 1 correct"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.last) == 2, "Coord count 2 correct"); LinkedGeo.LinkedGeoPolygon nextPolygon = LinkedGeo.addNewLinkedPolygon(ref polygon); Assert.True(nextPolygon != null, "polygon created"); Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 2, "Polygon count correct"); LinkedGeo.destroyLinkedPolygon(ref polygon); polygon = null; }
public void nestedDonutTransmeridian() { LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon(); // hollow 1-ring + hollow 3-ring around the hex at (0, -180) List <H3Index> set = new List <H3Index> { 0x897eb5722c7ffff, 0x897eb5722cfffff, 0x897eb572257ffff, 0x897eb57220bffff, 0x897eb572203ffff, 0x897eb572213ffff, 0x897eb57266fffff, 0x897eb5722d3ffff, 0x897eb5722dbffff, 0x897eb573537ffff, 0x897eb573527ffff, 0x897eb57225bffff, 0x897eb57224bffff, 0x897eb57224fffff, 0x897eb57227bffff, 0x897eb572263ffff, 0x897eb572277ffff, 0x897eb57223bffff, 0x897eb572233ffff, 0x897eb5722abffff, 0x897eb5722bbffff, 0x897eb572287ffff, 0x897eb572283ffff, 0x897eb57229bffff }; int numHexes = set.Count; Algos.h3SetToLinkedGeo(ref set, numHexes, ref polygon); // Note that the polygon order here is arbitrary, making this test // somewhat brittle, but it's difficult to assert correctness otherwise Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 2, "Polygon count correct"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 2, "Loop count on first polygon correct"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first) == 18, "Got expected outer loop"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.first.next) == 6, "Got expected inner loop"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon.next) == 2, "Loop count on second polygon correct"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first) == 42, "Got expected big outer loop"); Assert.True(LinkedGeo.countLinkedCoords(ref polygon.next.first.next) == 30, "Got expected big inner loop"); LinkedGeo.destroyLinkedPolygon(ref polygon); }
public void normalizeMultiPolygonNestedDonuts() { GeoCoord[] verts = { new GeoCoord(0.2, 0.2), new GeoCoord(0.2, -0.2), new GeoCoord(-0.2, -0.2), new GeoCoord(-0.2, 0.2) }; LinkedGeo.LinkedGeoLoop outer = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(outer); createLinkedLoop(ref outer, verts.ToList(), 4); GeoCoord[] verts2 = { new GeoCoord(0.1, 0.1), new GeoCoord(-0.1, 0.1), new GeoCoord(-0.1, -0.1), new GeoCoord(0.1, -0.1) }; LinkedGeo.LinkedGeoLoop inner = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(inner); createLinkedLoop(ref inner, verts2.ToList(), 4); GeoCoord[] verts3 = { new GeoCoord(0.6, 0.6), new GeoCoord(0.6, -0.6), new GeoCoord(-0.6, -0.6), new GeoCoord(-0.6, 0.6) }; LinkedGeo.LinkedGeoLoop outerBig = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(outerBig); createLinkedLoop(ref outerBig, verts3.ToList(), 4); GeoCoord[] verts4 = { new GeoCoord(0.5, 0.5), new GeoCoord(-0.5, 0.5), new GeoCoord(-0.5, -0.5), new GeoCoord(0.5, -0.5) }; LinkedGeo.LinkedGeoLoop innerBig = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(innerBig); createLinkedLoop(ref innerBig, verts4.ToList(), 4); LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon(); LinkedGeo.addLinkedLoop(ref polygon, ref inner); LinkedGeo.addLinkedLoop(ref polygon, ref outerBig); LinkedGeo.addLinkedLoop(ref polygon, ref innerBig); LinkedGeo.addLinkedLoop(ref polygon, ref outer); int result = LinkedGeo.normalizeMultiPolygon(ref polygon); Assert.True(result == LinkedGeo.NORMALIZATION_SUCCESS, "No error code returned"); Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 2, "Polygon count correct"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon) == 2, "Loop count on first polygon correct"); Assert.True(polygon.first == outerBig, "Got expected outer loop"); Assert.True(polygon.first.next == innerBig, "Got expected inner loop"); Assert.True(LinkedGeo.countLinkedLoops(ref polygon.next) == 2, "Loop count on second polygon correct"); Assert.True(polygon.next.first == outer, "Got expected outer loop"); Assert.True(polygon.next.first.next == inner, "Got expected inner loop"); }
public void normalizeMultiPolygonTwoDonuts() { GeoCoord[] verts = { new GeoCoord(0, 0), new GeoCoord(0, 3), new GeoCoord(3, 3), new GeoCoord(3, 0) }; LinkedGeo.LinkedGeoLoop outer = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(outer); createLinkedLoop(ref outer, verts.ToList(), 4); GeoCoord[] verts2 = { new GeoCoord(1, 1), new GeoCoord(2, 2), new GeoCoord(1, 2) }; LinkedGeo.LinkedGeoLoop inner = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(inner); createLinkedLoop(ref inner, verts2.ToList(), 3); GeoCoord[] verts3 = { new GeoCoord(0, 0), new GeoCoord(0, -3), new GeoCoord(-3, -3), new GeoCoord(-3, 0) }; LinkedGeo.LinkedGeoLoop outer2 = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(outer2); createLinkedLoop(ref outer2, verts3.ToList(), 4); GeoCoord[] verts4 = { new GeoCoord(-1, -1), new GeoCoord(-2, -2), new GeoCoord(-1, -2) }; LinkedGeo.LinkedGeoLoop inner2 = new LinkedGeo.LinkedGeoLoop(); Assert.NotNull(inner2); createLinkedLoop(ref inner2, verts4.ToList(), 3); LinkedGeo.LinkedGeoPolygon polygon = new LinkedGeo.LinkedGeoPolygon(); LinkedGeo.addLinkedLoop(ref polygon, ref inner2); LinkedGeo.addLinkedLoop(ref polygon, ref inner); LinkedGeo.addLinkedLoop(ref polygon, ref outer); LinkedGeo.addLinkedLoop(ref polygon, ref outer2); int result = LinkedGeo.normalizeMultiPolygon(ref polygon); Assert.True(result == LinkedGeo.NORMALIZATION_SUCCESS, "No error code returned"); Assert.True(LinkedGeo.countLinkedPolygons(ref polygon) == 2, "Polygon count correct"); Assert.True ( LinkedGeo.countLinkedLoops(ref polygon) == 2, "Loop count on first polygon correct" ); Assert.True ( LinkedGeo.countLinkedCoords(ref polygon.first) == 4, "Got expected outer loop" ); Assert.True ( LinkedGeo.countLinkedCoords(ref polygon.first.next) == 3, "Got expected inner loop" ); Assert.True ( LinkedGeo.countLinkedLoops(ref polygon.next) == 2, "Loop count on second polygon correct" ); Assert.True ( LinkedGeo.countLinkedCoords(ref polygon.next.first) == 4, "Got expected outer loop" ); Assert.True ( LinkedGeo.countLinkedCoords(ref polygon.next.first.next) == 3, "Got expected inner loop" ); }