diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cairo-bentley-ottmann.c | 19 | ||||
-rw-r--r-- | src/cairo-wideint-private.h | 10 | ||||
-rw-r--r-- | src/cairo-wideint.c | 48 |
3 files changed, 60 insertions, 17 deletions
diff --git a/src/cairo-bentley-ottmann.c b/src/cairo-bentley-ottmann.c index 28952dda..47ee8338 100644 --- a/src/cairo-bentley-ottmann.c +++ b/src/cairo-bentley-ottmann.c @@ -201,21 +201,13 @@ _slope_compare (cairo_bo_edge_t *a, * with respect to x. */ if ((adx ^ bdx) < 0) { return adx < 0 ? -1 : +1; - } - else { + } else { int32_t ady = a->bottom.y - a->top.y; int32_t bdy = b->bottom.y - b->top.y; int64_t adx_bdy = _cairo_int32x32_64_mul (adx, bdy); int64_t bdx_ady = _cairo_int32x32_64_mul (bdx, ady); - /* if (adx * bdy > bdx * ady) */ - if (_cairo_int64_gt (adx_bdy, bdx_ady)) - return 1; - - /* if (adx * bdy < bdx * ady) */ - if (_cairo_int64_lt (adx_bdy, bdx_ady)) - return -1; - return 0; + return _cairo_int64_cmp (adx_bdy, bdx_ady); } } @@ -320,12 +312,7 @@ edge_compare_for_y_against_x (const cairo_bo_edge_t *a, L = _cairo_int32x32_64_mul (dy, adx); R = _cairo_int32x32_64_mul (dx, ady); - /* return _cairo_int64_cmp (L, R); */ - if (_cairo_int64_lt (L, R)) - return -1; - if (_cairo_int64_gt (L, R)) - return 1; - return 0; + return _cairo_int64_cmp (L, R); } static int diff --git a/src/cairo-wideint-private.h b/src/cairo-wideint-private.h index 07380428..5f34e2b1 100644 --- a/src/cairo-wideint-private.h +++ b/src/cairo-wideint-private.h @@ -61,6 +61,7 @@ cairo_uint64_t I _cairo_uint64_lsl (cairo_uint64_t a, int shift); cairo_uint64_t I _cairo_uint64_rsl (cairo_uint64_t a, int shift); cairo_uint64_t I _cairo_uint64_rsa (cairo_uint64_t a, int shift); int I _cairo_uint64_lt (cairo_uint64_t a, cairo_uint64_t b); +int I _cairo_uint64_cmp (cairo_uint64_t a, cairo_uint64_t b); int I _cairo_uint64_eq (cairo_uint64_t a, cairo_uint64_t b); cairo_uint64_t I _cairo_uint64_negate (cairo_uint64_t a); #define _cairo_uint64_negative(a) (((int32_t) ((a).hi)) < 0) @@ -75,7 +76,8 @@ cairo_int64_t I _cairo_int32_to_int64(int32_t i); #define _cairo_int64_sub(a,b) _cairo_uint64_sub (a,b) #define _cairo_int64_mul(a,b) _cairo_uint64_mul (a,b) cairo_int64_t I _cairo_int32x32_64_mul (int32_t a, int32_t b); -int I _cairo_int64_lt (cairo_uint64_t a, cairo_uint64_t b); +int I _cairo_int64_lt (cairo_int64_t a, cairo_int64_t b); +int I _cairo_int64_cmp (cairo_int64_t a, cairo_int64_t b); #define _cairo_int64_eq(a,b) _cairo_uint64_eq (a,b) #define _cairo_int64_lsl(a,b) _cairo_uint64_lsl (a,b) #define _cairo_int64_rsl(a,b) _cairo_uint64_rsl (a,b) @@ -96,6 +98,7 @@ int I _cairo_int64_lt (cairo_uint64_t a, cairo_uint64_t b); #define _cairo_uint64_rsl(a,b) ((uint64_t) (a) >> (b)) #define _cairo_uint64_rsa(a,b) ((uint64_t) ((int64_t) (a) >> (b))) #define _cairo_uint64_lt(a,b) ((a) < (b)) +#define _cairo_uint64_cmp(a,b) ((a) == (b) ? 0 : (a) < (b) ? -1 : 1) #define _cairo_uint64_eq(a,b) ((a) == (b)) #define _cairo_uint64_negate(a) ((uint64_t) -((int64_t) (a))) #define _cairo_uint64_negative(a) ((int64_t) (a) < 0) @@ -111,6 +114,7 @@ int I _cairo_int64_lt (cairo_uint64_t a, cairo_uint64_t b); #define _cairo_int64_mul(a,b) ((a) * (b)) #define _cairo_int32x32_64_mul(a,b) ((int64_t) (a) * (b)) #define _cairo_int64_lt(a,b) ((a) < (b)) +#define _cairo_int64_cmp(a,b) ((a) == (b) ? 0 : (a) < (b) ? -1 : 1) #define _cairo_int64_eq(a,b) ((a) == (b)) #define _cairo_int64_lsl(a,b) ((a) << (b)) #define _cairo_int64_rsl(a,b) ((int64_t) ((uint64_t) (a) >> (b))) @@ -165,6 +169,7 @@ cairo_uint128_t I _cairo_uint128_lsl (cairo_uint128_t a, int shift); cairo_uint128_t I _cairo_uint128_rsl (cairo_uint128_t a, int shift); cairo_uint128_t I _cairo_uint128_rsa (cairo_uint128_t a, int shift); int I _cairo_uint128_lt (cairo_uint128_t a, cairo_uint128_t b); +int I _cairo_uint128_cmp (cairo_uint128_t a, cairo_uint128_t b); int I _cairo_uint128_eq (cairo_uint128_t a, cairo_uint128_t b); cairo_uint128_t I _cairo_uint128_negate (cairo_uint128_t a); #define _cairo_uint128_negative(a) (_cairo_uint64_negative(a.hi)) @@ -186,6 +191,7 @@ cairo_int128_t I _cairo_int64x64_128_mul (cairo_int64_t a, cairo_int64_t b); #define _cairo_int128_rsl(a,b) _cairo_uint128_rsl(a,b) #define _cairo_int128_rsa(a,b) _cairo_uint128_rsa(a,b) int I _cairo_int128_lt (cairo_int128_t a, cairo_int128_t b); +int I _cairo_int128_cmp (cairo_int128_t a, cairo_int128_t b); #define _cairo_int128_eq(a,b) _cairo_uint128_eq (a,b) #define _cairo_int128_negate(a) _cairo_uint128_negate(a) #define _cairo_int128_negative(a) (_cairo_uint128_negative(a)) @@ -205,6 +211,7 @@ int I _cairo_int128_lt (cairo_int128_t a, cairo_int128_t b); #define _cairo_uint128_rsl(a,b) ((uint128_t) (a) >> (b)) #define _cairo_uint128_rsa(a,b) ((uint128_t) ((int128_t) (a) >> (b))) #define _cairo_uint128_lt(a,b) ((a) < (b)) +#define _cairo_uint128_cmp(a,b) ((a) == (b) ? 0 : (a) < (b) ? -1 : 1) #define _cairo_uint128_eq(a,b) ((a) == (b)) #define _cairo_uint128_negate(a) ((uint128_t) -((int128_t) (a))) #define _cairo_uint128_negative(a) ((int128_t) (a) < 0) @@ -222,6 +229,7 @@ int I _cairo_int128_lt (cairo_int128_t a, cairo_int128_t b); #define _cairo_int128_mul(a,b) ((a) * (b)) #define _cairo_int64x64_128_mul(a,b) ((int128_t) (a) * (b)) #define _cairo_int128_lt(a,b) ((a) < (b)) +#define _cairo_int128_cmp(a,b) ((a) == (b) ? 0 : (a) < (b) ? -1 : 1) #define _cairo_int128_eq(a,b) ((a) == (b)) #define _cairo_int128_lsl(a,b) ((a) << (b)) #define _cairo_int128_rsl(a,b) ((int128_t) ((uint128_t) (a) >> (b))) diff --git a/src/cairo-wideint.c b/src/cairo-wideint.c index e8d3ab69..45655938 100644 --- a/src/cairo-wideint.c +++ b/src/cairo-wideint.c @@ -235,6 +235,32 @@ _cairo_int64_lt (cairo_int64_t a, cairo_int64_t b) return _cairo_uint64_lt (a, b); } +int +_cairo_uint64_cmp (cairo_uint64_t a, cairo_uint64_t b) +{ + if (a.hi < b.hi) + return -1; + else if (a.hi > b.hi) + return 1; + else if (a.lo < b.lo) + return -1; + else if (a.lo > b.lo) + return 1; + else + return 0; +} + +int +_cairo_int64_cmp (cairo_int64_t a, cairo_int64_t b) +{ + if (_cairo_int64_negative (a) && !_cairo_int64_negative (b)) + return -1; + if (!_cairo_int64_negative (a) && _cairo_int64_negative (b)) + return 1; + + return _cairo_uint64_cmp (a, b); +} + cairo_uint64_t _cairo_uint64_not (cairo_uint64_t a) { @@ -570,6 +596,28 @@ _cairo_int128_lt (cairo_int128_t a, cairo_int128_t b) } int +_cairo_uint128_cmp (cairo_uint128_t a, cairo_uint128_t b) +{ + int cmp; + + cmp = _cairo_uint64_cmp (a.hi, b.hi); + if (cmp) + return cmp; + return _cairo_uint64_cmp (a.lo, b.lo); +} + +int +_cairo_int128_cmp (cairo_int128_t a, cairo_int128_t b) +{ + if (_cairo_int128_negative (a) && !_cairo_int128_negative (b)) + return -1; + if (!_cairo_int128_negative (a) && _cairo_int128_negative (b)) + return 1; + + return _cairo_uint128_cmp (a, b); +} + +int _cairo_uint128_eq (cairo_uint128_t a, cairo_uint128_t b) { return (_cairo_uint64_eq (a.hi, b.hi) && |