Skip to content

Commit

Permalink
Part: Geometry functionality extension
Browse files Browse the repository at this point in the history
======================================

Added for curves:
getFirstParameter
getLastParameter
curvatureAt
length

Modified:
normalAt(double u, Base::Vector3d& dir)

as it was not working properly.
  • Loading branch information
abdullahtahiriyo authored and wwmayer committed Feb 21, 2017
1 parent 1bac54e commit 9c10b32
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 7 deletions.
91 changes: 85 additions & 6 deletions src/Mod/Part/App/Geometry.cpp
Expand Up @@ -93,6 +93,7 @@
# include <GC_MakeArcOfHyperbola.hxx>
# include <GC_MakeLine.hxx>
# include <GC_MakeSegment.hxx>
# include <GCPnts_AbscissaPoint.hxx>
# include <Precision.hxx>
# include <GeomAPI_ProjectPointOnCurve.hxx>
# include <ShapeConstruct_Curve.hxx>
Expand Down Expand Up @@ -375,15 +376,25 @@ Base::Vector3d GeomCurve::secondDerivativeAtParameter(double u) const
return Base::Vector3d(vec.X(),vec.Y(),vec.Z());
}

bool GeomCurve::normal(double u, gp_Dir& dir) const
bool GeomCurve::normalAt(double u, Base::Vector3d& dir) const
{
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(handle());
GeomLProp_CLProps prop(c,u,1,Precision::Confusion());
if (prop.IsTangentDefined()) {
prop.Normal(dir);
return true;

try {
if (!c.IsNull()) {
GeomLProp_CLProps prop(c,u,2,Precision::Confusion());
gp_Dir gdir;
prop.Normal(gdir);
dir = Base::Vector3d(gdir.X(), gdir.Y(), gdir.Z());

return true;
}
}

catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
throw Base::RuntimeError(e->GetMessageString());
}

return false;
}

Expand Down Expand Up @@ -433,6 +444,74 @@ bool GeomCurve::closestParameterToBasicCurve(const Base::Vector3d& point, double
}
}

double GeomCurve::getFirstParameter() const
{

Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(handle());

try {
if (!c.IsNull()) {
// pending check for RealFirst RealLast in case of infinite curve
return c->FirstParameter();
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
throw Base::RuntimeError(e->GetMessageString());
}

}
double GeomCurve::getLastParameter() const
{

Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(handle());

try {
if (!c.IsNull()) {
// pending check for RealFirst RealLast in case of infinite curve
return c->LastParameter();
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
throw Base::RuntimeError(e->GetMessageString());
}
}

double GeomCurve::curvatureAt(double u) const
{
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(handle());

try {
if (!c.IsNull()) {
GeomLProp_CLProps prop(c,u,2,Precision::Confusion());
return prop.Curvature();
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
throw Base::RuntimeError(e->GetMessageString());
}
}

double GeomCurve::length(double u, double v) const
{

Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(handle());

try {
if (!c.IsNull()) {
GeomAdaptor_Curve adaptor(c);
return GCPnts_AbscissaPoint::Length(adaptor,u,v,Precision::Confusion());
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
throw Base::RuntimeError(e->GetMessageString());
}
}


// -------------------------------------------------

TYPESYSTEM_SOURCE_ABSTRACT(Part::GeomBoundedCurve, Part::GeomCurve)
Expand Down
6 changes: 5 additions & 1 deletion src/Mod/Part/App/Geometry.h
Expand Up @@ -139,9 +139,13 @@ class PartExport GeomCurve : public Geometry
Base::Vector3d pointAtParameter(double u) const;
Base::Vector3d firstDerivativeAtParameter(double u) const;
Base::Vector3d secondDerivativeAtParameter(double u) const;
bool normal(double u, gp_Dir& dir) const;
bool closestParameter(const Base::Vector3d& point, double &u) const;
bool closestParameterToBasicCurve(const Base::Vector3d& point, double &u) const;
double getFirstParameter() const;
double getLastParameter() const;
double curvatureAt(double u) const;
double length(double u, double v) const;
bool normalAt(double u, Base::Vector3d& dir) const;
};

class PartExport GeomBoundedCurve : public GeomCurve
Expand Down

0 comments on commit 9c10b32

Please sign in to comment.