Exemplo n.º 1
0
 public void DeleteFromEdgeList(HalfEdge halfEdge)
 {
     halfEdge.Left.Right = halfEdge.Right;
     halfEdge.Right.Left = halfEdge.Left;
     halfEdge.IsDeleted  = true;
 }
Exemplo n.º 2
0
        // Returns true if point is to right of halfedge edge
        private static bool RightSideOf(HalfEdge halfEdge, Point point)
        {
            var above       = false;
            var edge        = halfEdge.EdgeListEdge;
            var topsite     = edge.Region1;
            var rightOfSite = point.X > topsite.Point.X;

            if (rightOfSite && halfEdge.EdgeListSide == Voronoi.LeftSide)
            {
                return(true);
            }

            if (!rightOfSite && halfEdge.EdgeListSide == Voronoi.RightSide)
            {
                return(false);
            }

            if (Voronoi.IsNearlyEqual(edge.A, 1D))
            {
                var deltaX = point.X - topsite.Point.X;
                var deltaY = point.Y - topsite.Point.Y;
                var fast   = false;

                if (!rightOfSite && edge.B < 0D || rightOfSite && edge.B >= 0D)
                {
                    above = deltaY >= edge.B * deltaX;
                    fast  = above;
                }
                else
                {
                    above = point.X + point.Y * edge.B > edge.C;

                    if (edge.B < 0D)
                    {
                        above = !above;
                    }

                    if (!above)
                    {
                        fast = true;
                    }
                }

                if (!fast)
                {
                    var dxs = topsite.Point.X - edge.Region0.Point.X;

                    above = edge.B * (deltaX * deltaX - deltaY * deltaY) < dxs * deltaY * (1.0 + 2.0 * deltaX / dxs + edge.B * edge.B);

                    if (edge.B < 0)
                    {
                        above = !above;
                    }
                }
            }
            else // edge.b == 1.0
            {
                var yl = edge.C - edge.A * point.X;
                var t1 = point.Y - yl;
                var t2 = point.X - topsite.Point.X;
                var t3 = yl - topsite.Point.Y;

                above = t1 * t1 > t2 * t2 + t3 * t3;
            }

            return(halfEdge.EdgeListSide == Voronoi.LeftSide ? above : !above);
        }