mirror of
https://github.com/Open-Cascade-SAS/OCCT.git
synced 2026-05-10 09:30:48 +08:00
- 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
72 lines
2.8 KiB
Plaintext
72 lines
2.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 _GeomHash_RectangularTrimmedSurfaceHasher_HeaderFile
|
|
#define _GeomHash_RectangularTrimmedSurfaceHasher_HeaderFile
|
|
|
|
#include <Standard_HashUtils.hxx>
|
|
#include <Geom_RectangularTrimmedSurface.hxx>
|
|
#include <GeomHash_SurfaceHasher.hxx>
|
|
#include <cmath>
|
|
|
|
//! OCCT-style hasher for Geom_RectangularTrimmedSurface.
|
|
//! Used for geometry deduplication.
|
|
struct GeomHash_RectangularTrimmedSurfaceHasher
|
|
{
|
|
// Hashes the trimmed surface by its trim bounds and basis surface.
|
|
std::size_t operator()(const Handle(Geom_RectangularTrimmedSurface)& theSurface) const noexcept
|
|
{
|
|
constexpr double aTolerance = 1e-12;
|
|
constexpr double aFactor = 1.0 / aTolerance;
|
|
|
|
const GeomHash_SurfaceHasher aSurfaceHasher;
|
|
|
|
double aU1, aU2, aV1, aV2;
|
|
theSurface->Bounds(aU1, aU2, aV1, aV2);
|
|
|
|
const std::size_t aHashes[5] = {
|
|
aSurfaceHasher(theSurface->BasisSurface()),
|
|
opencascade::hash(static_cast<int64_t>(std::round(aU1 * aFactor))),
|
|
opencascade::hash(static_cast<int64_t>(std::round(aU2 * aFactor))),
|
|
opencascade::hash(static_cast<int64_t>(std::round(aV1 * aFactor))),
|
|
opencascade::hash(static_cast<int64_t>(std::round(aV2 * aFactor)))};
|
|
return opencascade::hashBytes(aHashes, sizeof(aHashes));
|
|
}
|
|
|
|
// Compares two trimmed surfaces by their trim bounds and basis surfaces.
|
|
bool operator()(const Handle(Geom_RectangularTrimmedSurface)& theSurface1,
|
|
const Handle(Geom_RectangularTrimmedSurface)& theSurface2) const noexcept
|
|
{
|
|
constexpr double aTolerance = 1e-12;
|
|
|
|
const GeomHash_SurfaceHasher aSurfaceHasher;
|
|
|
|
// Compare basis surfaces
|
|
if (!aSurfaceHasher(theSurface1->BasisSurface(), theSurface2->BasisSurface()))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// Compare trim bounds
|
|
double aU1_1, aU2_1, aV1_1, aV2_1;
|
|
double aU1_2, aU2_2, aV1_2, aV2_2;
|
|
theSurface1->Bounds(aU1_1, aU2_1, aV1_1, aV2_1);
|
|
theSurface2->Bounds(aU1_2, aU2_2, aV1_2, aV2_2);
|
|
|
|
return std::abs(aU1_1 - aU1_2) <= aTolerance && std::abs(aU2_1 - aU2_2) <= aTolerance
|
|
&& std::abs(aV1_1 - aV1_2) <= aTolerance && std::abs(aV2_1 - aV2_2) <= aTolerance;
|
|
}
|
|
};
|
|
|
|
#endif // _GeomHash_RectangularTrimmedSurfaceHasher_HeaderFile
|