Flutter Engine
The Flutter Engine
SkPathOpsBounds.h
Go to the documentation of this file.
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 "include/core/SkRect.h"
12
13// SkPathOpsBounds, unlike SkRect, does not consider a line to be empty.
14struct SkPathOpsBounds : public SkRect {
15 static bool Intersects(const SkPathOpsBounds& a, const SkPathOpsBounds& b) {
16 return AlmostLessOrEqualUlps(a.fLeft, b.fRight)
17 && AlmostLessOrEqualUlps(b.fLeft, a.fRight)
18 && AlmostLessOrEqualUlps(a.fTop, b.fBottom)
19 && AlmostLessOrEqualUlps(b.fTop, a.fBottom);
20 }
21
22 // Note that add(), unlike SkRect::join() or SkRect::growToInclude()
23 // does not treat the bounds of horizontal and vertical lines as
24 // empty rectangles.
26 if (left < fLeft) fLeft = left;
27 if (top < fTop) fTop = top;
28 if (right > fRight) fRight = right;
30 }
31
32 void add(const SkPathOpsBounds& toAdd) {
33 add(toAdd.fLeft, toAdd.fTop, toAdd.fRight, toAdd.fBottom);
34 }
35
36 void add(const SkPoint& pt) {
37 if (pt.fX < fLeft) fLeft = pt.fX;
38 if (pt.fY < fTop) fTop = pt.fY;
39 if (pt.fX > fRight) fRight = pt.fX;
40 if (pt.fY > fBottom) fBottom = pt.fY;
41 }
42
43 void add(const SkDPoint& pt) {
44 if (pt.fX < fLeft) fLeft = SkDoubleToScalar(pt.fX);
45 if (pt.fY < fTop) fTop = SkDoubleToScalar(pt.fY);
46 if (pt.fX > fRight) fRight = SkDoubleToScalar(pt.fX);
47 if (pt.fY > fBottom) fBottom = SkDoubleToScalar(pt.fY);
48 }
49
50 bool almostContains(const SkPoint& pt) const {
55 }
56
57 bool contains(const SkPoint& pt) const {
58 return fLeft <= pt.fX && fTop <= pt.fY &&
59 fRight >= pt.fX && fBottom >= pt.fY;
60 }
61
63};
64
65#endif
bool AlmostLessOrEqualUlps(float a, float b)
#define SkDoubleToScalar(x)
Definition: SkScalar.h:64
float SkScalar
Definition: extension.cpp:12
static bool b
struct MyStruct a[10]
void add(const SkDPoint &pt)
static bool Intersects(const SkPathOpsBounds &a, const SkPathOpsBounds &b)
bool contains(const SkPoint &pt) const
bool almostContains(const SkPoint &pt) const
void add(const SkPoint &pt)
void add(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
void add(const SkPathOpsBounds &toAdd)
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
SkScalar fBottom
larger y-axis bounds
Definition: extension.cpp:17
constexpr float left() const
Definition: SkRect.h:734
constexpr float top() const
Definition: SkRect.h:741
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
constexpr float right() const
Definition: SkRect.h:748
constexpr float bottom() const
Definition: SkRect.h:755
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15