Loading files
f2929057eThis 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_CartesianPointHasher_HeaderFile
#define _StepTidy_CartesianPointHasher_HeaderFile
#include <Standard_HashUtils.hxx>
#include <StepGeom_CartesianPoint.hxx>
#include <TCollection_HAsciiString.hxx>
//! OCCT-style hasher for StepGeom_CartesianPoint entities.
struct StepTidy_CartesianPointHasher
{
// Hashes the Cartesian point by its name and coordinates.
std::size_t operator()(
const occ::handle<StepGeom_CartesianPoint>& theCartesianPoint) const noexcept
{
const std::array<double, 3>& aCoords = theCartesianPoint->Coordinates();
// If Cartesian point has no name, hash only coordinates.
if (theCartesianPoint->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>{}(theCartesianPoint->Name()->String())};
return opencascade::hashBytes(aHashes, sizeof(aHashes));
}
// Compares two Cartesian points by their names and coordinates.
bool operator()(const occ::handle<StepGeom_CartesianPoint>& theCartesianPoint1,
const occ::handle<StepGeom_CartesianPoint>& theCartesianPoint2) const noexcept
{
// Compare names.
if (theCartesianPoint1->Name().IsNull() != theCartesianPoint2->Name().IsNull())
{
return false;
}
if (!theCartesianPoint1->Name()->IsSameString(theCartesianPoint2->Name()))
{
return false;
}
// Compare coordinates.
constexpr double aTolerance = 1e-12;
const std::array<double, 3>& aCoords1 = theCartesianPoint1->Coordinates();
const std::array<double, 3>& aCoords2 = theCartesianPoint2->Coordinates();
if (theCartesianPoint1->NbCoordinates() != theCartesianPoint2->NbCoordinates())
{
return false;
}
for (int anIndex = 0; anIndex < theCartesianPoint1->NbCoordinates(); ++anIndex)
{
if (std::abs(aCoords1[anIndex] - aCoords2[anIndex]) > aTolerance)
{
return false;
}
}
return true;
}
};
#endif // _StepTidy_CartesianPointHasher_HeaderFile