From 901f42ae84b73ea1baa0b20379021a9ab37250fc Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 2 Dec 2017 15:45:50 +0100 Subject: Add color cmp. func. Signed-off-by: pacien --- include/blender/color.h | 16 ++++++++++++++++ src/blender/color.c | 8 ++++++++ test/blender/blender.c | 5 +---- 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/blender/color.c diff --git a/include/blender/color.h b/include/blender/color.h index 22ed563..1fef2cf 100644 --- a/include/blender/color.h +++ b/include/blender/color.h @@ -8,6 +8,9 @@ * A rainbow */ +#include +#include + /** * Type: ColorComponent * Represents a single colour component of 32-bits RGBa tuple. @@ -27,4 +30,17 @@ typedef union { MLV_Color mlv; } Color; +/** + * Function: color_equals + * Compares the supplied colors. + * + * Parameters: + * c1 - the first color + * c2 - the second color + * + * Returns: + * T(c1 is the same color as c2) + */ +bool color_equals(Color c1, Color c2); + #endif diff --git a/src/blender/color.c b/src/blender/color.c new file mode 100644 index 0000000..f92fba9 --- /dev/null +++ b/src/blender/color.c @@ -0,0 +1,8 @@ +#include "blender/color.h" + +bool color_equals(Color c1, Color c2) { + return c1.rgba.r == c2.rgba.r && + c1.rgba.g == c2.rgba.g && + c1.rgba.b == c2.rgba.b && + c1.rgba.a == c2.rgba.a; +} diff --git a/test/blender/blender.c b/test/blender/blender.c index 7c33198..344ce04 100644 --- a/test/blender/blender.c +++ b/test/blender/blender.c @@ -6,10 +6,7 @@ static void test_color_blending() { Color b = {{0x00, 0x47, 0xAB, 0x00}}; Color result = blender_blend_colors(a, b, 0.125); - assert(result.rgba.r == 0xEE && - result.rgba.g == 0xDF && - result.rgba.b == 0x3C && - result.rgba.a == 0x00); + assert(color_equals(result, (Color) {{0xEE, 0xDF, 0x3C, 0x00}})); } int main(int argc, char **argv) { -- cgit v1.2.3