Commit 5c83e306 authored by kraus's avatar kraus
Browse files

Merge branch...

Merge branch '569-fittint-bend-angle-in-bend2d-may-run-indefinitely-in-some-circumstances' into 'master'

Resolve "fitting bend angle in Bend2D may run indefinitely in some circumstances"

Closes #569

See merge request !398
parents 664fd16e f2927940
......@@ -692,31 +692,22 @@ void Bend2D::findBendStrength() {
if (error < tolerance)
return;
double fieldStep = estimateFieldAdjustmentStep(actualBendAngle);
double fieldStep = std::copysign(1.0, fieldAmplitude_m) * std::abs(estimateFieldAdjustmentStep(actualBendAngle));
double amplitude1 = fieldAmplitude_m;
double amplitude2 = amplitude1;
double bendAngle1 = actualBendAngle;
double amplitude2 = fieldAmplitude_m + fieldStep;
fieldAmplitude_m = amplitude2;
double bendAngle2 = calculateBendAngle();
if (std::abs(bendAngle1) > std::abs(angle_m)) {
while (std::abs(bendAngle2) > std::abs(angle_m)) {
amplitude1 = amplitude2;
bendAngle1 = bendAngle2;
amplitude2 += fieldStep;
fieldAmplitude_m = amplitude2;
bendAngle2 = calculateBendAngle();
}
} else {
while (std::abs(bendAngle2) < std::abs(angle_m)) {
amplitude1 = amplitude2;
bendAngle1 = bendAngle2;
amplitude2 += fieldStep;
fieldAmplitude_m = amplitude2;
bendAngle2 = calculateBendAngle();
double bendAngle2 = bendAngle1;
int stepSign = std::abs(bendAngle1) > std::abs(angle_m) ? -1: 1;
while (true) {
amplitude1 = amplitude2;
bendAngle1 = bendAngle2;
amplitude2 += stepSign * fieldStep;
fieldAmplitude_m = amplitude2;
bendAngle2 = calculateBendAngle();
if (stepSign * (std::abs(bendAngle2) - std::abs(angle_m)) > 0) {
break;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment