Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2012 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | #ifndef SkPathOpBounds_DEFINED |
michael@0 | 8 | #define SkPathOpBounds_DEFINED |
michael@0 | 9 | |
michael@0 | 10 | #include "SkPathOpsRect.h" |
michael@0 | 11 | #include "SkRect.h" |
michael@0 | 12 | |
michael@0 | 13 | // SkPathOpsBounds, unlike SkRect, does not consider a line to be empty. |
michael@0 | 14 | struct SkPathOpsBounds : public SkRect { |
michael@0 | 15 | static bool Intersects(const SkPathOpsBounds& a, const SkPathOpsBounds& b) { |
michael@0 | 16 | return AlmostLessOrEqualUlps(a.fLeft, b.fRight) |
michael@0 | 17 | && AlmostLessOrEqualUlps(b.fLeft, a.fRight) |
michael@0 | 18 | && AlmostLessOrEqualUlps(a.fTop, b.fBottom) |
michael@0 | 19 | && AlmostLessOrEqualUlps(b.fTop, a.fBottom); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | // Note that add(), unlike SkRect::join() or SkRect::growToInclude() |
michael@0 | 23 | // does not treat the bounds of horizontal and vertical lines as |
michael@0 | 24 | // empty rectangles. |
michael@0 | 25 | void add(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) { |
michael@0 | 26 | if (left < fLeft) fLeft = left; |
michael@0 | 27 | if (top < fTop) fTop = top; |
michael@0 | 28 | if (right > fRight) fRight = right; |
michael@0 | 29 | if (bottom > fBottom) fBottom = bottom; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | void add(const SkPathOpsBounds& toAdd) { |
michael@0 | 33 | add(toAdd.fLeft, toAdd.fTop, toAdd.fRight, toAdd.fBottom); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | void add(const SkPoint& pt) { |
michael@0 | 37 | if (pt.fX < fLeft) fLeft = pt.fX; |
michael@0 | 38 | if (pt.fY < fTop) fTop = pt.fY; |
michael@0 | 39 | if (pt.fX > fRight) fRight = pt.fX; |
michael@0 | 40 | if (pt.fY > fBottom) fBottom = pt.fY; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | bool almostContains(const SkPoint& pt) { |
michael@0 | 44 | return AlmostLessOrEqualUlps(fLeft, pt.fX) |
michael@0 | 45 | && AlmostLessOrEqualUlps(pt.fX, fRight) |
michael@0 | 46 | && AlmostLessOrEqualUlps(fTop, pt.fY) |
michael@0 | 47 | && AlmostLessOrEqualUlps(pt.fY, fBottom); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | // unlike isEmpty(), this permits lines, but not points |
michael@0 | 51 | // FIXME: unused for now |
michael@0 | 52 | bool isReallyEmpty() const { |
michael@0 | 53 | // use !<= instead of > to detect NaN values |
michael@0 | 54 | return !(fLeft <= fRight) || !(fTop <= fBottom) |
michael@0 | 55 | || (fLeft == fRight && fTop == fBottom); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | void setCubicBounds(const SkPoint a[4]); |
michael@0 | 59 | void setLineBounds(const SkPoint a[2]); |
michael@0 | 60 | void setQuadBounds(const SkPoint a[3]); |
michael@0 | 61 | |
michael@0 | 62 | void setPointBounds(const SkPoint& pt) { |
michael@0 | 63 | fLeft = fRight = pt.fX; |
michael@0 | 64 | fTop = fBottom = pt.fY; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | typedef SkRect INHERITED; |
michael@0 | 68 | }; |
michael@0 | 69 | |
michael@0 | 70 | extern void (SkPathOpsBounds::*SetCurveBounds[])(const SkPoint[]); |
michael@0 | 71 | |
michael@0 | 72 | #endif |