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

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

Issue 21359002: path ops work in progress (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: remove space Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « src/pathops/SkOpSpan.h ('k') | src/pathops/SkPathOpsCommon.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 SkPathOpBounds_DEFINED 7 #ifndef SkPathOpBounds_DEFINED
8 #define SkPathOpBounds_DEFINED 8 #define SkPathOpBounds_DEFINED
9 9
10 #include "SkPathOpsRect.h" 10 #include "SkPathOpsRect.h"
11 #include "SkRect.h" 11 #include "SkRect.h"
12 12
13 // SkPathOpsBounds, unlike SkRect, does not consider a line to be empty. 13 // SkPathOpsBounds, unlike SkRect, does not consider a line to be empty.
14 struct SkPathOpsBounds : public SkRect { 14 struct SkPathOpsBounds : public SkRect {
15 static bool Intersects(const SkPathOpsBounds& a, const SkPathOpsBounds& b) { 15 static bool Intersects(const SkPathOpsBounds& a, const SkPathOpsBounds& b) {
16 return a.fLeft <= b.fRight && b.fLeft <= a.fRight && 16 return AlmostLessOrEqualUlps(a.fLeft, b.fRight)
17 a.fTop <= b.fBottom && b.fTop <= a.fBottom; 17 && AlmostLessOrEqualUlps(b.fLeft, a.fRight)
18 && AlmostLessOrEqualUlps(a.fTop, b.fBottom)
19 && AlmostLessOrEqualUlps(b.fTop, a.fBottom);
18 } 20 }
19 21
20 // Note that add(), unlike SkRect::join() or SkRect::growToInclude() 22 // Note that add(), unlike SkRect::join() or SkRect::growToInclude()
21 // does not treat the bounds of horizontal and vertical lines as 23 // does not treat the bounds of horizontal and vertical lines as
22 // empty rectangles. 24 // empty rectangles.
23 void add(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) { 25 void add(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) {
24 if (left < fLeft) fLeft = left; 26 if (left < fLeft) fLeft = left;
25 if (top < fTop) fTop = top; 27 if (top < fTop) fTop = top;
26 if (right > fRight) fRight = right; 28 if (right > fRight) fRight = right;
27 if (bottom > fBottom) fBottom = bottom; 29 if (bottom > fBottom) fBottom = bottom;
28 } 30 }
29 31
30 void add(const SkPathOpsBounds& toAdd) { 32 void add(const SkPathOpsBounds& toAdd) {
31 add(toAdd.fLeft, toAdd.fTop, toAdd.fRight, toAdd.fBottom); 33 add(toAdd.fLeft, toAdd.fTop, toAdd.fRight, toAdd.fBottom);
32 } 34 }
33 35
34 void add(const SkPoint& pt) { 36 void add(const SkPoint& pt) {
35 if (pt.fX < fLeft) fLeft = pt.fX; 37 if (pt.fX < fLeft) fLeft = pt.fX;
36 if (pt.fY < fTop) fTop = pt.fY; 38 if (pt.fY < fTop) fTop = pt.fY;
37 if (pt.fX > fRight) fRight = pt.fX; 39 if (pt.fX > fRight) fRight = pt.fX;
38 if (pt.fY > fBottom) fBottom = pt.fY; 40 if (pt.fY > fBottom) fBottom = pt.fY;
39 } 41 }
40 42
43 bool almostContains(const SkPoint& pt) {
44 return AlmostLessOrEqualUlps(fLeft, pt.fX)
45 && AlmostLessOrEqualUlps(pt.fX, fRight)
46 && AlmostLessOrEqualUlps(fTop, pt.fY)
47 && AlmostLessOrEqualUlps(pt.fY, fBottom);
48 }
49
41 // unlike isEmpty(), this permits lines, but not points 50 // unlike isEmpty(), this permits lines, but not points
42 // FIXME: unused for now 51 // FIXME: unused for now
43 bool isReallyEmpty() const { 52 bool isReallyEmpty() const {
44 // use !<= instead of > to detect NaN values 53 // use !<= instead of > to detect NaN values
45 return !(fLeft <= fRight) || !(fTop <= fBottom) 54 return !(fLeft <= fRight) || !(fTop <= fBottom)
46 || (fLeft == fRight && fTop == fBottom); 55 || (fLeft == fRight && fTop == fBottom);
47 } 56 }
48 57
49 void setCubicBounds(const SkPoint a[4]); 58 void setCubicBounds(const SkPoint a[4]);
50 void setLineBounds(const SkPoint a[2]); 59 void setLineBounds(const SkPoint a[2]);
51 void setQuadBounds(const SkPoint a[3]); 60 void setQuadBounds(const SkPoint a[3]);
52 61
53 void setPointBounds(const SkPoint& pt) { 62 void setPointBounds(const SkPoint& pt) {
54 fLeft = fRight = pt.fX; 63 fLeft = fRight = pt.fX;
55 fTop = fBottom = pt.fY; 64 fTop = fBottom = pt.fY;
56 } 65 }
57 66
58 typedef SkRect INHERITED; 67 typedef SkRect INHERITED;
59 }; 68 };
60 69
61 extern void (SkPathOpsBounds::*SetCurveBounds[])(const SkPoint[]); 70 extern void (SkPathOpsBounds::*SetCurveBounds[])(const SkPoint[]);
62 71
63 #endif 72 #endif
OLDNEW
« no previous file with comments | « src/pathops/SkOpSpan.h ('k') | src/pathops/SkPathOpsCommon.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698