Exemplo n.º 1
0
        private static S1ChordAngle GetMaxDistanceToEdgeBruteForce(S2Cell cell, S2Point a, S2Point b)
        {
            // If any antipodal endpoint is within the cell, the max distance is Pi.
            if (cell.Contains(-a) || cell.Contains(-b))
            {
                return(S1ChordAngle.Straight);
            }

            S1ChordAngle max_dist = S1ChordAngle.Negative;

            for (int i = 0; i < 4; ++i)
            {
                S2Point v0 = cell.Vertex(i);
                S2Point v1 = cell.Vertex(i + 1);
                // If the antipodal edge crosses through the cell, max distance is Pi.
                if (S2.CrossingSign(-a, -b, v0, v1) >= 0)
                {
                    return(S1ChordAngle.Straight);
                }
                S2.UpdateMaxDistance(a, v0, v1, ref max_dist);
                S2.UpdateMaxDistance(b, v0, v1, ref max_dist);
                S2.UpdateMaxDistance(v0, a, b, ref max_dist);
            }
            return(max_dist);
        }
Exemplo n.º 2
0
        private static S1ChordAngle GetDistanceToPointBruteForce(S2Cell cell, S2Point target)
        {
            S1ChordAngle min_distance = S1ChordAngle.Infinity;

            for (int i = 0; i < 4; ++i)
            {
                S2.UpdateMinDistance(target, cell.Vertex(i),
                                     cell.Vertex(i + 1), ref min_distance);
            }
            return(min_distance);
        }
Exemplo n.º 3
0
        public void Test_S2Cell_GetMaxDistanceToEdge()
        {
            // Test an edge for which its antipode crosses the cell. Validates both the
            // standard and brute force implementations for this case.
            S2Cell  cell = S2Cell.FromFacePosLevel(0, 0, 20);
            S2Point a    = -S2.Interpolate(2.0, cell.Center(), cell.Vertex(0));
            S2Point b    = -S2.Interpolate(2.0, cell.Center(), cell.Vertex(2));

            S1ChordAngle actual   = cell.MaxDistance(a, b);
            S1ChordAngle expected = GetMaxDistanceToEdgeBruteForce(cell, a, b);

            Assert2.Near(expected.Radians(), S1ChordAngle.Straight.Radians(), S2.DoubleError);
            Assert2.Near(actual.Radians(), S1ChordAngle.Straight.Radians(), S2.DoubleError);
        }
Exemplo n.º 4
0
        private static S1ChordAngle GetMaxDistanceToPointBruteForce(S2Cell cell, S2Point target)
        {
            if (cell.Contains(-target))
            {
                return(S1ChordAngle.Straight);
            }
            S1ChordAngle max_distance = S1ChordAngle.Negative;

            for (int i = 0; i < 4; ++i)
            {
                S2.UpdateMaxDistance(target, cell.Vertex(i),
                                     cell.Vertex(i + 1), ref max_distance);
            }
            return(max_distance);
        }
Exemplo n.º 5
0
        private static S1ChordAngle GetDistanceToEdgeBruteForce(S2Cell cell, S2Point a, S2Point b)
        {
            if (cell.Contains(a) || cell.Contains(b))
            {
                return(S1ChordAngle.Zero);
            }

            S1ChordAngle min_dist = S1ChordAngle.Infinity;

            for (int i = 0; i < 4; ++i)
            {
                S2Point v0 = cell.Vertex(i);
                S2Point v1 = cell.Vertex(i + 1);
                // If the edge crosses through the cell, max distance is 0.
                if (S2.CrossingSign(a, b, v0, v1) >= 0)
                {
                    return(S1ChordAngle.Zero);
                }
                S2.UpdateMinDistance(a, v0, v1, ref min_dist);
                S2.UpdateMinDistance(b, v0, v1, ref min_dist);
                S2.UpdateMinDistance(v0, a, b, ref min_dist);
            }
            return(min_dist);
        }