[Part] Avoid nullptr when using createArc

We could make `GeomCurve::createArc(...) = 0`, but then it needs to be
implemented in many subclasses which cannot be incomplete. It is implemented for
some of them, but others may need additional work (e.g. offsets), and would need
some exception throwing similar to what is now used.
This commit is contained in:
Ajinkya Dahale
2024-11-25 23:32:55 +05:30
parent f0f70daa0e
commit 05448b980a
2 changed files with 23 additions and 5 deletions

View File

@@ -795,7 +795,7 @@ GeomBSplineCurve* GeomCurve::toNurbs(double first, double last) const
GeomCurve* GeomCurve::createArc([[maybe_unused]] double first, [[maybe_unused]] double last) const
{
return nullptr;
THROWM(Base::NotImplementedError, "createArc: not implemented for this type of curve");
}
bool GeomCurve::tangent(double u, gp_Dir& dir) const
@@ -3606,13 +3606,21 @@ void GeomHyperbola::setHandle(const Handle(Geom_Hyperbola)& c)
myCurve = Handle(Geom_Hyperbola)::DownCast(c->Copy());
}
Geometry *GeomHyperbola::copy() const
Geometry* GeomHyperbola::copy() const
{
GeomHyperbola *newHyp = new GeomHyperbola(myCurve);
newHyp->copyNonTag(this);
return newHyp;
}
GeomCurve* GeomHyperbola::createArc(double first, double last) const
{
auto newArc = new GeomArcOfHyperbola(Handle(Geom_Hyperbola)::DownCast(this->handle()->Copy()));
newArc->setRange(first, last, false);
return newArc;
}
GeomBSplineCurve* GeomHyperbola::toNurbs(double first, double last) const
{
return GeomConic::toNurbs(first, last);
@@ -4058,6 +4066,14 @@ Geometry *GeomParabola::copy() const
return newPar;
}
GeomCurve* GeomParabola::createArc(double first, double last) const
{
auto newArc = new GeomArcOfParabola(Handle(Geom_Parabola)::DownCast(this->handle()->Copy()));
newArc->setRange(first, last, false);
return newArc;
}
GeomBSplineCurve* GeomParabola::toNurbs(double first, double last) const
{
// the default implementation suffices because a non-rational B-spline with

View File

@@ -212,7 +212,7 @@ public:
*/
virtual GeomBSplineCurve* toNurbs(double first, double last) const;
/*!
* \brief getArc Generates a curve that is an arc of this curve between given parameters
* \brief createArc Generates a curve that is an arc of this curve between given parameters
* \param first Parameter at start of arc
* \param last Parameter at end of arc. This may be < `first` for periodic curves.
* \return the new curve
@@ -653,7 +653,8 @@ public:
GeomHyperbola();
explicit GeomHyperbola(const Handle(Geom_Hyperbola)&);
~GeomHyperbola() override;
Geometry *copy() const override;
Geometry* copy() const override;
GeomCurve* createArc(double first, double last) const override;
double getMajorRadius() const;
void setMajorRadius(double Radius);
@@ -717,7 +718,8 @@ public:
GeomParabola();
explicit GeomParabola(const Handle(Geom_Parabola)&);
~GeomParabola() override;
Geometry *copy() const override;
Geometry* copy() const override;
GeomCurve* createArc(double first, double last) const override;
double getFocal() const;
void setFocal(double length);