Code:
Handle(Geom_Line) line = Handle(Geom_Line)::DownCast(c);
qDebug() << "cutCurve (line):" << first << " | " << last << " <> " << orientation;
double dx = p1.X() - p0.X();
double dy = p1.Y() - p0.Y();
double gf = dy / dx;
double cf = rMaster / sqrt(1 + gf * gf);
double dr = sqrt(dx * dx + dy * dy);
double D = p0.X() * p1.Y() - p1.X() * p0.Y();
double res = rMaster * rMaster * dr * dr - D * D;
double sig = dy < 0 ? -1 : 1;
double cx0 = cf * gf;
double cy0 = -cf;
double cx1 = -cx0;
double cy1 = -cy0;
double x0 = ( D * dy + sig * dx * sqrt(res)) / (dr * dr);
double x1 = ( D * dy - sig * dx * sqrt(res)) / (dr * dr);
double y0 = (-D * dx + abs(dy) * sqrt(res)) / (dr * dr);
double y1 = (-D * dx + abs(dy) * sqrt(res)) / (dr * dr);
double col = first + (last - first) / 2;
if (res <= 0) qDebug() << "OUPS - fine calculations means no cutpoints?!?";
qDebug() << "cutpoints: " << cx0 << " / " << cy0
<< " and " << cx1 << " / " << cy1;
qDebug() << "alt cp: " << x0 << " / " << y0
<< " and " << x1 << " / " << y1;
// Core().view3D()->createAxisCross({cx0, cy0, 0}, 2, nullptr, Quantity_NOC_BLACK);
// Core().view3D()->createAxisCross({cx1, cy1, 0}, 2, nullptr, Quantity_NOC_WHITE);
Core().view3D()->createAxisCross({x0, y0, 0}, 2, nullptr, Quantity_NOC_BLACK);
Core().view3D()->createAxisCross({x1, y1, 0}, 2, nullptr, Quantity_NOC_WHITE);
// double param0 = ElCLib::Parameter(line->Lin(), {cx0, cy0, p0.Z()});
// double param1 = ElCLib::Parameter(line->Lin(), {cx1, cy1, p0.Z()});
double param0 = ElCLib::Parameter(line->Lin(), {x0, y0, p0.Z()});
double param1 = ElCLib::Parameter(line->Lin(), {x1, y1, p0.Z()});
if (param0 >= first && param0 <= last) {
qDebug() << "<<< first cutpoint is part of line segment ==> "
<< first << " <> " << param0 << " <> " << last << "orientation:" << orientation;
if (param0 < col) {
qDebug() << "\tsecond part is part of interest";
edge = BRepBuilderAPI_MakeEdge(c, {x0, y0, p0.Z()}, p1);
}
else {
qDebug() << "\tfirst part is part of interest";
edge = BRepBuilderAPI_MakeEdge(c, p0, {x0, y0, p0.Z()});
}
}
else if (param1 >= first && param1 <= last) {
qDebug() << ">>> second cutpoint is part of line segment ==> "
<< first << " <> " << param1 << " <> " << last << "orientation:" << orientation;
if (param1 < col) {
qDebug() << "\tsecond part is part of interest";
edge = BRepBuilderAPI_MakeEdge(c, {x1, y1, p0.Z()}, p1);
}
else {
qDebug() << "\tfirst part is part of interest";
edge = BRepBuilderAPI_MakeEdge(c, p0, {x1, y1, p0.Z()});
}
}
else {
qDebug() << "?!?!? - none of the calculated cutpoints is inside of line parameters?!?"
<< first << " <> " << param0 << "|" << param1 << last;
edge = BRepBuilderAPI_MakeEdge(c, first, last);
}
}