1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-08 14:17:06 +03:00

0028470: Foundation Classes, NCollection_Array1 - add Resize() method for re-allocating array with new limits

NCollection_Array1 now provides method Resize() for re-allocating array to new bounds.
Added Move Constructor and Move Assignment operator.
Added empty constructor defining array of zero size.

Poly_Triangulation, dropped duplicating fields myNbNodes and myNbTriangles.
Removed unused file Poly_Triangulation.lxx.

Use std::move within NCollection_Array1::operator=() [fix for 0028470]
This commit is contained in:
kgv
2017-02-17 12:35:13 +03:00
committed by bugmaster
parent 32e849ebc9
commit 4954e4970c
5 changed files with 148 additions and 164 deletions

View File

@@ -32,4 +32,3 @@ Poly_Triangle.hxx
Poly_Triangle.lxx
Poly_Triangulation.cxx
Poly_Triangulation.hxx
Poly_Triangulation.lxx

View File

@@ -28,16 +28,14 @@ IMPLEMENT_STANDARD_RTTIEXT (Poly_Triangulation, MMgt_TShared)
//function : Poly_Triangulation
//purpose :
//=======================================================================
Poly_Triangulation::Poly_Triangulation(const Standard_Integer NbNodes,
const Standard_Integer NbTriangles,
const Standard_Boolean UVNodes) :
myDeflection(0),
myNbNodes(NbNodes),
myNbTriangles(NbTriangles),
myNodes(1, NbNodes),
myTriangles(1, NbTriangles)
Poly_Triangulation::Poly_Triangulation(const Standard_Integer theNbNodes,
const Standard_Integer theNbTriangles,
const Standard_Boolean theHasUVNodes)
: myDeflection(0),
myNodes (1, theNbNodes),
myTriangles (1, theNbTriangles)
{
if (UVNodes) myUVNodes = new TColgp_HArray1OfPnt2d(1, myNbNodes);
if (theHasUVNodes) myUVNodes = new TColgp_HArray1OfPnt2d(1, theNbNodes);
}
//=======================================================================
@@ -45,16 +43,14 @@ Poly_Triangulation::Poly_Triangulation(const Standard_Integer NbNodes,
//purpose :
//=======================================================================
Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& Nodes,
const Poly_Array1OfTriangle& Triangles) :
myDeflection(0),
myNbNodes(Nodes.Length()),
myNbTriangles(Triangles.Length()),
myNodes(1, Nodes.Length()),
myTriangles(1, Triangles.Length())
Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& theNodes,
const Poly_Array1OfTriangle& theTriangles)
: myDeflection(0),
myNodes (1, theNodes.Length()),
myTriangles (1, theTriangles.Length())
{
myNodes = Nodes;
myTriangles = Triangles;
myNodes = theNodes;
myTriangles = theTriangles;
}
//=======================================================================
@@ -62,19 +58,17 @@ Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& Nodes,
//purpose :
//=======================================================================
Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& Nodes,
const TColgp_Array1OfPnt2d& UVNodes,
const Poly_Array1OfTriangle& Triangles) :
myDeflection(0),
myNbNodes(Nodes.Length()),
myNbTriangles(Triangles.Length()),
myNodes(1, Nodes.Length()),
myTriangles(1, Triangles.Length())
Poly_Triangulation::Poly_Triangulation(const TColgp_Array1OfPnt& theNodes,
const TColgp_Array1OfPnt2d& theUVNodes,
const Poly_Array1OfTriangle& theTriangles)
: myDeflection(0),
myNodes (1, theNodes.Length()),
myTriangles (1, theTriangles.Length())
{
myNodes = Nodes;
myTriangles = Triangles;
myUVNodes = new TColgp_HArray1OfPnt2d(1, myNbNodes);
myUVNodes->ChangeArray1() = UVNodes;
myNodes = theNodes;
myTriangles = theTriangles;
myUVNodes = new TColgp_HArray1OfPnt2d (1, theNodes.Length());
myUVNodes->ChangeArray1() = theUVNodes;
}
//=======================================================================
@@ -121,17 +115,7 @@ Poly_Triangulation::Poly_Triangulation (const Handle(Poly_Triangulation)& theTri
//purpose :
//=======================================================================
Standard_Real Poly_Triangulation::Deflection() const
{
return myDeflection;
}
//=======================================================================
//function : Deflection
//purpose :
//=======================================================================
void Poly_Triangulation::Deflection (const Standard_Real theDeflection)
void Poly_Triangulation::Deflection(const Standard_Real theDeflection)
{
myDeflection = theDeflection;
}
@@ -146,26 +130,6 @@ void Poly_Triangulation::RemoveUVNodes()
myUVNodes.Nullify();
}
//=======================================================================
//function : Nodes
//purpose :
//=======================================================================
const TColgp_Array1OfPnt& Poly_Triangulation::Nodes() const
{
return myNodes;
}
//=======================================================================
//function : ChangeNodes
//purpose :
//=======================================================================
TColgp_Array1OfPnt& Poly_Triangulation::ChangeNodes()
{
return myNodes;
}
//=======================================================================
//function : Node
//purpose :
@@ -194,26 +158,6 @@ gp_Pnt& Poly_Triangulation::ChangeNode (const Standard_Integer theIndex)
return myNodes.ChangeValue (theIndex);
}
//=======================================================================
//function : UVNodes
//purpose :
//=======================================================================
const TColgp_Array1OfPnt2d& Poly_Triangulation::UVNodes() const
{
return myUVNodes->Array1();
}
//=======================================================================
//function : ChangeUVNodes
//purpose :
//=======================================================================
TColgp_Array1OfPnt2d& Poly_Triangulation::ChangeUVNodes()
{
return myUVNodes->ChangeArray1();
}
//=======================================================================
//function : UVNode
//purpose :
@@ -242,26 +186,6 @@ gp_Pnt2d& Poly_Triangulation::ChangeUVNode (const Standard_Integer theIndex)
return myUVNodes->ChangeValue (theIndex);
}
//=======================================================================
//function : Triangles
//purpose :
//=======================================================================
const Poly_Array1OfTriangle& Poly_Triangulation::Triangles() const
{
return myTriangles;
}
//=======================================================================
//function : ChangeTriangles
//purpose :
//=======================================================================
Poly_Array1OfTriangle& Poly_Triangulation::ChangeTriangles()
{
return myTriangles;
}
//=======================================================================
//function : Triangle
//purpose :
@@ -298,7 +222,7 @@ Poly_Triangle& Poly_Triangulation::ChangeTriangle (const Standard_Integer theInd
void Poly_Triangulation::SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals)
{
if(theNormals.IsNull() || theNormals->Length() != 3*myNbNodes) {
if(theNormals.IsNull() || theNormals->Length() != 3 * NbNodes()) {
throw Standard_DomainError("Poly_Triangulation::SetNormals : wrong length");
}
@@ -313,7 +237,7 @@ void Poly_Triangulation::SetNormals (const Handle(TShort_HArray1OfShortReal)& th
const TShort_Array1OfShortReal& Poly_Triangulation::Normals() const
{
if(myNormals.IsNull() || myNormals->Length() != 3*myNbNodes) {
if(myNormals.IsNull() || myNormals->Length() != 3 * NbNodes()) {
throw Standard_NullObject("Poly_Triangulation::Normals : "
"wrong length or null array");
}
@@ -329,7 +253,7 @@ const TShort_Array1OfShortReal& Poly_Triangulation::Normals() const
TShort_Array1OfShortReal& Poly_Triangulation::ChangeNormals()
{
if(myNormals.IsNull() || myNormals->Length() != 3*myNbNodes) {
if(myNormals.IsNull() || myNormals->Length() != 3 * NbNodes()) {
throw Standard_NullObject("Poly_Triangulation::ChangeNormals : "
"wrong length or null array");
}
@@ -344,7 +268,7 @@ TShort_Array1OfShortReal& Poly_Triangulation::ChangeNormals()
Standard_Boolean Poly_Triangulation::HasNormals() const
{
if(myNormals.IsNull() || myNormals->Length() != 3*myNbNodes) {
if(myNormals.IsNull() || myNormals->Length() != 3 * NbNodes()) {
return Standard_False;
}
return Standard_True;

View File

@@ -97,7 +97,7 @@ public:
Standard_EXPORT Poly_Triangulation (const Handle(Poly_Triangulation)& theTriangulation);
//! Returns the deflection of this triangulation.
Standard_EXPORT Standard_Real Deflection() const;
Standard_Real Deflection() const { return myDeflection; }
//! Sets the deflection of this triangulation to theDeflection.
//! See more on deflection in Polygon2D
@@ -107,23 +107,23 @@ public:
Standard_EXPORT void RemoveUVNodes();
//! Returns the number of nodes for this triangulation.
Standard_Integer NbNodes() const { return myNbNodes; }
Standard_Integer NbNodes() const { return myNodes.Length(); }
//! Returns the number of triangles for this triangulation.
Standard_Integer NbTriangles() const { return myNbTriangles; }
Standard_Integer NbTriangles() const { return myTriangles.Length(); }
//! Returns Standard_True if 2D nodes are associated with 3D nodes for this triangulation.
Standard_Boolean HasUVNodes() const { return !myUVNodes.IsNull(); }
//! Returns the table of 3D nodes (3D points) for this triangulation.
Standard_EXPORT const TColgp_Array1OfPnt& Nodes() const;
const TColgp_Array1OfPnt& Nodes() const { return myNodes; }
//! Returns the table of 3D nodes (3D points) for this triangulation.
//! The returned array is
//! shared. Therefore if the table is selected by reference, you
//! can, by simply modifying it, directly modify the data
//! structure of this triangulation.
Standard_EXPORT TColgp_Array1OfPnt& ChangeNodes();
TColgp_Array1OfPnt& ChangeNodes() { return myNodes; }
//! Returns node at the given index.
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
@@ -138,7 +138,7 @@ public:
//! The function HasUVNodes checks if 2D nodes
//! are associated with the 3D nodes of this triangulation.
//! Const reference on the 2d nodes values.
Standard_EXPORT const TColgp_Array1OfPnt2d& UVNodes() const;
const TColgp_Array1OfPnt2d& UVNodes() const { return myUVNodes->Array1(); }
//! Returns the table of 2D nodes (2D points) associated with
//! each 3D node of this triangulation.
@@ -146,7 +146,7 @@ public:
//! Therefore if the table is selected by reference,
//! you can, by simply modifying it, directly modify the data
//! structure of this triangulation.
Standard_EXPORT TColgp_Array1OfPnt2d& ChangeUVNodes();
TColgp_Array1OfPnt2d& ChangeUVNodes() { return myUVNodes->ChangeArray1(); }
//! Returns UVNode at the given index.
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
@@ -157,14 +157,14 @@ public:
Standard_EXPORT gp_Pnt2d& ChangeUVNode (const Standard_Integer theIndex);
//! Returns the table of triangles for this triangulation.
Standard_EXPORT const Poly_Array1OfTriangle& Triangles() const;
const Poly_Array1OfTriangle& Triangles() const { return myTriangles; }
//! Returns the table of triangles for this triangulation.
//! Function ChangeUVNodes shares the returned array.
//! Therefore if the table is selected by reference,
//! you can, by simply modifying it, directly modify the data
//! structure of this triangulation.
Standard_EXPORT Poly_Array1OfTriangle& ChangeTriangles();
Poly_Array1OfTriangle& ChangeTriangles() { return myTriangles; }
//! Returns triangle at the given index.
//! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles.
@@ -199,8 +199,6 @@ public:
protected:
Standard_Real myDeflection;
Standard_Integer myNbNodes;
Standard_Integer myNbTriangles;
TColgp_Array1OfPnt myNodes;
Handle(TColgp_HArray1OfPnt2d) myUVNodes;
Poly_Array1OfTriangle myTriangles;

View File

@@ -1,46 +0,0 @@
// Created on: 1995-03-06
// Created by: Laurent PAINNOT
// Copyright (c) 1995-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.
//=======================================================================
//function : NbNodes
//purpose :
//=======================================================================
inline Standard_Integer Poly_Triangulation::NbNodes() const
{
return myNbNodes;
}
//=======================================================================
//function : NbTriangles
//purpose :
//=======================================================================
inline Standard_Integer Poly_Triangulation::NbTriangles() const
{
return myNbTriangles;
}
//=======================================================================
//function : HasUVNodes
//purpose :
//=======================================================================
inline Standard_Boolean Poly_Triangulation::HasUVNodes() const
{
return !myUVNodes.IsNull();
}