Skip to content

Commit 04b332d

Browse files
committed
Ratpoly - Less noise in terminal. Comment out expected dbg print and try harder to converge.
1 parent 4cceaa5 commit 04b332d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/srf/ratpoly.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,13 @@ void SSurface::ClosestPointTo(Vector p, double *u, double *v, bool mustConverge)
447447

448448
// If we failed to converge, then at least don't return NaN.
449449
if(mustConverge) {
450-
Vector p0 = PointAt(*u, *v);
451-
dbp("didn't converge");
452-
dbp("have %.3f %.3f %.3f", CO(p0));
453-
dbp("want %.3f %.3f %.3f", CO(p));
454-
dbp("distance = %g", (p.Minus(p0)).Magnitude());
450+
// This is expected not to converge when the target point is not on the surface but nearby.
451+
// let's not pollute the output window for normal use.
452+
// Vector p0 = PointAt(*u, *v);
453+
// dbp("didn't converge");
454+
// dbp("have %.3f %.3f %.3f", CO(p0));
455+
// dbp("want %.3f %.3f %.3f", CO(p));
456+
// dbp("distance = %g", (p.Minus(p0)).Magnitude());
455457
}
456458
if(IsReasonable(*u) || IsReasonable(*v)) {
457459
*u = *v = 0;
@@ -500,7 +502,7 @@ bool SSurface::ClosestPointNewton(Vector p, double *u, double *v, bool mustConve
500502
bool SSurface::PointIntersectingLine(Vector p0, Vector p1, double *u, double *v) const
501503
{
502504
int i;
503-
for(i = 0; i < 15; i++) {
505+
for(i = 0; i < 20; i++) {
504506
Vector pi, p, tu, tv;
505507
p = PointAt(*u, *v);
506508
TangentsAt(*u, *v, &tu, &tv);
@@ -510,7 +512,10 @@ bool SSurface::PointIntersectingLine(Vector p0, Vector p1, double *u, double *v)
510512

511513
bool parallel;
512514
pi = Vector::AtIntersectionOfPlaneAndLine(n, d, p0, p1, &parallel);
513-
if(parallel) break;
515+
if(parallel) {
516+
dbp("parallel (surface intersecting line)");
517+
break;
518+
}
514519

515520
// Check for convergence
516521
if(pi.Equals(p, RATPOLY_EPS)) return true;
@@ -617,7 +622,10 @@ void SSurface::PointOnSurfaces(SSurface *s1, SSurface *s2, double *up, double *v
617622
Vector pi = Vector::AtIntersectionOfPlanes(n[0], d[0],
618623
n[1], d[1],
619624
n[2], d[2], &parallel);
620-
if(parallel) break;
625+
626+
if(parallel) { // lets try something else for parallel planes
627+
pi = p[0].Plus(p[1]).Plus(p[2]).ScaledBy(1.0/3.0);
628+
}
621629

622630
for(j = 0; j < 3; j++) {
623631
Vector n = tu[j].Cross(tv[j]);

0 commit comments

Comments
 (0)