Rename our isnan() function to IsReasonable().
Commitpull/612/headea6db67
added an unusual isnan macro: #define isnan(x) (((x) != (x)) || (x > 1e11) || (x < -1e11)) Commit8bc322e
adds a preprocessor guard that looks like it would cause the isnan function from math.h to be preferred, but doesn't actually do that on many platforms, e.g. glibc: #ifndef isnan # define isnan(x) (((x) != (x)) || (x > 1e11) || (x < -1e11)) #endif This commit renames our isnan() to make it clear that it differs from the standard library operation, and makes it a function. Fixes #603.
parent
771086fa50
commit
0be42a8b29
|
@ -448,7 +448,7 @@ bool TextWindow::EditControlDoneForConfiguration(const std::string &s) {
|
||||||
Expr *e = Expr::From(s, /*popUpError=*/true);
|
Expr *e = Expr::From(s, /*popUpError=*/true);
|
||||||
if(e) {
|
if(e) {
|
||||||
double ev = e->Eval();
|
double ev = e->Eval();
|
||||||
if(fabs(ev) < 0.001 || isnan(ev)) {
|
if(fabs(ev) < 0.001 || IsReasonable(ev)) {
|
||||||
Error(_("Export scale must not be zero!"));
|
Error(_("Export scale must not be zero!"));
|
||||||
} else {
|
} else {
|
||||||
SS.exportScale = (float)ev;
|
SS.exportScale = (float)ev;
|
||||||
|
@ -460,7 +460,7 @@ bool TextWindow::EditControlDoneForConfiguration(const std::string &s) {
|
||||||
Expr *e = Expr::From(s, /*popUpError=*/true);
|
Expr *e = Expr::From(s, /*popUpError=*/true);
|
||||||
if(e) {
|
if(e) {
|
||||||
double ev = SS.ExprToMm(e);
|
double ev = SS.ExprToMm(e);
|
||||||
if(isnan(ev) || ev < 0) {
|
if(IsReasonable(ev) || ev < 0) {
|
||||||
Error(_("Cutter radius offset must not be negative!"));
|
Error(_("Cutter radius offset must not be negative!"));
|
||||||
} else {
|
} else {
|
||||||
SS.exportOffset = (float)ev;
|
SS.exportOffset = (float)ev;
|
||||||
|
|
|
@ -383,7 +383,7 @@ void GraphicsWindow::MakeTangentArc() {
|
||||||
if(fabs(tp[0] - t[0]) > 1e-3 || fabs(tp[1] - t[1]) > 1e-3 ||
|
if(fabs(tp[0] - t[0]) > 1e-3 || fabs(tp[1] - t[1]) > 1e-3 ||
|
||||||
t[0] < 0.01 || t[1] < 0.01 ||
|
t[0] < 0.01 || t[1] < 0.01 ||
|
||||||
t[0] > 0.99 || t[1] > 0.99 ||
|
t[0] > 0.99 || t[1] > 0.99 ||
|
||||||
isnan(t[0]) || isnan(t[1]))
|
IsReasonable(t[0]) || IsReasonable(t[1]))
|
||||||
{
|
{
|
||||||
Error(_("Couldn't round this corner. Try a smaller radius, or try "
|
Error(_("Couldn't round this corner. Try a smaller radius, or try "
|
||||||
"creating the desired geometry by hand with tangency "
|
"creating the desired geometry by hand with tangency "
|
||||||
|
|
|
@ -76,10 +76,6 @@ typedef struct _cairo_surface cairo_surface_t;
|
||||||
dbp("tri: (%.3f %.3f %.3f) (%.3f %.3f %.3f) (%.3f %.3f %.3f)", \
|
dbp("tri: (%.3f %.3f %.3f) (%.3f %.3f %.3f) (%.3f %.3f %.3f)", \
|
||||||
CO((tri).a), CO((tri).b), CO((tri).c))
|
CO((tri).a), CO((tri).b), CO((tri).c))
|
||||||
|
|
||||||
#ifndef isnan
|
|
||||||
# define isnan(x) (((x) != (x)) || (x > 1e11) || (x < -1e11))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace SolveSpace {
|
namespace SolveSpace {
|
||||||
|
|
||||||
using std::min;
|
using std::min;
|
||||||
|
@ -98,6 +94,10 @@ __attribute__((__format__ (__printf__, 1, 2)))
|
||||||
#endif
|
#endif
|
||||||
std::string ssprintf(const char *fmt, ...);
|
std::string ssprintf(const char *fmt, ...);
|
||||||
|
|
||||||
|
inline bool IsReasonable(double x) {
|
||||||
|
return std::isnan(x) || x > 1e11 || x < -1e11;
|
||||||
|
}
|
||||||
|
|
||||||
inline int WRAP(int v, int n) {
|
inline int WRAP(int v, int n) {
|
||||||
// Clamp it to the range [0, n)
|
// Clamp it to the range [0, n)
|
||||||
while(v >= n) v -= n;
|
while(v >= n) v -= n;
|
||||||
|
|
|
@ -443,7 +443,7 @@ void SSurface::ClosestPointTo(Vector p, double *u, double *v, bool mustConverge)
|
||||||
dbp("want %.3f %.3f %.3f", CO(p));
|
dbp("want %.3f %.3f %.3f", CO(p));
|
||||||
dbp("distance = %g", (p.Minus(p0)).Magnitude());
|
dbp("distance = %g", (p.Minus(p0)).Magnitude());
|
||||||
}
|
}
|
||||||
if(isnan(*u) || isnan(*v)) {
|
if(IsReasonable(*u) || IsReasonable(*v)) {
|
||||||
*u = *v = 0;
|
*u = *v = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,7 +293,7 @@ bool System::NewtonSolve(int tag) {
|
||||||
for(i = 0; i < mat.n; i++) {
|
for(i = 0; i < mat.n; i++) {
|
||||||
Param *p = param.FindById(mat.param[i]);
|
Param *p = param.FindById(mat.param[i]);
|
||||||
p->val -= mat.X[i];
|
p->val -= mat.X[i];
|
||||||
if(isnan(p->val)) {
|
if(IsReasonable(p->val)) {
|
||||||
// Very bad, and clearly not convergent
|
// Very bad, and clearly not convergent
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -306,7 +306,7 @@ bool System::NewtonSolve(int tag) {
|
||||||
// Check for convergence
|
// Check for convergence
|
||||||
converged = true;
|
converged = true;
|
||||||
for(i = 0; i < mat.m; i++) {
|
for(i = 0; i < mat.m; i++) {
|
||||||
if(isnan(mat.B.num[i])) {
|
if(IsReasonable(mat.B.num[i])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(fabs(mat.B.num[i]) > CONVERGE_TOLERANCE) {
|
if(fabs(mat.B.num[i]) > CONVERGE_TOLERANCE) {
|
||||||
|
@ -493,7 +493,7 @@ didnt_converge:
|
||||||
SK.constraint.ClearTags();
|
SK.constraint.ClearTags();
|
||||||
// Not using range-for here because index is used in additional ways
|
// Not using range-for here because index is used in additional ways
|
||||||
for(i = 0; i < eq.n; i++) {
|
for(i = 0; i < eq.n; i++) {
|
||||||
if(fabs(mat.B.num[i]) > CONVERGE_TOLERANCE || isnan(mat.B.num[i])) {
|
if(fabs(mat.B.num[i]) > CONVERGE_TOLERANCE || IsReasonable(mat.B.num[i])) {
|
||||||
// This constraint is unsatisfied.
|
// This constraint is unsatisfied.
|
||||||
if(!mat.eq[i].isFromConstraint()) continue;
|
if(!mat.eq[i].isFromConstraint()) continue;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue