Changeset 32066f2 in mainline for uspace/lib/gfx/src/coord.c


Ignore:
Timestamp:
2020-08-27T11:24:39Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e2776ff
Parents:
20d0098
git-author:
Jiri Svoboda <jiri@…> (2020-08-26 18:34:29)
git-committer:
Jiri Svoboda <jiri@…> (2020-08-27 11:24:39)
Message:

Need to be able to paint in the negative quadrants

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gfx/src/coord.c

    r20d0098 r32066f2  
    3939#include <stddef.h>
    4040
     41/** Divide @a a by @a b and round towards negative numbers.
     42 *
     43 * Regular integer division always rounds towards zero. This is not useful
     44 * e.g. for scaling down, where we always need to round towards negative
     45 * numbers.
     46 *
     47 * @param a Dividend
     48 * @param b Divisor
     49 * @return Quotient
     50 */
     51gfx_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
    4162/** Add two vectors.
    4263 *
Note: See TracChangeset for help on using the changeset viewer.