Exemple #1
0
        public HalfEdge Init(Edge edge, Side? side)
        {
            Edge = edge;
            LeftOrRight = side;
            NextInPriorityQueue = null;
            Vertex = null;

            return this;
        }
Exemple #2
0
 public void ReallyDispose()
 {
     EdgeListLeftNeighbor = null;
     EdgeListRightNeighbor = null;
     NextInPriorityQueue = null;
     Edge = null;
     LeftOrRight = null;
     Vertex = null;
     pool.Push(this);
 }
Exemple #3
0
        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.LeftOrRight == Side.Left) || (!rightOfSite && halfEdge.LeftOrRight == Side.Right))
                return null;

            return Create(intersectionX, intersectionY);
        }
        public void Insert(HalfEdge halfEdge)
        {
            HalfEdge next;
            var insertionBucket = Bucket(halfEdge);

            if (insertionBucket < minBucket)
            {
                minBucket = insertionBucket;
            }

            var previous = hash[insertionBucket];

            while ((next = previous.NextInPriorityQueue) != null
            && (halfEdge.YStar > next.YStar || (halfEdge.YStar == next.YStar && halfEdge.Vertex.X > next.Vertex.X)))
            {
                previous = next;
            }

            halfEdge.NextInPriorityQueue = previous.NextInPriorityQueue;
            previous.NextInPriorityQueue = halfEdge;
            count++;
        }
Exemple #5
0
        public void Dispose()
        {
            var halfEdge = LeftEnd;

            while (halfEdge != RightEnd)
            {
                var prevHalfEdge = halfEdge;
                halfEdge = halfEdge.EdgeListRightNeighbor;
                prevHalfEdge.Dispose();
            }

            LeftEnd = null;
            RightEnd.Dispose();
            RightEnd = null;

            int i;
            //todo: might not be needed
            for (i = 0; i < hashSize; ++i)
            {
                hash[i] = null;
            }

            hash = null;
        }
Exemple #6
0
 public void Remove(HalfEdge halfEdge)
 {
     halfEdge.EdgeListLeftNeighbor.EdgeListRightNeighbor = halfEdge.EdgeListRightNeighbor;
     halfEdge.EdgeListRightNeighbor.EdgeListLeftNeighbor = halfEdge.EdgeListLeftNeighbor;
     halfEdge.Edge = Edge.Deleted;
     halfEdge.EdgeListLeftNeighbor = halfEdge.EdgeListRightNeighbor = null;
 }
Exemple #7
0
        public void Insert(HalfEdge lb, HalfEdge newHalfEdge)
        {
            newHalfEdge.EdgeListLeftNeighbor = lb;
            newHalfEdge.EdgeListRightNeighbor = lb.EdgeListRightNeighbor;

            lb.EdgeListRightNeighbor.EdgeListLeftNeighbor = newHalfEdge;
            lb.EdgeListRightNeighbor = newHalfEdge;
        }
Exemple #8
0
 private static Site RightRegion(HalfEdge halfEdge, Site bottomMostSite)
 {
     var edge = halfEdge.Edge;
     return edge == null ? bottomMostSite : edge.Site(SideHelper.Other((Side)halfEdge.LeftOrRight));
 }
        public void Remove(HalfEdge halfEdge)
        {
            HalfEdge previous;
            var removalBucket = Bucket(halfEdge);

            if (halfEdge.Vertex == null) return;

            previous = hash[removalBucket];

            while (previous.NextInPriorityQueue != halfEdge)
            {
                previous = previous.NextInPriorityQueue;
            }

            previous.NextInPriorityQueue = halfEdge.NextInPriorityQueue;
            count--;
            halfEdge.Vertex = null;
            halfEdge.NextInPriorityQueue = null;
            halfEdge.Dispose();
        }
 private int Bucket(HalfEdge halfEdge)
 {
     var theBucket = (int)((halfEdge.YStar - yMin) / deltaY * hashSize);
     if (theBucket < 0)
         theBucket = 0;
     if (theBucket >= hashSize)
         theBucket = hashSize - 1;
     return theBucket;
 }