robustified r_find_t, removed extraneous elses

This commit is contained in:
Darren Ranalli 2002-05-11 01:43:59 +00:00
parent 3ed52cad07
commit 9ef80eec44

View File

@ -718,7 +718,8 @@ r_calc_length(float t1, float t2, const LPoint3f &p1, const LPoint3f &p2,
// Stop recursing--we've just walked off the limit for // Stop recursing--we've just walked off the limit for
// representing smaller values of t. // representing smaller values of t.
return 0.0f; return 0.0f;
} else { }
float tmid; float tmid;
LPoint3f pmid; LPoint3f pmid;
float left, right; float left, right;
@ -740,7 +741,6 @@ r_calc_length(float t1, float t2, const LPoint3f &p1, const LPoint3f &p2,
return r_calc_length(t1, tmid, p1, pmid, left) + return r_calc_length(t1, tmid, p1, pmid, left) +
r_calc_length(tmid, t2, pmid, p2, right); r_calc_length(tmid, t2, pmid, p2, right);
} }
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -752,8 +752,8 @@ r_calc_length(float t1, float t2, const LPoint3f &p1, const LPoint3f &p2,
// find. If the indicated target_length falls within // find. If the indicated target_length falls within
// this segment, returns true and sets found_t to the // this segment, returns true and sets found_t to the
// point along the segment. Otherwise, updates // point along the segment. Otherwise, updates
// seglength with the calculated length of the segment // seglength with the accurate calculated length of the
// and returns false. // segment and returns false.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool ParametricCurve:: bool ParametricCurve::
r_find_length(float target_length, float &found_t, r_find_length(float target_length, float &found_t,
@ -769,7 +769,8 @@ r_find_length(float target_length, float &found_t,
found_t = t1; found_t = t1;
return true; return true;
} else { }
float tmid; float tmid;
LPoint3f pmid; LPoint3f pmid;
float left, right; float left, right;
@ -815,7 +816,6 @@ r_find_length(float target_length, float &found_t,
seglength = left + right; seglength = left + right;
return false; return false;
} }
}
} }
@ -823,8 +823,8 @@ r_find_length(float target_length, float &found_t,
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: ParametricCurve::r_find_t // Function: ParametricCurve::r_find_t
// Access: Private // Access: Private
// Description: The recursive function to compute t value of a // Description: computes the t value in the parametric domain of a
// target point along a staight section of a curve. // target point along a straight section of a curve.
// This is similar to r_calc_length, above. // This is similar to r_calc_length, above.
// target_length is the length along the curve past t1 // target_length is the length along the curve past t1
// that we hope to find. If the indicated target_length // that we hope to find. If the indicated target_length
@ -835,7 +835,8 @@ bool ParametricCurve::
r_find_t(float target_length, float &found_t, r_find_t(float target_length, float &found_t,
float t1, float t2, float t1, float t2,
const LPoint3f &p1, const LPoint3f &p2) const { const LPoint3f &p1, const LPoint3f &p2) const {
static const float t_tolerance = 0.001f; static const float length_tolerance = 0.0001f;
static const float t_tolerance = 0.0001f;
if (parametrics_cat.is_spam()) { if (parametrics_cat.is_spam()) {
parametrics_cat.spam() parametrics_cat.spam()
@ -843,7 +844,7 @@ r_find_t(float target_length, float &found_t,
} }
// Is the target point close to the near endpoint // Is the target point close to the near endpoint
if (target_length < t_tolerance) { if (target_length < length_tolerance) {
found_t = t1; found_t = t1;
return true; return true;
} }
@ -858,11 +859,18 @@ r_find_t(float target_length, float &found_t,
} }
// Is the target point close to far endpoint? // Is the target point close to far endpoint?
if ( (point_dist - target_length ) < t_tolerance ) { if ( (point_dist - target_length ) < length_tolerance ) {
found_t = t2; found_t = t2;
return true; return true;
} }
// are we running out of parametric precision?
if ((t2 - t1) < t_tolerance) {
found_t = t1;
return true;
}
// No, subdivide and continue // No, subdivide and continue
float tmid; float tmid;
LPoint3f pmid; LPoint3f pmid;
@ -882,6 +890,9 @@ r_find_t(float target_length, float &found_t,
if (r_find_t(target_length - left, found_t, tmid, t2, pmid, p2)) { if (r_find_t(target_length - left, found_t, tmid, t2, pmid, p2)) {
return true; return true;
} }
// not found in either half, keep looking
return false;
} }