public void testIntervalOps(S2LatLngRect x, S2LatLngRect y, String expectedRelation, S2LatLngRect expectedUnion, S2LatLngRect expectedIntersection) { // Test all of the interval operations on the given pair of intervals. // "expected_relation" is a sequence of "T" and "F" characters corresponding // to the expected results of Contains(), InteriorContains(), Intersects(), // and InteriorIntersects() respectively. assertEquals(x.Contains(y), expectedRelation[0] == 'T'); assertEquals(x.InteriorContains(y), expectedRelation[1] == 'T'); assertEquals(x.Intersects(y), expectedRelation[2] == 'T'); assertEquals(x.InteriorIntersects(y), expectedRelation[3] == 'T'); assertEquals(x.Contains(y), x.Union(y).Equals(x)); assertEquals(x.Intersects(y), !x.Intersection(y).IsEmpty); assertTrue(x.Union(y).Equals(expectedUnion)); assertTrue(x.Intersection(y).Equals(expectedIntersection)); if (y.Size == S2LatLng.FromRadians(0, 0)) { var r = x.AddPoint(y.Lo); assertTrue(r == expectedUnion); } }
private static void TestIntervalOps(S2LatLngRect x, S2LatLngRect y, string expected_relation, S2LatLngRect expected_union, S2LatLngRect expected_intersection) { // Test all of the interval operations on the given pair of intervals. // "expected_relation" is a sequence of "T" and "F" characters corresponding // to the expected results of Contains(), InteriorContains(), Intersects(), // and InteriorIntersects() respectively. Assert.Equal(x.Contains(y), expected_relation[0] == 'T'); Assert.Equal(x.InteriorContains(y), expected_relation[1] == 'T'); Assert.Equal(x.Intersects(y), expected_relation[2] == 'T'); Assert.Equal(x.InteriorIntersects(y), expected_relation[3] == 'T'); Assert.Equal(x.Contains(y), x.Union(y) == x); Assert.Equal(x.Intersects(y), !x.Intersection(y).IsEmpty()); Assert.Equal(x.Union(y), expected_union); Assert.Equal(x.Intersection(y), expected_intersection); if (y.Size() == S2LatLng.FromRadians(0, 0)) { S2LatLngRect r = x; r.AddPoint(y.Lo()); Assert.Equal(r, expected_union); } }
public void testIntervalOps(S2LatLngRect x, S2LatLngRect y, String expectedRelation, S2LatLngRect expectedUnion, S2LatLngRect expectedIntersection) { // Test all of the interval operations on the given pair of intervals. // "expected_relation" is a sequence of "T" and "F" characters corresponding // to the expected results of Contains(), InteriorContains(), Intersects(), // and InteriorIntersects() respectively. assertEquals(x.Contains(y), expectedRelation[0] == 'T'); assertEquals(x.InteriorContains(y), expectedRelation[1] == 'T'); assertEquals(x.Intersects(y), expectedRelation[2] == 'T'); assertEquals(x.InteriorIntersects(y), expectedRelation[3] == 'T'); assertEquals(x.Contains(y), x.Union(y).Equals(x)); assertEquals(x.Intersects(y), !x.Intersection(y).IsEmpty); assertTrue(x.Union(y).Equals(expectedUnion)); assertTrue(x.Intersection(y).Equals(expectedIntersection)); if (y.Size == S2LatLng.FromRadians(0, 0)) { var r = x.AddPoint(y.Lo); assertTrue(r == expectedUnion); } }
private static S1Angle BruteForceDistance(S2LatLngRect a, S2LatLngRect b) { if (a.Intersects(b)) { return(S1Angle.FromRadians(0)); } // Compare every point in 'a' against every latitude edge and longitude edge // in 'b', and vice-versa, for a total of 16 point-vs-latitude-edge tests and // 16 point-vs-longitude-edge tests. var pnt_a = new S2LatLng[4]; var pnt_b = new S2LatLng[4]; pnt_a[0] = new S2LatLng(a.LatLo(), a.LngLo()); pnt_a[1] = new S2LatLng(a.LatLo(), a.LngHi()); pnt_a[2] = new S2LatLng(a.LatHi(), a.LngHi()); pnt_a[3] = new S2LatLng(a.LatHi(), a.LngLo()); pnt_b[0] = new S2LatLng(b.LatLo(), b.LngLo()); pnt_b[1] = new S2LatLng(b.LatLo(), b.LngHi()); pnt_b[2] = new S2LatLng(b.LatHi(), b.LngHi()); pnt_b[3] = new S2LatLng(b.LatHi(), b.LngLo()); // Make arrays containing the lo/hi latitudes and the lo/hi longitude edges. var lat_a = new S1Angle[2] { a.LatLo(), a.LatHi() }; var lat_b = new S1Angle[2] { b.LatLo(), b.LatHi() }; var lng_edge_a = new S2Point[][] { new S2Point[] { pnt_a[0].ToPoint(), pnt_a[3].ToPoint() }, new S2Point[] { pnt_a[1].ToPoint(), pnt_a[2].ToPoint() } }; var lng_edge_b = new S2Point[][] { new S2Point[] { pnt_b[0].ToPoint(), pnt_b[3].ToPoint() }, new S2Point[] { pnt_b[1].ToPoint(), pnt_b[2].ToPoint() } }; S1Angle min_distance = S1Angle.FromDegrees(180.0); for (int i = 0; i < 4; ++i) { // For each point in a and b. var current_a = pnt_a[i]; var current_b = pnt_b[i]; for (int j = 0; j < 2; ++j) { // Get distances to latitude and longitude edges. S1Angle a_to_lat = GetDistance(current_a, lat_b[j], b.Lng); S1Angle b_to_lat = GetDistance(current_b, lat_a[j], a.Lng); S1Angle a_to_lng = S2.GetDistance(current_a.ToPoint(), lng_edge_b[j][0], lng_edge_b[j][1]); S1Angle b_to_lng = S2.GetDistance(current_b.ToPoint(), lng_edge_a[j][0], lng_edge_a[j][1]); min_distance = new[] { min_distance, a_to_lat, b_to_lat, a_to_lng, b_to_lng }.Min(); } } return(min_distance); }
private static S1Angle bruteForceDistance(S2LatLngRect a, S2LatLngRect b) { if (a.Intersects(b)) { return(S1Angle.FromRadians(0)); } // Compare every point in 'a' against every latitude edge and longitude edge // in 'b', and vice-versa, for a total of 16 point-vs-latitude-edge tests // and 16 point-vs-longitude-edge tests. S2LatLng[] pntA = { new S2LatLng(a.LatLo, a.LngLo), new S2LatLng(a.LatLo, a.LngHi), new S2LatLng(a.LatHi, a.LngHi), new S2LatLng(a.LatHi, a.LngLo) }; S2LatLng[] pntB = { new S2LatLng(b.LatLo, b.LngLo), new S2LatLng(b.LatLo, b.LngHi), new S2LatLng(b.LatHi, b.LngHi), new S2LatLng(b.LatHi, b.LngLo) }; // Make arrays containing the lo/hi latitudes and the lo/hi longitude edges. S1Angle[] latA = { a.LatLo, a.LatHi }; S1Angle[] latB = { b.LatLo, b.LatHi }; S2Point[][] lng_edge_a = { new[] { pntA[0].ToPoint(), pntA[3].ToPoint() }, new[] { pntA[1].ToPoint(), pntA[2].ToPoint() } }; S2Point[][] lng_edge_b = { new[] { pntB[0].ToPoint(), pntB[3].ToPoint() }, new[] { pntB[1].ToPoint(), pntB[2].ToPoint() } }; var minDistance = S1Angle.FromDegrees(180.0); for (var i = 0; i < 4; ++i) { // For each point in a and b. var currentA = pntA[i]; var currentB = pntB[i]; for (var j = 0; j < 2; ++j) { // Get distances to latitude and longitude edges. var aToLat = getDistance(currentA, latB[j], b.Lng); var bToLat = getDistance(currentB, latA[j], a.Lng); var aToLng = S2EdgeUtil.GetDistance(currentA.ToPoint(), lng_edge_b[j][0], lng_edge_b[j][1]); var bToLng = S2EdgeUtil.GetDistance(currentB.ToPoint(), lng_edge_a[j][0], lng_edge_a[j][1]); minDistance = S1Angle.Min( minDistance, S1Angle.Min(aToLat, S1Angle.Min(bToLat, S1Angle.Min(aToLng, bToLng)))); } } return(minDistance); }
private static S1Angle bruteForceDistance(S2LatLngRect a, S2LatLngRect b) { if (a.Intersects(b)) { return S1Angle.FromRadians(0); } // Compare every point in 'a' against every latitude edge and longitude edge // in 'b', and vice-versa, for a total of 16 point-vs-latitude-edge tests // and 16 point-vs-longitude-edge tests. S2LatLng[] pntA = { new S2LatLng(a.LatLo, a.LngLo), new S2LatLng(a.LatLo, a.LngHi), new S2LatLng(a.LatHi, a.LngHi), new S2LatLng(a.LatHi, a.LngLo) }; S2LatLng[] pntB = { new S2LatLng(b.LatLo, b.LngLo), new S2LatLng(b.LatLo, b.LngHi), new S2LatLng(b.LatHi, b.LngHi), new S2LatLng(b.LatHi, b.LngLo) }; // Make arrays containing the lo/hi latitudes and the lo/hi longitude edges. S1Angle[] latA = {a.LatLo, a.LatHi}; S1Angle[] latB = {b.LatLo, b.LatHi}; S2Point[][] lng_edge_a = {new[] {pntA[0].ToPoint(), pntA[3].ToPoint()}, new[] {pntA[1].ToPoint(), pntA[2].ToPoint()}}; S2Point[][] lng_edge_b = {new[] {pntB[0].ToPoint(), pntB[3].ToPoint()}, new[] {pntB[1].ToPoint(), pntB[2].ToPoint()}}; var minDistance = S1Angle.FromDegrees(180.0); for (var i = 0; i < 4; ++i) { // For each point in a and b. var currentA = pntA[i]; var currentB = pntB[i]; for (var j = 0; j < 2; ++j) { // Get distances to latitude and longitude edges. var aToLat = getDistance(currentA, latB[j], b.Lng); var bToLat = getDistance(currentB, latA[j], a.Lng); var aToLng = S2EdgeUtil.GetDistance(currentA.ToPoint(), lng_edge_b[j][0], lng_edge_b[j][1]); var bToLng = S2EdgeUtil.GetDistance(currentB.ToPoint(), lng_edge_a[j][0], lng_edge_a[j][1]); minDistance = S1Angle.Min( minDistance, S1Angle.Min(aToLat, S1Angle.Min(bToLat, S1Angle.Min(aToLng, bToLng)))); } } return minDistance; }
public void testCellOps(S2LatLngRect r, S2Cell cell, int level) { // Test the relationship between the given rectangle and cell: // 0 == no intersection, 1 == MayIntersect, 2 == Intersects, // 3 == Vertex Containment, 4 == Contains var vertexContained = false; for (var i = 0; i < 4; ++i) { if (r.Contains(cell.GetVertexRaw(i)) || (!r.IsEmpty && cell.Contains(r.GetVertex(i).ToPoint()))) { vertexContained = true; } } assertEquals(r.MayIntersect(cell), level >= 1); assertEquals(r.Intersects(cell), level >= 2); assertEquals(vertexContained, level >= 3); assertEquals(r.Contains(cell), level >= 4); }
private static void TestCellOps(S2LatLngRect r, S2Cell cell, int level) { // Test the relationship between the given rectangle and cell: // 0 == no intersection, 1 == MayIntersect, 2 == Intersects, // 3 == Vertex Containment, 4 == Contains bool vertex_contained = false; for (int i = 0; i < 4; ++i) { if (r.Contains(cell.VertexRaw(i)) || (!r.IsEmpty() && cell.Contains(r.Vertex(i).ToPoint()))) { vertex_contained = true; } } Assert.Equal(r.MayIntersect(cell), level >= 1); Assert.Equal(r.Intersects(cell), level >= 2); Assert.Equal(vertex_contained, level >= 3); Assert.Equal(r.Contains(cell), level >= 4); }
public void testCellOps(S2LatLngRect r, S2Cell cell, int level) { // Test the relationship between the given rectangle and cell: // 0 == no intersection, 1 == MayIntersect, 2 == Intersects, // 3 == Vertex Containment, 4 == Contains var vertexContained = false; for (var i = 0; i < 4; ++i) { if (r.Contains(cell.GetVertexRaw(i)) || (!r.IsEmpty && cell.Contains(r.GetVertex(i).ToPoint()))) { vertexContained = true; } } assertEquals(r.MayIntersect(cell), level >= 1); assertEquals(r.Intersects(cell), level >= 2); assertEquals(vertexContained, level >= 3); assertEquals(r.Contains(cell), level >= 4); }
private static bool ContainsGeodataToFind(S2CellId c, S2LatLngRect latLngRect) { return(latLngRect.Intersects(new S2Cell(c))); }