Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-29 09:18:39

0001 // Copyright (c) 2013 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _BRepMesh_Edge_HeaderFile
0015 #define _BRepMesh_Edge_HeaderFile
0016 
0017 #include <Standard.hxx>
0018 #include <BRepMesh_DegreeOfFreedom.hxx>
0019 #include <BRepMesh_OrientedEdge.hxx>
0020 #include <Standard_HashUtils.hxx>
0021 
0022 //! Light weighted structure representing link of the mesh.
0023 class BRepMesh_Edge : public BRepMesh_OrientedEdge
0024 {
0025 public:
0026   //! Default constructor.
0027   BRepMesh_Edge()
0028       : myMovability(BRepMesh_Deleted)
0029   {
0030   }
0031 
0032   //! Constructs a link between two vertices.
0033   BRepMesh_Edge(const int                      theFirstNode,
0034                 const int                      theLastNode,
0035                 const BRepMesh_DegreeOfFreedom theMovability)
0036       : BRepMesh_OrientedEdge(theFirstNode, theLastNode),
0037         myMovability(theMovability)
0038   {
0039   }
0040 
0041   //! Returns movability flag of the Link.
0042   BRepMesh_DegreeOfFreedom Movability() const { return myMovability; }
0043 
0044   //! Sets movability flag of the Link.
0045   //! @param theMovability flag to be set.
0046   void SetMovability(const BRepMesh_DegreeOfFreedom theMovability) { myMovability = theMovability; }
0047 
0048   //! Checks if the given edge and this one have the same orientation.
0049   //! @param theOther edge to be checked against this one.
0050   //! \return TRUE if edges have the same orientation, FALSE if not.
0051   bool IsSameOrientation(const BRepMesh_Edge& theOther) const
0052   {
0053     return BRepMesh_OrientedEdge::IsEqual(theOther);
0054   }
0055 
0056   //! Checks for equality with another edge.
0057   //! @param theOther edge to be checked against this one.
0058   //! @return TRUE if equal, FALSE if not.
0059   bool IsEqual(const BRepMesh_Edge& theOther) const
0060   {
0061     if (myMovability == BRepMesh_Deleted || theOther.myMovability == BRepMesh_Deleted)
0062       return false;
0063 
0064     return IsSameOrientation(theOther)
0065            || (FirstNode() == theOther.LastNode() && LastNode() == theOther.FirstNode());
0066   }
0067 
0068   //! Alias for IsEqual.
0069   bool operator==(const BRepMesh_Edge& Other) const { return IsEqual(Other); }
0070 
0071 private:
0072   BRepMesh_DegreeOfFreedom myMovability;
0073 };
0074 
0075 namespace std
0076 {
0077 template <>
0078 struct hash<BRepMesh_Edge>
0079 {
0080   size_t operator()(const BRepMesh_Edge& theEdge) const noexcept
0081   {
0082     union Combination {
0083       unsigned short Arr[2]; // Node can be represented as a short
0084       uint32_t       Hash;
0085 
0086     } aCombination;
0087 
0088     aCombination.Arr[0] = static_cast<unsigned short>(theEdge.FirstNode());
0089     aCombination.Arr[1] = static_cast<unsigned short>(theEdge.LastNode());
0090     if (aCombination.Arr[0] > aCombination.Arr[1])
0091     {
0092       std::swap(aCombination.Arr[0], aCombination.Arr[1]);
0093     }
0094     return static_cast<size_t>(aCombination.Hash);
0095   }
0096 };
0097 } // namespace std
0098 
0099 #endif