blob: d4e5f5489a4f1f7de798e4a52ab0f60770a42f0e [file] [log] [blame]
caryclark@google.com07393ca2013-04-08 11:47:37 +00001/*
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 SkPathOpsRect_DEFINED
8#define SkPathOpsRect_DEFINED
9
10#include "SkPathOpsPoint.h"
11
12struct SkDRect {
13 double fLeft, fTop, fRight, fBottom;
14
15 void add(const SkDPoint& pt) {
caryclark54359292015-03-26 07:52:43 -070016 fLeft = SkTMin(fLeft, pt.fX);
17 fTop = SkTMin(fTop, pt.fY);
18 fRight = SkTMax(fRight, pt.fX);
19 fBottom = SkTMax(fBottom, pt.fY);
caryclark@google.com07393ca2013-04-08 11:47:37 +000020 }
21
caryclark@google.com07393ca2013-04-08 11:47:37 +000022 bool contains(const SkDPoint& pt) const {
23 return approximately_between(fLeft, pt.fX, fRight)
24 && approximately_between(fTop, pt.fY, fBottom);
25 }
26
caryclarked0935a2015-10-22 07:23:52 -070027 void debugInit();
28
caryclark54359292015-03-26 07:52:43 -070029 bool intersects(const SkDRect& r) const {
caryclark@google.com07393ca2013-04-08 11:47:37 +000030 SkASSERT(fLeft <= fRight);
31 SkASSERT(fTop <= fBottom);
caryclark54359292015-03-26 07:52:43 -070032 SkASSERT(r.fLeft <= r.fRight);
33 SkASSERT(r.fTop <= r.fBottom);
34 return r.fLeft <= fRight && fLeft <= r.fRight && r.fTop <= fBottom && fTop <= r.fBottom;
caryclark@google.com07393ca2013-04-08 11:47:37 +000035 }
36
37 void set(const SkDPoint& pt) {
38 fLeft = fRight = pt.fX;
39 fTop = fBottom = pt.fY;
40 }
41
caryclark@google.coma5e55922013-05-07 18:51:31 +000042 double width() const {
43 return fRight - fLeft;
44 }
45
46 double height() const {
47 return fBottom - fTop;
48 }
49
caryclarkaec25102015-04-29 08:28:30 -070050 void setBounds(const SkDConic& curve) {
51 setBounds(curve, curve, 0, 1);
52 }
53
54 void setBounds(const SkDConic& curve, const SkDConic& sub, double tStart, double tEnd);
55
56 void setBounds(const SkDCubic& curve) {
57 setBounds(curve, curve, 0, 1);
58 }
59
60 void setBounds(const SkDCubic& curve, const SkDCubic& sub, double tStart, double tEnd);
61
62 void setBounds(const SkDQuad& curve) {
63 setBounds(curve, curve, 0, 1);
64 }
65
66 void setBounds(const SkDQuad& curve, const SkDQuad& sub, double tStart, double tEnd);
caryclark@google.com07393ca2013-04-08 11:47:37 +000067};
68
69#endif