示例#1
0
文件: Vertex.cs 项目: mrommel/dx11
        public static Vertex Intersect(HalfEdge he0, HalfEdge he1)
        {
            var edge0 = he0.Edge;
            var edge1 = he1.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)
            {
                return(null);
            }
            var intersectionX = (edge0.C * edge1.B - edge1.C * edge0.B) / determinant;
            var intersectionY = (edge1.C * edge0.A - edge0.C * edge1.A) / determinant;

            HalfEdge halfEdge;
            Edge     edge;

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

            if ((rightOfSite && halfEdge.LeftRight == LR.Left) || (!rightOfSite && halfEdge.LeftRight == LR.Right))
            {
                return(null);
            }
            return(Create(intersectionX, intersectionY));
        }
示例#2
0
            public int Compare(Site s1, Site s2)
            {
                var ret = Voronoi.CompareByYThenX(s1, s2);

                if (ret == -1)
                {
                    if (s1._siteIndex > s2._siteIndex)
                    {
                        var tempIndex = s1._siteIndex;
                        s1._siteIndex = s2._siteIndex;
                        s2._siteIndex = tempIndex;
                    }
                    else if (ret == 1)
                    {
                        var tempIndex = s2._siteIndex;
                        s2._siteIndex = s1._siteIndex;
                        s1._siteIndex = tempIndex;
                    }
                }
                return(ret);
            }