michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: #ifndef SkPathOpBounds_DEFINED michael@0: #define SkPathOpBounds_DEFINED michael@0: michael@0: #include "SkPathOpsRect.h" michael@0: #include "SkRect.h" michael@0: michael@0: // SkPathOpsBounds, unlike SkRect, does not consider a line to be empty. michael@0: struct SkPathOpsBounds : public SkRect { michael@0: static bool Intersects(const SkPathOpsBounds& a, const SkPathOpsBounds& b) { michael@0: return AlmostLessOrEqualUlps(a.fLeft, b.fRight) michael@0: && AlmostLessOrEqualUlps(b.fLeft, a.fRight) michael@0: && AlmostLessOrEqualUlps(a.fTop, b.fBottom) michael@0: && AlmostLessOrEqualUlps(b.fTop, a.fBottom); michael@0: } michael@0: michael@0: // Note that add(), unlike SkRect::join() or SkRect::growToInclude() michael@0: // does not treat the bounds of horizontal and vertical lines as michael@0: // empty rectangles. michael@0: void add(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) { michael@0: if (left < fLeft) fLeft = left; michael@0: if (top < fTop) fTop = top; michael@0: if (right > fRight) fRight = right; michael@0: if (bottom > fBottom) fBottom = bottom; michael@0: } michael@0: michael@0: void add(const SkPathOpsBounds& toAdd) { michael@0: add(toAdd.fLeft, toAdd.fTop, toAdd.fRight, toAdd.fBottom); michael@0: } michael@0: michael@0: void add(const SkPoint& pt) { michael@0: if (pt.fX < fLeft) fLeft = pt.fX; michael@0: if (pt.fY < fTop) fTop = pt.fY; michael@0: if (pt.fX > fRight) fRight = pt.fX; michael@0: if (pt.fY > fBottom) fBottom = pt.fY; michael@0: } michael@0: michael@0: bool almostContains(const SkPoint& pt) { michael@0: return AlmostLessOrEqualUlps(fLeft, pt.fX) michael@0: && AlmostLessOrEqualUlps(pt.fX, fRight) michael@0: && AlmostLessOrEqualUlps(fTop, pt.fY) michael@0: && AlmostLessOrEqualUlps(pt.fY, fBottom); michael@0: } michael@0: michael@0: // unlike isEmpty(), this permits lines, but not points michael@0: // FIXME: unused for now michael@0: bool isReallyEmpty() const { michael@0: // use !<= instead of > to detect NaN values michael@0: return !(fLeft <= fRight) || !(fTop <= fBottom) michael@0: || (fLeft == fRight && fTop == fBottom); michael@0: } michael@0: michael@0: void setCubicBounds(const SkPoint a[4]); michael@0: void setLineBounds(const SkPoint a[2]); michael@0: void setQuadBounds(const SkPoint a[3]); michael@0: michael@0: void setPointBounds(const SkPoint& pt) { michael@0: fLeft = fRight = pt.fX; michael@0: fTop = fBottom = pt.fY; michael@0: } michael@0: michael@0: typedef SkRect INHERITED; michael@0: }; michael@0: michael@0: extern void (SkPathOpsBounds::*SetCurveBounds[])(const SkPoint[]); michael@0: michael@0: #endif