1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/pathops/SkPathOpsBounds.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 1.4 +/* 1.5 + * Copyright 2012 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 +#ifndef SkPathOpBounds_DEFINED 1.11 +#define SkPathOpBounds_DEFINED 1.12 + 1.13 +#include "SkPathOpsRect.h" 1.14 +#include "SkRect.h" 1.15 + 1.16 +// SkPathOpsBounds, unlike SkRect, does not consider a line to be empty. 1.17 +struct SkPathOpsBounds : public SkRect { 1.18 + static bool Intersects(const SkPathOpsBounds& a, const SkPathOpsBounds& b) { 1.19 + return AlmostLessOrEqualUlps(a.fLeft, b.fRight) 1.20 + && AlmostLessOrEqualUlps(b.fLeft, a.fRight) 1.21 + && AlmostLessOrEqualUlps(a.fTop, b.fBottom) 1.22 + && AlmostLessOrEqualUlps(b.fTop, a.fBottom); 1.23 + } 1.24 + 1.25 + // Note that add(), unlike SkRect::join() or SkRect::growToInclude() 1.26 + // does not treat the bounds of horizontal and vertical lines as 1.27 + // empty rectangles. 1.28 + void add(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) { 1.29 + if (left < fLeft) fLeft = left; 1.30 + if (top < fTop) fTop = top; 1.31 + if (right > fRight) fRight = right; 1.32 + if (bottom > fBottom) fBottom = bottom; 1.33 + } 1.34 + 1.35 + void add(const SkPathOpsBounds& toAdd) { 1.36 + add(toAdd.fLeft, toAdd.fTop, toAdd.fRight, toAdd.fBottom); 1.37 + } 1.38 + 1.39 + void add(const SkPoint& pt) { 1.40 + if (pt.fX < fLeft) fLeft = pt.fX; 1.41 + if (pt.fY < fTop) fTop = pt.fY; 1.42 + if (pt.fX > fRight) fRight = pt.fX; 1.43 + if (pt.fY > fBottom) fBottom = pt.fY; 1.44 + } 1.45 + 1.46 + bool almostContains(const SkPoint& pt) { 1.47 + return AlmostLessOrEqualUlps(fLeft, pt.fX) 1.48 + && AlmostLessOrEqualUlps(pt.fX, fRight) 1.49 + && AlmostLessOrEqualUlps(fTop, pt.fY) 1.50 + && AlmostLessOrEqualUlps(pt.fY, fBottom); 1.51 + } 1.52 + 1.53 + // unlike isEmpty(), this permits lines, but not points 1.54 + // FIXME: unused for now 1.55 + bool isReallyEmpty() const { 1.56 + // use !<= instead of > to detect NaN values 1.57 + return !(fLeft <= fRight) || !(fTop <= fBottom) 1.58 + || (fLeft == fRight && fTop == fBottom); 1.59 + } 1.60 + 1.61 + void setCubicBounds(const SkPoint a[4]); 1.62 + void setLineBounds(const SkPoint a[2]); 1.63 + void setQuadBounds(const SkPoint a[3]); 1.64 + 1.65 + void setPointBounds(const SkPoint& pt) { 1.66 + fLeft = fRight = pt.fX; 1.67 + fTop = fBottom = pt.fY; 1.68 + } 1.69 + 1.70 + typedef SkRect INHERITED; 1.71 +}; 1.72 + 1.73 +extern void (SkPathOpsBounds::*SetCurveBounds[])(const SkPoint[]); 1.74 + 1.75 +#endif