[PATCH 02/12] d2d1: Add cubic bezier bounds functions.

Connor McAdams conmanx360 at gmail.com
Tue Feb 25 13:21:42 CST 2020


Is there anything that can be done in the case of t_c_cube to lower
the possibility of that happening?

I didn't even notice that I wasn't using the constant in that function
specifically, that value gets used in a later patch. Good catch. I'll
fix that. Is it a good idea to have a macro constant for values like
that, or is it better to just make them literals?

On Tue, Feb 25, 2020 at 9:45 AM Henri Verbeet <hverbeet at gmail.com> wrote:
>
> On Tue, 25 Feb 2020 at 06:03, Connor McAdams <conmanx360 at 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.



More information about the wine-devel mailing list