+
+void GeomAPI_Edge::setRange(const double& theFirst, const double& theLast)
+{
+ TopoDS_Edge anEdge = impl<TopoDS_Edge>();
+ double aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+ double aTolerance = BRep_Tool::Tolerance(anEdge);
+ if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
+ aCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve)->BasisCurve();
+ BRep_Builder().UpdateEdge(anEdge, aCurve, aTolerance);
+ }
+ BRep_Builder().Range(anEdge, theFirst, theLast);
+}
+
+void GeomAPI_Edge::getRange(double& theFirst, double& theLast) const
+{
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, theFirst, theLast);
+}
+
+// LCOV_EXCL_START
+bool GeomAPI_Edge::isInPlane(std::shared_ptr<GeomAPI_Pln> thePlane) const
+{
+ double aFirst, aLast;
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
+ if (aCurve.IsNull())
+ return false;
+
+ double A, B, C, D;
+ thePlane->coefficients(A, B, C, D);
+ gp_Pln aPlane(A, B, C, D);
+
+ bool inPlane = false;
+ if (aCurve->IsKind(STANDARD_TYPE(Geom_Line))) {
+ // check start and end points on the plane
+ gp_Pnt aFirstPnt = aCurve->Value(aFirst);
+ gp_Pnt aLastPnt = aCurve->Value(aLast);
+ inPlane = aPlane.SquareDistance(aFirstPnt) < Precision::SquareConfusion() &&
+ aPlane.SquareDistance(aLastPnt) < Precision::SquareConfusion();
+ } else {
+ Handle(Geom_Circle) aCirc = circ(aCurve);
+ if (!aCirc.IsNull()) {
+ gp_Pnt aCenter = aCirc->Location();
+ Standard_Real aDot = aPlane.Axis().Direction().Dot(aCirc->Axis().Direction());
+ inPlane = aPlane.SquareDistance(aCenter) < Precision::SquareConfusion() &&
+ Abs(Abs(aDot) - 1.0) < Precision::Confusion();
+ } else {
+ // three points checking
+ gp_Pnt aFirstPnt = aCurve->Value(aFirst);
+ gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.);
+ gp_Pnt aLastPnt = aCurve->Value(aLast);
+ inPlane = aPlane.SquareDistance(aFirstPnt) < Precision::SquareConfusion() &&
+ aPlane.SquareDistance(aMidPnt) < Precision::SquareConfusion() &&
+ aPlane.SquareDistance(aLastPnt) < Precision::SquareConfusion();
+ }
+ }
+ return inPlane;
+}
+// LCOV_EXCL_STOP
+
+void GeomAPI_Edge::intersectWithPlane(const std::shared_ptr<GeomAPI_Pln> thePlane,
+ std::list<std::shared_ptr<GeomAPI_Pnt>>& theResult) const
+{
+ double aFirst, aLast;
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
+ if (!aCurve.IsNull()) {
+ double A, B, C, D;
+ thePlane->coefficients(A, B, C, D);
+ gp_Pln aPln(A, B, C, D);
+ Handle(Geom_Plane) aPlane = new Geom_Plane(aPln);
+
+ // intersect the plane with the curve
+ GeomAPI_IntCS aIntersect;
+ aIntersect.Perform(aCurve, aPlane);
+ if (aIntersect.IsDone() && (aIntersect.NbPoints() > 0)) {
+ gp_Pnt aPnt;
+ for (int i = 1; i <= aIntersect.NbPoints(); i++) {
+ // check the parameter of intersection in the edge range
+ aIntersect.Parameters(i, A, B, C);
+ if (aCurve->IsPeriodic())
+ C = ElCLib::InPeriod(C, aFirst, aFirst + aCurve->Period());
+ if (C < aFirst - Precision::PConfusion() || C > aLast + Precision::PConfusion())
+ continue;
+
+ // obtain intersection point
+ aPnt = aIntersect.Point(i);
+ std::shared_ptr<GeomAPI_Pnt> aPntPtr(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
+ theResult.push_back(aPntPtr);
+ }
+ }
+ else {
+ // find minimal distance between the plane and the curve
+ GeomAPI_ExtremaCurveSurface anExtrema(aCurve, aPlane);
+ double aTolerance = BRep_Tool::Tolerance(TopoDS::Edge(aShape));
+ if (anExtrema.NbExtrema() > 0 &&
+ !anExtrema.Extrema().IsParallel() &&
+ anExtrema.LowerDistance() < aTolerance) {
+ // distance is lower than tolerance => tangent case
+ gp_Pnt aPntC, aPntS;
+ anExtrema.NearestPoints(aPntC, aPntS);
+ std::shared_ptr<GeomAPI_Pnt> aPntPtr(new GeomAPI_Pnt(aPntS.X(), aPntS.Y(), aPntS.Z()));
+ theResult.push_back(aPntPtr);
+ }
+ }
+ }
+}
+
+double GeomAPI_Edge::length() const
+{
+ const TopoDS_Edge& anEdge = TopoDS::Edge(impl<TopoDS_Shape>());
+ BRepAdaptor_Curve aBRepAdaptor = BRepAdaptor_Curve(anEdge);
+ Adaptor3d_Curve* anAdaptor3d = &aBRepAdaptor;
+ return GCPnts_AbscissaPoint::Length(*anAdaptor3d);
+}
+
+bool GeomAPI_Edge::isClosed() const
+{
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
+ if (aShape.IsNull())
+ return false;
+ double aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
+ if (aCurve.IsNull() || !aCurve->IsPeriodic())
+ return false;
+ aLast += aLast > aFirst ? -aCurve->Period() : aCurve->Period();;
+
+ return fabs(aFirst - aLast) < 1.e-9;
+}
+
+bool GeomAPI_Edge::isDegenerated() const
+{
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
+ if (aShape.IsNull() || aShape.ShapeType() != TopAbs_EDGE)
+ return false;
+ return BRep_Tool::Degenerated(TopoDS::Edge(aShape));
+}
+
+void GeomAPI_Edge::setFirstPointTolerance(const double theTolerance)
+{
+ TopoDS_Edge anEdge = impl<TopoDS_Edge>();
+ TopoDS_Vertex aVFirst, aVLast;
+ TopExp::Vertices(anEdge, aVFirst, aVLast);
+ BRep_Builder().UpdateVertex(aVFirst, theTolerance);
+}
+
+void GeomAPI_Edge::setLastPointTolerance(const double theTolerance)
+{
+ TopoDS_Edge anEdge = impl<TopoDS_Edge>();
+ TopoDS_Vertex aVFirst, aVLast;
+ TopExp::Vertices(anEdge, aVFirst, aVLast);
+ BRep_Builder().UpdateVertex(aVLast, theTolerance);
+}
+
+double GeomAPI_Edge::firstPointTolerance() const
+{
+ TopoDS_Edge anEdge = impl<TopoDS_Edge>();
+ TopoDS_Vertex aVFirst, aVLast;
+ TopExp::Vertices(anEdge, aVFirst, aVLast);
+ return BRep_Tool::Tolerance(aVFirst);
+}
+
+double GeomAPI_Edge::lastPointTolerance() const
+{
+ TopoDS_Edge anEdge = impl<TopoDS_Edge>();
+ TopoDS_Vertex aVFirst, aVLast;
+ TopExp::Vertices(anEdge, aVFirst, aVLast);
+ return BRep_Tool::Tolerance(aVLast);
+}
+
+GeomPointPtr GeomAPI_Edge::middlePoint() const
+{
+ GeomPointPtr aMiddlePoint;
+
+ const TopoDS_Edge& anEdge = impl<TopoDS_Edge>();
+ if (anEdge.IsNull())
+ return aMiddlePoint;
+ double aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+ if (aCurve.IsNull())
+ return aMiddlePoint;
+
+ static const int NB_POINTS = 3;
+ GeomAdaptor_Curve aCurveAdaptor(aCurve, aFirst, aLast);
+ GCPnts_UniformAbscissa anAlgo(aCurveAdaptor, NB_POINTS);
+ if (anAlgo.IsDone()) {
+ gp_Pnt aPnt = aCurveAdaptor.Value(anAlgo.Parameter(2));
+ aMiddlePoint = GeomPointPtr(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
+ }
+ return aMiddlePoint;
+}