eina: added bounds_get api to Eina_Bezier
authorSubhransu Mohanty <sub.mohanty@samsung.com>
Tue, 10 Nov 2015 04:22:19 +0000 (13:22 +0900)
committerCedric BAIL <cedric@osg.samsung.com>
Sun, 22 Nov 2015 22:28:09 +0000 (23:28 +0100)
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
src/lib/eina/eina_bezier.c
src/lib/eina/eina_bezier.h
src/tests/eina/eina_test_bezier.c

index 4e8ffca..f07ca61 100644 (file)
@@ -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;
+}
index aef32e4..407deb5 100644 (file)
@@ -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
index a7ad8f2..fdfd9a3 100644 (file)
@@ -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);
 }