29 curve_coef[0] = p1[dim];
30 curve_coef[1] = 0.5f * (-p0[dim] + p2[dim]);
31 curve_coef[2] = 0.5f * (2 * p0[dim] - 5 * p1[dim] + 4 * p2[dim] - p3[dim]);
32 curve_coef[3] = 0.5f * (-p0[dim] + 3 * p1[dim] - 3 * p2[dim] + p3[dim]);
34 float discroot = curve_coef[2] * curve_coef[2] - 3 * curve_coef[3] * curve_coef[1];
38 if (discroot >= 0 && curve_coef[3] != 0.0f) {
39 discroot =
sqrtf(discroot);
40 ta = (-curve_coef[2] - discroot) / (3 * curve_coef[3]);
41 tb = (-curve_coef[2] + discroot) / (3 * curve_coef[3]);
42 ta = (ta > 1.0f || ta < 0.0f) ? -1.0f : ta;
43 tb = (tb > 1.0f || tb < 0.0f) ? -1.0f : tb;
46 *upper =
max(p1[dim], p2[dim]);
47 *lower =
min(p1[dim], p2[dim]);
55 exa = curve_coef[3] * t3 + curve_coef[2] * t2 + curve_coef[1] * ta + curve_coef[0];
60 exb = curve_coef[3] * t3 + curve_coef[2] * t2 + curve_coef[1] * tb + curve_coef[0];
63 *upper =
max(*upper,
max(exa, exb));
64 *lower =
min(*lower,
min(exa, exb));