Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/pathops/SkPathOpsPoint.h

Issue 131103009: update pathops to circle sort (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: disable old test that still fails on linux 32 release Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pathops/SkPathOpsOp.cpp ('k') | src/pathops/SkPathOpsQuad.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #ifndef SkPathOpsPoint_DEFINED 7 #ifndef SkPathOpsPoint_DEFINED
8 #define SkPathOpsPoint_DEFINED 8 #define SkPathOpsPoint_DEFINED
9 9
10 #include "SkPathOpsTypes.h" 10 #include "SkPathOpsTypes.h"
11 #include "SkPoint.h" 11 #include "SkPoint.h"
12 12
13 inline bool AlmostEqualUlps(const SkPoint& pt1, const SkPoint& pt2) { 13 inline bool AlmostEqualUlps(const SkPoint& pt1, const SkPoint& pt2) {
14 return AlmostEqualUlps(pt1.fX, pt2.fX) && AlmostEqualUlps(pt1.fY, pt2.fY); 14 return AlmostEqualUlps(pt1.fX, pt2.fX) && AlmostEqualUlps(pt1.fY, pt2.fY);
15 } 15 }
16 16
17 struct SkDVector { 17 struct SkDVector {
18 double fX, fY; 18 double fX;
19 double fY;
20
21 void set(const SkVector& pt) {
22 fX = pt.fX;
23 fY = pt.fY;
24 }
19 25
20 friend SkDPoint operator+(const SkDPoint& a, const SkDVector& b); 26 friend SkDPoint operator+(const SkDPoint& a, const SkDVector& b);
21 27
22 void operator+=(const SkDVector& v) { 28 void operator+=(const SkDVector& v) {
23 fX += v.fX; 29 fX += v.fX;
24 fY += v.fY; 30 fY += v.fY;
25 } 31 }
26 32
27 void operator-=(const SkDVector& v) { 33 void operator-=(const SkDVector& v) {
28 fX -= v.fX; 34 fX -= v.fX;
(...skipping 12 matching lines...) Expand all
41 47
42 SkVector asSkVector() const { 48 SkVector asSkVector() const {
43 SkVector v = {SkDoubleToScalar(fX), SkDoubleToScalar(fY)}; 49 SkVector v = {SkDoubleToScalar(fX), SkDoubleToScalar(fY)};
44 return v; 50 return v;
45 } 51 }
46 52
47 double cross(const SkDVector& a) const { 53 double cross(const SkDVector& a) const {
48 return fX * a.fY - fY * a.fX; 54 return fX * a.fY - fY * a.fX;
49 } 55 }
50 56
57 // similar to cross, this bastardization considers nearly coincident to be z ero
58 double crossCheck(const SkDVector& a) const {
59 double xy = fX * a.fY;
60 double yx = fY * a.fX;
61 return AlmostEqualUlps(xy, yx) ? 0 : xy - yx;
62 }
63
51 double dot(const SkDVector& a) const { 64 double dot(const SkDVector& a) const {
52 return fX * a.fX + fY * a.fY; 65 return fX * a.fX + fY * a.fY;
53 } 66 }
54 67
55 double length() const { 68 double length() const {
56 return sqrt(lengthSquared()); 69 return sqrt(lengthSquared());
57 } 70 }
58 71
59 double lengthSquared() const { 72 double lengthSquared() const {
60 return fX * fX + fY * fY; 73 return fX * fX + fY * fY;
(...skipping 17 matching lines...) Expand all
78 91
79 friend bool operator!=(const SkDPoint& a, const SkDPoint& b) { 92 friend bool operator!=(const SkDPoint& a, const SkDPoint& b) {
80 return a.fX != b.fX || a.fY != b.fY; 93 return a.fX != b.fX || a.fY != b.fY;
81 } 94 }
82 95
83 void operator=(const SkPoint& pt) { 96 void operator=(const SkPoint& pt) {
84 fX = pt.fX; 97 fX = pt.fX;
85 fY = pt.fY; 98 fY = pt.fY;
86 } 99 }
87 100
88
89 void operator+=(const SkDVector& v) { 101 void operator+=(const SkDVector& v) {
90 fX += v.fX; 102 fX += v.fX;
91 fY += v.fY; 103 fY += v.fY;
92 } 104 }
93 105
94 void operator-=(const SkDVector& v) { 106 void operator-=(const SkDVector& v) {
95 fX -= v.fX; 107 fX -= v.fX;
96 fY -= v.fY; 108 fY -= v.fY;
97 } 109 }
98 110
(...skipping 30 matching lines...) Expand all
129 SkDPoint dA, dB; 141 SkDPoint dA, dB;
130 dA.set(a); 142 dA.set(a);
131 dB.set(b); 143 dB.set(b);
132 double dist = dA.distance(dB); // OPTIMIZATION: can we compare against distSq instead ? 144 double dist = dA.distance(dB); // OPTIMIZATION: can we compare against distSq instead ?
133 float tiniest = SkTMin(SkTMin(SkTMin(a.fX, b.fX), a.fY), b.fY); 145 float tiniest = SkTMin(SkTMin(SkTMin(a.fX, b.fX), a.fY), b.fY);
134 float largest = SkTMax(SkTMax(SkTMax(a.fX, b.fX), a.fY), b.fY); 146 float largest = SkTMax(SkTMax(SkTMax(a.fX, b.fX), a.fY), b.fY);
135 largest = SkTMax(largest, -tiniest); 147 largest = SkTMax(largest, -tiniest);
136 return AlmostBequalUlps((double) largest, largest + dist); // is dist wi thin ULPS tolerance? 148 return AlmostBequalUlps((double) largest, largest + dist); // is dist wi thin ULPS tolerance?
137 } 149 }
138 150
151 #if SK_DEBUG
152 static bool RoughlyEqual(const SkPoint& a, const SkPoint& b) {
153 if (approximately_equal(a.fX, b.fX) && approximately_equal(a.fY, b.fY)) {
154 return true;
155 }
156 return RoughlyEqualUlps(a.fX, b.fX) && RoughlyEqualUlps(a.fY, b.fY);
157 }
158 #endif
159
139 bool approximatelyPEqual(const SkDPoint& a) const { 160 bool approximatelyPEqual(const SkDPoint& a) const {
140 if (approximately_equal(fX, a.fX) && approximately_equal(fY, a.fY)) { 161 if (approximately_equal(fX, a.fX) && approximately_equal(fY, a.fY)) {
141 return true; 162 return true;
142 } 163 }
143 if (!RoughlyEqualUlps(fX, a.fX) || !RoughlyEqualUlps(fY, a.fY)) { 164 if (!RoughlyEqualUlps(fX, a.fX) || !RoughlyEqualUlps(fY, a.fY)) {
144 return false; 165 return false;
145 } 166 }
146 double dist = distance(a); // OPTIMIZATION: can we compare against dist Sq instead ? 167 double dist = distance(a); // OPTIMIZATION: can we compare against dist Sq instead ?
147 double tiniest = SkTMin(SkTMin(SkTMin(fX, a.fX), fY), a.fY); 168 double tiniest = SkTMin(SkTMin(SkTMin(fX, a.fX), fY), a.fY);
148 double largest = SkTMax(SkTMax(SkTMax(fX, a.fX), fY), a.fY); 169 double largest = SkTMax(SkTMax(SkTMax(fX, a.fX), fY), a.fY);
149 largest = SkTMax(largest, -tiniest); 170 largest = SkTMax(largest, -tiniest);
150 return AlmostPequalUlps(largest, largest + dist); // is the dist within ULPS tolerance? 171 return AlmostPequalUlps(largest, largest + dist); // is the dist within ULPS tolerance?
151 } 172 }
152 173
174 bool approximatelyDEqual(const SkDPoint& a) const {
175 if (approximately_equal(fX, a.fX) && approximately_equal(fY, a.fY)) {
176 return true;
177 }
178 if (!RoughlyEqualUlps(fX, a.fX) || !RoughlyEqualUlps(fY, a.fY)) {
179 return false;
180 }
181 double dist = distance(a); // OPTIMIZATION: can we compare against dist Sq instead ?
182 double tiniest = SkTMin(SkTMin(SkTMin(fX, a.fX), fY), a.fY);
183 double largest = SkTMax(SkTMax(SkTMax(fX, a.fX), fY), a.fY);
184 largest = SkTMax(largest, -tiniest);
185 return AlmostDequalUlps(largest, largest + dist); // is the dist within ULPS tolerance?
186 }
187
153 bool approximatelyZero() const { 188 bool approximatelyZero() const {
154 return approximately_zero(fX) && approximately_zero(fY); 189 return approximately_zero(fX) && approximately_zero(fY);
155 } 190 }
156 191
157 SkPoint asSkPoint() const { 192 SkPoint asSkPoint() const {
158 SkPoint pt = {SkDoubleToScalar(fX), SkDoubleToScalar(fY)}; 193 SkPoint pt = {SkDoubleToScalar(fX), SkDoubleToScalar(fY)};
159 return pt; 194 return pt;
160 } 195 }
161 196
162 double distance(const SkDPoint& a) const { 197 double distance(const SkDPoint& a) const {
(...skipping 21 matching lines...) Expand all
184 double tiniest = SkTMin(SkTMin(SkTMin(fX, a.fX), fY), a.fY); 219 double tiniest = SkTMin(SkTMin(SkTMin(fX, a.fX), fY), a.fY);
185 double largest = SkTMax(SkTMax(SkTMax(fX, a.fX), fY), a.fY); 220 double largest = SkTMax(SkTMax(SkTMax(fX, a.fX), fY), a.fY);
186 largest = SkTMax(largest, -tiniest); 221 largest = SkTMax(largest, -tiniest);
187 return RoughlyEqualUlps(largest, largest + dist); // is the dist within ULPS tolerance? 222 return RoughlyEqualUlps(largest, largest + dist); // is the dist within ULPS tolerance?
188 } 223 }
189 224
190 bool roughlyEqual(const SkDPoint& a) const { 225 bool roughlyEqual(const SkDPoint& a) const {
191 return roughly_equal(a.fY, fY) && roughly_equal(a.fX, fX); 226 return roughly_equal(a.fY, fY) && roughly_equal(a.fX, fX);
192 } 227 }
193 228
194 #ifdef SK_DEBUG 229 // utilities callable by the user from the debugger when the implementation code is linked in
195 void dump() { 230 void dump() const;
196 SkDebugf("{"); 231 static void Dump(const SkPoint& pt);
197 DebugDumpDouble(fX);
198 SkDebugf(", ");
199 DebugDumpDouble(fY);
200 SkDebugf("}");
201 }
202
203 static void dump(const SkPoint& pt) {
204 SkDebugf("{");
205 DebugDumpFloat(pt.fX);
206 SkDebugf(", ");
207 DebugDumpFloat(pt.fY);
208 SkDebugf("}");
209 }
210 #endif
211 }; 232 };
212 233
213 #endif 234 #endif
OLDNEW
« no previous file with comments | « src/pathops/SkPathOpsOp.cpp ('k') | src/pathops/SkPathOpsQuad.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698