alexhong2001 wrote:
I don't see much usage of "assert()." Am I missing its importance?
This is a function to determine the number of steps required to
approximate the portion of a curve, between parametric values t_start
and t_end, to a given tolerance.
int Curve::num_steps(
double t_start,
double t_end,
double eps
) const
{
CHECKVALID_CLASS;
ASSERT_STATE(!invalid(),"Curve::num_steps");
ASSERT_STATE(!infinite(),"Curve::num_steps");
ASSERT_ARGUMENT(eps>0.0,"Curve::num_steps");
ASSERT_ARGUMENT(t_min()<=t_start, "Curve::num_steps");
ASSERT_ARGUMENT(t_end>=t_start, "Curve::num_steps");
ASSERT_ARGUMENT(t_end<=t_max(), "Curve::num_steps");
// compute the number of spans to match given tolerance.
const int nspans = utMath::ceiling((t_end - t_start) *
utMath::sqrt(deriv2_max(t_start,t_end)/(8.0*eps)));
// make sure we have at least one span.
return nspans<1 ? 1 : nspans;
}
As you can see assertions of one form or another dominate the function.
Asserts help you to build reliable systems, detect and zero in on bugs
quickly, and provide the mechanism for writing automatic tests.