Loading files
3d097a032This file is pinned to the selected release. Download the original to open it in your design tool.
// Copyright (c) 2025 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _StepTidy_DirectionHasher_HeaderFile
#define _StepTidy_DirectionHasher_HeaderFile
#include <Standard_HashUtils.hxx>
#include <StepGeom_Direction.hxx>
#include <TCollection_HAsciiString.hxx>
//! OCCT-style hasher for StepGeom_Direction entities.
struct StepTidy_DirectionHasher
{
// Hashes the direction by its name and direction ratios.
std::size_t operator()(const occ::handle<StepGeom_Direction>& theDirection) const noexcept
{
const std::array<double, 3>& aCoords = theDirection->DirectionRatios();
// If Cartesian point has no name, hash only directional ratios.
if (theDirection->Name().IsNull())
{
return opencascade::hashBytes(aCoords.data(), static_cast<int>(aCoords.size()));
}
// Otherwise, hash both coordinates and name.
const size_t aHashes[2]{
opencascade::hashBytes(aCoords.data(), static_cast<int>(aCoords.size())),
std::hash<TCollection_AsciiString>{}(theDirection->Name()->String())};
return opencascade::hashBytes(aHashes, sizeof(aHashes));
}
// Compares two directions by their names and direction ratios.
bool operator()(const occ::handle<StepGeom_Direction>& theDirection1,
const occ::handle<StepGeom_Direction>& theDirection2) const noexcept
{
// Compare names.
if (theDirection1->Name().IsNull() != theDirection2->Name().IsNull())
{
return false;
}
if (!theDirection1->Name()->IsSameString(theDirection2->Name()))
{
return false;
}
// Compare coordinates.
constexpr double aTolerance = 1e-12;
const std::array<double, 3>& aCoords1 = theDirection1->DirectionRatios();
const std::array<double, 3>& aCoords2 = theDirection2->DirectionRatios();
if (theDirection1->NbDirectionRatios() != theDirection2->NbDirectionRatios())
{
return false;
}
for (int anIndex = 0; anIndex < theDirection1->NbDirectionRatios(); ++anIndex)
{
if (std::abs(aCoords1[anIndex] - aCoords2[anIndex]) > aTolerance)
{
return false;
}
}
return true;
}
};
#endif // _StepTidy_DirectionHasher_HeaderFile