X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAPI%2FGeomAPI_Curve.cpp;h=2ffc946464537d2a2ac5a92a46c5ef42dd23ff9b;hb=ea593bc59e7e9461f6c4e2afd3f24d621edb1011;hp=7276c848597b451c2dca046099d894e6b26ac7aa;hpb=ea0dd4be94762fb8c508cabeb86c53e5eb3e17f0;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_Curve.cpp b/src/GeomAPI/GeomAPI_Curve.cpp index 7276c8485..2ffc94646 100644 --- a/src/GeomAPI/GeomAPI_Curve.cpp +++ b/src/GeomAPI/GeomAPI_Curve.cpp @@ -23,8 +23,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -33,7 +35,9 @@ #define MY_CURVE (*(implPtr())) GeomAPI_Curve::GeomAPI_Curve() - : GeomAPI_Interface(new Handle_Geom_Curve()), myStart(0), myEnd(1) + : GeomAPI_Interface(new Handle_Geom_Curve()), + myStart(-Precision::Infinite()), + myEnd(Precision::Infinite()) { } @@ -55,14 +59,53 @@ bool GeomAPI_Curve::isNull() const return MY_CURVE.IsNull() == Standard_True; } +static bool isCurveType(const Handle(Geom_Curve)& theCurve, const Handle(Standard_Type)& theType) +{ + if (theCurve.IsNull()) + return false; + Handle(Geom_Curve) aCurve = theCurve; + if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) + aCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve)->BasisCurve(); + return aCurve->DynamicType() == theType; +} + bool GeomAPI_Curve::isLine() const { - return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Line); + return isCurveType(MY_CURVE, STANDARD_TYPE(Geom_Line)); } bool GeomAPI_Curve::isCircle() const { - return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Circle); + return isCurveType(MY_CURVE, STANDARD_TYPE(Geom_Circle)); +} + +bool GeomAPI_Curve::isEllipse() const +{ + return isCurveType(MY_CURVE, STANDARD_TYPE(Geom_Ellipse)); +} + +double GeomAPI_Curve::startParam() +{ + if (Precision::IsInfinite(myStart)) { + if (isTrimmed()) { + myStart = Handle(Geom_TrimmedCurve)::DownCast(MY_CURVE)->FirstParameter(); + } + else if (MY_CURVE->IsClosed() && MY_CURVE->IsPeriodic()) + myStart = 0.0; + } + return myStart; +} + +double GeomAPI_Curve::endParam() +{ + if (Precision::IsInfinite(myEnd)) { + if (isTrimmed()) { + myEnd = Handle(Geom_TrimmedCurve)::DownCast(MY_CURVE)->LastParameter(); + } + else if (MY_CURVE->IsClosed() && MY_CURVE->IsPeriodic()) + myEnd = MY_CURVE->Period(); + } + return myEnd; } std::shared_ptr GeomAPI_Curve::getPoint(double theParam) @@ -82,8 +125,6 @@ bool GeomAPI_Curve::isTrimmed() const return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve); } -// unused in the unit tests for now -// LCOV_EXCL_START GeomCurvePtr GeomAPI_Curve::basisCurve() const { Handle(Geom_Curve) aCurve = MY_CURVE; @@ -94,7 +135,25 @@ GeomCurvePtr GeomAPI_Curve::basisCurve() const aNewCurve->setImpl(new Handle(Geom_Curve)(aCurve)); return aNewCurve; } -// LCOV_EXCL_STOP + + +const std::shared_ptr GeomAPI_Curve::project( + const std::shared_ptr& thePoint) const +{ + std::shared_ptr aResult; + if (MY_CURVE.IsNull()) + return aResult; + + const gp_Pnt& aPoint = thePoint->impl(); + + GeomAPI_ProjectPointOnCurve aProj(aPoint, MY_CURVE); + Standard_Integer aNbPoint = aProj.NbPoints(); + if (aNbPoint > 0) { + gp_Pnt aNearest = aProj.NearestPoint(); + aResult = GeomPointPtr(new GeomAPI_Pnt(aNearest.X(), aNearest.Y(), aNearest.Z())); + } + return aResult; +} // ================================================================================================