1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-16 10:08:36 +03:00

0032640: Coding Rules - fix misprints in GeomliteTest_API2dCommands.cxx

This commit is contained in:
kgv 2021-10-24 12:09:02 +03:00 committed by smoskvin
parent f706c128c2
commit 4f7ad5fb76
2 changed files with 151 additions and 140 deletions

View File

@ -46,6 +46,7 @@
#include <IntRes2d_IntersectionPoint.hxx> #include <IntRes2d_IntersectionPoint.hxx>
#include <Geom2dAdaptor_Curve.hxx> #include <Geom2dAdaptor_Curve.hxx>
#include <Message.hxx> #include <Message.hxx>
#include <NCollection_Shared.hxx>
#include <memory> #include <memory>
#include <stdio.h> #include <stdio.h>
@ -60,38 +61,38 @@ Standard_IMPORT Draw_Viewer dout;
static Standard_Integer proj (Draw_Interpretor& di, Standard_Integer n, const char** a) static Standard_Integer proj (Draw_Interpretor& di, Standard_Integer n, const char** a)
{ {
if ( n < 4) return 1; if (n != 4)
{
gp_Pnt2d P(Draw::Atof(a[2]),Draw::Atof(a[3])); di << "Syntax error: wrong number of arguments";
return 1;
char name[100]; }
Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[1]); Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[1]);
if (GC.IsNull()) if (GC.IsNull())
{
di << "Syntax error: '" << a[1] << "' is NULL";
return 1; return 1;
}
Geom2dAPI_ProjectPointOnCurve proj(P,GC,GC->FirstParameter(), const gp_Pnt2d P (Draw::Atof (a[2]), Draw::Atof (a[3]));
GC->LastParameter()); Geom2dAPI_ProjectPointOnCurve proj(P,GC,GC->FirstParameter(), GC->LastParameter());
for (Standard_Integer i = 1; i <= proj.NbPoints(); i++) for (Standard_Integer i = 1; i <= proj.NbPoints(); i++)
{ {
gp_Pnt2d aP1 = proj.Point(i); gp_Pnt2d aP1 = proj.Point(i);
const Standard_Real aDist = P.Distance(aP1); const Standard_Real aDist = P.Distance(aP1);
Sprintf(name, "%s%d", "ext_", i); const TCollection_AsciiString aName = TCollection_AsciiString ("ext_") + i;
if (aDist > Precision::PConfusion()) if (aDist > Precision::PConfusion())
{ {
Handle(Geom2d_Line) L = new Geom2d_Line(P, gp_Dir2d(aP1.XY() - P.XY())); Handle(Geom2d_Line) L = new Geom2d_Line(P, gp_Dir2d(aP1.XY() - P.XY()));
Handle(Geom2d_TrimmedCurve) CT = new Geom2d_TrimmedCurve(L, 0., aDist); Handle(Geom2d_TrimmedCurve) CT = new Geom2d_TrimmedCurve(L, 0., aDist);
DrawTrSurf::Set(name, CT); DrawTrSurf::Set (aName.ToCString(), CT);
} }
else else
{ {
DrawTrSurf::Set(name, aP1); DrawTrSurf::Set (aName.ToCString(), aP1);
} }
di << name << " "; di << aName << " ";
} }
return 0; return 0;
@ -119,18 +120,18 @@ static Standard_Integer appro(Draw_Interpretor& di, Standard_Integer n, const ch
// 2dappro result nbpoint x1 dx y1 y2 .. // 2dappro result nbpoint x1 dx y1 y2 ..
// - tableau de points (x1,y1) (x1+dx,y2) ... avec x = t // - tableau de points (x1,y1) (x1+dx,y2) ... avec x = t
static Standard_Real Tol2d = 1.e-6; static Standard_Real Tol2d = 1.e-6;
if (n < 3)
if (n < 3) { {
if (n == 2) if (n == 2)
{
Tol2d = Draw::Atof(a[1]); Tol2d = Draw::Atof(a[1]);
}
di << "Tolerance for 2d approx : "<< Tol2d << "\n"; di << "Tolerance for 2d approx : "<< Tol2d << "\n";
return 0; return 0;
} }
Standard_Integer i, Nb = Draw::Atoi(a[2]); Standard_Integer i, Nb = Draw::Atoi(a[2]);
Standard_Boolean hasPoints = Standard_True; Standard_Boolean hasPoints = Standard_True;
@ -257,9 +258,7 @@ static Standard_Integer appro(Draw_Interpretor& di, Standard_Integer n, const ch
DrawTrSurf::Set(a[1], TheCurve); DrawTrSurf::Set(a[1], TheCurve);
di << a[1]; di << a[1];
return 0; return 0;
} }
//======================================================================= //=======================================================================
@ -269,25 +268,29 @@ static Standard_Integer appro(Draw_Interpretor& di, Standard_Integer n, const ch
static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const char** a) static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const char** a)
{ {
if ( n<3) return 1; if (n != 3)
{
Handle(Geom2d_Curve) GC1, GC2; di << "Syntax error: wrong number of arguments";
Standard_Real U1f,U1l,U2f,U2l;
GC1 = DrawTrSurf::GetCurve2d(a[1]);
if ( GC1.IsNull())
return 1; return 1;
U1f = GC1->FirstParameter(); }
U1l = GC1->LastParameter();
GC2 = DrawTrSurf::GetCurve2d(a[2]); Handle(Geom2d_Curve) GC1 = DrawTrSurf::GetCurve2d (a[1]);
if ( GC2.IsNull()) Handle(Geom2d_Curve) GC2 = DrawTrSurf::GetCurve2d (a[2]);
if (GC1.IsNull())
{
di << "Syntax error: '" << a[1] << "' is NULL";
return 1; return 1;
U2f = GC2->FirstParameter(); }
U2l = GC2->LastParameter(); if (GC2.IsNull())
{
di << "Syntax error: '" << a[2] << "' is NULL";
return 1;
}
char name[100]; const Standard_Real U1f = GC1->FirstParameter();
const Standard_Real U1l = GC1->LastParameter();
const Standard_Real U2f = GC2->FirstParameter();
const Standard_Real U2l = GC2->LastParameter();
Geom2dAPI_ExtremaCurveCurve Ex(GC1,GC2,U1f,U1l,U2f,U2l); Geom2dAPI_ExtremaCurveCurve Ex(GC1,GC2,U1f,U1l,U2f,U2l);
Standard_Boolean isInfinitySolutions = Ex.Extrema().IsParallel(); Standard_Boolean isInfinitySolutions = Ex.Extrema().IsParallel();
@ -308,25 +311,23 @@ static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const
gp_Pnt2d P1,P2; gp_Pnt2d P1,P2;
Ex.Points(i,P1,P2); Ex.Points(i,P1,P2);
di << "dist " << i << ": " << Ex.Distance(i) << " "; di << "dist " << i << ": " << Ex.Distance(i) << " ";
const TCollection_AsciiString aName = TCollection_AsciiString("ext_") + i;
if (Ex.Distance(i) <= Precision::PConfusion()) if (Ex.Distance(i) <= Precision::PConfusion())
{ {
Handle(Draw_Marker2D) mark = new Draw_Marker2D( P1, Draw_X, Draw_vert); Handle(Draw_Marker2D) mark = new Draw_Marker2D( P1, Draw_X, Draw_vert);
dout << mark; dout << mark;
dout.Flush(); dout.Flush();
Sprintf(name,"%s%d","ext_",i); const char* temp = aName.ToCString();
char* temp = name;
DrawTrSurf::Set(temp, P1); DrawTrSurf::Set(temp, P1);
di << name << "\n";
} }
else else
{ {
Handle(Geom2d_Line) L = new Geom2d_Line(P1,gp_Vec2d(P1,P2)); Handle(Geom2d_Line) L = new Geom2d_Line(P1,gp_Vec2d(P1,P2));
Handle(Geom2d_TrimmedCurve) CT = new Geom2d_TrimmedCurve(L, 0., P1.Distance(P2)); Handle(Geom2d_TrimmedCurve) CT = new Geom2d_TrimmedCurve(L, 0., P1.Distance(P2));
Sprintf(name,"%s%d","ext_",i); const char* temp = aName.ToCString();
char* temp = name; // portage WNT
DrawTrSurf::Set(temp, CT); DrawTrSurf::Set(temp, CT);
di << name << "\n";
} }
di << aName << "\n";
} }
return 0; return 0;
@ -338,25 +339,12 @@ static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const
//======================================================================= //=======================================================================
static Standard_Integer intersect(Draw_Interpretor& di, Standard_Integer n, const char** a) static Standard_Integer intersect(Draw_Interpretor& di, Standard_Integer n, const char** a)
{ {
if (n < 2) Handle(Geom2d_Curve) C1, C2;
{
di.PrintHelp(a[0]);
return 1;
}
Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[1]);
if (C1.IsNull())
{
di << "Curve " << a[1] << " is null\n";
return 1;
}
Handle(Geom2d_Curve) C2;
Standard_Real Tol = 0.001; Standard_Real Tol = 0.001;
Standard_Boolean bPrintState = Standard_False; Standard_Boolean bPrintState = Standard_False;
// Retrieve other parameters if any // Retrieve other parameters if any
for (Standard_Integer i = 2; i < n; ++i) for (Standard_Integer i = 1; i < n; ++i)
{ {
if (!strcmp(a[i], "-tol")) if (!strcmp(a[i], "-tol"))
{ {
@ -366,25 +354,47 @@ static Standard_Integer intersect(Draw_Interpretor& di, Standard_Integer n, cons
{ {
bPrintState = Standard_True; bPrintState = Standard_True;
} }
else else if (C1.IsNull())
{
C1 = DrawTrSurf::GetCurve2d (a[i]);
if (C1.IsNull())
{
di << "Syntax error: curve '" << a[i] << "' is null";
return 1;
}
}
else if (C2.IsNull())
{ {
C2 = DrawTrSurf::GetCurve2d(a[i]); C2 = DrawTrSurf::GetCurve2d(a[i]);
if (C2.IsNull()) if (C2.IsNull())
{ {
di << "Curve " << a[i] << " is null\n"; di << "Syntax error: curve '" << a[i] << "' is null";
return 1; return 1;
} }
} }
else
{
di << "Syntax error at '" << a[i] << "'";
return 1;
}
}
if (C1.IsNull())
{
di << "Syntax error: wrong number of arguments";
return 1;
} }
Geom2dAPI_InterCurveCurve Intersector; Geom2dAPI_InterCurveCurve Intersector;
if (!C2.IsNull()) if (!C2.IsNull())
{
// Curves intersection // Curves intersection
Intersector.Init(C1, C2, Tol); Intersector.Init(C1, C2, Tol);
}
else else
{
// Self-intersection of the curve // Self-intersection of the curve
Intersector.Init(C1, Tol); Intersector.Init(C1, Tol);
}
const Geom2dInt_GInter& anIntTool = Intersector.Intersector(); const Geom2dInt_GInter& anIntTool = Intersector.Intersector();
if (!anIntTool.IsDone()) if (!anIntTool.IsDone())
@ -394,7 +404,9 @@ static Standard_Integer intersect(Draw_Interpretor& di, Standard_Integer n, cons
} }
if (anIntTool.IsEmpty()) if (anIntTool.IsEmpty())
{
return 0; return 0;
}
Standard_Integer aNbPoints = Intersector.NbPoints(); Standard_Integer aNbPoints = Intersector.NbPoints();
for (Standard_Integer i = 1; i <= aNbPoints; i++) for (Standard_Integer i = 1; i <= aNbPoints; i++)
@ -430,7 +442,6 @@ static Standard_Integer intersect(Draw_Interpretor& di, Standard_Integer n, cons
} }
dout.Flush(); dout.Flush();
return 0; return 0;
} }
@ -441,28 +452,25 @@ static Standard_Integer intersect(Draw_Interpretor& di, Standard_Integer n, cons
static Standard_Integer intersect_ana(Draw_Interpretor& di, Standard_Integer n, const char** a) static Standard_Integer intersect_ana(Draw_Interpretor& di, Standard_Integer n, const char** a)
{ {
if (n < 2) if (n != 3)
{ {
Message::SendFail() << "2dintana circle circle"; di << "Syntax error: wrong number of arguments";
return 1; return 1;
} }
Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[1]); Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[1]);
if (C1.IsNull() && !C1->IsKind(STANDARD_TYPE(Geom2d_Circle)))
return 1;
Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[2]); Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[2]);
if (C2.IsNull() && !C2->IsKind(STANDARD_TYPE(Geom2d_Circle)))
return 1;
Handle(Geom2d_Circle) aCir1 = Handle(Geom2d_Circle)::DownCast(C1); Handle(Geom2d_Circle) aCir1 = Handle(Geom2d_Circle)::DownCast(C1);
Handle(Geom2d_Circle) aCir2 = Handle(Geom2d_Circle)::DownCast(C2); Handle(Geom2d_Circle) aCir2 = Handle(Geom2d_Circle)::DownCast(C2);
if (aCir1.IsNull() || aCir2.IsNull())
{
di << "Syntax error: '" << a[aCir1.IsNull() ? 1 : 2] << "' is not a circle";
return 1;
}
IntAna2d_AnaIntersection Intersector(aCir1->Circ2d(), aCir2->Circ2d()); IntAna2d_AnaIntersection Intersector(aCir1->Circ2d(), aCir2->Circ2d());
for (Standard_Integer i = 1; i <= Intersector.NbPoints(); i++)
Standard_Integer i; {
for (i = 1; i <= Intersector.NbPoints(); i++) {
gp_Pnt2d P = Intersector.Point(i).Value(); gp_Pnt2d P = Intersector.Point(i).Value();
di << "Intersection point " << i << " : " << P.X() << " " << P.Y() << "\n"; di << "Intersection point " << i << " : " << P.X() << " " << P.Y() << "\n";
di << "parameter on the fist: " << Intersector.Point(i).ParamOnFirst(); di << "parameter on the fist: " << Intersector.Point(i).ParamOnFirst();
@ -471,7 +479,6 @@ static Standard_Integer intersect_ana(Draw_Interpretor& di, Standard_Integer n,
dout << mark; dout << mark;
} }
dout.Flush(); dout.Flush();
return 0; return 0;
} }
@ -482,90 +489,88 @@ static Standard_Integer intersect_ana(Draw_Interpretor& di, Standard_Integer n,
static Standard_Integer intconcon(Draw_Interpretor& di, Standard_Integer n, const char** a) static Standard_Integer intconcon(Draw_Interpretor& di, Standard_Integer n, const char** a)
{ {
if( n < 2) if (n != 3)
{ {
Message::SendFail() << "intconcon con1 con2"; di << "Syntax error: wrong number of arguments";
return 1; return 1;
} }
Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[1]); Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[1]);
if (C1.IsNull()) if (C1.IsNull())
{ {
Message::SendFail() << a[1] << " is Null"; di << "Syntax error: '" << a[1] << "' is Null";
return 1; return 1;
} }
Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[2]); Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[2]);
if (C2.IsNull()) if (C2.IsNull())
{ {
Message::SendFail() << a[2] << " is Null"; di << "Syntax error: '" << a[2] << "' is Null";
return 1; return 1;
} }
Geom2dAdaptor_Curve AC1(C1), AC2(C2); Geom2dAdaptor_Curve AC1(C1), AC2(C2);
GeomAbs_CurveType T1 = AC1.GetType(), T2 = AC2.GetType(); GeomAbs_CurveType T1 = AC1.GetType(), T2 = AC2.GetType();
#if (defined(_MSC_VER) && (_MSC_VER < 1600)) Handle(NCollection_Shared<IntAna2d_Conic>) pCon;
std::auto_ptr<IntAna2d_Conic> pCon;
#else
std::unique_ptr<IntAna2d_Conic> pCon;
#endif
switch (T2) switch (T2)
{ {
case GeomAbs_Line: case GeomAbs_Line:
{ {
pCon.reset(new IntAna2d_Conic(AC2.Line())); pCon.reset (new NCollection_Shared<IntAna2d_Conic>(AC2.Line()));
break; break;
} }
case GeomAbs_Circle: case GeomAbs_Circle:
{ {
pCon.reset(new IntAna2d_Conic(AC2.Circle())); pCon.reset (new NCollection_Shared<IntAna2d_Conic>(AC2.Circle()));
break; break;
} }
case GeomAbs_Ellipse: case GeomAbs_Ellipse:
{ {
pCon.reset(new IntAna2d_Conic(AC2.Ellipse())); pCon.reset (new NCollection_Shared<IntAna2d_Conic>(AC2.Ellipse()));
break; break;
} }
case GeomAbs_Hyperbola: case GeomAbs_Hyperbola:
{ {
pCon.reset(new IntAna2d_Conic(AC2.Hyperbola())); pCon.reset (new NCollection_Shared<IntAna2d_Conic>(AC2.Hyperbola()));
break; break;
} }
case GeomAbs_Parabola: case GeomAbs_Parabola:
{ {
pCon.reset(new IntAna2d_Conic(AC2.Parabola())); pCon.reset (new NCollection_Shared<IntAna2d_Conic>(AC2.Parabola()));
break; break;
} }
default: default:
Message::SendFail() << a[2] << " is not conic"; {
return 1; di << "Syntax error: '" << a[2] << "' is not conic";
return 1;
}
} }
IntAna2d_AnaIntersection Intersector; IntAna2d_AnaIntersection Intersector;
switch (T1) switch (T1)
{ {
case GeomAbs_Line: case GeomAbs_Line:
Intersector.Perform(AC1.Line(), *pCon); Intersector.Perform(AC1.Line(), *pCon);
break; break;
case GeomAbs_Circle: case GeomAbs_Circle:
Intersector.Perform(AC1.Circle(), *pCon); Intersector.Perform(AC1.Circle(), *pCon);
break; break;
case GeomAbs_Ellipse: case GeomAbs_Ellipse:
Intersector.Perform(AC1.Ellipse(), *pCon); Intersector.Perform(AC1.Ellipse(), *pCon);
break; break;
case GeomAbs_Hyperbola: case GeomAbs_Hyperbola:
Intersector.Perform(AC1.Hyperbola(), *pCon); Intersector.Perform(AC1.Hyperbola(), *pCon);
break; break;
case GeomAbs_Parabola: case GeomAbs_Parabola:
Intersector.Perform(AC1.Parabola(), *pCon); Intersector.Perform(AC1.Parabola(), *pCon);
break; break;
default: default:
Message::SendFail() << a[1] << " is not conic"; di << "Syntax error: '" << a[1] << "' is not conic";
return 1; return 1;
} }
Standard_Integer i; for (Standard_Integer i = 1; i <= Intersector.NbPoints(); i++)
for ( i = 1; i <= Intersector.NbPoints(); i++) { {
gp_Pnt2d P = Intersector.Point(i).Value(); gp_Pnt2d P = Intersector.Point(i).Value();
di<<"Intersection point "<<i<<" : "<<P.X()<<" "<<P.Y()<<"\n"; di<<"Intersection point "<<i<<" : "<<P.X()<<" "<<P.Y()<<"\n";
di << "parameter on the fist: " << Intersector.Point(i).ParamOnFirst(); di << "parameter on the fist: " << Intersector.Point(i).ParamOnFirst();
@ -581,12 +586,9 @@ static Standard_Integer intconcon(Draw_Interpretor& di, Standard_Integer n, cons
dout << mark; dout << mark;
} }
dout.Flush(); dout.Flush();
return 0; return 0;
} }
void GeomliteTest::API2dCommands(Draw_Interpretor& theCommands) void GeomliteTest::API2dCommands(Draw_Interpretor& theCommands)
{ {
static Standard_Boolean done = Standard_False; static Standard_Boolean done = Standard_False;
@ -621,8 +623,12 @@ void GeomliteTest::API2dCommands(Draw_Interpretor& theCommands)
" -state - allows printing the intersection state for each point.", " -state - allows printing the intersection state for each point.",
__FILE__, intersect, g); __FILE__, intersect, g);
theCommands.Add("2dintanalytical", "intersect circle1 and circle2 using IntAna",__FILE__, theCommands.Add("2dintanalytical",
intersect_ana,g); "2dintanalytical circle1 circle2"
theCommands.Add("intconcon", "intersect conic curve1 and conic curve2 using IntAna", __FILE__, "Intersect circle1 and circle2 using IntAna2d_AnaIntersection.",
intconcon, g); __FILE__, intersect_ana, g);
theCommands.Add("intconcon",
"intconcon curve1 curve2"
"Intersect conic curve1 and conic curve2 using IntAna2d_AnaIntersection",
__FILE__, intconcon, g);
} }

View File

@ -7140,6 +7140,11 @@ static Standard_Integer VAnimation (Draw_Interpretor& theDI,
} }
} }
} }
if (anAnimation.IsNull())
{
Message::SendFail() << "Syntax error: wrong number of arguments";
return 1;
}
if (anArgIter >= theArgNb) if (anArgIter >= theArgNb)
{ {