Esempio n. 1
0
        private Site FortunesAlgorithm_rightRegion(Halfedge he)
        {
            Edge edge = he.edge;

            if (edge == null)
            {
                return(fortunesAlgorithm_bottomMostSite);
            }
            return(edge.Site(SideHelper.Other((Side)he.leftRight)));
        }
Esempio n. 2
0
        private Site FortunesAlgorithm_rightRegion(HalfEdge he)
        {
            var edge = he.Edge;

            if (edge == null)
            {
                return(_fortunesAlgorithmBottomMostSite);
            }
            return(edge.Site(SideHelper.Other((Side)he.LeftRight)));
        }
Esempio n. 3
0
        /// <summary>
        /// 博客日历回调
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="reason"></param>
        private void ArticleCategoriesOnRemoveCallback(string key, object value, CacheItemRemovedReason reason)
        {
            DateTime now        = DateTime.Now;
            var      Categories = SideHelper.GetSideCategoryCategories();
            object   obj        = CacheHelper.GetCacheValue(key);

            if (obj != null)
            {
                HttpRuntime.Cache.Remove(key);
            }
            CacheHelper.Insert("ArticleCategories", Categories, now.AddMinutes(CacheTime), ArticleCategoriesOnRemoveCallback);
        }
Esempio n. 4
0
        private Site FortunesAlgorithm_rightRegion(Halfedge he)
        {
            Edge edge = he.edge;

            if (edge == null)
            {
                return(fortunesAlgorithm_bottomMostSite);
            }
            Edge edge2     = edge;
            Side?leftRight = he.leftRight;

            return(edge2.Site(SideHelper.Other(leftRight.Value)));
        }
Esempio n. 5
0
        public void ArticleCacheManager()
        {
            DateTime now        = DateTime.Now;
            object   Categories = CacheHelper.GetCacheValue("ArticleCategories");
            object   Calendars  = CacheHelper.GetCacheValue("ArticleCalendars");

            if (Categories == null || Calendars == null)
            {
                Categories = SideHelper.GetSideCategoryCategories();
                Calendars  = SideHelper.GetSideArticleCalendars();
                CacheHelper.Insert("ArticleCategories", Categories, now.AddMinutes(CacheTime), ArticleCategoriesOnRemoveCallback);
                CacheHelper.Insert("ArticleCalendars", Calendars, now.AddMinutes(CacheTime), ArticleCalendarsOnRemoveCallback);
            }
        }
Esempio n. 6
0
        private List <Vector2> ClipToBounds(Rect bounds)
        {
            List <Vector2> points = new List <Vector2> ();
            int            n      = _edges.Count;
            int            i      = 0;
            Edge           edge;

            while (i < n && ((_edges[i] as Edge).visible == false))
            {
                ++i;
            }

            if (i == n)
            {
                // no Edges visible
                return(new List <Vector2> ());
            }
            edge = _edges [i];
            Side orientation = _edgeOrientations [i];

            if (edge.clippedEnds [orientation] == null)
            {
                Debug.LogError("XXX: Null detected when there should be a Vector2!");
            }
            if (edge.clippedEnds [SideHelper.Other(orientation)] == null)
            {
                Debug.LogError("XXX: Null detected when there should be a Vector2!");
            }
            points.Add((Vector2)edge.clippedEnds [orientation]);
            points.Add((Vector2)edge.clippedEnds [SideHelper.Other(orientation)]);

            for (int j = i + 1; j < n; ++j)
            {
                edge = _edges [j];
                if (edge.visible == false)
                {
                    continue;
                }
                Connect(points, j, bounds);
            }
            // close up the polygon by adding another corner point of the bounds if needed:
            Connect(points, i, bounds, true);

            return(points);
        }
Esempio n. 7
0
        private List <Point> ClipToBounds(Rect bounds)
        {
            var  points = new List <Point>();
            var  n      = Edges.Count;
            var  i      = 0;
            Edge edge;

            while (i < n && (Edges[i].Visible == false))
            {
                ++i;
            }

            if (i == n)
            {
                // no edges visible
                return(new List <Point>());
            }
            edge = Edges[i];
            var orientation = EdgeOrientations[i];

            if (edge.ClippedEnds[orientation] == null)
            {
                Debug.WriteLine("XXX: Null detected when there should be a Point!", "Error");
            }
            if (edge.ClippedEnds[SideHelper.Other(orientation)] == null)
            {
                Debug.WriteLine("XXX: Null detected when there should be a Point!", "Error");
            }
            points.Add((Point)edge.ClippedEnds[orientation]);
            points.Add((Point)edge.ClippedEnds[SideHelper.Other(orientation)]);

            for (var j = i + 1; j < n; ++j)
            {
                edge = Edges[j];
                if (edge.Visible == false)
                {
                    continue;
                }
                Connect(points, j, bounds);
            }
            // close up the polygon by adding another corner point of the bounds if needed:
            Connect(points, i, bounds, true);

            return(points);
        }
Esempio n. 8
0
        private List <Vector2> ClipToBounds(Rect bounds)
        {
            List <Vector2> list  = new List <Vector2>();
            int            count = _edges.Count;
            int            i;

            for (i = 0; i < count && !_edges[i].visible; i++)
            {
            }
            if (i == count)
            {
                return(new List <Vector2>());
            }
            Edge edge = _edges[i];
            Side side = _edgeOrientations[i];

            if (!edge.clippedEnds[side].HasValue)
            {
                UnityEngine.Debug.LogError("XXX: Null detected when there should be a Vector2!");
            }
            if (!edge.clippedEnds[SideHelper.Other(side)].HasValue)
            {
                UnityEngine.Debug.LogError("XXX: Null detected when there should be a Vector2!");
            }
            list.Add(edge.clippedEnds[side].Value);
            list.Add(edge.clippedEnds[SideHelper.Other(side)].Value);
            for (int j = i + 1; j < count; j++)
            {
                edge = _edges[j];
                if (edge.visible)
                {
                    Connect(list, j, bounds);
                }
            }
            Connect(list, i, bounds, closingUp: true);
            return(list);
        }
Esempio n. 9
0
        private void Connect(List <Vector2> points, int j, Rect bounds, bool closingUp = false)
        {
            Vector2 rightPoint     = points [points.Count - 1];
            Edge    newEdge        = _edges [j] as Edge;
            Side    newOrientation = _edgeOrientations [j];

            // the point that  must be connected to rightPoint:
            if (newEdge.clippedEnds [newOrientation] == null)
            {
                Debug.LogError("XXX: Null detected when there should be a Vector2!");
            }
            Vector2 newPoint = (Vector2)newEdge.clippedEnds [newOrientation];

            if (!CloseEnough(rightPoint, newPoint))
            {
                // The points do not coincide, so they must have been clipped at the bounds;
                // see if they are on the same border of the bounds:
                if (rightPoint.x != newPoint.x &&
                    rightPoint.y != newPoint.y)
                {
                    // They are on different borders of the bounds;
                    // insert one or two corners of bounds as needed to hook them up:
                    // (NOTE this will not be correct if the region should take up more than
                    // half of the bounds rect, for then we will have gone the wrong way
                    // around the bounds and included the smaller part rather than the larger)
                    int   rightCheck = BoundsCheck.Check(rightPoint, bounds);
                    int   newCheck = BoundsCheck.Check(newPoint, bounds);
                    float px, py;
                    if ((rightCheck & BoundsCheck.RIGHT) != 0)
                    {
                        px = bounds.xMax;
                        if ((newCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            py = bounds.yMax;
                            points.Add(new Vector2(px, py));
                        }
                        else if ((newCheck & BoundsCheck.TOP) != 0)
                        {
                            py = bounds.yMin;
                            points.Add(new Vector2(px, py));
                        }
                        else if ((newCheck & BoundsCheck.LEFT) != 0)
                        {
                            if (rightPoint.y - bounds.y + newPoint.y - bounds.y < bounds.height)
                            {
                                py = bounds.yMin;
                            }
                            else
                            {
                                py = bounds.yMax;
                            }
                            points.Add(new Vector2(px, py));
                            points.Add(new Vector2(bounds.xMin, py));
                        }
                    }
                    else if ((rightCheck & BoundsCheck.LEFT) != 0)
                    {
                        px = bounds.xMin;
                        if ((newCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            py = bounds.yMax;
                            points.Add(new Vector2(px, py));
                        }
                        else if ((newCheck & BoundsCheck.TOP) != 0)
                        {
                            py = bounds.yMin;
                            points.Add(new Vector2(px, py));
                        }
                        else if ((newCheck & BoundsCheck.RIGHT) != 0)
                        {
                            if (rightPoint.y - bounds.y + newPoint.y - bounds.y < bounds.height)
                            {
                                py = bounds.yMin;
                            }
                            else
                            {
                                py = bounds.yMax;
                            }
                            points.Add(new Vector2(px, py));
                            points.Add(new Vector2(bounds.xMax, py));
                        }
                    }
                    else if ((rightCheck & BoundsCheck.TOP) != 0)
                    {
                        py = bounds.yMin;
                        if ((newCheck & BoundsCheck.RIGHT) != 0)
                        {
                            px = bounds.xMax;
                            points.Add(new Vector2(px, py));
                        }
                        else if ((newCheck & BoundsCheck.LEFT) != 0)
                        {
                            px = bounds.xMin;
                            points.Add(new Vector2(px, py));
                        }
                        else if ((newCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            if (rightPoint.x - bounds.x + newPoint.x - bounds.x < bounds.width)
                            {
                                px = bounds.xMin;
                            }
                            else
                            {
                                px = bounds.xMax;
                            }
                            points.Add(new Vector2(px, py));
                            points.Add(new Vector2(px, bounds.yMax));
                        }
                    }
                    else if ((rightCheck & BoundsCheck.BOTTOM) != 0)
                    {
                        py = bounds.yMax;
                        if ((newCheck & BoundsCheck.RIGHT) != 0)
                        {
                            px = bounds.xMax;
                            points.Add(new Vector2(px, py));
                        }
                        else if ((newCheck & BoundsCheck.LEFT) != 0)
                        {
                            px = bounds.xMin;
                            points.Add(new Vector2(px, py));
                        }
                        else if ((newCheck & BoundsCheck.TOP) != 0)
                        {
                            if (rightPoint.x - bounds.x + newPoint.x - bounds.x < bounds.width)
                            {
                                px = bounds.xMin;
                            }
                            else
                            {
                                px = bounds.xMax;
                            }
                            points.Add(new Vector2(px, py));
                            points.Add(new Vector2(px, bounds.yMin));
                        }
                    }
                }
                if (closingUp)
                {
                    // newEdge's ends have already been added
                    return;
                }
                points.Add(newPoint);
            }
            if (newEdge.clippedEnds [SideHelper.Other(newOrientation)] == null)
            {
                Debug.LogError("XXX: Null detected when there should be a Vector2!");
            }
            Vector2 newRightPoint = (Vector2)newEdge.clippedEnds [SideHelper.Other(newOrientation)];

            if (!CloseEnough(points [0], newRightPoint))
            {
                points.Add(newRightPoint);
            }
        }
Esempio n. 10
0
        private void FortunesAlgorithm()
        {
            Site     newSite, bottomSite, topSite, tempSite;
            Vertex   v, vertex;
            Vector2  newintstar = Vector2.zero;            //Because the compiler doesn't know that it will have a value - Julian
            Side     leftRight;
            Halfedge lbnd, rbnd, llbnd, rrbnd, bisector;
            Edge     edge;

            Rect dataBounds = _sites.GetSitesBounds();

            int sqrt_nsites            = (int)(Mathf.Sqrt(_sites.Count + 4));
            HalfedgePriorityQueue heap = new HalfedgePriorityQueue(dataBounds.y, dataBounds.height, sqrt_nsites);
            EdgeList        edgeList   = new EdgeList(dataBounds.x, dataBounds.width, sqrt_nsites);
            List <Halfedge> halfEdges  = new List <Halfedge> ();
            List <Vertex>   vertices   = new List <Vertex> ();

            fortunesAlgorithm_bottomMostSite = _sites.Next();
            newSite = _sites.Next();

            for (;;)
            {
                if (heap.Empty() == false)
                {
                    newintstar = heap.Min();
                }

                if (newSite != null &&
                    (heap.Empty() || CompareByYThenX(newSite, newintstar) < 0))
                {
                    /* new site is smallest */
                    //trace("smallest: new site " + newSite);

                    // Step 8:
                    lbnd = edgeList.EdgeListLeftNeighbor(newSite.Coord);                // the Halfedge just to the left of newSite
                    //trace("lbnd: " + lbnd);
                    rbnd = lbnd.edgeListRightNeighbor;                                  // the Halfedge just to the right
                    //trace("rbnd: " + rbnd);
                    bottomSite = FortunesAlgorithm_rightRegion(lbnd);                   // this is the same as leftRegion(rbnd)
                    // this Site determines the region containing the new site
                    //trace("new Site is in region of existing site: " + bottomSite);

                    // Step 9:
                    edge = Edge.CreateBisectingEdge(bottomSite, newSite);
                    //trace("new edge: " + edge);
                    _edges.Add(edge);

                    bisector = Halfedge.Create(edge, Side.LEFT);
                    halfEdges.Add(bisector);
                    // inserting two Halfedges into edgeList constitutes Step 10:
                    // insert bisector to the right of lbnd:
                    edgeList.Insert(lbnd, bisector);

                    // first half of Step 11:
                    if ((vertex = Vertex.Intersect(lbnd, bisector)) != null)
                    {
                        vertices.Add(vertex);
                        heap.Remove(lbnd);
                        lbnd.vertex = vertex;
                        lbnd.ystar  = vertex.y + newSite.Dist(vertex);
                        heap.Insert(lbnd);
                    }

                    lbnd     = bisector;
                    bisector = Halfedge.Create(edge, Side.RIGHT);
                    halfEdges.Add(bisector);
                    // second Halfedge for Step 10:
                    // insert bisector to the right of lbnd:
                    edgeList.Insert(lbnd, bisector);

                    // second half of Step 11:
                    if ((vertex = Vertex.Intersect(bisector, rbnd)) != null)
                    {
                        vertices.Add(vertex);
                        bisector.vertex = vertex;
                        bisector.ystar  = vertex.y + newSite.Dist(vertex);
                        heap.Insert(bisector);
                    }

                    newSite = _sites.Next();
                }
                else if (heap.Empty() == false)
                {
                    /* intersection is smallest */
                    lbnd       = heap.ExtractMin();
                    llbnd      = lbnd.edgeListLeftNeighbor;
                    rbnd       = lbnd.edgeListRightNeighbor;
                    rrbnd      = rbnd.edgeListRightNeighbor;
                    bottomSite = FortunesAlgorithm_leftRegion(lbnd);
                    topSite    = FortunesAlgorithm_rightRegion(rbnd);
                    // these three sites define a Delaunay triangle
                    // (not actually using these for anything...)
                    // ******ADDED******
                    _triangles.Add(new Triangle(bottomSite, topSite, FortunesAlgorithm_rightRegion(lbnd)));

                    v = lbnd.vertex;
                    v.SetIndex();
                    lbnd.edge.SetVertex((Side)lbnd.leftRight, v);
                    rbnd.edge.SetVertex((Side)rbnd.leftRight, v);
                    edgeList.Remove(lbnd);
                    heap.Remove(rbnd);
                    edgeList.Remove(rbnd);
                    leftRight = Side.LEFT;
                    if (bottomSite.y > topSite.y)
                    {
                        tempSite   = bottomSite;
                        bottomSite = topSite;
                        topSite    = tempSite;
                        leftRight  = Side.RIGHT;
                    }
                    edge = Edge.CreateBisectingEdge(bottomSite, topSite);
                    _edges.Add(edge);
                    bisector = Halfedge.Create(edge, leftRight);
                    halfEdges.Add(bisector);
                    edgeList.Insert(llbnd, bisector);
                    edge.SetVertex(SideHelper.Other(leftRight), v);
                    if ((vertex = Vertex.Intersect(llbnd, bisector)) != null)
                    {
                        vertices.Add(vertex);
                        heap.Remove(llbnd);
                        llbnd.vertex = vertex;
                        llbnd.ystar  = vertex.y + bottomSite.Dist(vertex);
                        heap.Insert(llbnd);
                    }
                    if ((vertex = Vertex.Intersect(bisector, rrbnd)) != null)
                    {
                        vertices.Add(vertex);
                        bisector.vertex = vertex;
                        bisector.ystar  = vertex.y + bottomSite.Dist(vertex);
                        heap.Insert(bisector);
                    }
                }
                else
                {
                    break;
                }
            }

            // heap should be empty now
            heap.Dispose();
            edgeList.Dispose();

            for (int hIndex = 0; hIndex < halfEdges.Count; hIndex++)
            {
                Halfedge halfEdge = halfEdges [hIndex];
                halfEdge.ReallyDispose();
            }
            halfEdges.Clear();

            // we need the vertices to clip the edges
            for (int eIndex = 0; eIndex < _edges.Count; eIndex++)
            {
                edge = _edges [eIndex];
                edge.ClipVertices(_plotBounds);
            }
            // but we don't actually ever use them again!
            for (int vIndex = 0; vIndex < vertices.Count; vIndex++)
            {
                vertex = vertices [vIndex];
                vertex.Dispose();
            }
            vertices.Clear();
        }
Esempio n. 11
0
        private void FortunesAlgorithm()
        {
            Vertex vertex;
            var    newintstar = default(Point);
            Edge   edge;

            var dataBounds = _sites.GetSitesBounds();

            var sqrtNsites = (int)Math.Sqrt(_sites.Count + 4);
            var heap       = new HalfEdgePriorityQueue(dataBounds.Y, dataBounds.Height, sqrtNsites);
            var edgeList   = new EdgeList(dataBounds.X, dataBounds.Width, sqrtNsites);
            var halfEdges  = new List <HalfEdge>();
            var vertices   = new List <Vertex>();

            _fortunesAlgorithmBottomMostSite = _sites.Next();
            var newSite = _sites.Next();

            for (;;)
            {
                if (heap.Empty() == false)
                {
                    newintstar = heap.Min();
                }

                Site     bottomSite;
                HalfEdge lbnd;
                HalfEdge rbnd;
                HalfEdge bisector;
                if (newSite != null &&
                    (heap.Empty() || CompareByYThenX(newSite, newintstar) < 0))
                {
                    /* new site is smallest */
                    //trace("smallest: new site " + newSite);

                    // Step 8:
                    lbnd = edgeList.EdgeListLeftNeighbor(newSite.Coord); // the Halfedge just to the left of newSite
                    //trace("lbnd: " + lbnd);
                    rbnd = lbnd.EdgeListRightNeighbor;                   // the Halfedge just to the right
                    //trace("rbnd: " + rbnd);
                    bottomSite = FortunesAlgorithm_rightRegion(lbnd);    // this is the same as leftRegion(rbnd)
                    // this Site determines the region containing the new site
                    //trace("new Site is in region of existing site: " + bottomSite);

                    // Step 9:
                    edge = Edge.CreateBisectingEdge(bottomSite, newSite);
                    //trace("new edge: " + edge);
                    _edges.Add(edge);

                    bisector = HalfEdge.Create(edge, Side.Left);
                    halfEdges.Add(bisector);
                    // inserting two Halfedges into edgeList constitutes Step 10:
                    // insert bisector to the right of lbnd:
                    edgeList.Insert(lbnd, bisector);

                    // first half of Step 11:
                    if ((vertex = Vertex.Intersect(lbnd, bisector)) != null)
                    {
                        vertices.Add(vertex);
                        heap.Remove(lbnd);
                        lbnd.Vertex = vertex;
                        lbnd.Ystar  = vertex.Y + newSite.Dist(vertex);
                        heap.Insert(lbnd);
                    }

                    lbnd     = bisector;
                    bisector = HalfEdge.Create(edge, Side.Right);
                    halfEdges.Add(bisector);
                    // second Halfedge for Step 10:
                    // insert bisector to the right of lbnd:
                    edgeList.Insert(lbnd, bisector);

                    // second half of Step 11:
                    if ((vertex = Vertex.Intersect(bisector, rbnd)) != null)
                    {
                        vertices.Add(vertex);
                        bisector.Vertex = vertex;
                        bisector.Ystar  = vertex.Y + newSite.Dist(vertex);
                        heap.Insert(bisector);
                    }

                    newSite = _sites.Next();
                }
                else if (heap.Empty() == false)
                {
                    /* intersection is smallest */
                    lbnd = heap.ExtractMin();
                    var llbnd = lbnd.EdgeListLeftNeighbor;
                    rbnd = lbnd.EdgeListRightNeighbor;
                    var rrbnd = rbnd.EdgeListRightNeighbor;
                    bottomSite = FortunesAlgorithm_leftRegion(lbnd);
                    var topSite = FortunesAlgorithm_rightRegion(rbnd);
                    // these three sites define a Delaunay triangle
                    // (not actually using these for anything...)
                    //_triangles.push(new Triangle(bottomSite, topSite, rightRegion(lbnd)));

                    var v = lbnd.Vertex;
                    v.SetIndex();
                    lbnd.Edge.SetVertex((Side)lbnd.LeftRight, v);
                    rbnd.Edge.SetVertex((Side)rbnd.LeftRight, v);
                    edgeList.Remove(lbnd);
                    heap.Remove(rbnd);
                    edgeList.Remove(rbnd);
                    var leftRight = Side.Left;
                    if (bottomSite.Y > topSite.Y)
                    {
                        var tempSite = bottomSite;
                        bottomSite = topSite;
                        topSite    = tempSite;
                        leftRight  = Side.Right;
                    }
                    edge = Edge.CreateBisectingEdge(bottomSite, topSite);
                    _edges.Add(edge);
                    bisector = HalfEdge.Create(edge, leftRight);
                    halfEdges.Add(bisector);
                    edgeList.Insert(llbnd, bisector);
                    edge.SetVertex(SideHelper.Other(leftRight), v);
                    if ((vertex = Vertex.Intersect(llbnd, bisector)) != null)
                    {
                        vertices.Add(vertex);
                        heap.Remove(llbnd);
                        llbnd.Vertex = vertex;
                        llbnd.Ystar  = vertex.Y + bottomSite.Dist(vertex);
                        heap.Insert(llbnd);
                    }
                    if ((vertex = Vertex.Intersect(bisector, rrbnd)) != null)
                    {
                        vertices.Add(vertex);
                        bisector.Vertex = vertex;
                        bisector.Ystar  = vertex.Y + bottomSite.Dist(vertex);
                        heap.Insert(bisector);
                    }
                }
                else
                {
                    break;
                }
            }

            // heap should be empty now
            heap.Dispose();
            edgeList.Dispose();

            foreach (var halfEdge in halfEdges)
            {
                halfEdge.ReallyDispose();
            }
            halfEdges.Clear();

            // we need the vertices to clip the edges
            foreach (Edge t in _edges)
            {
                edge = t;
                edge.ClipVertices(PlotBounds);
            }
            // but we don't actually ever use them again!
            foreach (Vertex t in vertices)
            {
                vertex = t;
                vertex.Dispose();
            }
            vertices.Clear();
        }
Esempio n. 12
0
        private void FortunesAlgorithm()
        {
            Vector2 s           = Vector2.zero;
            Rect    sitesBounds = _sites.GetSitesBounds();
            int     sqrt_nsites = (int)Mathf.Sqrt(_sites.Count + 4);
            HalfedgePriorityQueue halfedgePriorityQueue = new HalfedgePriorityQueue(sitesBounds.y, sitesBounds.height, sqrt_nsites);
            EdgeList        edgeList = new EdgeList(sitesBounds.x, sitesBounds.width, sqrt_nsites);
            List <Halfedge> list     = new List <Halfedge>();
            List <Vertex>   list2    = new List <Vertex>();

            fortunesAlgorithm_bottomMostSite = _sites.Next();
            Site site = _sites.Next();

            while (true)
            {
                if (!halfedgePriorityQueue.Empty())
                {
                    s = halfedgePriorityQueue.Min();
                }
                if (site != null && (halfedgePriorityQueue.Empty() || CompareByYThenX(site, s) < 0))
                {
                    Halfedge halfedge = edgeList.EdgeListLeftNeighbor(site.Coord);
                    Halfedge edgeListRightNeighbor = halfedge.edgeListRightNeighbor;
                    Site     site2 = FortunesAlgorithm_rightRegion(halfedge);
                    Edge     edge  = Edge.CreateBisectingEdge(site2, site);
                    _edges.Add(edge);
                    Halfedge halfedge2 = Halfedge.Create(edge, Side.LEFT);
                    list.Add(halfedge2);
                    edgeList.Insert(halfedge, halfedge2);
                    Vertex vertex;
                    if ((vertex = Vertex.Intersect(halfedge, halfedge2)) != null)
                    {
                        list2.Add(vertex);
                        halfedgePriorityQueue.Remove(halfedge);
                        halfedge.vertex = vertex;
                        halfedge.ystar  = vertex.y + site.Dist(vertex);
                        halfedgePriorityQueue.Insert(halfedge);
                    }
                    halfedge  = halfedge2;
                    halfedge2 = Halfedge.Create(edge, Side.RIGHT);
                    list.Add(halfedge2);
                    edgeList.Insert(halfedge, halfedge2);
                    if ((vertex = Vertex.Intersect(halfedge2, edgeListRightNeighbor)) != null)
                    {
                        list2.Add(vertex);
                        halfedge2.vertex = vertex;
                        halfedge2.ystar  = vertex.y + site.Dist(vertex);
                        halfedgePriorityQueue.Insert(halfedge2);
                    }
                    site = _sites.Next();
                    continue;
                }
                if (!halfedgePriorityQueue.Empty())
                {
                    Halfedge halfedge               = halfedgePriorityQueue.ExtractMin();
                    Halfedge edgeListLeftNeighbor   = halfedge.edgeListLeftNeighbor;
                    Halfedge edgeListRightNeighbor  = halfedge.edgeListRightNeighbor;
                    Halfedge edgeListRightNeighbor2 = edgeListRightNeighbor.edgeListRightNeighbor;
                    Site     site2 = FortunesAlgorithm_leftRegion(halfedge);
                    Site     site3 = FortunesAlgorithm_rightRegion(edgeListRightNeighbor);
                    _triangles.Add(new Triangle(site2, site3, FortunesAlgorithm_rightRegion(halfedge)));
                    Vertex vertex2 = halfedge.vertex;
                    vertex2.SetIndex();
                    Edge edge2     = halfedge.edge;
                    Side?leftRight = halfedge.leftRight;
                    edge2.SetVertex(leftRight.Value, vertex2);
                    Edge edge3      = edgeListRightNeighbor.edge;
                    Side?leftRight2 = edgeListRightNeighbor.leftRight;
                    edge3.SetVertex(leftRight2.Value, vertex2);
                    edgeList.Remove(halfedge);
                    halfedgePriorityQueue.Remove(edgeListRightNeighbor);
                    edgeList.Remove(edgeListRightNeighbor);
                    Side side = Side.LEFT;
                    if (site2.y > site3.y)
                    {
                        Site site4 = site2;
                        site2 = site3;
                        site3 = site4;
                        side  = Side.RIGHT;
                    }
                    Edge edge = Edge.CreateBisectingEdge(site2, site3);
                    _edges.Add(edge);
                    Halfedge halfedge2 = Halfedge.Create(edge, side);
                    list.Add(halfedge2);
                    edgeList.Insert(edgeListLeftNeighbor, halfedge2);
                    edge.SetVertex(SideHelper.Other(side), vertex2);
                    Vertex vertex;
                    if ((vertex = Vertex.Intersect(edgeListLeftNeighbor, halfedge2)) != null)
                    {
                        list2.Add(vertex);
                        halfedgePriorityQueue.Remove(edgeListLeftNeighbor);
                        edgeListLeftNeighbor.vertex = vertex;
                        edgeListLeftNeighbor.ystar  = vertex.y + site2.Dist(vertex);
                        halfedgePriorityQueue.Insert(edgeListLeftNeighbor);
                    }
                    if ((vertex = Vertex.Intersect(halfedge2, edgeListRightNeighbor2)) != null)
                    {
                        list2.Add(vertex);
                        halfedge2.vertex = vertex;
                        halfedge2.ystar  = vertex.y + site2.Dist(vertex);
                        halfedgePriorityQueue.Insert(halfedge2);
                    }
                    continue;
                }
                break;
            }
            halfedgePriorityQueue.Dispose();
            edgeList.Dispose();
            for (int i = 0; i < list.Count; i++)
            {
                Halfedge halfedge3 = list[i];
                halfedge3.ReallyDispose();
            }
            list.Clear();
            for (int j = 0; j < _edges.Count; j++)
            {
                Edge edge = _edges[j];
                edge.ClipVertices(_plotBounds);
            }
            for (int k = 0; k < list2.Count; k++)
            {
                Vertex vertex = list2[k];
                vertex.Dispose();
            }
            list2.Clear();
        }
        private void Connect(List <Point> points, int j, Rect bounds, bool closingUp = false)
        {
            Point rightPoint     = points[points.Count - 1];
            Edge  newEdge        = _edges[j] as Edge;
            Side  newOrientation = _edgeOrientations[j];

            // the point that  must be connected to rightPoint:
            if (newEdge.clippedEnds[newOrientation] == null)
            {
                Debug.WriteLine("XXX: Null detected when there should be a Point!", "Error");
            }
            Point newPoint = (Point)newEdge.clippedEnds[newOrientation];

            if (!CloseEnough(rightPoint, newPoint))
            {
                // The points do not coincide, so they must have been clipped at the bounds;
                // see if they are on the same border of the bounds:
                if (rightPoint.X != newPoint.X &&
                    rightPoint.Y != newPoint.Y)
                {
                    // They are on different borders of the bounds;
                    // insert one or two corners of bounds as needed to hook them up:
                    // (NOTE this will not be correct if the region should take up more than
                    // half of the bounds rect, for then we will have gone the wrong way
                    // around the bounds and included the smaller part rather than the larger)
                    int    rightCheck = BoundsCheck.Check(rightPoint, bounds);
                    int    newCheck = BoundsCheck.Check(newPoint, bounds);
                    double px, py;
                    if ((rightCheck & BoundsCheck.RIGHT) != 0)
                    {
                        px = bounds.Right;
                        if ((newCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            py = bounds.Bottom;
                            points.Add(new Point(px, py));
                        }
                        else if ((newCheck & BoundsCheck.TOP) != 0)
                        {
                            py = bounds.Top;
                            points.Add(new Point(px, py));
                        }
                        else if ((newCheck & BoundsCheck.LEFT) != 0)
                        {
                            if (rightPoint.Y - bounds.Y + newPoint.Y - bounds.Y < bounds.Height)
                            {
                                py = bounds.Top;
                            }
                            else
                            {
                                py = bounds.Bottom;
                            }
                            points.Add(new Point(px, py));
                            points.Add(new Point(bounds.Left, py));
                        }
                    }
                    else if ((rightCheck & BoundsCheck.LEFT) != 0)
                    {
                        px = bounds.Left;
                        if ((newCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            py = bounds.Bottom;
                            points.Add(new Point(px, py));
                        }
                        else if ((newCheck & BoundsCheck.TOP) != 0)
                        {
                            py = bounds.Top;
                            points.Add(new Point(px, py));
                        }
                        else if ((newCheck & BoundsCheck.RIGHT) != 0)
                        {
                            if (rightPoint.Y - bounds.Y + newPoint.Y - bounds.Y < bounds.Height)
                            {
                                py = bounds.Top;
                            }
                            else
                            {
                                py = bounds.Bottom;
                            }
                            points.Add(new Point(px, py));
                            points.Add(new Point(bounds.Right, py));
                        }
                    }
                    else if ((rightCheck & BoundsCheck.TOP) != 0)
                    {
                        py = bounds.Top;
                        if ((newCheck & BoundsCheck.RIGHT) != 0)
                        {
                            px = bounds.Right;
                            points.Add(new Point(px, py));
                        }
                        else if ((newCheck & BoundsCheck.LEFT) != 0)
                        {
                            px = bounds.Left;
                            points.Add(new Point(px, py));
                        }
                        else if ((newCheck & BoundsCheck.BOTTOM) != 0)
                        {
                            if (rightPoint.X - bounds.X + newPoint.X - bounds.X < bounds.Width)
                            {
                                px = bounds.Left;
                            }
                            else
                            {
                                px = bounds.Right;
                            }
                            points.Add(new Point(px, py));
                            points.Add(new Point(px, bounds.Bottom));
                        }
                    }
                    else if ((rightCheck & BoundsCheck.BOTTOM) != 0)
                    {
                        py = bounds.Bottom;
                        if ((newCheck & BoundsCheck.RIGHT) != 0)
                        {
                            px = bounds.Right;
                            points.Add(new Point(px, py));
                        }
                        else if ((newCheck & BoundsCheck.LEFT) != 0)
                        {
                            px = bounds.Left;
                            points.Add(new Point(px, py));
                        }
                        else if ((newCheck & BoundsCheck.TOP) != 0)
                        {
                            if (rightPoint.X - bounds.X + newPoint.X - bounds.X < bounds.Width)
                            {
                                px = bounds.Left;
                            }
                            else
                            {
                                px = bounds.Right;
                            }
                            points.Add(new Point(px, py));
                            points.Add(new Point(px, bounds.Top));
                        }
                    }
                }
                if (closingUp)
                {
                    // newEdge's ends have already been added
                    return;
                }
                points.Add(newPoint);
            }
            if (newEdge.clippedEnds[SideHelper.Other(newOrientation)] == null)
            {
                Debug.WriteLine("XXX: Null detected when there should be a Point!", "Error");
            }
            Point newRightPoint = (Point)newEdge.clippedEnds[SideHelper.Other(newOrientation)];

            if (!CloseEnough(points[0], newRightPoint))
            {
                points.Add(newRightPoint);
            }
        }
Esempio n. 14
0
        private void Connect(List <Vector2> points, int j, Rect bounds, bool closingUp = false)
        {
            Vector2 vector = points[points.Count - 1];
            Edge    edge   = _edges[j];
            Side    side   = _edgeOrientations[j];

            if (!edge.clippedEnds[side].HasValue)
            {
                UnityEngine.Debug.LogError("XXX: Null detected when there should be a Vector2!");
            }
            Vector2 value = edge.clippedEnds[side].Value;

            if (!CloseEnough(vector, value))
            {
                if (vector.x != value.x && vector.y != value.y)
                {
                    int num  = BoundsCheck.Check(vector, bounds);
                    int num2 = BoundsCheck.Check(value, bounds);
                    if ((num & BoundsCheck.RIGHT) != 0)
                    {
                        float xMax = bounds.xMax;
                        if ((num2 & BoundsCheck.BOTTOM) != 0)
                        {
                            float yMax = bounds.yMax;
                            points.Add(new Vector2(xMax, yMax));
                        }
                        else if ((num2 & BoundsCheck.TOP) != 0)
                        {
                            float yMax = bounds.yMin;
                            points.Add(new Vector2(xMax, yMax));
                        }
                        else if ((num2 & BoundsCheck.LEFT) != 0)
                        {
                            float yMax = (!(vector.y - bounds.y + value.y - bounds.y < bounds.height)) ? bounds.yMax : bounds.yMin;
                            points.Add(new Vector2(xMax, yMax));
                            points.Add(new Vector2(bounds.xMin, yMax));
                        }
                    }
                    else if ((num & BoundsCheck.LEFT) != 0)
                    {
                        float xMax = bounds.xMin;
                        if ((num2 & BoundsCheck.BOTTOM) != 0)
                        {
                            float yMax = bounds.yMax;
                            points.Add(new Vector2(xMax, yMax));
                        }
                        else if ((num2 & BoundsCheck.TOP) != 0)
                        {
                            float yMax = bounds.yMin;
                            points.Add(new Vector2(xMax, yMax));
                        }
                        else if ((num2 & BoundsCheck.RIGHT) != 0)
                        {
                            float yMax = (!(vector.y - bounds.y + value.y - bounds.y < bounds.height)) ? bounds.yMax : bounds.yMin;
                            points.Add(new Vector2(xMax, yMax));
                            points.Add(new Vector2(bounds.xMax, yMax));
                        }
                    }
                    else if ((num & BoundsCheck.TOP) != 0)
                    {
                        float yMax = bounds.yMin;
                        if ((num2 & BoundsCheck.RIGHT) != 0)
                        {
                            float xMax = bounds.xMax;
                            points.Add(new Vector2(xMax, yMax));
                        }
                        else if ((num2 & BoundsCheck.LEFT) != 0)
                        {
                            float xMax = bounds.xMin;
                            points.Add(new Vector2(xMax, yMax));
                        }
                        else if ((num2 & BoundsCheck.BOTTOM) != 0)
                        {
                            float xMax = (!(vector.x - bounds.x + value.x - bounds.x < bounds.width)) ? bounds.xMax : bounds.xMin;
                            points.Add(new Vector2(xMax, yMax));
                            points.Add(new Vector2(xMax, bounds.yMax));
                        }
                    }
                    else if ((num & BoundsCheck.BOTTOM) != 0)
                    {
                        float yMax = bounds.yMax;
                        if ((num2 & BoundsCheck.RIGHT) != 0)
                        {
                            float xMax = bounds.xMax;
                            points.Add(new Vector2(xMax, yMax));
                        }
                        else if ((num2 & BoundsCheck.LEFT) != 0)
                        {
                            float xMax = bounds.xMin;
                            points.Add(new Vector2(xMax, yMax));
                        }
                        else if ((num2 & BoundsCheck.TOP) != 0)
                        {
                            float xMax = (!(vector.x - bounds.x + value.x - bounds.x < bounds.width)) ? bounds.xMax : bounds.xMin;
                            points.Add(new Vector2(xMax, yMax));
                            points.Add(new Vector2(xMax, bounds.yMin));
                        }
                    }
                }
                if (closingUp)
                {
                    return;
                }
                points.Add(value);
            }
            if (!edge.clippedEnds[SideHelper.Other(side)].HasValue)
            {
                UnityEngine.Debug.LogError("XXX: Null detected when there should be a Vector2!");
            }
            Vector2 value2 = edge.clippedEnds[SideHelper.Other(side)].Value;

            if (!CloseEnough(points[0], value2))
            {
                points.Add(value2);
            }
        }