1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-06 18:26:22 +03:00

0026837: SameParameter algorithm throws an exception

Test case for issue CR26837
This commit is contained in:
ifv 2015-11-17 10:53:51 +03:00 committed by bugmaster
parent d2dfbc4d7d
commit 54f91e0332
2 changed files with 59 additions and 34 deletions

View File

@ -882,62 +882,68 @@ void GeomLib::SameRange(const Standard_Real Tolerance,
{ {
if(CurvePtr.IsNull()) Standard_Failure::Raise(); if(CurvePtr.IsNull()) Standard_Failure::Raise();
if (Abs(LastOnCurve - RequestedLast) <= Tolerance && if (Abs(LastOnCurve - RequestedLast) <= Tolerance &&
Abs(FirstOnCurve - RequestedFirst) <= Tolerance) { Abs(FirstOnCurve - RequestedFirst) <= Tolerance)
NewCurvePtr = CurvePtr; {
return; NewCurvePtr = CurvePtr;
return;
} }
// the parametrisation lentgh must at least be the same. // the parametrisation lentgh must at least be the same.
if (Abs(LastOnCurve - FirstOnCurve - RequestedLast + RequestedFirst) if (Abs(LastOnCurve - FirstOnCurve - RequestedLast + RequestedFirst)
<= Tolerance) { <= Tolerance)
if (CurvePtr->IsKind(STANDARD_TYPE(Geom2d_Line))) { {
if (CurvePtr->IsKind(STANDARD_TYPE(Geom2d_Line)))
{
Handle(Geom2d_Line) Line = Handle(Geom2d_Line) Line =
Handle(Geom2d_Line)::DownCast(CurvePtr->Copy()); Handle(Geom2d_Line)::DownCast(CurvePtr->Copy());
Standard_Real dU = FirstOnCurve - RequestedFirst; Standard_Real dU = FirstOnCurve - RequestedFirst;
gp_Dir2d D = Line->Direction() ; gp_Dir2d D = Line->Direction() ;
Line->Translate(dU * gp_Vec2d(D)); Line->Translate(dU * gp_Vec2d(D));
NewCurvePtr = Line; NewCurvePtr = Line;
} }
else if (CurvePtr->IsKind(STANDARD_TYPE(Geom2d_Circle))) { else if (CurvePtr->IsKind(STANDARD_TYPE(Geom2d_Circle)))
{
gp_Trsf2d Trsf; gp_Trsf2d Trsf;
NewCurvePtr = Handle(Geom2d_Curve)::DownCast(CurvePtr->Copy()); NewCurvePtr = Handle(Geom2d_Curve)::DownCast(CurvePtr->Copy());
Handle(Geom2d_Circle) Circ = Handle(Geom2d_Circle) Circ =
Handle(Geom2d_Circle)::DownCast(NewCurvePtr); Handle(Geom2d_Circle)::DownCast(NewCurvePtr);
gp_Pnt2d P = Circ->Location(); gp_Pnt2d P = Circ->Location();
Standard_Real dU; Standard_Real dU;
if (Circ->Circ2d().IsDirect()) { if (Circ->Circ2d().IsDirect()) {
dU = FirstOnCurve - RequestedFirst; dU = FirstOnCurve - RequestedFirst;
} }
else { else {
dU = RequestedFirst - FirstOnCurve; dU = RequestedFirst - FirstOnCurve;
} }
Trsf.SetRotation(P,dU); Trsf.SetRotation(P,dU);
NewCurvePtr->Transform(Trsf) ; NewCurvePtr->Transform(Trsf) ;
} }
else if (CurvePtr->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) { else if (CurvePtr->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve)))
{
Handle(Geom2d_TrimmedCurve) TC = Handle(Geom2d_TrimmedCurve) TC =
Handle(Geom2d_TrimmedCurve)::DownCast(CurvePtr); Handle(Geom2d_TrimmedCurve)::DownCast(CurvePtr);
GeomLib::SameRange(Tolerance, GeomLib::SameRange(Tolerance,
TC->BasisCurve(), TC->BasisCurve(),
FirstOnCurve , LastOnCurve, FirstOnCurve , LastOnCurve,
RequestedFirst, RequestedLast, RequestedFirst, RequestedLast,
NewCurvePtr); NewCurvePtr);
NewCurvePtr = new Geom2d_TrimmedCurve( NewCurvePtr, RequestedFirst, RequestedLast ); NewCurvePtr = new Geom2d_TrimmedCurve( NewCurvePtr, RequestedFirst, RequestedLast );
} }
// //
// attention a des problemes de limitation : utiliser le MEME test que dans // attention a des problemes de limitation : utiliser le MEME test que dans
// Geom2d_TrimmedCurve::SetTrim car sinon comme on risque de relimite sur // Geom2d_TrimmedCurve::SetTrim car sinon comme on risque de relimite sur
// RequestedFirst et RequestedLast on aura un probleme // RequestedFirst et RequestedLast on aura un probleme
// //
// //
else if (Abs(LastOnCurve - FirstOnCurve) > Precision::PConfusion() || else if (Abs(LastOnCurve - FirstOnCurve) > Precision::PConfusion() ||
Abs(RequestedLast + RequestedFirst) > Precision::PConfusion()) { Abs(RequestedLast + RequestedFirst) > Precision::PConfusion())
{
Handle(Geom2d_TrimmedCurve) TC = Handle(Geom2d_TrimmedCurve) TC =
new Geom2d_TrimmedCurve(CurvePtr,FirstOnCurve,LastOnCurve); new Geom2d_TrimmedCurve(CurvePtr,FirstOnCurve,LastOnCurve);
Handle(Geom2d_BSplineCurve) BS = Handle(Geom2d_BSplineCurve) BS =
Geom2dConvert::CurveToBSplineCurve(TC); Geom2dConvert::CurveToBSplineCurve(TC);
TColStd_Array1OfReal Knots(1,BS->NbKnots()); TColStd_Array1OfReal Knots(1,BS->NbKnots());
BS->Knots(Knots); BS->Knots(Knots);
@ -946,11 +952,13 @@ void GeomLib::SameRange(const Standard_Real Tolerance,
BS->SetKnots(Knots); BS->SetKnots(Knots);
NewCurvePtr = BS; NewCurvePtr = BS;
} }
} }
else { // On segmente le resultat else
{ // On segmente le resultat
Standard_Real Udeb = Max(CurvePtr->FirstParameter(), FirstOnCurve);
Standard_Real Ufin = Min(CurvePtr->LastParameter(), LastOnCurve);
Handle(Geom2d_TrimmedCurve) TC = Handle(Geom2d_TrimmedCurve) TC =
new Geom2d_TrimmedCurve( CurvePtr, FirstOnCurve, LastOnCurve ); new Geom2d_TrimmedCurve( CurvePtr, Udeb, Ufin );
// //
Handle(Geom2d_BSplineCurve) BS = Handle(Geom2d_BSplineCurve) BS =
Geom2dConvert::CurveToBSplineCurve(TC); Geom2dConvert::CurveToBSplineCurve(TC);

View File

@ -0,0 +1,17 @@
puts "========================"
puts "OCC26837"
puts "========================"
puts ""
#################################################
# SameParameter algorithm throws an exception
#################################################
restore [locate_data_file bug26837_e.brep] result
if [catch {sameparameter result} catch_result] {
puts "Faulty : SameParameter algorithm throws an exception"
} else {
puts "OK : SameParameter algorithm works properly"
}
set 2dviewer 1