示例#1
0
        public void InsertEdge(HBEdge edge)
        {
            edge.Vertex = this;

            if (Edge == null)
            {
                Edge = edge;
            }
            else if (EdgeCount == 1)
            {
                Edge.Next = edge.Opposite;
                edge.Opposite.Previous = Edge;
                edge.Next = Edge.Opposite;
                Edge.Opposite.Previous = edge;
            }
            else
            {
                var last = Edge;
                foreach (var e in EnumerateEdges())
                {
                    last = e;
                }

                edge.Next = Edge.Opposite;
                Edge.Opposite.Previous = edge;

                edge.Opposite.Previous = last;
                last.Next = edge.Opposite;
            }
        }
示例#2
0
        public IEnumerable <HBEdge> EnumerateEdges(bool ccw = true)
        {
            HBEdge start = Edge;
            HBEdge e     = start;

            do
            {
                if (e == null)
                {
                    yield break;
                }
                yield return(e);

                if (ccw)
                {
                    if (e.Next == null)
                    {
                        yield break;
                    }
                    e = e.Next.Opposite;
                }
                else
                {
                    if (e.Opposite == null)
                    {
                        yield break;
                    }
                    e = e.Opposite.Previous;
                }
            }while (!ReferenceEquals(start, e));
        }
示例#3
0
文件: HBEdge.cs 项目: andybak/CGAL
 public void Set(HBVertex vertex, HBFace face, HBEdge previous, HBEdge next, HBEdge opposite)
 {
     Vertex   = vertex;
     Face     = face;
     Previous = previous;
     Next     = next;
     Opposite = opposite;
 }
示例#4
0
文件: HBMesh.cs 项目: andybak/CGAL
        public int IndexOf(HBEdge edge)
        {
            EDGE e = edge as EDGE;

            if (e == null)
            {
                return(-1);
            }
            return(Edges.IndexOf(e));
        }
示例#5
0
        public void InsertEdgeByAngle(HBEdge edge)
        {
            edge.Vertex = this;

            if (Edge == null)
            {
                Edge = edge;
            }
            else if (EdgeCount == 1)
            {
                Edge.Next = edge.Opposite;
                edge.Opposite.Previous = Edge;
                edge.Next = Edge.Opposite;
                Edge.Opposite.Previous = edge;
            }
            else
            {
                var   p0       = Edge.Opposite.GetVertex <HBVertex2f>().Position - Position;
                var   p1       = edge.Opposite.GetVertex <HBVertex2f>().Position - Position;
                float a01      = Vector2f.Angle360(p0, p1);
                var   previous = Edge;

                foreach (var e in EnumerateEdges())
                {
                    var   p2  = e.Opposite.GetVertex <HBVertex2f>().Position - Position;
                    float a02 = Vector2f.Angle360(p0, p2);

                    if (a01 <= a02)
                    {
                        edge.Next           = e.Opposite;
                        e.Opposite.Previous = edge;

                        edge.Opposite.Previous = previous;
                        previous.Next          = edge.Opposite;
                        return;
                    }

                    previous = e;
                }

                edge.Next = Edge.Opposite;
                Edge.Opposite.Previous = edge;

                edge.Opposite.Previous = previous;
                previous.Next          = edge.Opposite;
            }
        }
示例#6
0
        private bool SetOppositeEdge(HBEdge edge, HBFace neighbor)
        {
            if (neighbor == null)
            {
                return(false);
            }

            if (edge == null)
            {
                throw new NullReferenceException("Edge is null.");
            }

            if (edge.Vertex == null)
            {
                throw new NullReferenceException("Edge has null vertex.");
            }

            if (neighbor.Edge == null)
            {
                throw new NullReferenceException("Neighbor has null edge.");
            }

            var v0 = edge.Vertex;
            var v1 = edge.Previous.Vertex;

            foreach (var nedge in neighbor.Edge.EnumerateEdges())
            {
                if (nedge.Vertex == null)
                {
                    throw new NullReferenceException("Neighbor edge has null vertex.");
                }

                if (ReferenceEquals(v0, nedge.Previous.Vertex) &&
                    ReferenceEquals(v1, nedge.Vertex))
                {
                    edge.Opposite  = nedge;
                    nedge.Opposite = edge;
                    return(true);
                }
            }

            return(false);
        }
示例#7
0
        public void RemoveEdge(HBEdge edge)
        {
            if (Edge == null)
            {
                return;
            }
            if (!ReferenceEquals(edge, Edge))
            {
                return;
            }

            HBEdge tmp = null;

            foreach (var e in EnumerateEdges())
            {
                if (!ReferenceEquals(edge, e))
                {
                    tmp = e;
                    break;
                }
            }

            Edge = tmp;
        }
示例#8
0
文件: HBEdge.cs 项目: andybak/CGAL
 public HBEdge(HBVertex vertex, HBFace face, HBEdge previous, HBEdge next, HBEdge opposite)
 {
     Set(vertex, face, previous, next, opposite);
 }