コード例 #1
0
        private bool loopsEqual(S2Loop a, S2Loop b, double maxError)
        {
            // Return true if two loops have the same cyclic vertex sequence.

            if (a.NumVertices != b.NumVertices)
            {
                return(false);
            }
            for (var offset = 0; offset < a.NumVertices; ++offset)
            {
                if (S2.ApproxEquals(a.Vertex(offset), b.Vertex(0), maxError))
                {
                    var success = true;
                    for (var i = 0; i < a.NumVertices; ++i)
                    {
                        if (!S2.ApproxEquals(a.Vertex(i + offset), b.Vertex(i), maxError))
                        {
                            success = false;
                            break;
                        }
                    }
                    if (success)
                    {
                        return(true);
                    }
                    // Otherwise continue looping. There may be more than one candidate
                    // starting offset since vertices are only matched approximately.
                }
            }
            return(false);
        }
コード例 #2
0
        private void assertPointApproximatelyEquals(
            S2Loop s2Loop, int vertexIndex, double lat, double lng, double error)
        {
            var latLng = new S2LatLng(s2Loop.Vertex(vertexIndex));

            assertDoubleNear(latLng.LatDegrees, lat, error);
            assertDoubleNear(latLng.LngDegrees, lng, error);
        }
コード例 #3
0
 private S2Loop rotate(S2Loop loop)
 {
     var vertices = new List<S2Point>();
     for (var i = 1; i <= loop.NumVertices; ++i)
     {
         vertices.Add(loop.Vertex(i));
     }
     return new S2Loop(vertices);
 }
コード例 #4
0
        private S2Loop rotate(S2Loop loop)
        {
            var vertices = new List <S2Point>();

            for (var i = 1; i <= loop.NumVertices; ++i)
            {
                vertices.Add(loop.Vertex(i));
            }
            return(new S2Loop(vertices));
        }
コード例 #5
0
 private static bool LoopHasVertex(S2Loop loop, S2Point p)
 {
     for (int i = 0; i < loop.NumVertices; ++i)
     {
         if (loop.Vertex(i) == p)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #6
0
        public void testBounds()
        {
            assertTrue(candyCane.RectBound.Lng.IsFull);
            assertTrue(candyCane.RectBound.LatLo.Degrees < -20);
            assertTrue(candyCane.RectBound.LatHi.Degrees > 10);
            assertTrue(smallNeCw.RectBound.IsFull);
            assertEquals(arctic80.RectBound,
                         new S2LatLngRect(S2LatLng.FromDegrees(80, -180), S2LatLng.FromDegrees(90, 180)));
            assertEquals(antarctic80.RectBound,
                         new S2LatLngRect(S2LatLng.FromDegrees(-90, -180), S2LatLng.FromDegrees(-80, 180)));

            arctic80.Invert();
            // The highest latitude of each edge is attained at its midpoint.
            var mid = (arctic80.Vertex(0) + arctic80.Vertex(1)) * 0.5;

            assertDoubleNear(arctic80.RectBound.LatHi.Radians, new S2LatLng(mid).Lat.Radians);
            arctic80.Invert();

            assertTrue(southHemi.RectBound.Lng.IsFull);
            assertEquals(southHemi.RectBound.Lat, new R1Interval(-S2.PiOver2, 0));
        }
コード例 #7
0
ファイル: S2ConvexHullQuery.cs プロジェクト: alas/s2geometry
 // Add a loop to the input geometry.
 public void AddLoop(S2Loop loop)
 {
     bound_ = bound_.Union(loop.GetRectBound());
     if (loop.IsEmptyOrFull())
     {
         // The empty and full loops consist of a single fake "vertex" that should
         // not be added to our point collection.
         return;
     }
     for (int i = 0; i < loop.NumVertices; ++i)
     {
         points_.Add(loop.Vertex(i));
     }
 }
コード例 #8
0
        private bool loopsEqual(S2Loop a, S2Loop b, double maxError)
        {
            // Return true if two loops have the same cyclic vertex sequence.

            if (a.NumVertices != b.NumVertices)
            {
                return false;
            }
            for (var offset = 0; offset < a.NumVertices; ++offset)
            {
                if (S2.ApproxEquals(a.Vertex(offset), b.Vertex(0), maxError))
                {
                    var success = true;
                    for (var i = 0; i < a.NumVertices; ++i)
                    {
                        if (!S2.ApproxEquals(a.Vertex(i + offset), b.Vertex(i), maxError))
                        {
                            success = false;
                            break;
                        }
                    }
                    if (success)
                    {
                        return true;
                    }
                    // Otherwise continue looping. There may be more than one candidate
                    // starting offset since vertices are only matched approximately.
                }
            }
            return false;
        }
コード例 #9
0
 private void dumpCrossings(S2Loop loop)
 {
     Console.WriteLine("Ortho(v1): " + S2.Ortho(loop.Vertex(1)));
     Console.WriteLine("Contains(kOrigin): {0}\n", loop.Contains(S2.Origin));
     for (var i = 1; i <= loop.NumVertices; ++i)
     {
         var a = S2.Ortho(loop.Vertex(i));
         var b = loop.Vertex(i - 1);
         var c = loop.Vertex(i + 1);
         var o = loop.Vertex(i);
         Console.WriteLine("Vertex {0}: [%.17g, %.17g, %.17g], "
                           + "%d%dR=%d, %d%d%d=%d, R%d%d=%d, inside: %b\n",
                           i,
                           loop.Vertex(i).X,
                           loop.Vertex(i).Y,
                           loop.Vertex(i).Z,
                           i - 1,
                           i,
                           S2.RobustCcw(b, o, a),
                           i + 1,
                           i,
                           i - 1,
                           S2.RobustCcw(c, o, b),
                           i,
                           i + 1,
                           S2.RobustCcw(a, o, c),
                           S2.OrderedCcw(a, b, c, o));
     }
     for (var i = 0; i < loop.NumVertices + 2; ++i)
     {
         var orig = S2.Origin;
         S2Point dest;
         if (i < loop.NumVertices)
         {
             dest = loop.Vertex(i);
             Console.WriteLine("Origin->{0} crosses:", i);
         }
         else
         {
             dest = new S2Point(0, 0, 1);
             if (i == loop.NumVertices + 1)
             {
                 orig = loop.Vertex(1);
             }
             Console.WriteLine("Case {0}:", i);
         }
         for (var j = 0; j < loop.NumVertices; ++j)
         {
             Console.WriteLine(
                 " " + S2EdgeUtil.EdgeOrVertexCrossing(orig, dest, loop.Vertex(j), loop.Vertex(j + 1)));
         }
         Console.WriteLine();
     }
     for (var i = 0; i <= 2; i += 2)
     {
         Console.WriteLine("Origin->v1 crossing v{0}->v1: ", i);
         var a = S2.Ortho(loop.Vertex(1));
         var b = loop.Vertex(i);
         var c = S2.Origin;
         var o = loop.Vertex(1);
         Console.WriteLine("{0}1R={1}, M1{2}={3}, R1M={4}, crosses: {5}\n",
                           i,
                           S2.RobustCcw(b, o, a),
                           i,
                           S2.RobustCcw(c, o, b),
                           S2.RobustCcw(a, o, c),
                           S2EdgeUtil.EdgeOrVertexCrossing(c, o, b, a));
     }
 }
コード例 #10
0
 private void assertPointApproximatelyEquals(
     S2Loop s2Loop, int vertexIndex, double lat, double lng, double error)
 {
     var latLng = new S2LatLng(s2Loop.Vertex(vertexIndex));
     assertDoubleNear(latLng.LatDegrees, lat, error);
     assertDoubleNear(latLng.LngDegrees, lng, error);
 }
コード例 #11
0
 private void dumpCrossings(S2Loop loop)
 {
     Console.WriteLine("Ortho(v1): " + S2.Ortho(loop.Vertex(1)));
     Console.WriteLine("Contains(kOrigin): {0}\n", loop.Contains(S2.Origin));
     for (var i = 1; i <= loop.NumVertices; ++i)
     {
         var a = S2.Ortho(loop.Vertex(i));
         var b = loop.Vertex(i - 1);
         var c = loop.Vertex(i + 1);
         var o = loop.Vertex(i);
         Console.WriteLine("Vertex {0}: [%.17g, %.17g, %.17g], "
                           + "%d%dR=%d, %d%d%d=%d, R%d%d=%d, inside: %b\n",
                           i,
                           loop.Vertex(i).X,
                           loop.Vertex(i).Y,
                           loop.Vertex(i).Z,
                           i - 1,
                           i,
                           S2.RobustCcw(b, o, a),
                           i + 1,
                           i,
                           i - 1,
                           S2.RobustCcw(c, o, b),
                           i,
                           i + 1,
                           S2.RobustCcw(a, o, c),
                           S2.OrderedCcw(a, b, c, o));
     }
     for (var i = 0; i < loop.NumVertices + 2; ++i)
     {
         var     orig = S2.Origin;
         S2Point dest;
         if (i < loop.NumVertices)
         {
             dest = loop.Vertex(i);
             Console.WriteLine("Origin->{0} crosses:", i);
         }
         else
         {
             dest = new S2Point(0, 0, 1);
             if (i == loop.NumVertices + 1)
             {
                 orig = loop.Vertex(1);
             }
             Console.WriteLine("Case {0}:", i);
         }
         for (var j = 0; j < loop.NumVertices; ++j)
         {
             Console.WriteLine(
                 " " + S2EdgeUtil.EdgeOrVertexCrossing(orig, dest, loop.Vertex(j), loop.Vertex(j + 1)));
         }
         Console.WriteLine();
     }
     for (var i = 0; i <= 2; i += 2)
     {
         Console.WriteLine("Origin->v1 crossing v{0}->v1: ", i);
         var a = S2.Ortho(loop.Vertex(1));
         var b = loop.Vertex(i);
         var c = S2.Origin;
         var o = loop.Vertex(1);
         Console.WriteLine("{0}1R={1}, M1{2}={3}, R1M={4}, crosses: {5}\n",
                           i,
                           S2.RobustCcw(b, o, a),
                           i,
                           S2.RobustCcw(c, o, b),
                           S2.RobustCcw(a, o, c),
                           S2EdgeUtil.EdgeOrVertexCrossing(c, o, b, a));
     }
 }