diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2010-02-09 18:30:59 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2010-02-09 18:30:59 +0000 |
commit | eebf5cb6c0f5ed2630de2e7712d61b4ec1d49015 (patch) | |
tree | 291354b16917cd7810ca63fcfd1885c3d5419c93 /include/core | |
parent | d3aa4ff7a564953dff9a15ff03fd42eebf64569f (diff) |
add copysign for ints and floats
fix addArc to not wrap around if the sweepAngle is close to 360 but lost
precision when convert to radians (and then to unit vectors ala sin/cos)
git-svn-id: http://skia.googlecode.com/svn/trunk@495 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core')
-rw-r--r-- | include/core/SkFloatingPoint.h | 6 | ||||
-rw-r--r-- | include/core/SkMath.h | 5 | ||||
-rw-r--r-- | include/core/SkScalar.h | 4 |
3 files changed, 15 insertions, 0 deletions
diff --git a/include/core/SkFloatingPoint.h b/include/core/SkFloatingPoint.h index e6856cf750..8c3bb835ca 100644 --- a/include/core/SkFloatingPoint.h +++ b/include/core/SkFloatingPoint.h @@ -31,6 +31,12 @@ static inline float sk_float_pow(float base, float exp) { static_cast<double>(exp))); } +static inline float sk_float_copysign(float x, float y) { + int32_t xbits = SkFloat2Bits(x); + int32_t ybits = SkFloat2Bits(y); + return SkBits2Float((xbits & 0x7FFFFFFF) | (ybits & 0x80000000)); +} + #ifdef SK_BUILD_FOR_WINCE #define sk_float_sqrt(x) (float)::sqrt(x) #define sk_float_sin(x) (float)::sin(x) diff --git a/include/core/SkMath.h b/include/core/SkMath.h index 3f3c660bcb..e0f23617ee 100644 --- a/include/core/SkMath.h +++ b/include/core/SkMath.h @@ -64,6 +64,11 @@ static inline int32_t SkApplySign(int32_t n, int32_t sign) { return (n ^ sign) - sign; } +/** Return x with the sign of y */ +static inline int32_t SkCopySign32(int32_t x, int32_t y) { + return SkApplySign(x, SkExtractSign(x ^ y)); +} + /** Returns (value < 0 ? 0 : value) efficiently (i.e. no compares or branches) */ static inline int SkClampPos(int value) { diff --git a/include/core/SkScalar.h b/include/core/SkScalar.h index 5be809f9e3..9130a7cf12 100644 --- a/include/core/SkScalar.h +++ b/include/core/SkScalar.h @@ -91,6 +91,9 @@ /** Returns the absolute value of the specified SkScalar */ #define SkScalarAbs(x) sk_float_abs(x) + /** Return x with the sign of y + */ + #define SkScalarCopySign(x, y) sk_float_copysign(x, y) /** Returns the value pinned between 0 and max inclusive */ inline SkScalar SkScalarClampMax(SkScalar x, SkScalar max) { @@ -189,6 +192,7 @@ #define SkScalarCeil(x) SkFixedCeil(x) #define SkScalarFloor(x) SkFixedFloor(x) #define SkScalarAbs(x) SkFixedAbs(x) + #define SkScalarCopySign(x, y) SkCopySign32(x, y) #define SkScalarClampMax(x, max) SkClampMax(x, max) #define SkScalarPin(x, min, max) SkPin32(x, min, max) #define SkScalarSquare(x) SkFixedSquare(x) |