1 /**************************************************************************/ 2 /* Copyright 2009 Tim Day */ 3 /* */ 4 /* This file is part of Fracplanet */ 5 /* */ 6 /* Fracplanet is free software: you can redistribute it and/or modify */ 7 /* it under the terms of the GNU General Public License as published by */ 8 /* the Free Software Foundation, either version 3 of the License, or */ 9 /* (at your option) any later version. */ 10 /* */ 11 /* Fracplanet is distributed in the hope that it will be useful, */ 12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ 14 /* GNU General Public License for more details. */ 15 /* */ 16 /* You should have received a copy of the GNU General Public License */ 17 /* along with Fracplanet. If not, see <http://www.gnu.org/licenses/>. */ 18 /**************************************************************************/ 19 20 /*! \file 21 \brief Interface for class TriangleEdge. 22 */ 23 24 #ifndef _triangle_edge_h_ 25 #define _triangle_edge_h_ 26 27 #include "common.h" 28 29 //! Class to store triangle edges. 30 /*! An edge is described by two vertices. 31 These are ordered internally for more efficient sorting and comparison. 32 This class is useful for, for example, discovering adjacent triangles through edges they have in common. 33 NB There is no void constructor because the const vertices wouldn't be set. 34 */ 35 class TriangleEdge 36 { 37 public: 38 39 //! Constructor. Sorts arguments to ensure _vertex0<_vertex1 TriangleEdge(uint v0,uint v1)40 TriangleEdge(uint v0,uint v1) 41 :_vertex0(v0<v1 ? v0 : v1) 42 ,_vertex1(v0>v1 ? v0 : v1) 43 {} 44 45 //! Copy constructor. TriangleEdge(const TriangleEdge & e)46 TriangleEdge(const TriangleEdge& e) 47 :_vertex0(e._vertex0) 48 ,_vertex1(e._vertex1) 49 {} 50 51 //! Destructor. ~TriangleEdge()52 ~TriangleEdge() 53 {} 54 55 //! Accessor. vertex0()56 uint vertex0() const 57 {return _vertex0;} 58 59 //! Accessor. vertex1()60 uint vertex1() const 61 {return _vertex1;} 62 63 protected: 64 65 //! One vertex of the edge. This should always be the lesser valued index. 66 const uint _vertex0; 67 68 //! The other vertex of the edge. This should always be the greater valued index. 69 const uint _vertex1; 70 }; 71 72 //! Comparison operator, required to build ordered STL data-structures. 73 inline bool operator<(const TriangleEdge& e0,const TriangleEdge& e1) 74 { 75 return 76 ( 77 e0.vertex0()<e1.vertex0() 78 || 79 ( 80 e0.vertex0()==e1.vertex0() 81 && 82 e0.vertex1()<e1.vertex1() 83 ) 84 ); 85 } 86 87 #endif 88