Coding - Implement move semantics and default constructor for CSLib_Class2d (#919)

- Added a default constructor to CSLib_Class2d for creating empty classifiers.
- Implemented move constructor and move assignment operator to optimize resource management.
- Updated IntTools_FClass2d and BRepTopAdaptor_FClass2d to utilize the new move semantics, eliminating unnecessary dynamic memory allocations.
- Replaced deprecated pointer-based storage with NCollection_Sequence for better memory management.
- Removed the obsolete BRepTopAdaptor_SeqOfPtr class to streamline the codebase.
This commit is contained in:
Pasukhin Dmitry
2025-12-16 13:18:42 +00:00
committed by GitHub
parent 4a9f416b8c
commit bd3ce7be7c
7 changed files with 82 additions and 85 deletions

View File

@@ -48,6 +48,9 @@ public:
DEFINE_STANDARD_ALLOC
//! Default constructor. Creates an empty classifier.
CSLib_Class2d() = default;
//! Constructs a 2D classifier from an array of polygon vertices.
//!
//! The polygon is automatically closed (no need to repeat the first point at the end).
@@ -87,6 +90,38 @@ public:
double theUMax,
double theVMax);
//! Move constructor.
CSLib_Class2d(CSLib_Class2d&& theOther) noexcept
: myPnts2dX(std::move(theOther.myPnts2dX)),
myPnts2dY(std::move(theOther.myPnts2dY)),
myTolU(theOther.myTolU),
myTolV(theOther.myTolV),
myPointsCount(theOther.myPointsCount),
myUMin(theOther.myUMin),
myVMin(theOther.myVMin),
myUMax(theOther.myUMax),
myVMax(theOther.myVMax)
{
}
//! Move assignment operator.
CSLib_Class2d& operator=(CSLib_Class2d&& theOther) noexcept
{
if (this != &theOther)
{
myPnts2dX = std::move(theOther.myPnts2dX);
myPnts2dY = std::move(theOther.myPnts2dY);
myTolU = theOther.myTolU;
myTolV = theOther.myTolV;
myPointsCount = theOther.myPointsCount;
myUMin = theOther.myUMin;
myVMin = theOther.myVMin;
myUMax = theOther.myUMax;
myVMax = theOther.myVMax;
}
return *this;
}
//! Classifies a point relative to the polygon.
//!
//! @param[in] thePoint The 2D point to classify
@@ -134,7 +169,10 @@ private:
double theUMax,
double theVMax);
//! Assignment operator is forbidden.
//! Copy constructor is deleted.
CSLib_Class2d(const CSLib_Class2d&) = delete;
//! Copy assignment operator is deleted.
CSLib_Class2d& operator=(const CSLib_Class2d&) = delete;
private:

View File

@@ -404,7 +404,7 @@ void IntTools_FClass2d::Init(const TopoDS_Face& aFace, const Standard_Real TolUV
gp_Pnt2d anInitPnt(0., 0.);
//
PClass.Init(anInitPnt);
TabClass.Append((void*)new CSLib_Class2d(PClass, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax));
TabClass.Append(CSLib_Class2d(PClass, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax));
BadWire = 1;
TabOrien.Append(-1);
}
@@ -506,8 +506,7 @@ void IntTools_FClass2d::Init(const TopoDS_Face& aFace, const Standard_Real TolUV
if (FlecheV < Toluv)
FlecheV = Toluv;
TabClass.Append(
(void*)new CSLib_Class2d(SeqPnt2d, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax));
TabClass.Append(CSLib_Class2d(SeqPnt2d, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax));
//
if (std::abs(aS) < Precision::SquareConfusion())
{
@@ -534,8 +533,7 @@ void IntTools_FClass2d::Init(const TopoDS_Face& aFace, const Standard_Real TolUV
TabOrien.Append(-1);
TColgp_Array1OfPnt2d PPClass(1, 2);
SeqPnt2d.Clear();
TabClass.Append(
(void*)new CSLib_Class2d(SeqPnt2d, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax));
TabClass.Append(CSLib_Class2d(SeqPnt2d, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax));
}
} // else if(WireIsNotEmpty)
} // for(; aExpF.More(); aExpF.Next()) {
@@ -649,7 +647,7 @@ TopAbs_State IntTools_FClass2d::Perform(const gp_Pnt2d& _Puv,
Standard_Integer n, cur, TabOrien_n;
for (n = 1; n <= nbtabclass; n++)
{
cur = ((CSLib_Class2d*)TabClass(n))->SiDans(Puv);
cur = TabClass(n).SiDans(Puv);
TabOrien_n = TabOrien(n);
if (cur == 1)
@@ -809,7 +807,7 @@ TopAbs_State IntTools_FClass2d::TestOnRestriction(const gp_Pnt2d& _Puv,
{
for (Standard_Integer n = 1; n <= nbtabclass; n++)
{
Standard_Integer cur = ((CSLib_Class2d*)TabClass(n))->SiDans_OnMode(Puv, Tol);
Standard_Integer cur = TabClass(n).SiDans_OnMode(Puv, Tol);
if (cur == 1)
{
if (TabOrien(n) == 0)
@@ -890,13 +888,5 @@ TopAbs_State IntTools_FClass2d::TestOnRestriction(const gp_Pnt2d& _Puv,
IntTools_FClass2d::~IntTools_FClass2d()
{
Standard_Integer nbtabclass = TabClass.Length();
for (Standard_Integer d = 1; d <= nbtabclass; d++)
{
if (TabClass(d))
{
delete ((CSLib_Class2d*)TabClass(d));
TabClass(d) = NULL;
}
}
TabClass.Clear();
}

View File

@@ -22,10 +22,12 @@
#include <Standard_Handle.hxx>
#include <BRepClass_FaceExplorer.hxx>
#include <BRepTopAdaptor_SeqOfPtr.hxx>
#include <CSLib_Class2d.hxx>
#include <NCollection_Sequence.hxx>
#include <TColStd_SequenceOfInteger.hxx>
#include <TopoDS_Face.hxx>
#include <TopAbs_State.hxx>
#include <memory>
class gp_Pnt2d;
@@ -72,19 +74,19 @@ public:
Standard_EXPORT Standard_Boolean IsHole() const;
private:
BRepTopAdaptor_SeqOfPtr TabClass;
TColStd_SequenceOfInteger TabOrien;
Standard_Real Toluv;
TopoDS_Face Face;
Standard_Real U1;
Standard_Real V1;
Standard_Real U2;
Standard_Real V2;
Standard_Real Umin;
Standard_Real Umax;
Standard_Real Vmin;
Standard_Real Vmax;
Standard_Boolean myIsHole;
NCollection_Sequence<CSLib_Class2d> TabClass;
TColStd_SequenceOfInteger TabOrien;
Standard_Real Toluv;
TopoDS_Face Face;
Standard_Real U1;
Standard_Real V1;
Standard_Real U2;
Standard_Real V2;
Standard_Real Umin;
Standard_Real Umax;
Standard_Real Vmin;
Standard_Real Vmax;
Standard_Boolean myIsHole;
mutable std::unique_ptr<BRepClass_FaceExplorer> myFExplorer;
};

View File

@@ -265,7 +265,7 @@ BRepTopAdaptor_FClass2d::BRepTopAdaptor_FClass2d(const TopoDS_Face& aFace,
//// modified by jgv, 28.04.2009 ////
PClass.Init(gp_Pnt2d(0., 0.));
/////////////////////////////////////
TabClass.Append((void*)new CSLib_Class2d(PClass, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax));
TabClass.Append(CSLib_Class2d(PClass, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax));
anIsBadWire = true;
TabOrien.Append(-1);
}
@@ -406,7 +406,7 @@ BRepTopAdaptor_FClass2d::BRepTopAdaptor_FClass2d(const TopoDS_Face& aFace,
FlecheU = Toluv;
if (FlecheV < Toluv)
FlecheV = Toluv;
TabClass.Append((void*)new CSLib_Class2d(PClass, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax));
TabClass.Append(CSLib_Class2d(PClass, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax));
} // if(nbpoints>3
else
{
@@ -415,8 +415,7 @@ BRepTopAdaptor_FClass2d::BRepTopAdaptor_FClass2d(const TopoDS_Face& aFace,
TColgp_Array1OfPnt2d xPClass(1, 2);
xPClass(1) = SeqPnt2d(1);
xPClass(2) = SeqPnt2d(2);
TabClass.Append(
(void*)new CSLib_Class2d(xPClass, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax));
TabClass.Append(CSLib_Class2d(xPClass, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax));
}
} // else if(WareIsNotEmpty
} // for(FaceExplorer
@@ -532,7 +531,7 @@ TopAbs_State BRepTopAdaptor_FClass2d::Perform(const gp_Pnt2d& _Puv,
{
for (Standard_Integer n = 1; n <= nbtabclass; n++)
{
Standard_Integer cur = ((CSLib_Class2d*)TabClass(n))->SiDans(Puv);
Standard_Integer cur = TabClass(n).SiDans(Puv);
if (cur == 1)
{
if (TabOrien(n) == 0)
@@ -673,7 +672,7 @@ TopAbs_State BRepTopAdaptor_FClass2d::TestOnRestriction(
{
for (Standard_Integer n = 1; n <= nbtabclass; n++)
{
Standard_Integer cur = ((CSLib_Class2d*)TabClass(n))->SiDans_OnMode(Puv, Tol);
Standard_Integer cur = TabClass(n).SiDans_OnMode(Puv, Tol);
if (cur == 1)
{
if (TabOrien(n) == 0)
@@ -748,15 +747,7 @@ TopAbs_State BRepTopAdaptor_FClass2d::TestOnRestriction(
void BRepTopAdaptor_FClass2d::Destroy()
{
Standard_Integer nbtabclass = TabClass.Length();
for (Standard_Integer d = 1; d <= nbtabclass; d++)
{
if (TabClass(d))
{
delete ((CSLib_Class2d*)TabClass(d));
TabClass(d) = NULL;
}
}
TabClass.Clear();
}
#include <Standard_ConstructionError.hxx>

View File

@@ -20,10 +20,12 @@
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <BRepTopAdaptor_SeqOfPtr.hxx>
#include <CSLib_Class2d.hxx>
#include <NCollection_Sequence.hxx>
#include <TColStd_SequenceOfInteger.hxx>
#include <TopoDS_Face.hxx>
#include <TopAbs_State.hxx>
class gp_Pnt2d;
class BRepTopAdaptor_FClass2d
@@ -57,20 +59,19 @@ public:
const Standard_Real Tol,
const Standard_Boolean RecadreOnPeriodic = Standard_True) const;
protected:
private:
BRepTopAdaptor_SeqOfPtr TabClass;
TColStd_SequenceOfInteger TabOrien;
Standard_Real Toluv;
TopoDS_Face Face;
Standard_Real U1;
Standard_Real V1;
Standard_Real U2;
Standard_Real V2;
Standard_Real Umin;
Standard_Real Umax;
Standard_Real Vmin;
Standard_Real Vmax;
NCollection_Sequence<CSLib_Class2d> TabClass;
TColStd_SequenceOfInteger TabOrien;
Standard_Real Toluv;
TopoDS_Face Face;
Standard_Real U1;
Standard_Real V1;
Standard_Real U2;
Standard_Real V2;
Standard_Real Umin;
Standard_Real Umax;
Standard_Real Vmin;
Standard_Real Vmax;
};
#endif // _BRepTopAdaptor_FClass2d_HeaderFile

View File

@@ -1,24 +0,0 @@
// Created on: 1994-04-01
// Created by: Modelistation
// Copyright (c) 1994-1999 Matra Datavision
// Copyright (c) 1999-2014 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 _BRepTopAdaptor_SeqOfPtr_HeaderFile
#define _BRepTopAdaptor_SeqOfPtr_HeaderFile
#include <TColStd_SequenceOfAddress.hxx>
typedef TColStd_SequenceOfAddress BRepTopAdaptor_SeqOfPtr;
#endif // _BRepTopAdaptor_SeqOfPtr_HeaderFile

View File

@@ -9,7 +9,6 @@ set(OCCT_BRepTopAdaptor_FILES
BRepTopAdaptor_HVertex.hxx
BRepTopAdaptor_HVertex.lxx
BRepTopAdaptor_MapOfShapeTool.hxx
BRepTopAdaptor_SeqOfPtr.hxx
BRepTopAdaptor_Tool.cxx
BRepTopAdaptor_Tool.hxx
BRepTopAdaptor_TopolTool.cxx