Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2012 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 #ifndef SkPathOpBounds_DEFINED | |
| 8 #define SkPathOpBounds_DEFINED | |
| 9 | |
| 10 #include "SkPathOpsRect.h" | |
| 11 #include "SkRect.h" | |
| 12 | |
| 13 // Bounds, unlike Rect, does not consider a line to be empty. | |
| 14 struct SkPathOpsBounds : public SkRect { | |
| 15 static bool Intersects(const SkPathOpsBounds& a, const SkPathOpsBounds& b) { | |
| 16 return a.fLeft <= b.fRight && b.fLeft <= a.fRight && | |
| 17 a.fTop <= b.fBottom && b.fTop <= a.fBottom; | |
| 18 } | |
| 19 | |
| 20 void add(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) { | |
|
whunt
2013/03/22 18:16:06
add is a very overloaded word. I'd recommend "Uni
caryclark
2013/03/22 19:38:51
Point taken. However, union is unavailable -- Skia
danakj
2013/03/22 19:52:18
We've used "unite" in the past instead
| |
| 21 if (left < fLeft) { | |
|
whunt
2013/03/22 18:16:06
Use std::min and std::max. In 64 bit mode and any
caryclark
2013/03/22 19:38:51
Certainly worth investigating. Skia uses the 'if
| |
| 22 fLeft = left; | |
| 23 } | |
| 24 if (top < fTop) { | |
| 25 fTop = top; | |
| 26 } | |
| 27 if (right > fRight) { | |
| 28 fRight = right; | |
| 29 } | |
| 30 if (bottom > fBottom) { | |
| 31 fBottom = bottom; | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 void add(const SkPathOpsBounds& toAdd) { | |
|
reed1
2013/03/22 15:58:04
this, and add(point), could likely be added to SkR
caryclark
2013/03/22 19:38:51
Done.
| |
| 36 add(toAdd.fLeft, toAdd.fTop, toAdd.fRight, toAdd.fBottom); | |
| 37 } | |
| 38 | |
| 39 void add(const SkPoint& pt) { | |
| 40 if (pt.fX < fLeft) fLeft = pt.fX; | |
| 41 if (pt.fY < fTop) fTop = pt.fY; | |
| 42 if (pt.fX > fRight) fRight = pt.fX; | |
| 43 if (pt.fY > fBottom) fBottom = pt.fY; | |
| 44 } | |
| 45 | |
| 46 bool isEmpty() { | |
|
reed1
2013/03/22 15:58:04
const?
Can we find a different name, since this o
danakj
2013/03/22 19:11:42
it seems interesting that a 0x0 area is empty but
whunt
2013/03/22 19:37:28
0x0 should not be empty, it should contain a point
caryclark
2013/03/22 19:38:51
Done. isReallyEmpty() ? (BTW, this function turns
caryclark
2013/03/22 20:05:00
In this use case, that is the correct behavior. No
caryclark
2013/03/22 20:05:00
Not for this application.
| |
| 47 return fLeft > fRight || fTop > fBottom | |
|
whunt
2013/03/22 18:16:06
the implementation should be:
!(fLeft < fRight &&
whunt
2013/03/22 19:37:28
revised to to account for zero area, non-empty bou
caryclark
2013/03/22 19:38:51
Done.
caryclark
2013/03/22 20:05:00
Noted.
| |
| 48 || (fLeft == fRight && fTop == fBottom) | |
|
whunt
2013/03/22 19:37:28
I think this check (for single point) is wrong, se
caryclark
2013/03/22 20:05:00
For this use case, it is not wrong.
| |
| 49 || sk_double_isnan(fLeft) || sk_double_isnan(fRight) | |
|
reed1
2013/03/22 15:58:04
fLeft is SkScalar, not double. Should we use SkSca
caryclark
2013/03/22 19:38:51
Done.
| |
| 50 || sk_double_isnan(fTop) || sk_double_isnan(fBottom); | |
| 51 } | |
| 52 | |
| 53 void setCubicBounds(const SkPoint a[4]); | |
| 54 void setLineBounds(const SkPoint a[2]); | |
| 55 void setQuadBounds(const SkPoint a[3]); | |
| 56 | |
| 57 void setPoint(const SkPoint& pt) { | |
|
reed1
2013/03/22 15:58:04
Crazy suggestion: setPointBounds (like the above m
caryclark
2013/03/22 19:38:51
Done.
| |
| 58 fLeft = fRight = pt.fX; | |
| 59 fTop = fBottom = pt.fY; | |
| 60 } | |
| 61 }; | |
| 62 | |
| 63 extern void (SkPathOpsBounds::*SetCurveBounds[])(const SkPoint[]); | |
| 64 | |
| 65 #endif | |
| OLD | NEW |