KiCad PCB EDA Suite
hedart.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
3  * Applied Mathematics, Norway.
4  *
5  * Contact information: E-mail: tor.dokken@sintef.no
6  * SINTEF ICT, Department of Applied Mathematics,
7  * P.O. Box 124 Blindern,
8  * 0314 Oslo, Norway.
9  *
10  * This file is part of TTL.
11  *
12  * TTL is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Affero General Public License as
14  * published by the Free Software Foundation, either version 3 of the
15  * License, or (at your option) any later version.
16  *
17  * TTL is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Affero General Public License for more details.
21  *
22  * You should have received a copy of the GNU Affero General Public
23  * License along with TTL. If not, see
24  * <http://www.gnu.org/licenses/>.
25  *
26  * In accordance with Section 7(b) of the GNU Affero General Public
27  * License, a covered work must retain the producer line in every data
28  * file that is created or manipulated using TTL.
29  *
30  * Other Usage
31  * You can be released from the requirements of the license by purchasing
32  * a commercial license. Buying such a license is mandatory as soon as you
33  * develop commercial activities involving the TTL library without
34  * disclosing the source code of your own applications.
35  *
36  * This file may be used in accordance with the terms contained in a
37  * written agreement between you and SINTEF ICT.
38  */
39 
40 #ifndef _HALF_EDGE_DART_
41 #define _HALF_EDGE_DART_
42 
43 #include <ttl/halfedge/hetriang.h>
44 
45 namespace hed
46 {
54 class DART
55 {
57 
59  bool m_dir;
60 
61 public:
63  DART()
64  {
65  m_dir = true;
66  }
67 
69  DART( const EDGE_PTR& aEdge, bool aDir = true )
70  {
71  m_edge = aEdge;
72  assert ( m_edge );
73  m_dir = aDir;
74  }
75 
77  DART( const DART& aDart )
78  {
79  m_edge = aDart.m_edge;
80  assert ( m_edge );
81  m_dir = aDart.m_dir;
82  }
83 
86  {
87  }
88 
90  DART& operator=( const DART& aDart )
91  {
92  if( this == &aDart )
93  return *this;
94 
95  m_edge = aDart.m_edge;
96  assert ( m_edge );
97  m_dir = aDart.m_dir;
98 
99  return *this;
100  }
101 
103  bool operator==( const DART& aDart ) const
104  {
105  return ( aDart.m_edge == m_edge && aDart.m_dir == m_dir );
106  }
107 
109  bool operator!=( const DART& aDart ) const
110  {
111  return !( aDart == *this );
112  }
113 
116  {
117  m_dir = !m_dir;
118  return *this;
119  }
120 
123  {
124  if( m_dir )
125  {
126  m_edge = m_edge->GetNextEdgeInFace()->GetNextEdgeInFace();
127  assert ( m_edge );
128  m_dir = false;
129  }
130  else
131  {
132  m_edge = m_edge->GetNextEdgeInFace();
133  assert ( m_edge );
134  m_dir = true;
135  }
136 
137  return *this;
138  }
139 
142  {
143  if( m_edge->GetTwinEdge() )
144  {
145  m_edge = m_edge->GetTwinEdge();
146  assert ( m_edge );
147  m_dir = !m_dir;
148  }
149 
150  // else, the dart is at the boundary and should not be changed
151  return *this;
152  }
153 
156  void Init( const EDGE_PTR& aEdge, bool aDir = true )
157  {
158  m_edge = aEdge;
159  assert(m_edge);
160  m_dir = aDir;
161  }
162 
163  double X() const
164  {
165  return GetNode()->GetX();
166  }
167 
168  double Y() const
169  {
170  return GetNode()->GetY();
171  }
172 
173  bool IsCCW() const
174  {
175  return m_dir;
176  }
177 
178  const NODE_PTR& GetNode() const
179  {
180  return m_dir ? m_edge->GetSourceNode() : m_edge->GetTargetNode();
181  }
182 
183  const NODE_PTR& GetOppositeNode() const
184  {
185  return m_dir ? m_edge->GetTargetNode() : m_edge->GetSourceNode();
186  }
187 
189  {
190  return m_edge;
191  }
192 
194 };
195 
196 } // End of hed namespace
197 
198 #endif
const NODE_PTR & GetNode() const
Definition: hedart.h:178
~DART()
Destructor.
Definition: hedart.h:85
double Y() const
Definition: hedart.h:168
bool IsCCW() const
Definition: hedart.h:173
double X() const
Definition: hedart.h:163
DART & Alpha0()
Maps the dart to a different node.
Definition: hedart.h:115
std::shared_ptr< EDGE > EDGE_PTR
Definition: hetriang.h:75
void Init(const EDGE_PTR &aEdge, bool aDir=true)
Definition: hedart.h:156
DART(const EDGE_PTR &aEdge, bool aDir=true)
Constructor.
Definition: hedart.h:69
bool operator!=(const DART &aDart) const
Comparing dart objects.
Definition: hedart.h:109
const NODE_PTR & GetOppositeNode() const
Definition: hedart.h:183
bool m_dir
Dart direction: true if dart is counterclockwise in face.
Definition: hedart.h:59
std::shared_ptr< NODE > NODE_PTR
Definition: hetriang.h:73
DART & Alpha2()
Maps the dart to a different triangle. Note: the dart is not changed if it is at the boundary! ...
Definition: hedart.h:141
The half-edge data structure.
Definition: hedart.h:45
DART()
Default constructor.
Definition: hedart.h:63
EDGE_PTR & GetEdge()
Definition: hedart.h:188
bool operator==(const DART &aDart) const
Comparing dart objects.
Definition: hedart.h:103
DART(const DART &aDart)
Copy constructor.
Definition: hedart.h:77
EDGE_PTR m_edge
Definition: hedart.h:56
DART & operator=(const DART &aDart)
Assignment operator.
Definition: hedart.h:90
DART & Alpha1()
Maps the dart to a different edge.
Definition: hedart.h:122