Example #1
0
        internal SkeletonEventResult Handle_Edge_Event(_EdgeEvent egdeEvent)
        {
            var sinks  = new List <Vector2>();
            var events = new List <IEvent>();


            var lav = egdeEvent.vertex_a.Vertices;

            if (egdeEvent.vertex_a.Previous == egdeEvent.vertex_b.Next)
            {
                //Debug.WriteLine("{0} Peak event at intersection {1} from <{2},{3},{4}> in {5}", egdeEvent.Distance, egdeEvent.IntersectionPoint, egdeEvent.vertex_a, egdeEvent.vertex_b, egdeEvent.vertex_a.Previous, lav);

                this.Remove(lav);

                foreach (var vertex in lav)
                {
                    sinks.Add(vertex.Point);
                    vertex.Invalidate();
                }
            }
            else
            {
                // Debug.WriteLine("{0} Edge event at intersection {1} from <{2},{3}> in {4}", egdeEvent.Distance, egdeEvent.IntersectionPoint, egdeEvent.vertex_a, egdeEvent.vertex_b, lav);
                var new_vertex = lav.Unify(egdeEvent.vertex_a, egdeEvent.vertex_b, egdeEvent.IntersectionPoint);
                if ((new List <SkeletonVertex>()
                {
                    egdeEvent.vertex_a, egdeEvent.vertex_b
                }).Contains(lav.Head))
                {
                    lav.Head = new_vertex;
                }
                sinks.AddRange(new[] { egdeEvent.vertex_a.Point, egdeEvent.vertex_b.Point });
                var next_event = new_vertex.NextEvent(lav._originalEdges);
                if (next_event != null)
                {
                    events.Add(next_event);
                }
            }

            return(new SkeletonEventResult(new SkeletonSubtree(egdeEvent.IntersectionPoint, egdeEvent.Distance, sinks), events));
        }
        internal void Siftdown(int startpos, int pos)
        {
            var         item        = _heap[pos];
            _EdgeEvent  itemAsEdge  = null;
            _SplitEvent itemAsSplit = null;

            if (item is _EdgeEvent)
            {
                itemAsEdge = item as _EdgeEvent;
            }
            else if (item is _SplitEvent)
            {
                itemAsSplit = item as _SplitEvent;
            }

            while (pos > startpos)
            {
                var         parentpos     = (pos - 1) >> 1;
                var         parent        = _heap[parentpos];
                _EdgeEvent  parentAsEdge  = null;
                _SplitEvent parentAsSplit = null;

                if (parent is _EdgeEvent)
                {
                    parentAsEdge = parent as _EdgeEvent;
                }
                else if (parent is _SplitEvent)
                {
                    parentAsSplit = parent as _SplitEvent;
                }

                if (itemAsEdge != null)
                {
                    if (parentAsEdge != null)
                    {
                        if (itemAsEdge.Distance < parentAsEdge.Distance)
                        {
                            _heap[pos] = parent;
                            pos        = parentpos;
                            continue;
                        }
                    }
                    else if (parentAsSplit != null)
                    {
                        if (itemAsEdge.Distance < parentAsSplit.Distance)
                        {
                            _heap[pos] = parent;
                            pos        = parentpos;
                            continue;
                        }
                    }
                }
                else if (itemAsSplit != null)
                {
                    if (parentAsEdge != null)
                    {
                        if (itemAsSplit.Distance < parentAsEdge.Distance)
                        {
                            _heap[pos] = parent;
                            pos        = parentpos;
                            continue;
                        }
                    }
                    else if (parentAsSplit != null)
                    {
                        if (itemAsSplit.Distance < parentAsSplit.Distance)
                        {
                            _heap[pos] = parent;
                            pos        = parentpos;
                            continue;
                        }
                    }
                }

                break;
            }
            _heap[pos] = item;
        }
        void SiftUp(int pos)
        {
            var endpos   = this._heap.Length;
            var startpos = pos;
            var newitem  = _heap[pos];
            var childpos = 2 * pos + 1;    // leftmost child position

            while (childpos < endpos)
            {
                var cmd_gt   = false;
                var rightpos = childpos + 1;
                if (rightpos < endpos)
                {
                    _EdgeEvent  rightItemAsEdge  = null;
                    _SplitEvent rightItemAsSplit = null;
                    if (this._heap[rightpos] is _EdgeEvent)
                    {
                        rightItemAsEdge = this._heap[rightpos] as _EdgeEvent;
                    }
                    else if (this._heap[rightpos] is _SplitEvent)
                    {
                        rightItemAsSplit = this._heap[rightpos] as _SplitEvent;
                    }

                    _EdgeEvent  childItemAsEdge  = null;
                    _SplitEvent childItemAsSplit = null;
                    if (this._heap[childpos] is _EdgeEvent)
                    {
                        childItemAsEdge = this._heap[childpos] as _EdgeEvent;
                    }
                    else if (this._heap[rightpos] is _SplitEvent)
                    {
                        childItemAsSplit = this._heap[childpos] as _SplitEvent;
                    }


                    if (rightItemAsEdge != null)
                    {
                        if (childItemAsEdge != null)
                        {
                            if (childItemAsEdge.Distance >= rightItemAsEdge.Distance)
                            {
                                cmd_gt = true;
                            }
                        }
                        else if (childItemAsSplit != null)
                        {
                            if (childItemAsSplit.Distance >= rightItemAsEdge.Distance)
                            {
                                cmd_gt = true;
                            }
                        }
                    }
                    else if (rightItemAsSplit != null)
                    {
                        if (childItemAsEdge != null)
                        {
                            if (childItemAsEdge.Distance >= rightItemAsSplit.Distance)
                            {
                                cmd_gt = true;
                            }
                        }
                        else if (childItemAsSplit != null)
                        {
                            if (childItemAsSplit.Distance >= rightItemAsSplit.Distance)
                            {
                                cmd_gt = true;
                            }
                        }
                    }
                }
                if (cmd_gt)
                {
                    childpos = rightpos;
                }


                this._heap[pos] = this._heap[childpos];
                pos             = childpos;
                childpos        = 2 * pos + 1;
            }
            this._heap[pos] = newitem;
            Siftdown(startpos, pos);
        }