Changes in uspace/lib/gfx/src/coord.c [266ec54:afcf704] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfx/src/coord.c
r266ec54 rafcf704 39 39 #include <stddef.h> 40 40 41 /** Divide @a a by @a b and round towards negative numbers.42 *43 * Regular integer division always rounds towards zero. This is not useful44 * e.g. for scaling down, where we always need to round towards negative45 * numbers.46 *47 * @param a Dividend48 * @param b Divisor49 * @return Quotient50 */51 gfx_coord_t gfx_coord_div_rneg(gfx_coord_t a, gfx_coord_t b)52 {53 if ((a > 0 && b > 0) || (a < 0 && b < 0)) {54 /* Result is non-negative, round towards zero */55 return a / b;56 } else {57 /* Result is negative, round away from zero */58 return (a - b + 1) / b;59 }60 }61 62 41 /** Add two vectors. 63 42 * … … 238 217 } 239 218 240 /** Center rectangle on rectangle.241 *242 * Translate rectangle @a a so that its center coincides with the243 * center of rectangle @a b, saving the result in @a dest.244 *245 * @param a Rectnagle to translate246 * @param b Rectangle on which to center247 * @param dest Place to store resulting rectangle248 */249 void gfx_rect_ctr_on_rect(gfx_rect_t *a, gfx_rect_t *b, gfx_rect_t *dest)250 {251 gfx_coord2_t adim;252 gfx_coord2_t bdim;253 254 gfx_rect_dims(a, &adim);255 gfx_rect_dims(b, &bdim);256 257 dest->p0.x = b->p0.x + bdim.x / 2 - adim.x / 2;258 dest->p0.y = b->p0.y + bdim.y / 2 - adim.y / 2;259 260 dest->p1.x = dest->p0.x + adim.x;261 dest->p1.y = dest->p0.y + adim.y;262 }263 264 219 /** Sort points of a rectangle. 265 220 *
Note:
See TracChangeset
for help on using the changeset viewer.