Remove some of the oops() calls that tend to blow because of issues

in the numerical code.

And clean some other stuff, in particular simplifying whenever I
have to take the maximum (or minimum) of three quantities.

[git-p4: depot-paths = "//depot/solvespace/": change = 1855]
This commit is contained in:
Jonathan Westhues 2008-02-10 05:34:32 -08:00
parent 22b78e4427
commit ddf2b30b98
5 changed files with 27 additions and 25 deletions

View File

@ -222,7 +222,7 @@ SBsp3 *SBsp3::InsertConvex(STriMeta meta, Vector *vertex, int cnt,
vpos[npos++] = vi;
vneg[nneg++] = vi;
if(inters >= 2) oops();
if(inters >= 2) goto triangulate; // XXX shouldn't happen but does
inter[inters++] = vi;
}
}
@ -237,9 +237,11 @@ SBsp3 *SBsp3::InsertConvex(STriMeta meta, Vector *vertex, int cnt,
edges = edges->InsertEdge(&se, n, out);
} else if(inters == 0 && onc == 2) {
// We already handled this on-plane existing edge
} else oops();
} else {
goto triangulate;
}
}
if(nneg < 3 || npos < 3) oops();
if(nneg < 3 || npos < 3) goto triangulate; // XXX
InsertConvexHow(NEG, meta, vneg, nneg, instead);
InsertConvexHow(POS, meta, vpos, npos, instead);

View File

@ -609,12 +609,14 @@ Expr *Constraint::VectorsParallel(int eq, ExprVector a, ExprVector b) {
// plane, then the z component of the cross product is most important).
// So find the strongest component of a and b, and that's the component
// of the cross product to ignore.
double m = max(mx, max(my, mz));
Expr *e0, *e1;
if(m == mx) { e0 = r.y; e1 = r.z; }
else if(m == my) { e0 = r.z; e1 = r.x; }
else if(m == mz) { e0 = r.x; e1 = r.y; }
else oops();
if(mx > my && mx > mz) {
e0 = r.y; e1 = r.z;
} else if(my > mz) {
e0 = r.z; e1 = r.x;
} else {
e0 = r.x; e1 = r.y;
}
if(eq == 0) return e0;
if(eq == 1) return e1;

View File

@ -165,7 +165,7 @@ void SMesh::Simplify(int start) {
double bDot = (ab.Cross(bc)).Dot(n);
bDot /= min(ab.Magnitude(), bc.Magnitude());
if(bDot < 0) oops();
if(bDot < 0) return; // XXX, shouldn't happen
}
for(i = 0; i < convc - 2; i++) {

View File

@ -131,26 +131,25 @@ Quaternion Quaternion::From(Vector u, Vector v)
q.vy = (n.x - u.z)/s;
q.vz = (u.y - v.x)/s;
} else {
double m = max(u.x, max(v.y, n.z));
if(m == u.x) {
if(u.x > v.y && u.x > n.z) {
s = 2*sqrt(1 + u.x - v.y - n.z);
q.w = (v.z - n.y)/s;
q.vx = s/4;
q.vy = (u.y + v.x)/s;
q.vz = (n.x + u.z)/s;
} else if(m == v.y) {
} else if(v.y > n.z) {
s = 2*sqrt(1 - u.x + v.y - n.z);
q.w = (n.x - u.z)/s;
q.vx = (u.y + v.x)/s;
q.vy = s/4;
q.vz = (v.z + n.y)/s;
} else if(m == n.z) {
} else {
s = 2*sqrt(1 - u.x - v.y + n.z);
q.w = (u.y - v.x)/s;
q.vx = (n.x + u.z)/s;
q.vy = (v.z + n.y)/s;
q.vz = s/4;
} else oops();
}
}
return q.WithMagnitude(1);
@ -517,27 +516,27 @@ Point2d Vector::Project2d(Vector u, Vector v) {
}
double Vector::DivPivoting(Vector delta) {
double m = max(fabs(delta.x), max(fabs(delta.y), fabs(delta.z)));
double mx = fabs(delta.x), my = fabs(delta.y), mz = fabs(delta.z);
if(m == fabs(delta.x)) {
if(mx > my && mx > mz) {
return x/delta.x;
} else if(m == fabs(delta.y)) {
} else if(my > mz) {
return y/delta.y;
} else if(m == fabs(delta.z)) {
} else {
return z/delta.z;
} else oops();
}
}
Vector Vector::ClosestOrtho(void) {
double m = max(fabs(x), max(fabs(y), fabs(z)));
double mx = fabs(x), my = fabs(y), mz = fabs(z);
if(m == fabs(x)) {
if(mx > my && mx > mz) {
return From((x > 0) ? 1 : -1, 0, 0);
} else if(m == fabs(y)) {
} else if(my > mz) {
return From(0, (y > 0) ? 1 : -1, 0);
} else if(m == fabs(z)) {
} else {
return From(0, 0, (z > 0) ? 1 : -1);
} else oops();
}
}
Vector Vector::AtIntersectionOfPlanes(Vector n1, double d1,

View File

@ -1,5 +1,4 @@
get rid of the oops() calls in the mesh codes
leak fixing