#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
-#include <Standard_Macro.hxx>
+#include <Standard_HashUtils.hxx>
#include <BRepMesh_DegreeOfFreedom.hxx>
//! Default constructor.
BRepMesh_Triangle()
- : myEdge1(0),
- myEdge2(0),
- myEdge3(0),
- myOrientation1(Standard_False),
- myOrientation2(Standard_False),
- myOrientation3(Standard_False),
- myMovability (BRepMesh_Free)
+ : myMovability (BRepMesh_Free)
{
+ myEdges[0] = 0;
+ myEdges[1] = 0;
+ myEdges[2] = 0;
+ myOrientations[0] = Standard_False;
+ myOrientations[1] = Standard_False;
+ myOrientations[2] = Standard_False;
}
//! Constructor.
//! @param theEdges array of edges of triangle.
//! @param theOrientations array of edge's orientations.
//! @param theMovability movability of triangle.
- inline void Initialize(
+ void Initialize(
const Standard_Integer (&theEdges)[3],
const Standard_Boolean (&theOrientations)[3],
const BRepMesh_DegreeOfFreedom theMovability)
{
- myEdge1 = theEdges[0];
- myEdge2 = theEdges[1];
- myEdge3 = theEdges[2];
- myOrientation1 = theOrientations[0];
- myOrientation2 = theOrientations[1];
- myOrientation3 = theOrientations[2];
+ memcpy(myEdges, theEdges, sizeof(theEdges));
+ memcpy(myOrientations, theOrientations, sizeof(theOrientations));
myMovability = theMovability;
}
//! Gets edges with orientations composing the triangle.
//! @param[out] theEdges array edges are stored to.
//! @param[out] theOrientations array orientations are stored to.
- inline void Edges(Standard_Integer (&theEdges)[3],
- Standard_Boolean (&theOrientations)[3]) const
+ void Edges(Standard_Integer (&theEdges)[3],
+ Standard_Boolean (&theOrientations)[3]) const
{
- theEdges[0] = myEdge1;
- theEdges[1] = myEdge2;
- theEdges[2] = myEdge3;
- theOrientations[0] = myOrientation1;
- theOrientations[1] = myOrientation2;
- theOrientations[2] = myOrientation3;
+ memcpy(theEdges, myEdges, sizeof(myEdges));
+ memcpy(theOrientations, myOrientations, sizeof(myOrientations));
}
//! Returns movability of the triangle.
- inline BRepMesh_DegreeOfFreedom Movability() const
+ BRepMesh_DegreeOfFreedom Movability() const
{
return myMovability;
}
//! Sets movability of the triangle.
- inline void SetMovability(const BRepMesh_DegreeOfFreedom theMovability)
+ void SetMovability(const BRepMesh_DegreeOfFreedom theMovability)
{
myMovability = theMovability;
}
-
- //! Returns hash code for this triangle.
- //! @param theUpper upper index in the container.
- //! @return hash code.
- Standard_Integer HashCode(const Standard_Integer theUpper) const
- {
- return ::HashCode(myEdge1 + myEdge2 + myEdge3, theUpper);
- }
-
+
//! Checks for equality with another triangle.
//! @param theOther triangle to be checked against this one.
//! @return TRUE if equal, FALSE if not.
if (myMovability == BRepMesh_Deleted || theOther.myMovability == BRepMesh_Deleted)
return Standard_False;
- if (myEdge1 == theOther.myEdge1 &&
- myEdge2 == theOther.myEdge2 &&
- myEdge3 == theOther.myEdge3)
+ if (myEdges[0] == theOther.myEdges[0] &&
+ myEdges[1] == theOther.myEdges[1] &&
+ myEdges[2] == theOther.myEdges[2])
{
return Standard_True;
}
- if (myEdge1 == theOther.myEdge2 &&
- myEdge2 == theOther.myEdge3 &&
- myEdge3 == theOther.myEdge1)
+ if (myEdges[0] == theOther.myEdges[1] &&
+ myEdges[1] == theOther.myEdges[2] &&
+ myEdges[2] == theOther.myEdges[0])
{
return Standard_True;
}
- if (myEdge1 == theOther.myEdge3 &&
- myEdge2 == theOther.myEdge1 &&
- myEdge3 == theOther.myEdge2)
+ if (myEdges[0] == theOther.myEdges[2] &&
+ myEdges[1] == theOther.myEdges[0] &&
+ myEdges[2] == theOther.myEdges[1])
{
return Standard_True;
}
return IsEqual(theOther);
}
-private:
-
- Standard_Integer myEdge1;
- Standard_Integer myEdge2;
- Standard_Integer myEdge3;
- Standard_Boolean myOrientation1;
- Standard_Boolean myOrientation2;
- Standard_Boolean myOrientation3;
+ Standard_Integer myEdges[3];
+ Standard_Boolean myOrientations[3];
BRepMesh_DegreeOfFreedom myMovability;
};
-inline Standard_Integer HashCode(const BRepMesh_Triangle& theTriangle,
- const Standard_Integer theUpper)
+namespace std
{
- return theTriangle.HashCode(theUpper);
+ template <>
+ struct hash<BRepMesh_Triangle>
+ {
+ size_t operator()(const BRepMesh_Triangle& theTriangle) const noexcept
+ {
+ int aCombination[3] = { theTriangle.myEdges[0], theTriangle.myEdges[1], theTriangle.myEdges[2] };
+ std::sort(aCombination, aCombination + 3); // Sort the numbers in ascending order
+ return opencascade::hashBytes(aCombination, sizeof(aCombination));
+ }
+ };
}
#endif