Exemple #1
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, edge0, edge1;
            Halfedge halfedge;
            float    determinant, intersectionX, intersectionY;
            bool     rightOfSite;

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

            determinant = edge0.a * edge1.b - edge0.b * edge1.a;
            if (Math.Pow(-1.0, 10) < determinant && determinant < Math.Pow(1.0, -10))
            {
                // The edges are parallel
                return(null);
            }

            intersectionX = (edge0.c * edge1.b - edge1.c * edge0.b) / determinant;
            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;
            }
            rightOfSite = intersectionX >= edge.RightSite.x;
            if ((rightOfSite && halfedge.leftRight == LR.LEFT) ||
                (!rightOfSite && halfedge.leftRight == LR.RIGHT))
            {
                return(null);
            }

            return(Vertex.Create(intersectionX, intersectionY));
        }