Files
OCCT/src/ModelingData/TKG2d/Geom2dHash/Geom2dHash_PointHasher.pxx
Pasukhin Dmitry 052c37669b Modeling Data - Add GeomHash and Geom2dHash packages (#845)
- Implementation of hashers for analytic curves (Line, Circle, Ellipse, Hyperbola, Parabola) and freeform curves (Bezier, BSpline, Trimmed, Offset) in both 2D and 3D
- Implementation of hashers for surfaces including elementary surfaces (Plane, Cylinder, Cone, Sphere, Torus) and derived surfaces (Revolution, LinearExtrusion, RectangularTrimmed, Offset)
- Comprehensive test coverage for all hasher implementations
2025-11-22 11:16:25 +00:00

48 lines
1.8 KiB
Plaintext

// 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 _Geom2dHash_PointHasher_HeaderFile
#define _Geom2dHash_PointHasher_HeaderFile
#include <Standard_HashUtils.hxx>
#include <gp_Pnt2d.hxx>
#include <cmath>
//! OCCT-style hasher for gp_Pnt2d (2D points).
//! Used for geometry deduplication.
struct Geom2dHash_PointHasher
{
// Hashes the 2D point by its XY coordinates.
std::size_t operator()(const gp_Pnt2d& thePoint) const noexcept
{
constexpr double aTolerance = 1e-12;
constexpr double aFactor = 1.0 / aTolerance;
// Round each coordinate to tolerance precision before hashing
const std::size_t aHashes[2] = {
opencascade::hash(static_cast<int64_t>(std::round(thePoint.X() * aFactor))),
opencascade::hash(static_cast<int64_t>(std::round(thePoint.Y() * aFactor)))};
return opencascade::hashBytes(aHashes, sizeof(aHashes));
}
// Compares two 2D points with fixed tolerance.
bool operator()(const gp_Pnt2d& thePoint1, const gp_Pnt2d& thePoint2) const noexcept
{
constexpr double aTolerance = 1e-12;
return std::abs(thePoint1.X() - thePoint2.X()) <= aTolerance
&& std::abs(thePoint1.Y() - thePoint2.Y()) <= aTolerance;
}
};
#endif // _Geom2dHash_PointHasher_HeaderFile