Пример #1
0
        /**
         * sort sites on y, then x, coord
         * also change each site's _siteIndex to match its new position in the list
         * so the _siteIndex can be used to identify the site for nearest-neighbor queries
         *
         * haha "also" - means more than one responsibility...
         *
         */

        public int CompareTo(object obj)
        // XXX: Really, really worried about this because it depends on how sorting works in AS3 impl - Julian
        {
            var s2 = (Site)obj;

            var returnValue = Voronoi.CompareByYThenX(this, s2);

            // swap _siteIndex values if necessary to match new ordering:
            uint tempIndex;

            if (returnValue == -1)
            {
                if (_siteIndex > s2._siteIndex)
                {
                    tempIndex     = _siteIndex;
                    _siteIndex    = s2._siteIndex;
                    s2._siteIndex = tempIndex;
                }
            }
            else if (returnValue == 1)
            {
                if (s2._siteIndex > _siteIndex)
                {
                    tempIndex     = s2._siteIndex;
                    s2._siteIndex = _siteIndex;
                    _siteIndex    = tempIndex;
                }
            }

            return(returnValue);
        }
Пример #2
0
        /**
         * This is the only way to make a Vertex
         *
         * @param halfedge0
         * @param halfedge1
         * @return
         *
         */

        public static Vertex Intersect(HalfEdge halfedge0, HalfEdge halfedge1)
        {
            Edge     edge;
            HalfEdge halfEdge;

            var edge0 = halfedge0.Edge;
            var edge1 = halfedge1.Edge;

            if (edge0 == null || edge1 == null)
            {
                return(null);
            }
            if (edge0.RightSite == edge1.RightSite)
            {
                return(null);
            }

            var determinant = edge0.A * edge1.B - edge0.B * edge1.A;

            if (-1.0e-10 < determinant && determinant < 1.0e-10)
            {
                // the edges are parallel
                return(null);
            }

            var intersectionX = (edge0.C * edge1.B - edge1.C * edge0.B) / determinant;
            var intersectionY = (edge1.C * edge0.A - edge0.C * edge1.A) / determinant;

            if (Voronoi.CompareByYThenX(edge0.RightSite, edge1.RightSite) < 0)
            {
                halfEdge = halfedge0;
                edge     = edge0;
            }
            else
            {
                halfEdge = halfedge1;
                edge     = edge1;
            }
            var rightOfSite = intersectionX >= edge.RightSite.X;

            if ((rightOfSite && halfEdge.LeftRight == Side.Left) ||
                (!rightOfSite && halfEdge.LeftRight == Side.Right))
            {
                return(null);
            }

            return(Create(intersectionX, intersectionY));
        }