Fix issues in ellipse creation (#18800)
* Sketcher: Handle exceptions in onViewValueChanged Because the method onViewValueChanged is used as a Qt slot it must handle all possibly raised exceptions as otherwise they will slip through GUIApplication::notify() that usually results into a crash on some platforms like macOS * Sketch: Handle undefined values in calculateThroughPointMinorAxisParameters * The argument of acos() must be in the range [-1, +1], otherwise it returns nan (not a number) * The value of sin(0) = 0. So, it cannot be used in the denominator of a fraction
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#ifndef SKETCHERGUI_DrawSketchController_H
|
||||
#define SKETCHERGUI_DrawSketchController_H
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Tools2D.h>
|
||||
#include <Gui/EditableDatumLabel.h>
|
||||
|
||||
@@ -350,6 +351,21 @@ public:
|
||||
* It is intended to remote control the DrawSketchDefaultWidgetHandler
|
||||
*/
|
||||
void onViewValueChanged(int onviewparameterindex, double value)
|
||||
{
|
||||
// Since this method is used as a Qt slot we must handle
|
||||
// all exceptions here
|
||||
try {
|
||||
tryViewValueChanged(onviewparameterindex, value);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
e.ReportException();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
Base::Console().Error("C++ exception in onViewValueChanged: %s\n", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void tryViewValueChanged(int onviewparameterindex, double value)
|
||||
{
|
||||
int nextindex = onviewparameterindex + 1;
|
||||
if (isOnViewParameterOfCurrentMode(nextindex)) {
|
||||
|
||||
@@ -325,9 +325,18 @@ private:
|
||||
auto lprojx = projx.Length(); // Px = a cos t
|
||||
auto lprojy = projy.Length(); // Py = b sin t
|
||||
|
||||
double t = std::acos(lprojx / firstRadius);
|
||||
|
||||
secondRadius = lprojy / std::sin(t); // b = Py / sin t
|
||||
if (lprojx > firstRadius) {
|
||||
secondRadius = 0.0;
|
||||
}
|
||||
else {
|
||||
double t = std::acos(lprojx / firstRadius);
|
||||
if (t == 0.0) {
|
||||
secondRadius = 0.0;
|
||||
}
|
||||
else {
|
||||
secondRadius = lprojy / std::sin(t); // b = Py / sin t
|
||||
}
|
||||
}
|
||||
|
||||
secondAxis = projy.Normalize() * secondRadius;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user