On Tue, 25 Feb 2020 at 06:03, Connor McAdams conmanx360@gmail.com wrote:
static void d2d_point_calculate_bezier(D2D1_POINT_2F *out, const D2D1_POINT_2F *p0,
const D2D1_POINT_2F *p1, const D2D1_POINT_2F *p2, float t)
const D2D1_POINT_2F *p1, const D2D1_POINT_2F *p2, const D2D1_POINT_2F *p3, float t)
{ float t_c = 1.0f - t;
- float t_c_cube = t_c * t_c * t_c, t_cube = t * t * t;
- float t_c_sq = t_c * t_c, t_sq = t * t;
- out->x = t_c * (t_c * p0->x + t * p1->x) + t * (t_c * p1->x + t * p2->x);
- out->y = t_c * (t_c * p0->y + t * p1->y) + t * (t_c * p1->y + t * p2->y);
- out->x = t_c_cube * p0->x + 3.0f * t_c_sq * t * p1->x + 3.0f * t_c * t_sq * p2->x + t_cube * p3->x;
- out->y = t_c_cube * p0->y + 3.0f * t_c_sq * t * p1->y + 3.0f * t_c * t_sq * p2->y + t_cube * p3->y;
}
Careful with that. Consider the relative size of the error in "t_c = 1.0f - t" for values of t close to 1.0f. However bad that error may be, "t_c_cube = t_c * t_c * t_c" raises it to the third power.
+/*
- This value is useful for many different cubic bezier operations, including
- root finding, derivative checking, and texture coordinate calculations.
- */
+#define D2D1_CUBIC_BEZIER_EPSILON 0.00005f +static float d2d_cubic_bezier_round_to_zero(float a) +{
- if (a < 0.00005f && a > -0.00005f)
return 0.0f;
- return a;
+}
This looks fairly arbitrary; what makes it worse is defining the constant and then not using it.