caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 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 | // SkPathOpsBounds, unlike SkRect, 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 | // FIXME: add() is generically useful and could be added directly to SkRect |
| 21 | void add(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) { |
| 22 | if (left < fLeft) fLeft = left; |
| 23 | if (top < fTop) fTop = top; |
| 24 | if (right > fRight) fRight = right; |
| 25 | if (bottom > fBottom) fBottom = bottom; |
| 26 | } |
| 27 | |
| 28 | void add(const SkPathOpsBounds& toAdd) { |
| 29 | add(toAdd.fLeft, toAdd.fTop, toAdd.fRight, toAdd.fBottom); |
| 30 | } |
| 31 | |
| 32 | void add(const SkPoint& pt) { |
| 33 | if (pt.fX < fLeft) fLeft = pt.fX; |
| 34 | if (pt.fY < fTop) fTop = pt.fY; |
| 35 | if (pt.fX > fRight) fRight = pt.fX; |
| 36 | if (pt.fY > fBottom) fBottom = pt.fY; |
| 37 | } |
| 38 | |
| 39 | // unlike isEmpty(), this permits lines, but not points |
| 40 | // FIXME: unused for now |
| 41 | bool isReallyEmpty() const { |
| 42 | // use !<= instead of > to detect NaN values |
| 43 | return !(fLeft <= fRight) || !(fTop <= fBottom) |
| 44 | || (fLeft == fRight && fTop == fBottom); |
| 45 | } |
| 46 | |
| 47 | void setCubicBounds(const SkPoint a[4]); |
| 48 | void setLineBounds(const SkPoint a[2]); |
| 49 | void setQuadBounds(const SkPoint a[3]); |
| 50 | |
| 51 | void setPointBounds(const SkPoint& pt) { |
| 52 | fLeft = fRight = pt.fX; |
| 53 | fTop = fBottom = pt.fY; |
| 54 | } |
| 55 | |
| 56 | typedef SkRect INHERITED; |
| 57 | }; |
| 58 | |
| 59 | extern void (SkPathOpsBounds::*SetCurveBounds[])(const SkPoint[]); |
| 60 | |
| 61 | #endif |