blob: a429273a258b0976772c6a0b967611c6fee70e65 [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
Cary Clark0a671982018-10-11 12:16:49 -040012class SkTCurve;
13
caryclark@google.com07393ca2013-04-08 11:47:37 +000014struct SkDRect {
15 double fLeft, fTop, fRight, fBottom;
16
17 void add(const SkDPoint& pt) {
caryclark54359292015-03-26 07:52:43 -070018 fLeft = SkTMin(fLeft, pt.fX);
19 fTop = SkTMin(fTop, pt.fY);
20 fRight = SkTMax(fRight, pt.fX);
21 fBottom = SkTMax(fBottom, pt.fY);
caryclark@google.com07393ca2013-04-08 11:47:37 +000022 }
23
caryclark@google.com07393ca2013-04-08 11:47:37 +000024 bool contains(const SkDPoint& pt) const {
25 return approximately_between(fLeft, pt.fX, fRight)
26 && approximately_between(fTop, pt.fY, fBottom);
27 }
28
caryclarked0935a2015-10-22 07:23:52 -070029 void debugInit();
30
caryclark54359292015-03-26 07:52:43 -070031 bool intersects(const SkDRect& r) const {
caryclark@google.com07393ca2013-04-08 11:47:37 +000032 SkASSERT(fLeft <= fRight);
33 SkASSERT(fTop <= fBottom);
caryclark54359292015-03-26 07:52:43 -070034 SkASSERT(r.fLeft <= r.fRight);
35 SkASSERT(r.fTop <= r.fBottom);
36 return r.fLeft <= fRight && fLeft <= r.fRight && r.fTop <= fBottom && fTop <= r.fBottom;
caryclark@google.com07393ca2013-04-08 11:47:37 +000037 }
38
39 void set(const SkDPoint& pt) {
40 fLeft = fRight = pt.fX;
41 fTop = fBottom = pt.fY;
42 }
43
caryclark@google.coma5e55922013-05-07 18:51:31 +000044 double width() const {
45 return fRight - fLeft;
46 }
47
48 double height() const {
49 return fBottom - fTop;
50 }
51
caryclarkaec25102015-04-29 08:28:30 -070052 void setBounds(const SkDConic& curve) {
53 setBounds(curve, curve, 0, 1);
54 }
55
56 void setBounds(const SkDConic& curve, const SkDConic& sub, double tStart, double tEnd);
57
58 void setBounds(const SkDCubic& curve) {
59 setBounds(curve, curve, 0, 1);
60 }
61
62 void setBounds(const SkDCubic& curve, const SkDCubic& sub, double tStart, double tEnd);
63
64 void setBounds(const SkDQuad& curve) {
65 setBounds(curve, curve, 0, 1);
66 }
67
68 void setBounds(const SkDQuad& curve, const SkDQuad& sub, double tStart, double tEnd);
caryclarka35ab3e2016-10-20 08:32:18 -070069
Cary Clark0a671982018-10-11 12:16:49 -040070 void setBounds(const SkTCurve& curve);
71
caryclarka35ab3e2016-10-20 08:32:18 -070072 bool valid() const {
73 return fLeft <= fRight && fTop <= fBottom;
74 }
caryclark@google.com07393ca2013-04-08 11:47:37 +000075};
76
77#endif