2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
13 const double PointEpsilon = 0.000001;
14 const double SquaredEpsilon = PointEpsilon * PointEpsilon;
17 const int UlpsEpsilon = 16;
19 _Vector operator-(const _Point& a, const _Point& b) {
20 _Vector v = {a.x - b.x, a.y - b.y};
24 _Point operator+(const _Point& a, const _Vector& b) {
25 _Point v = {a.x + b.x, a.y + b.y};
29 // from http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
32 Float_t(float num = 0.0f) : f(num) {}
33 // Portable extraction of components.
34 bool negative() const { return (i >> 31) != 0; }
36 int32_t RawMantissa() const { return i & ((1 << 23) - 1); }
37 int32_t RawExponent() const { return (i >> 23) & 0xFF; }
43 { // Bitfields for exploration. Do not use in production code.
44 uint32_t mantissa : 23;
45 uint32_t exponent : 8;
51 bool AlmostEqualUlps(float A, float B)
56 // Different signs means they do not match.
57 if (uA.negative() != uB.negative())
59 // Check for equality to make sure +0==-0
63 // Find the difference in ULPs.
64 int ulpsDiff = abs(uA.i - uB.i);
65 return ulpsDiff <= UlpsEpsilon;
68 // FIXME: obsolete, delete
70 int UlpsDiff(float A, float B)
75 return abs(uA.i - uB.i);
80 void mathematica_ize(char* str, size_t bufferLen) {
81 size_t len = strlen(str);
83 for (size_t idx = 0; idx < len; ++idx) {
84 if (num && str[idx] == 'e') {
85 if (len + 2 >= bufferLen) {
88 memmove(&str[idx + 2], &str[idx + 1], len - idx);
93 num = str[idx] >= '0' && str[idx] <= '9';
97 bool valid_wind(int wind) {
98 return wind > SK_MinS32 + 0xFFFF && wind < SK_MaxS32 - 0xFFFF;
101 void winding_printf(int wind) {
102 if (wind == SK_MinS32) {
105 SkDebugf("%d", wind);