Commit 6fa2f060 authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Formatted ttl library to comply with KiCad coding policy.

parent a0fb4ed0
Loading
Loading
Loading
Loading
+556 −560

File changed.

Preview size limit exceeded, changes collapsed.

+108 −67
Original line number Diff line number Diff line
@@ -40,111 +40,152 @@
#ifndef _HALF_EDGE_DART_
#define _HALF_EDGE_DART_


#include <ttl/halfedge/hetriang.h>


namespace hed {


  //------------------------------------------------------------------------------------------------
  // Dart class for the half-edge data structure
  //------------------------------------------------------------------------------------------------

  /** \class Dart
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;

  class Dart {

    EdgePtr edge_;
    bool dir_; // true if dart is counterclockwise in face
    /// Dart direction: true if dart is counterclockwise in face
    bool m_dir;

public:
    /// Default constructor
    Dart() { dir_ = true; }
    DART()
    {
        m_dir = true;
    }

    /// Constructor
    Dart(const EdgePtr& edge, bool dir = true) { edge_ = edge; dir_ = dir; }
    DART( const EDGE_PTR& aEdge, bool aDir = true )
    {
        m_edge = aEdge;
        m_dir = aDir;
    }

    /// Copy constructor
    Dart(const Dart& dart) { edge_ = dart.edge_; dir_ = dart.dir_; }
    DART( const DART& aDart )
    {
        m_edge = aDart.m_edge;
        m_dir  = aDart.m_dir;
    }

    /// Destructor
    ~Dart() {}
    ~DART()
    {
    }

    /// Assignment operator
    Dart& operator = (const Dart& dart) {
      if (this == &dart)
    DART& operator=( const DART& aDart )
    {
        if( this == &aDart )
            return *this;
      edge_ = dart.edge_;
      dir_  = dart.dir_;

        m_edge = aDart.m_edge;
        m_dir = aDart.m_dir;

        return *this;
    }

    /// Comparing dart objects
    bool operator==(const Dart& dart) const {
      if (dart.edge_ == edge_ && dart.dir_ == dir_)
        return true;
      return false;
    bool operator==( const DART& aDart ) const
    {
        return ( aDart.m_edge == m_edge && aDart.m_dir == m_dir );
    }

    /// Comparing dart objects
    bool operator!=(const Dart& dart) const {
      return !(dart==*this);
    bool operator!=( const DART& aDart ) const
    {
        return !( aDart == *this );
    }

    /// Maps the dart to a different node
    Dart& alpha0() { dir_ = !dir_; return *this; }
    DART& Alpha0()
    {
        m_dir = !m_dir;
        return *this;
    }

    /// Maps the dart to a different edge
    Dart& alpha1() {
      if (dir_) {
        edge_ = edge_->getNextEdgeInFace()->getNextEdgeInFace();
        dir_ = false;
    DART& Alpha1()
    {
        if( m_dir )
        {
            m_edge = m_edge->GetNextEdgeInFace()->GetNextEdgeInFace();
            m_dir = false;
        }
      else {
        edge_ = edge_->getNextEdgeInFace();
        dir_ = true;
        else
        {
            m_edge = m_edge->GetNextEdgeInFace();
            m_dir = true;
        }

        return *this;
    }

    /// Maps the dart to a different triangle. \b Note: the dart is not changed if it is at the boundary!
    Dart& alpha2() {
      if (edge_->getTwinEdge()) {
        edge_ = edge_->getTwinEdge();
        dir_ = !dir_;
    DART& Alpha2()
    {
        if( m_edge->GetTwinEdge() )
        {
            m_edge = m_edge->GetTwinEdge();
            m_dir = !m_dir;
        }

        // else, the dart is at the boundary and should not be changed
        return *this;
    }


    // Utilities not required by TTL
    // -----------------------------

    /** @name Utilities not required by TTL */
    //@{
    void Init( const EDGE_PTR& aEdge, bool aDir = true )
    {
        m_edge = aEdge;
        m_dir = aDir;
    }

    double X() const
    {
        return GetNode()->GetX();
    }

    void init(const EdgePtr& edge, bool dir = true) { edge_ = edge; dir_ = dir; }
    double Y() const
    {
        return GetNode()->GetY();
    }

    double x() const { return getNode()->GetX(); } // x-coordinate of source node
    double y() const { return getNode()->GetY(); } // y-coordinate of source node
    bool IsCCW() const
    {
        return m_dir;
    }

    bool isCounterClockWise() const { return dir_; }
    const NODE_PTR& GetNode() const
    {
        return m_dir ? m_edge->GetSourceNode() : m_edge->GetTargetNode();
    }

    const NodePtr& getNode() const { return dir_ ? edge_->getSourceNode() : edge_->getTargetNode(); }
    const NodePtr& getOppositeNode() const { return dir_ ? edge_->getTargetNode() : edge_->getSourceNode(); }
    EdgePtr& getEdge() { return edge_; }
    const NODE_PTR& GetOppositeNode() const
    {
        return m_dir ? m_edge->GetTargetNode() : m_edge->GetSourceNode();
    }

    //@} // End of Utilities not required by TTL
    EDGE_PTR& GetEdge()
    {
        return m_edge;
    }

    //@} // End of Utilities not required by TTL
};

}; // End of hed namespace
} // End of hed namespace

#endif
+124 −111
Original line number Diff line number Diff line
@@ -40,19 +40,13 @@
#ifndef _HALF_EDGE_TRAITS_
#define _HALF_EDGE_TRAITS_


#include <ttl/halfedge/hetriang.h>
#include <ttl/halfedge/hedart.h>


namespace hed {


  //------------------------------------------------------------------------------------------------
  // Traits class for the half-edge data structure
  //------------------------------------------------------------------------------------------------
  
  /** \struct TTLtraits
namespace hed
{
/**
 * \struct TTLtraits
 * \brief \b Traits class (static struct) for the half-edge data structure.
 *
 * The member functions are those required by different function templates
@@ -64,108 +58,127 @@ namespace hed {
 * half-edge data structure.
 *
 * \see \ref api
  *
 */

  struct TTLtraits {
    
    /** The floating point type used in calculations
    *   involving scalar products and cross products.
struct TTLtraits
{
    /**
     * The floating point type used in calculations involving scalar products and cross products.
     */
    typedef double real_type;


    //----------------------------------------------------------------------------------------------
    // ------------------------------- Geometric Predicates Group ---------------------------------
    //----------------------------------------------------------------------------------------------
    typedef double REAL_TYPE;
    
    /** @name Geometric Predicates */
    //@{

    //----------------------------------------------------------------------------------------------
    /** Scalar product between two 2D vectors represented as darts.\n
    /**
     * Scalar product between two 2D vectors represented as darts.\n
     *
     * ttl_util::scalarProduct2d can be used.
     */
    static real_type scalarProduct2d(const Dart& v1, const Dart& v2) {
      Dart v10 = v1; v10.alpha0();
      Dart v20 = v2; v20.alpha0();
      return ttl_util::scalarProduct2d(v10.x()-v1.x(), v10.y()-v1.y(),
                                       v20.x()-v2.x(), v20.y()-v2.y());
    }
    static REAL_TYPE ScalarProduct2D( const DART& aV1, const DART& aV2 )
    {
        DART v10 = aV1;
        v10.Alpha0();

        DART v20 = aV2;
        v20.Alpha0();

    //----------------------------------------------------------------------------------------------
    /** Scalar product between two 2D vectors.
        return ttl_util::ScalarProduct2D( v10.X() - aV1.X(),  v10.Y() - aV1.Y(),
                                          v20.X() - aV2.X(),  v20.Y() - aV2.Y() );
    }

    /**
     * Scalar product between two 2D vectors.
     * The first vector is represented by a dart \e v, and the second
     * vector has direction from the source node of \e v to the point \e p.\n
     *
    *   ttl_util::scalarProduct2d can be used.
     * ttl_util::ScalarProduct2D can be used.
     */
    static real_type scalarProduct2d(const Dart& v, const NodePtr& p) {
      Dart d0 = v; d0.alpha0();
      return ttl_util::scalarProduct2d(d0.x() - v.x(), d0.y() - v.y(),
                                       p->GetX() - v.x(), p->GetY() - v.y());
    }
    static REAL_TYPE ScalarProduct2D( const DART& aV, const NODE_PTR& aP )
    {
        DART d0 = aV;
        d0.Alpha0();

        return ttl_util::ScalarProduct2D( d0.X() - aV.X(),     d0.Y() - aV.Y(),
                                          aP->GetX() - aV.X(), aP->GetY() - aV.Y() );
    }

    //----------------------------------------------------------------------------------------------
    /** Cross product between two vectors in the plane represented as darts.
    /**
     * Cross product between two vectors in the plane represented as darts.
     * The z-component of the cross product is returned.\n
     *
    *   ttl_util::crossProduct2d can be used.
     * ttl_util::CrossProduct2D can be used.
     */
    static real_type crossProduct2d(const Dart& v1, const Dart& v2) {
      Dart v10 = v1; v10.alpha0();
      Dart v20 = v2; v20.alpha0();
      return ttl_util::crossProduct2d(v10.x()-v1.x(), v10.y()-v1.y(), 
                                      v20.x()-v2.x(), v20.y()-v2.y());
    }
    static REAL_TYPE CrossProduct2D( const DART& aV1, const DART& aV2 )
    {
        DART v10 = aV1;
        v10.Alpha0();

        DART v20 = aV2;
        v20.Alpha0();

    //----------------------------------------------------------------------------------------------
    /** Cross product between two vectors in the plane.
        return ttl_util::CrossProduct2D( v10.X() - aV1.X(), v10.Y() - aV1.Y(),
                                         v20.X() - aV2.X(), v20.Y() - aV2.Y() );
    }

    /**
     * Cross product between two vectors in the plane.
     * The first vector is represented by a dart \e v, and the second
     * vector has direction from the source node of \e v to the point \e p.
     * The z-component of the cross product is returned.\n
     *
    *   ttl_util::crossProduct2d can be used.
     * ttl_util::CrossProduct2d can be used.
     */
    static real_type crossProduct2d(const Dart& v, const NodePtr& p) {
      Dart d0 = v; d0.alpha0();
      return ttl_util::crossProduct2d(d0.x() - v.x(), d0.y() - v.y(),
                                      p->GetX() - v.x(), p->GetY() - v.y());
    }
    static REAL_TYPE CrossProduct2D( const DART& aV, const NODE_PTR& aP )
    {
        DART d0 = aV;
        d0.Alpha0();

        return ttl_util::CrossProduct2D( d0.X() - aV.X(),     d0.Y() - aV.Y(),
                                         aP->GetX() - aV.X(), aP->GetY() - aV.Y() );
    }

    //----------------------------------------------------------------------------------------------
    /** Let \e n1 and \e n2 be the nodes associated with two darts, and let \e p
    /**
     * Let \e n1 and \e n2 be the nodes associated with two darts, and let \e p
     * be a point in the plane. Return a positive value if \e n1, \e n2,
     * and \e p occur in counterclockwise order; a negative value if they occur
     * in clockwise order; and zero if they are collinear.
     */
    static real_type orient2d(const Dart& n1, const Dart& n2, const NodePtr& p) {
      real_type pa[2]; real_type pb[2]; real_type pc[2];
      pa[0] = n1.x(); pa[1] = n1.y();
      pb[0] = n2.x(); pb[1] = n2.y();
      pc[0] = p->GetX(); pc[1] = p->GetY();
      return ttl_util::orient2dfast(pa, pb, pc);
    static REAL_TYPE Orient2D( const DART& aN1, const DART& aN2, const NODE_PTR& aP )
    {
        REAL_TYPE pa[2];
        REAL_TYPE pb[2];
        REAL_TYPE pc[2];

        pa[0] = aN1.X();
        pa[1] = aN1.Y();
        pb[0] = aN2.X();
        pb[1] = aN2.Y();
        pc[0] = aP->GetX();
        pc[1] = aP->GetY();

        return ttl_util::Orient2DFast( pa, pb, pc );
    }


    //----------------------------------------------------------------------------------------------
    /** This is the same predicate as represented with the function above,
    /**
     * This is the same predicate as represented with the function above,
     * but with a slighty different interface:
     * The last parameter is given as a dart where the source node of the dart
     * represents a point in the plane.
     * This function is required for constrained triangulation.
     */
    static real_type orient2d(const Dart& n1, const Dart& n2, const Dart& p) {
      real_type pa[2]; real_type pb[2]; real_type pc[2];
      pa[0] = n1.x(); pa[1] = n1.y();
      pb[0] = n2.x(); pb[1] = n2.y();
      pc[0] =  p.x(); pc[1] =  p.y();
      return ttl_util::orient2dfast(pa, pb, pc);
    static REAL_TYPE Orient2D( const DART& aN1, const DART& aN2, const DART& aP )
    {
        REAL_TYPE pa[2];
        REAL_TYPE pb[2];
        REAL_TYPE pc[2];

        pa[0] = aN1.X();
        pa[1] = aN1.Y();
        pb[0] = aN2.X();
        pb[1] = aN2.Y();
        pc[0] = aP.X();
        pc[1] = aP.Y();

        return ttl_util::Orient2DFast( pa, pb, pc );
    }

    //@} // End of Geometric Predicates Group
+277 −207

File changed.

Preview size limit exceeded, changes collapsed.

+1510 −1479

File changed.

Preview size limit exceeded, changes collapsed.

Loading