[EGIT] [core/efl] master 03/04: eina: add a substraction in rectangles and more helpers
cedric pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=b98ee971f3b139b94a09c136ff2a6f709067d594 commit b98ee971f3b139b94a09c136ff2a6f709067d594 Author: Jorge Zapata jorgeluis.zap...@gmail.com Date: Mon Sep 23 21:13:52 2013 +0200 eina: add a substraction in rectangles and more helpers Also add functions to cut a rectangle in the different lengths/coordinates. Add helper macros to printf a rectangle --- src/lib/eina/eina_inline_rectangle.x | 138 +++ src/lib/eina/eina_rectangle.h| 10 +++ 2 files changed, 148 insertions(+) diff --git a/src/lib/eina/eina_inline_rectangle.x b/src/lib/eina/eina_inline_rectangle.x index dbd7f11..42a87f8 100644 --- a/src/lib/eina/eina_inline_rectangle.x +++ b/src/lib/eina/eina_inline_rectangle.x @@ -247,6 +247,144 @@ eina_rectangle_rescale_out(const Eina_Rectangle *out, const Eina_Rectangle *in, res-h = out-h; } +static inline Eina_Bool +eina_rectangle_is_valid(const Eina_Rectangle *r) +{ + if (r-w = 0 || r-h = 0) + return EINA_FALSE; + return EINA_TRUE; +} + +static inline int +eina_rectangle_max_x(Eina_Rectangle *thiz) +{ + return thiz-x + thiz-w; +} + +static inline int +eina_rectangle_max_y(Eina_Rectangle *thiz) +{ + return thiz-y + thiz-h; +} + +static inline Eina_Bool +eina_rectangle_x_cut(Eina_Rectangle *thiz, Eina_Rectangle *slice, Eina_Rectangle *leftover, int amount) +{ + Eina_Rectangle tmp1, tmp2; + if (amount thiz-w) + return EINA_FALSE; + eina_rectangle_coords_from(tmp1, thiz-x, thiz-y, amount, thiz-h); + eina_rectangle_coords_from(tmp2, thiz-x + amount, thiz-y, thiz-w - amount, thiz-h); + if (slice) *slice = tmp1; + if (leftover) *leftover = tmp2; + return EINA_TRUE; +} + +static inline Eina_Bool +eina_rectangle_y_cut(Eina_Rectangle *thiz, Eina_Rectangle *slice, Eina_Rectangle *leftover, int amount) +{ + Eina_Rectangle tmp1, tmp2; + if (amount thiz-h) + return EINA_FALSE; + eina_rectangle_coords_from(tmp1, thiz-x, thiz-y, thiz-w, amount); + eina_rectangle_coords_from(tmp2, thiz-x, thiz-y + amount, thiz-w, thiz-h - amount); + if (slice) *slice = tmp1; + if (leftover) *leftover = tmp2; + return EINA_TRUE; +} + +static inline Eina_Bool +eina_rectangle_width_cut(Eina_Rectangle *thiz, Eina_Rectangle *slice, Eina_Rectangle *leftover, int amount) +{ + Eina_Rectangle tmp1, tmp2; + if (thiz-w - amount 0) + return EINA_FALSE; + eina_rectangle_coords_from(tmp1, thiz-x + (thiz-w - amount), thiz-y, amount, thiz-h); + eina_rectangle_coords_from(tmp2, thiz-x, thiz-y, thiz-w - amount, thiz-h); + if (slice) *slice = tmp1; + if (leftover) *leftover = tmp2; + return EINA_TRUE; +} + +static inline Eina_Bool +eina_rectangle_height_cut(Eina_Rectangle *thiz, Eina_Rectangle *slice, Eina_Rectangle *leftover, int amount) +{ + Eina_Rectangle tmp1, tmp2; + if (thiz-h - amount 0) + return EINA_FALSE; + eina_rectangle_coords_from(tmp1, thiz-x, thiz-y + (thiz-h - amount), thiz-w, amount); + eina_rectangle_coords_from(tmp2, thiz-x, thiz-y, thiz-w, thiz-h - amount); + if (slice) *slice = tmp1; + if (leftover) *leftover = tmp2; + return EINA_TRUE; +} + +/** + * @brief Subtract two rectangles. + * + * @param thiz The minuend rectangle + * @param src The subtrahend rectangle + * + * This function subtract two rectangles. The difference is stored on @p out + * There will be at most four differences, use eina_rectangle_is_valid to + * confirm the number of differences. + */ +static inline Eina_Bool +eina_rectangle_subtract(Eina_Rectangle *thiz, Eina_Rectangle *other, Eina_Rectangle out[4]) +{ + Eina_Rectangle intersection; + Eina_Rectangle leftover = EINA_RECTANGLE_INIT; + Eina_Rectangle tmp; + int cut = 0; + + if (!eina_rectangle_is_valid(thiz)) + return EINA_FALSE; + + eina_rectangle_coords_from(out[0], 0, 0, 0, 0); + eina_rectangle_coords_from(out[1], 0, 0, 0, 0); + eina_rectangle_coords_from(out[2], 0, 0, 0, 0); + eina_rectangle_coords_from(out[3], 0, 0, 0, 0); + intersection = *thiz; + if (!eina_rectangle_intersection(intersection, other)) + { + out[0] = *thiz; + return EINA_TRUE; + } + + /* cut in height */ + { + cut = thiz-h - (intersection.y - thiz-y); + if (cut thiz-h) { cut = thiz-h; } + eina_rectangle_height_cut(thiz, leftover, out[0], cut); + } + /* cut in y */ + tmp = leftover; + if (eina_rectangle_intersection(tmp, intersection)) + { + cut = leftover.h - (eina_rectangle_max_y(leftover) - eina_rectangle_max_y(tmp)); + if (cut leftover.h) { cut = leftover.h
[EGIT] [core/efl] master 01/04: eina: add double_from/to and helper defines in f16p16
cedric pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=538821f09d4dcd71642eb7f4d782ef350b956ddf commit 538821f09d4dcd71642eb7f4d782ef350b956ddf Author: Jorge Zapata jorgeluis.zap...@gmail.com Date: Mon Sep 23 20:48:52 2013 +0200 eina: add double_from/to and helper defines in f16p16 --- src/lib/eina/eina_fp.h| 6 ++ src/lib/eina/eina_inline_fp.x | 17 + 2 files changed, 23 insertions(+) diff --git a/src/lib/eina/eina_fp.h b/src/lib/eina/eina_fp.h index c73dc16..bc6c78d 100644 --- a/src/lib/eina/eina_fp.h +++ b/src/lib/eina/eina_fp.h @@ -60,8 +60,14 @@ static inline unsigned int eina_f32p32_fracc_get(Eina_F32p32 v); EAPI Eina_F32p32 eina_f32p32_cos(Eina_F32p32 a); EAPI Eina_F32p32 eina_f32p32_sin(Eina_F32p32 a); + +#define EINA_F16P16_ONE (1 16) +#define EINA_F16P16_HALF (1 15) + static inline Eina_F16p16 eina_f16p16_int_from(int32_t v); static inline int32_t eina_f16p16_int_to(Eina_F16p16 v); +static inline Eina_F16p16 eina_f16p16_double_from(double v); +static inline double eina_f16p16_double_to(Eina_F16p16 v); static inline Eina_F16p16 eina_f16p16_float_from(float v); static inline floateina_f16p16_float_to(Eina_F16p16 v); diff --git a/src/lib/eina/eina_inline_fp.x b/src/lib/eina/eina_inline_fp.x index de44123..e459f82 100644 --- a/src/lib/eina/eina_inline_fp.x +++ b/src/lib/eina/eina_inline_fp.x @@ -80,6 +80,23 @@ eina_f16p16_float_to(Eina_F16p16 v) return r; } +static inline Eina_F16p16 +eina_f16p16_double_from(double v) +{ + Eina_F16p16 r; + + r = (Eina_F16p16)(v * 65536.0 + (v 0 ? -0.5 : 0.5)); + return r; +} + +static inline double +eina_f16p16_double_to(Eina_F16p16 v) +{ + double r; + + r = v / 65536.0; + return r; +} static inline Eina_F8p24 --
[EGIT] [core/efl] master 04/04: eina: add functions to alloc strings from a printf fmt
cedric pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=b5fce696c743c50ea0a049c4f879756b5ed231d4 commit b5fce696c743c50ea0a049c4f879756b5ed231d4 Author: Jorge Zapata jorgeluis.zap...@gmail.com Date: Mon Sep 23 21:13:18 2013 +0200 eina: add functions to alloc strings from a printf fmt --- src/lib/eina/eina_str.c | 41 + src/lib/eina/eina_str.h | 33 + 2 files changed, 74 insertions(+) diff --git a/src/lib/eina/eina_str.c b/src/lib/eina/eina_str.c index 11fef3c..283476b 100644 --- a/src/lib/eina/eina_str.c +++ b/src/lib/eina/eina_str.c @@ -652,3 +652,44 @@ eina_str_toupper(char **str) for (p = *str; (*p); p++) *p = toupper((unsigned char)(*p)); } + +EAPI size_t +eina_str_vprintf_length(const char *format, va_list args) +{ +char c; +size_t len; + +len = vsnprintf(c, 1, format, args) + 1; +return len; +} + +EAPI char * +eina_str_vprintf_dup(const char *format, va_list args) +{ +size_t length; +char *ret; +va_list copy; + +/* be sure to use a copy or the printf implementation will + * step into the args + */ +va_copy(copy, args); +length = eina_str_vprintf_length(format, copy); +va_end(copy); + +ret = calloc(length, sizeof(char)); +vsprintf(ret, format, args); +return ret; +} + +EAPI char * +eina_str_printf_dup(const char *format, ...) +{ +char *ret; +va_list args; + +va_start(args, format); +ret = eina_str_vprintf_dup(format, args); +va_end(args); +return ret; +} diff --git a/src/lib/eina/eina_str.h b/src/lib/eina/eina_str.h index dae592b..1d8edae 100644 --- a/src/lib/eina/eina_str.h +++ b/src/lib/eina/eina_str.h @@ -345,6 +345,39 @@ static inline size_t eina_str_join(char *dst, size_t size, char sep, const char static inline size_t eina_strlen_bounded(const char *str, size_t maxlen) EINA_PURE EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1); +/** + * @brief Gets the length needed for a string based on a printf format and args + * + * @param format The printf format + * @param args The printf args + * @return The length needed for such format and args + * @since 1.7.9 + */ +EAPI size_t eina_str_vprintf_length(const char *format, va_list args); + +/** + * @brief Gets a newly allocated string that represents the printf format and args + * + * @param format The printf format + * @param args The printf args + * @return A newly allocated string + * + * @see eina_str_dup_printf + * @since 1.7.9 + */ +EAPI char * eina_str_vprintf_dup(const char *format, va_list args); + +/** + * @brief Gets a newly allocated string that represents the printf format and args + * + * @param format The printf format + * @return A newly allocated string + * + * @see eina_str_dup_vprintf + * @since 1.7.9 + */ +EAPI char * eina_str_printf_dup(const char *format, ...); + #include eina_inline_str.x /** --