Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2012 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | #ifndef SkPathOpsPoint_DEFINED |
michael@0 | 8 | #define SkPathOpsPoint_DEFINED |
michael@0 | 9 | |
michael@0 | 10 | #include "SkPathOpsTypes.h" |
michael@0 | 11 | #include "SkPoint.h" |
michael@0 | 12 | |
michael@0 | 13 | inline bool AlmostEqualUlps(const SkPoint& pt1, const SkPoint& pt2) { |
michael@0 | 14 | return AlmostEqualUlps(pt1.fX, pt2.fX) && AlmostEqualUlps(pt1.fY, pt2.fY); |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | struct SkDVector { |
michael@0 | 18 | double fX, fY; |
michael@0 | 19 | |
michael@0 | 20 | friend SkDPoint operator+(const SkDPoint& a, const SkDVector& b); |
michael@0 | 21 | |
michael@0 | 22 | void operator+=(const SkDVector& v) { |
michael@0 | 23 | fX += v.fX; |
michael@0 | 24 | fY += v.fY; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | void operator-=(const SkDVector& v) { |
michael@0 | 28 | fX -= v.fX; |
michael@0 | 29 | fY -= v.fY; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | void operator/=(const double s) { |
michael@0 | 33 | fX /= s; |
michael@0 | 34 | fY /= s; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | void operator*=(const double s) { |
michael@0 | 38 | fX *= s; |
michael@0 | 39 | fY *= s; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | SkVector asSkVector() const { |
michael@0 | 43 | SkVector v = {SkDoubleToScalar(fX), SkDoubleToScalar(fY)}; |
michael@0 | 44 | return v; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | double cross(const SkDVector& a) const { |
michael@0 | 48 | return fX * a.fY - fY * a.fX; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | double dot(const SkDVector& a) const { |
michael@0 | 52 | return fX * a.fX + fY * a.fY; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | double length() const { |
michael@0 | 56 | return sqrt(lengthSquared()); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | double lengthSquared() const { |
michael@0 | 60 | return fX * fX + fY * fY; |
michael@0 | 61 | } |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | struct SkDPoint { |
michael@0 | 65 | double fX; |
michael@0 | 66 | double fY; |
michael@0 | 67 | |
michael@0 | 68 | void set(const SkPoint& pt) { |
michael@0 | 69 | fX = pt.fX; |
michael@0 | 70 | fY = pt.fY; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | friend SkDVector operator-(const SkDPoint& a, const SkDPoint& b); |
michael@0 | 74 | |
michael@0 | 75 | friend bool operator==(const SkDPoint& a, const SkDPoint& b) { |
michael@0 | 76 | return a.fX == b.fX && a.fY == b.fY; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | friend bool operator!=(const SkDPoint& a, const SkDPoint& b) { |
michael@0 | 80 | return a.fX != b.fX || a.fY != b.fY; |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | void operator=(const SkPoint& pt) { |
michael@0 | 84 | fX = pt.fX; |
michael@0 | 85 | fY = pt.fY; |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | |
michael@0 | 89 | void operator+=(const SkDVector& v) { |
michael@0 | 90 | fX += v.fX; |
michael@0 | 91 | fY += v.fY; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | void operator-=(const SkDVector& v) { |
michael@0 | 95 | fX -= v.fX; |
michael@0 | 96 | fY -= v.fY; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | // note: this can not be implemented with |
michael@0 | 100 | // return approximately_equal(a.fY, fY) && approximately_equal(a.fX, fX); |
michael@0 | 101 | // because that will not take the magnitude of the values into account |
michael@0 | 102 | bool approximatelyEqual(const SkDPoint& a) const { |
michael@0 | 103 | if (approximately_equal(fX, a.fX) && approximately_equal(fY, a.fY)) { |
michael@0 | 104 | return true; |
michael@0 | 105 | } |
michael@0 | 106 | if (!RoughlyEqualUlps(fX, a.fX) || !RoughlyEqualUlps(fY, a.fY)) { |
michael@0 | 107 | return false; |
michael@0 | 108 | } |
michael@0 | 109 | double dist = distance(a); // OPTIMIZATION: can we compare against distSq instead ? |
michael@0 | 110 | double tiniest = SkTMin(SkTMin(SkTMin(fX, a.fX), fY), a.fY); |
michael@0 | 111 | double largest = SkTMax(SkTMax(SkTMax(fX, a.fX), fY), a.fY); |
michael@0 | 112 | largest = SkTMax(largest, -tiniest); |
michael@0 | 113 | return AlmostBequalUlps(largest, largest + dist); // is the dist within ULPS tolerance? |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | bool approximatelyEqual(const SkPoint& a) const { |
michael@0 | 117 | SkDPoint dA; |
michael@0 | 118 | dA.set(a); |
michael@0 | 119 | return approximatelyEqual(dA); |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | static bool ApproximatelyEqual(const SkPoint& a, const SkPoint& b) { |
michael@0 | 123 | if (approximately_equal(a.fX, b.fX) && approximately_equal(a.fY, b.fY)) { |
michael@0 | 124 | return true; |
michael@0 | 125 | } |
michael@0 | 126 | if (!RoughlyEqualUlps(a.fX, b.fX) || !RoughlyEqualUlps(a.fY, b.fY)) { |
michael@0 | 127 | return false; |
michael@0 | 128 | } |
michael@0 | 129 | SkDPoint dA, dB; |
michael@0 | 130 | dA.set(a); |
michael@0 | 131 | dB.set(b); |
michael@0 | 132 | double dist = dA.distance(dB); // OPTIMIZATION: can we compare against distSq instead ? |
michael@0 | 133 | float tiniest = SkTMin(SkTMin(SkTMin(a.fX, b.fX), a.fY), b.fY); |
michael@0 | 134 | float largest = SkTMax(SkTMax(SkTMax(a.fX, b.fX), a.fY), b.fY); |
michael@0 | 135 | largest = SkTMax(largest, -tiniest); |
michael@0 | 136 | return AlmostBequalUlps((double) largest, largest + dist); // is dist within ULPS tolerance? |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | bool approximatelyPEqual(const SkDPoint& a) const { |
michael@0 | 140 | if (approximately_equal(fX, a.fX) && approximately_equal(fY, a.fY)) { |
michael@0 | 141 | return true; |
michael@0 | 142 | } |
michael@0 | 143 | if (!RoughlyEqualUlps(fX, a.fX) || !RoughlyEqualUlps(fY, a.fY)) { |
michael@0 | 144 | return false; |
michael@0 | 145 | } |
michael@0 | 146 | double dist = distance(a); // OPTIMIZATION: can we compare against distSq instead ? |
michael@0 | 147 | double tiniest = SkTMin(SkTMin(SkTMin(fX, a.fX), fY), a.fY); |
michael@0 | 148 | double largest = SkTMax(SkTMax(SkTMax(fX, a.fX), fY), a.fY); |
michael@0 | 149 | largest = SkTMax(largest, -tiniest); |
michael@0 | 150 | return AlmostPequalUlps(largest, largest + dist); // is the dist within ULPS tolerance? |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | bool approximatelyZero() const { |
michael@0 | 154 | return approximately_zero(fX) && approximately_zero(fY); |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | SkPoint asSkPoint() const { |
michael@0 | 158 | SkPoint pt = {SkDoubleToScalar(fX), SkDoubleToScalar(fY)}; |
michael@0 | 159 | return pt; |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | double distance(const SkDPoint& a) const { |
michael@0 | 163 | SkDVector temp = *this - a; |
michael@0 | 164 | return temp.length(); |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | double distanceSquared(const SkDPoint& a) const { |
michael@0 | 168 | SkDVector temp = *this - a; |
michael@0 | 169 | return temp.lengthSquared(); |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | static SkDPoint Mid(const SkDPoint& a, const SkDPoint& b) { |
michael@0 | 173 | SkDPoint result; |
michael@0 | 174 | result.fX = (a.fX + b.fX) / 2; |
michael@0 | 175 | result.fY = (a.fY + b.fY) / 2; |
michael@0 | 176 | return result; |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | bool moreRoughlyEqual(const SkDPoint& a) const { |
michael@0 | 180 | if (roughly_equal(fX, a.fX) && roughly_equal(fY, a.fY)) { |
michael@0 | 181 | return true; |
michael@0 | 182 | } |
michael@0 | 183 | double dist = distance(a); // OPTIMIZATION: can we compare against distSq instead ? |
michael@0 | 184 | double tiniest = SkTMin(SkTMin(SkTMin(fX, a.fX), fY), a.fY); |
michael@0 | 185 | double largest = SkTMax(SkTMax(SkTMax(fX, a.fX), fY), a.fY); |
michael@0 | 186 | largest = SkTMax(largest, -tiniest); |
michael@0 | 187 | return RoughlyEqualUlps(largest, largest + dist); // is the dist within ULPS tolerance? |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | bool roughlyEqual(const SkDPoint& a) const { |
michael@0 | 191 | return roughly_equal(a.fY, fY) && roughly_equal(a.fX, fX); |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | #ifdef SK_DEBUG |
michael@0 | 195 | void dump() { |
michael@0 | 196 | SkDebugf("{"); |
michael@0 | 197 | DebugDumpDouble(fX); |
michael@0 | 198 | SkDebugf(", "); |
michael@0 | 199 | DebugDumpDouble(fY); |
michael@0 | 200 | SkDebugf("}"); |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | static void dump(const SkPoint& pt) { |
michael@0 | 204 | SkDebugf("{"); |
michael@0 | 205 | DebugDumpFloat(pt.fX); |
michael@0 | 206 | SkDebugf(", "); |
michael@0 | 207 | DebugDumpFloat(pt.fY); |
michael@0 | 208 | SkDebugf("}"); |
michael@0 | 209 | } |
michael@0 | 210 | #endif |
michael@0 | 211 | }; |
michael@0 | 212 | |
michael@0 | 213 | #endif |