From 07bb5483b4acc0bc3ded4ccb7d61a24e545a2ff8 Mon Sep 17 00:00:00 2001 From: Subhransu Mohanty Date: Tue, 10 Nov 2015 13:22:19 +0900 Subject: [PATCH] eina: added bounds_get api to Eina_Bezier Signed-off-by: Cedric BAIL --- src/lib/eina/eina_bezier.c | 40 +++++++++++++++++++++++++++++++ src/lib/eina/eina_bezier.h | 14 +++++++++++ src/tests/eina/eina_test_bezier.c | 21 ++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/src/lib/eina/eina_bezier.c b/src/lib/eina/eina_bezier.c index 4e8ffcae80..f07ca61cc7 100644 --- a/src/lib/eina/eina_bezier.c +++ b/src/lib/eina/eina_bezier.c @@ -273,3 +273,43 @@ eina_bezier_split_at_length(const Eina_Bezier *b, double len, t = eina_bezier_t_at(right, len); _eina_bezier_split_left(right, t, left); } + +EAPI void +eina_bezier_bounds_get(const Eina_Bezier *b, double *x, double *y, double *w, double *h) +{ + double xmin = b->start.x; + double xmax = b->start.x; + double ymin = b->start.y; + double ymax = b->start.y; + + if (b->ctrl_start.x < xmin) + xmin = b->ctrl_start.x; + else if (b->ctrl_start.x > xmax) + xmax = b->ctrl_start.x; + if (b->ctrl_end.x < xmin) + xmin = b->ctrl_end.x; + else if (b->ctrl_end.x > xmax) + xmax = b->ctrl_end.x; + if (b->end.x < xmin) + xmin = b->end.x; + else if (b->end.x > xmax) + xmax = b->end.x; + + if (b->ctrl_start.y < ymin) + ymin = b->ctrl_start.y; + else if (b->ctrl_start.y > ymax) + ymax = b->ctrl_start.y; + if (b->ctrl_end.y < ymin) + ymin = b->ctrl_end.y; + else if (b->ctrl_end.y > ymax) + ymax = b->ctrl_end.y; + if (b->end.y < ymin) + ymin = b->end.y; + else if (b->end.y > ymax) + ymax = b->end.y; + + if (x) *x = xmin; + if (y) *y = ymin; + if (w) *w = xmax - xmin; + if (h) *h = ymax - ymin; +} diff --git a/src/lib/eina/eina_bezier.h b/src/lib/eina/eina_bezier.h index aef32e4ea1..407deb5ad9 100644 --- a/src/lib/eina/eina_bezier.h +++ b/src/lib/eina/eina_bezier.h @@ -143,4 +143,18 @@ EAPI double eina_bezier_angle_at(const Eina_Bezier *b, double t) EINA_ARG_NONNUL */ EAPI void eina_bezier_split_at_length(const Eina_Bezier *b, double len, Eina_Bezier *left, Eina_Bezier *right) EINA_ARG_NONNULL(1); +/** + * @brief get the bound of the the bezier. + * + * @param b The floating point bezier. + * @param x x coordinate of bounding box. + * @param y y coordinate of bounding box. + * @param w width of bounding box. + * @param h height of bounding box. + * + * @p b. No check is done on @p b. + * @since 1.16 + */ +EAPI void eina_bezier_bounds_get(const Eina_Bezier *b, double *x, double *y, double *w, double *h) EINA_ARG_NONNULL(1); + #endif // EINA_BEZIER_H diff --git a/src/tests/eina/eina_test_bezier.c b/src/tests/eina/eina_test_bezier.c index a7ad8f226f..fdfd9a3d73 100644 --- a/src/tests/eina/eina_test_bezier.c +++ b/src/tests/eina/eina_test_bezier.c @@ -175,6 +175,26 @@ START_TEST(eina_bezier_test_split_at_length) } END_TEST +START_TEST(eina_bezier_test_bounds_get) +{ + Eina_Bezier b; + double x, y, w, h; + + eina_init(); + eina_bezier_values_set(&b, + 0, 0, + 100, 0, + 0, 100, + 100, 100); + + eina_bezier_bounds_get(&b, &x, &y, &w, &h); + + fail_if(x !=0 || y!=0 || w !=100 || h !=100 ); + + eina_shutdown(); +} +END_TEST + void eina_test_bezier(TCase *tc) { @@ -184,4 +204,5 @@ eina_test_bezier(TCase *tc) tcase_add_test(tc, eina_bezier_test_t_at); tcase_add_test(tc, eina_bezier_test_point_at); tcase_add_test(tc, eina_bezier_test_split_at_length); + tcase_add_test(tc, eina_bezier_test_bounds_get); }