From 0de6ae8175e44c5f3f2407161c786a4d3c6c6f7a Mon Sep 17 00:00:00 2001 From: anon Date: Fri, 10 Jan 2025 13:17:03 +0100 Subject: [PATCH] +absolute moving functions --- dyrect.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/dyrect.h b/dyrect.h index 7076980..332e8ee 100644 --- a/dyrect.h +++ b/dyrect.h @@ -18,6 +18,7 @@ // TODO: further macro hell x, y, width and height so they can be user overwritten too // TODO: theres a logical inconsistency between ride-hang and rock-paper; either justify it or normalize it +// TODO: absolute sizing functions /* Dyrect can use an arbitrary C style namespace, * or use the prefix `dr_` if the following feature macro is requested. @@ -85,6 +86,8 @@ static inline rect_t DYRECT_PREFIX(get_unit_rect)(void); static inline rect_t DYRECT_PREFIX(scaley)(rect_t a, float f); static inline rect_t DYRECT_PREFIX(scalex)(rect_t a, float f); static inline rect_t DYRECT_PREFIX(scale)(rect_t a, float f); +static inline rect_t DYRECT_PREFIX(shift)(rect_t source, int n); +static inline rect_t DYRECT_PREFIX(slip)(rect_t source, int n); static inline rect_t DYRECT_PREFIX(balance)(rect_t dest, rect_t source); static inline rect_t DYRECT_PREFIX(buoyance)(rect_t dest, rect_t source); static inline rect_t DYRECT_PREFIX(center)(rect_t dest, rect_t source); @@ -183,6 +186,40 @@ rect_t DYRECT_PREFIX(scale)(rect_t a, float f) { }; } +/* Move horizontally by an absolute number of units. + * + * +-+ __\ +-+ + * +-+ / +-+ + * + */ +static inline +rect_t DYRECT_PREFIX(shift)(rect_t source, int n) { + return (rect_t) { + .x = source.x + n, + .y = source.y, + .width = source.width, + .height = source.height, + }; +} + +/* Move vertically by an absolute number of units. + * + * +-+ + * +-+ + * V + * +-+ + * +-+ + */ +static inline +rect_t DYRECT_PREFIX(slip)(rect_t source, int n) { + return (rect_t) { + .x = source.x, + .y = source.y + n, + .width = source.width, + .height = source.height, + }; +} + /* Align to the middle horizontally * * +---+---+---+