mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
robustified r_find_t, removed extraneous elses
This commit is contained in:
parent
3ed52cad07
commit
9ef80eec44
@ -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
|
||||
// representing smaller values of t.
|
||||
return 0.0f;
|
||||
} else {
|
||||
}
|
||||
|
||||
float tmid;
|
||||
LPoint3f pmid;
|
||||
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) +
|
||||
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
|
||||
// this segment, returns true and sets found_t to the
|
||||
// point along the segment. Otherwise, updates
|
||||
// seglength with the calculated length of the segment
|
||||
// and returns false.
|
||||
// seglength with the accurate calculated length of the
|
||||
// segment and returns false.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool ParametricCurve::
|
||||
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;
|
||||
return true;
|
||||
|
||||
} else {
|
||||
}
|
||||
|
||||
float tmid;
|
||||
LPoint3f pmid;
|
||||
float left, right;
|
||||
@ -815,7 +816,6 @@ r_find_length(float target_length, float &found_t,
|
||||
seglength = left + right;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -823,8 +823,8 @@ r_find_length(float target_length, float &found_t,
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ParametricCurve::r_find_t
|
||||
// Access: Private
|
||||
// Description: The recursive function to compute t value of a
|
||||
// target point along a staight section of a curve.
|
||||
// Description: computes the t value in the parametric domain of a
|
||||
// target point along a straight section of a curve.
|
||||
// This is similar to r_calc_length, above.
|
||||
// target_length is the length along the curve past t1
|
||||
// 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,
|
||||
float t1, float t2,
|
||||
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()) {
|
||||
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
|
||||
if (target_length < t_tolerance) {
|
||||
if (target_length < length_tolerance) {
|
||||
found_t = t1;
|
||||
return true;
|
||||
}
|
||||
@ -858,11 +859,18 @@ r_find_t(float target_length, float &found_t,
|
||||
}
|
||||
|
||||
// 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;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// are we running out of parametric precision?
|
||||
if ((t2 - t1) < t_tolerance) {
|
||||
found_t = t1;
|
||||
return true;
|
||||
}
|
||||
|
||||
// No, subdivide and continue
|
||||
float tmid;
|
||||
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)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// not found in either half, keep looking
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user