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 SkPathOpsRect_DEFINED michael@0: #define SkPathOpsRect_DEFINED michael@0: michael@0: #include "SkPathOpsPoint.h" michael@0: michael@0: struct SkDRect { michael@0: double fLeft, fTop, fRight, fBottom; michael@0: michael@0: void add(const SkDPoint& pt) { michael@0: if (fLeft > pt.fX) { michael@0: fLeft = pt.fX; michael@0: } michael@0: if (fTop > pt.fY) { michael@0: fTop = pt.fY; michael@0: } michael@0: if (fRight < pt.fX) { michael@0: fRight = pt.fX; michael@0: } michael@0: if (fBottom < pt.fY) { michael@0: fBottom = pt.fY; michael@0: } michael@0: } michael@0: michael@0: bool contains(const SkDPoint& pt) const { michael@0: return approximately_between(fLeft, pt.fX, fRight) michael@0: && approximately_between(fTop, pt.fY, fBottom); michael@0: } michael@0: michael@0: bool intersects(SkDRect* r) const { michael@0: SkASSERT(fLeft <= fRight); michael@0: SkASSERT(fTop <= fBottom); michael@0: SkASSERT(r->fLeft <= r->fRight); michael@0: SkASSERT(r->fTop <= r->fBottom); michael@0: return r->fLeft <= fRight && fLeft <= r->fRight && r->fTop <= fBottom && fTop <= r->fBottom; michael@0: } michael@0: michael@0: void set(const SkDPoint& pt) { michael@0: fLeft = fRight = pt.fX; michael@0: fTop = fBottom = pt.fY; michael@0: } michael@0: michael@0: double width() const { michael@0: return fRight - fLeft; michael@0: } michael@0: michael@0: double height() const { michael@0: return fBottom - fTop; michael@0: } michael@0: michael@0: void setBounds(const SkDLine&); michael@0: void setBounds(const SkDCubic&); michael@0: void setBounds(const SkDQuad&); michael@0: void setRawBounds(const SkDCubic&); michael@0: void setRawBounds(const SkDQuad&); michael@0: }; michael@0: michael@0: #endif