/**
         *  Indexing structure to efficiently clipEdge() of a polygon. This is an
         * abstract class because we need to use if for both polygons (for
         * initToIntersection() and friends) and for sets of lists of points (for
         * initToSimplified()).
         *
         *  Usage -- in your subclass, create an array of vertex counts for each loop
         * in the loop sequence and pass it to this constructor. Overwrite
         * edgeFromTo(), calling decodeIndex() and use the resulting two indices to
         * access your accessing vertices.
         */

        private static void AddIntersection(S2Point a0,
                                            S2Point a1,
                                            S2Point b0,
                                            S2Point b1,
                                            bool addSharedEdges,
                                            int crossing, System.Collections.Generic.ICollection <ParametrizedS2Point> intersections)
        {
            if (crossing > 0)
            {
                // There is a proper edge crossing.
                var x = S2EdgeUtil.GetIntersection(a0, a1, b0, b1);
                var t = S2EdgeUtil.GetDistanceFraction(x, a0, a1);
                intersections.Add(new ParametrizedS2Point(t, x));
            }
            else if (S2EdgeUtil.VertexCrossing(a0, a1, b0, b1))
            {
                // There is a crossing at one of the vertices. The basic rule is simple:
                // if a0 equals one of the "b" vertices, the crossing occurs at t=0;
                // otherwise, it occurs at t=1.
                //
                // This has the effect that when two symmetric edges are encountered (an
                // edge an its reverse), neither one is included in the output. When two
                // duplicate edges are encountered, both are included in the output. The
                // "addSharedEdges" flag allows one of these two copies to be removed by
                // changing its intersection parameter from 0 to 1.
                double t = (a0 == b0 || a0 == b1) ? 0 : 1;
                if (!addSharedEdges && a1 == b1)
                {
                    t = 1;
                }
                intersections.Add(new ParametrizedS2Point(t, t == 0 ? a0 : a1));
            }
        }
Example #2
0
        /**
         * This method is equivalent to the S2EdgeUtil.edgeOrVertexCrossing() method
         * defined below. It is similar to robustCrossing, but handles cases where
         * two vertices are identical in a way that makes it easy to implement
         * point-in-polygon containment tests.
         */

        public bool EdgeOrVertexCrossing(S2Point d)
        {
            // We need to copy c since it is clobbered by robustCrossing().
            var c2 = new S2Point(c[0], c[1], c[2]);

            var crossing = RobustCrossing(d);

            if (crossing < 0)
            {
                return(false);
            }
            if (crossing > 0)
            {
                return(true);
            }

            return(S2EdgeUtil.VertexCrossing(a, b, c2, d));
        }