kicad/include/ttl/halfedge/hedart.h

199 lines
4.5 KiB
C
Raw Normal View History

2013-11-25 15:50:03 +00:00
/*
* Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
* Applied Mathematics, Norway.
*
2017-03-22 13:43:10 +00:00
* Contact information: E-mail: tor.dokken@sintef.no
* SINTEF ICT, Department of Applied Mathematics,
* P.O. Box 124 Blindern,
* 0314 Oslo, Norway.
2013-11-25 15:50:03 +00:00
*
* This file is part of TTL.
*
* TTL is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
2017-03-22 13:43:10 +00:00
* License, or (at your option) any later version.
2013-11-25 15:50:03 +00:00
*
2017-03-22 13:43:10 +00:00
* TTL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2013-11-25 15:50:03 +00:00
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with TTL. If not, see
* <http://www.gnu.org/licenses/>.
*
* In accordance with Section 7(b) of the GNU Affero General Public
* License, a covered work must retain the producer line in every data
* file that is created or manipulated using TTL.
*
* Other Usage
* You can be released from the requirements of the license by purchasing
* a commercial license. Buying such a license is mandatory as soon as you
* develop commercial activities involving the TTL library without
* disclosing the source code of your own applications.
*
* This file may be used in accordance with the terms contained in a
2017-03-22 13:43:10 +00:00
* written agreement between you and SINTEF ICT.
2013-11-25 15:50:03 +00:00
*/
#ifndef _HALF_EDGE_DART_
#define _HALF_EDGE_DART_
#include <ttl/halfedge/hetriang.h>
namespace hed
{
/**
* \class Dart
* \brief \b %Dart class for the half-edge data structure.
*
* See \ref api for a detailed description of how the member functions
* should be implemented.
*/
class DART
{
EDGE_PTR m_edge;
2013-11-25 15:50:03 +00:00
/// Dart direction: true if dart is counterclockwise in face
bool m_dir;
2013-11-25 15:50:03 +00:00
public:
2013-11-25 15:50:03 +00:00
/// Default constructor
DART()
{
m_dir = true;
}
2013-11-25 15:50:03 +00:00
/// Constructor
DART( const EDGE_PTR& aEdge, bool aDir = true )
{
m_edge = aEdge;
2017-03-22 13:43:10 +00:00
assert ( m_edge );
m_dir = aDir;
}
2013-11-25 15:50:03 +00:00
/// Copy constructor
DART( const DART& aDart )
{
m_edge = aDart.m_edge;
2017-03-22 13:43:10 +00:00
assert ( m_edge );
m_dir = aDart.m_dir;
}
2013-11-25 15:50:03 +00:00
/// Destructor
~DART()
{
}
2013-11-25 15:50:03 +00:00
/// Assignment operator
DART& operator=( const DART& aDart )
{
if( this == &aDart )
return *this;
m_edge = aDart.m_edge;
2017-03-22 13:43:10 +00:00
assert ( m_edge );
m_dir = aDart.m_dir;
2013-11-25 15:50:03 +00:00
return *this;
}
/// Comparing dart objects
bool operator==( const DART& aDart ) const
{
return ( aDart.m_edge == m_edge && aDart.m_dir == m_dir );
2013-11-25 15:50:03 +00:00
}
/// Comparing dart objects
bool operator!=( const DART& aDart ) const
{
return !( aDart == *this );
2013-11-25 15:50:03 +00:00
}
/// Maps the dart to a different node
DART& Alpha0()
{
m_dir = !m_dir;
return *this;
}
2013-11-25 15:50:03 +00:00
/// Maps the dart to a different edge
DART& Alpha1()
{
if( m_dir )
{
m_edge = m_edge->GetNextEdgeInFace()->GetNextEdgeInFace();
2017-03-22 13:43:10 +00:00
assert ( m_edge );
m_dir = false;
}
else
{
m_edge = m_edge->GetNextEdgeInFace();
2017-03-22 13:43:10 +00:00
assert ( m_edge );
m_dir = true;
}
return *this;
2013-11-25 15:50:03 +00:00
}
/// Maps the dart to a different triangle. \b Note: the dart is not changed if it is at the boundary!
DART& Alpha2()
{
if( m_edge->GetTwinEdge() )
{
m_edge = m_edge->GetTwinEdge();
2017-03-22 13:43:10 +00:00
assert ( m_edge );
m_dir = !m_dir;
}
// else, the dart is at the boundary and should not be changed
return *this;
2013-11-25 15:50:03 +00:00
}
/** @name Utilities not required by TTL */
//@{
void Init( const EDGE_PTR& aEdge, bool aDir = true )
{
m_edge = aEdge;
2017-03-22 13:43:10 +00:00
assert(m_edge);
m_dir = aDir;
}
2013-11-25 15:50:03 +00:00
double X() const
{
return GetNode()->GetX();
}
2013-11-25 15:50:03 +00:00
double Y() const
{
return GetNode()->GetY();
}
2013-11-25 15:50:03 +00:00
bool IsCCW() const
{
return m_dir;
}
2013-11-25 15:50:03 +00:00
const NODE_PTR& GetNode() const
{
return m_dir ? m_edge->GetSourceNode() : m_edge->GetTargetNode();
}
2013-11-25 15:50:03 +00:00
const NODE_PTR& GetOppositeNode() const
{
return m_dir ? m_edge->GetTargetNode() : m_edge->GetSourceNode();
}
2013-11-25 15:50:03 +00:00
EDGE_PTR& GetEdge()
{
return m_edge;
}
//@} // End of Utilities not required by TTL
};
2013-11-25 15:50:03 +00:00
} // End of hed namespace
2013-11-25 15:50:03 +00:00
#endif