[PATCH] d2d1: Implement and test a few easy functions.

Henri Verbeet hverbeet at gmail.com
Fri Oct 16 06:22:47 CDT 2020


On Fri, 16 Oct 2020 at 12:12, Giovanni Mascellani <wine at mascellani.eu> wrote:
>
> Signed-off-by: Giovanni Mascellani <wine at mascellani.eu>
> ---
>  dlls/d2d1/d2d1.spec    |  6 ++---
>  dlls/d2d1/factory.c    | 16 +++++++++++
>  dlls/d2d1/tests/d2d1.c | 61 ++++++++++++++++++++++++++++++++++++++++++
>  include/d2d1_1.idl     |  3 +++
>  4 files changed, 83 insertions(+), 3 deletions(-)
>
It's true that these functions are mostly trivial, but as a matter of
principle, one patch per function please. That would also allow us to
have more descriptive commit messages.

> +void WINAPI D2D1SinCos(FLOAT angle, FLOAT *s, FLOAT *c)
I don't think there's a compelling reason to prefer "FLOAT" over "float".

> +FLOAT WINAPI D2D1Vec3Length(FLOAT x, FLOAT y, FLOAT z)
> +{
> +    return sqrtf(x*x + y*y + z*z);
> +}
Space around operators, please.

> +static int compare_fp(FLOAT res, FLOAT exp)
> +{
> +    if (exp == 0.0f)
> +        return fabsf(res) <= 10 * FLT_MIN;
> +    else
> +        return fabsf((res-exp) / exp) <= 10 * FLT_EPSILON;
> +}
We already have compare_float(). That obviously(?) has issues with
comparing values close to zero, but it shouldn't be hard to extend to
handle those if needed.

> +    static const FLOAT sc_data[] =
> +    {
> +        0.0, 0.0, 1.0,
> +        1.0, 0.8414709568, 0.5403022766,
> +        2.0, 0.9092974067, -0.4161468446,
> +        M_PI / 2.0, 1.0, -4.371138829e-008,
> +        M_PI, -8.742277657e-008, -1.0,
> +    };
> +
...
> +    for (i = 0; i < sizeof(sc_data) / sizeof(sc_data[0]); i += 3) {
> +        D2D1SinCos(sc_data[i], &s, &c);
> +        ok(compare_fp(s, sc_data[i+1]), "Wrong sin(%.10g) (%.10g instead of %.10g).\n", sc_data[i], s, sc_data[i+1]);
> +        ok(compare_fp(c, sc_data[i+2]), "Wrong cos(%.10g) (%.10g instead of %.10g).\n", sc_data[i], c, sc_data[i+2]);
> +    }
ARRAY_SIZE, brace placement. Defining a structure for sc_data[] would
make this much more readable, and would get rid of the "i += 3" in the
loop.

We use %.8e for printing floating point values everywhere else. That
should probably be %.9e instead, but please keep things somewhat
consistent.



More information about the wine-devel mailing list