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  m_dir = aDir;
73  }
74 
76  DART( const DART& aDart )
77  {
78  m_edge = aDart.m_edge;
79  m_dir = aDart.m_dir;
80  }
81 
84  {
85  }
86 
88  DART& operator=( const DART& aDart )
89  {
90  if( this == &aDart )
91  return *this;
92 
93  m_edge = aDart.m_edge;
94  m_dir = aDart.m_dir;
95 
96  return *this;
97  }
98 
100  bool operator==( const DART& aDart ) const
101  {
102  return ( aDart.m_edge == m_edge && aDart.m_dir == m_dir );
103  }
104 
106  bool operator!=( const DART& aDart ) const
107  {
108  return !( aDart == *this );
109  }
110 
113  {
114  m_dir = !m_dir;
115  return *this;
116  }
117 
120  {
121  if( m_dir )
122  {
123  m_edge = m_edge->GetNextEdgeInFace()->GetNextEdgeInFace();
124  m_dir = false;
125  }
126  else
127  {
128  m_edge = m_edge->GetNextEdgeInFace();
129  m_dir = true;
130  }
131 
132  return *this;
133  }
134 
137  {
138  if( m_edge->GetTwinEdge() )
139  {
140  m_edge = m_edge->GetTwinEdge();
141  m_dir = !m_dir;
142  }
143 
144  // else, the dart is at the boundary and should not be changed
145  return *this;
146  }
147 
150  void Init( const EDGE_PTR& aEdge, bool aDir = true )
151  {
152  m_edge = aEdge;
153  m_dir = aDir;
154  }
155 
156  double X() const
157  {
158  return GetNode()->GetX();
159  }
160 
161  double Y() const
162  {
163  return GetNode()->GetY();
164  }
165 
166  bool IsCCW() const
167  {
168  return m_dir;
169  }
170 
171  const NODE_PTR& GetNode() const
172  {
173  return m_dir ? m_edge->GetSourceNode() : m_edge->GetTargetNode();
174  }
175 
176  const NODE_PTR& GetOppositeNode() const
177  {
178  return m_dir ? m_edge->GetTargetNode() : m_edge->GetSourceNode();
179  }
180 
182  {
183  return m_edge;
184  }
185 
187 };
188 
189 } // End of hed namespace
190 
191 #endif
const NODE_PTR & GetNode() const
Definition: hedart.h:171
~DART()
Destructor.
Definition: hedart.h:83
double Y() const
Definition: hedart.h:161
bool IsCCW() const
Definition: hedart.h:166
double X() const
Definition: hedart.h:156
DART & Alpha0()
Maps the dart to a different node.
Definition: hedart.h:112
std::shared_ptr< EDGE > EDGE_PTR
Definition: hetriang.h:73
void Init(const EDGE_PTR &aEdge, bool aDir=true)
Definition: hedart.h:150
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:106
const NODE_PTR & GetOppositeNode() const
Definition: hedart.h:176
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:71
DART & Alpha2()
Maps the dart to a different triangle. Note: the dart is not changed if it is at the boundary! ...
Definition: hedart.h:136
The half-edge data structure.
Definition: hedart.h:45
DART()
Default constructor.
Definition: hedart.h:63
EDGE_PTR & GetEdge()
Definition: hedart.h:181
bool operator==(const DART &aDart) const
Comparing dart objects.
Definition: hedart.h:100
DART(const DART &aDart)
Copy constructor.
Definition: hedart.h:76
EDGE_PTR m_edge
Definition: hedart.h:56
DART & operator=(const DART &aDart)
Assignment operator.
Definition: hedart.h:88
DART & Alpha1()
Maps the dart to a different edge.
Definition: hedart.h:119