+// 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);
+ }
+ }
+ }
+}