Fix the case of the only section without points

This commit is contained in:
skv 2014-09-30 19:45:14 +04:00
parent 4033cfe508
commit 302d0ca95c

View File

@ -34,33 +34,27 @@
void GEOMImpl_IPolyline2D::SetCoords void GEOMImpl_IPolyline2D::SetCoords
(const std::list <std::list <double> > &theValue) (const std::list <std::list <double> > &theValue)
{ {
const Standard_Integer aNbSec = theValue.size();
if (aNbSec > 0) {
// Compute the total number of points and fill the array of start indices. // Compute the total number of points and fill the array of start indices.
Standard_Integer i; Standard_Integer i;
const Standard_Integer aNbSec = theValue.size();
Standard_Integer aNbCoords = 0; Standard_Integer aNbCoords = 0;
Handle(TColStd_HArray1OfInteger) anIndices; Handle(TColStd_HArray1OfInteger) anIndices =
std::list <std::list <double> >::const_iterator aSecIter; new TColStd_HArray1OfInteger(1, aNbSec);
Handle(TColStd_HArray1OfReal) aCoords;
std::list <std::list <double> >::const_iterator aSecIter = theValue.begin();
if (aNbSec == 1) { for (i = 1; aSecIter != theValue.end(); ++aSecIter, ++i) {
// There is only one section.
aNbCoords = theValue.front().size();
} else {
// Here we assume that there are more than one section.
anIndices = new TColStd_HArray1OfInteger(1, aNbSec - 1);
aSecIter = theValue.begin();
aNbCoords += aSecIter->size();
for (i = 1, ++aSecIter; aSecIter != theValue.end(); ++aSecIter, ++i) {
anIndices->SetValue(i, aNbCoords + 1); anIndices->SetValue(i, aNbCoords + 1);
aNbCoords += aSecIter->size(); aNbCoords += aSecIter->size();
} }
}
if (aNbCoords > 0) {
// Fill the array of coordinates. // Fill the array of coordinates.
Handle(TColStd_HArray1OfReal) aCoords =
new TColStd_HArray1OfReal(1, aNbCoords);
std::list<double>::const_iterator aCIter; std::list<double>::const_iterator aCIter;
aCoords = new TColStd_HArray1OfReal(1, aNbCoords);
aSecIter = theValue.begin(); aSecIter = theValue.begin();
for (i = 1; aSecIter != theValue.end(); ++aSecIter) { for (i = 1; aSecIter != theValue.end(); ++aSecIter) {
@ -68,11 +62,13 @@ void GEOMImpl_IPolyline2D::SetCoords
aCoords->SetValue(i++, *aCIter); aCoords->SetValue(i++, *aCIter);
} }
} }
}
// Store the coordinates. // Store the coordinates.
if (aCoords.IsNull() == Standard_False) {
_func->SetRealArray(POLY_ARG_COORDS, aCoords); _func->SetRealArray(POLY_ARG_COORDS, aCoords);
}
if (anIndices.IsNull() == Standard_False) {
_func->SetIntegerArray(POLY_ARG_START_INDICES, anIndices); _func->SetIntegerArray(POLY_ARG_START_INDICES, anIndices);
} }
} }
@ -91,35 +87,26 @@ void GEOMImpl_IPolyline2D::GetCoords(std::list <std::list <double> > &theValue)
Handle(TColStd_HArray1OfInteger) anIndices = Handle(TColStd_HArray1OfInteger) anIndices =
_func->GetIntegerArray(POLY_ARG_START_INDICES); _func->GetIntegerArray(POLY_ARG_START_INDICES);
if (aCoords.IsNull() == Standard_False) {
std::list <double> anEmptyList;
Standard_Integer i;
Standard_Integer iNextSec = 0;
Standard_Integer aNextSecIndex = aCoords->Upper() + 1;
if (anIndices.IsNull() == Standard_False) { if (anIndices.IsNull() == Standard_False) {
iNextSec = anIndices->Lower(); const Standard_Integer aNbSec = anIndices->Length();
aNextSecIndex = anIndices->Value(iNextSec);
}
theValue.push_back(anEmptyList); // Create an empty sections.
theValue.resize(aNbSec);
for (i = aCoords->Lower(); i <= aCoords->Upper(); ++i) { if (aCoords.IsNull() == Standard_False) {
// Check if it is necessary to create a new section. Standard_Integer i;
// Assume a case if there are empty sections. Standard_Integer j;
while (i == aNextSecIndex) { std::list <std::list <double> >::iterator anIt = theValue.begin();
// Create a next section.
theValue.push_back(anEmptyList);
++iNextSec;
if (iNextSec > anIndices->Upper()) { for (i = anIndices->Lower(); i <= anIndices->Upper(); ++i, ++anIt) {
aNextSecIndex = aCoords->Upper() + 1; const Standard_Integer iCoord1 = anIndices->Value(i);
} else { const Standard_Integer iCoord2 = i + 1 > anIndices->Upper() ?
aNextSecIndex = anIndices->Value(iNextSec); aCoords->Upper() + 1 : anIndices->Value(i + 1);
}
}
theValue.back().push_back(aCoords->Value(i)); for (j = iCoord1; j < iCoord2; ++j) {
anIt->push_back(aCoords->Value(j));
}
}
} }
} }
} }