diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2024-10-27 20:03:31 +0000 |
|---|---|---|
| committer | j-p <jp_bruyere@hotmail.com> | 2025-03-24 19:12:00 +0100 |
| commit | 15ecf40ff47bfbdedddd3161b7d6d9d1418e64bb (patch) | |
| tree | 49001433bd5b102118593642bf1a749494e7ea54 /tests/transform.c | |
| parent | 7b2f17b8d8f3763d974c52bfbe9a429779aa6f7b (diff) | |
clang format
Diffstat (limited to 'tests/transform.c')
| -rw-r--r-- | tests/transform.c | 142 |
1 files changed, 68 insertions, 74 deletions
diff --git a/tests/transform.c b/tests/transform.c index b89db50..cc282b0 100644 --- a/tests/transform.c +++ b/tests/transform.c @@ -22,95 +22,89 @@ #include "test.h" +void _test_rounded_rect(VkvgContext cr) { + /* a custom shape that could be wrapped in a function */ + float x0 = -100, /* parameters like vkvg_rectangle */ + y0 = -100, rect_width = 200, rect_height = 200, radius = 102.4f; /* and an approximate curvature radius */ -void _test_rounded_rect (VkvgContext cr) { - /* a custom shape that could be wrapped in a function */ - float x0 = -100, /* parameters like vkvg_rectangle */ - y0 = -100, - rect_width = 200, - rect_height = 200, - radius = 102.4f; /* and an approximate curvature radius */ + float x1, y1; - float x1,y1; + x1 = x0 + rect_width; + y1 = y0 + rect_height; + if (!rect_width || !rect_height) + return; + if (rect_width / 2 < radius) { + if (rect_height / 2 < radius) { + vkvg_move_to(cr, x0, (y0 + y1) / 2); + vkvg_curve_to(cr, x0, y0, x0, y0, (x0 + x1) / 2, y0); + vkvg_curve_to(cr, x1, y0, x1, y0, x1, (y0 + y1) / 2); + vkvg_curve_to(cr, x1, y1, x1, y1, (x1 + x0) / 2, y1); + vkvg_curve_to(cr, x0, y1, x0, y1, x0, (y0 + y1) / 2); + } else { + vkvg_move_to(cr, x0, y0 + radius); + vkvg_curve_to(cr, x0, y0, x0, y0, (x0 + x1) / 2, y0); + vkvg_curve_to(cr, x1, y0, x1, y0, x1, y0 + radius); + vkvg_line_to(cr, x1, y1 - radius); + vkvg_curve_to(cr, x1, y1, x1, y1, (x1 + x0) / 2, y1); + vkvg_curve_to(cr, x0, y1, x0, y1, x0, y1 - radius); + } + } else { + if (rect_height / 2 < radius) { + vkvg_move_to(cr, x0, (y0 + y1) / 2); + vkvg_curve_to(cr, x0, y0, x0, y0, x0 + radius, y0); + vkvg_line_to(cr, x1 - radius, y0); + vkvg_curve_to(cr, x1, y0, x1, y0, x1, (y0 + y1) / 2); + vkvg_curve_to(cr, x1, y1, x1, y1, x1 - radius, y1); + vkvg_line_to(cr, x0 + radius, y1); + vkvg_curve_to(cr, x0, y1, x0, y1, x0, (y0 + y1) / 2); + } else { + vkvg_move_to(cr, x0, y0 + radius); + vkvg_curve_to(cr, x0, y0, x0, y0, x0 + radius, y0); + vkvg_line_to(cr, x1 - radius, y0); + vkvg_curve_to(cr, x1, y0, x1, y0, x1, y0 + radius); + vkvg_line_to(cr, x1, y1 - radius); + vkvg_curve_to(cr, x1, y1, x1, y1, x1 - radius, y1); + vkvg_line_to(cr, x0 + radius, y1); + vkvg_curve_to(cr, x0, y1, x0, y1, x0, y1 - radius); + } + } + vkvg_close_path(cr); - x1=x0+rect_width; - y1=y0+rect_height; - if (!rect_width || !rect_height) - return; - if (rect_width/2<radius) { - if (rect_height/2<radius) { - vkvg_move_to (cr, x0, (y0 + y1)/2); - vkvg_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0); - vkvg_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2); - vkvg_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1); - vkvg_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2); - } else { - vkvg_move_to (cr, x0, y0 + radius); - vkvg_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0); - vkvg_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius); - vkvg_line_to (cr, x1 , y1 - radius); - vkvg_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1); - vkvg_curve_to (cr, x0, y1, x0, y1, x0, y1- radius); - } - } else { - if (rect_height/2<radius) { - vkvg_move_to (cr, x0, (y0 + y1)/2); - vkvg_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0); - vkvg_line_to (cr, x1 - radius, y0); - vkvg_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2); - vkvg_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1); - vkvg_line_to (cr, x0 + radius, y1); - vkvg_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2); - } else { - vkvg_move_to (cr, x0, y0 + radius); - vkvg_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0); - vkvg_line_to (cr, x1 - radius, y0); - vkvg_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius); - vkvg_line_to (cr, x1 , y1 - radius); - vkvg_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1); - vkvg_line_to (cr, x0 + radius, y1); - vkvg_curve_to (cr, x0, y1, x0, y1, x0, y1- radius); - } - } - vkvg_close_path (cr); - - vkvg_set_source_rgb (cr, 0.5f, 0.5f, 1); - vkvg_fill_preserve (cr); - vkvg_set_source_rgba (cr, 0.5f, 0, 0, 0.5f); - vkvg_set_line_width (cr, 10.0f); - vkvg_stroke (cr); + vkvg_set_source_rgb(cr, 0.5f, 0.5f, 1); + vkvg_fill_preserve(cr); + vkvg_set_source_rgba(cr, 0.5f, 0, 0, 0.5f); + vkvg_set_line_width(cr, 10.0f); + vkvg_stroke(cr); } - static float rotation = 0.f; -void cairo_tests () { - rotation+=0.002f; +void cairo_tests() { + rotation += 0.002f; - VkvgContext ctx = vkvg_create(surf); - vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); - vkvg_set_source_rgba(ctx,1.0f,1.0f,1.0f,1); - vkvg_paint(ctx); + VkvgContext ctx = vkvg_create(surf); + vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); + vkvg_set_source_rgba(ctx, 1.0f, 1.0f, 1.0f, 1); + vkvg_paint(ctx); - vkvg_set_line_width(ctx,10); + vkvg_set_line_width(ctx, 10); - vkvg_set_source_rgb(ctx,0,0,1); + vkvg_set_source_rgb(ctx, 0, 0, 1); - vkvg_translate (ctx, test_width/2,test_height/2); - vkvg_rotate(ctx, rotation); - //vkvg_scale(ctx, 200,200); + vkvg_translate(ctx, test_width / 2, test_height / 2); + vkvg_rotate(ctx, rotation); + // vkvg_scale(ctx, 200,200); - vkvg_arc (ctx, 0, 0, 150, 0, M_PI*1.5); - vkvg_stroke(ctx); + vkvg_arc(ctx, 0, 0, 150, 0, M_PI * 1.5); + vkvg_stroke(ctx); - _test_rounded_rect(ctx); + _test_rounded_rect(ctx); - vkvg_destroy(ctx); + vkvg_destroy(ctx); } - int main(int argc, char *argv[]) { - no_test_size = true; - PERFORM_TEST (cairo_tests, argc, argv); - return 0; + no_test_size = true; + PERFORM_TEST(cairo_tests, argc, argv); + return 0; } |