caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 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 SkPathOpsRect_DEFINED |
| 8 | #define SkPathOpsRect_DEFINED |
| 9 | |
| 10 | #include "SkPathOpsPoint.h" |
| 11 | |
Cary Clark | 0a67198 | 2018-10-11 12:16:49 -0400 | [diff] [blame] | 12 | class SkTCurve; |
| 13 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 14 | struct SkDRect { |
| 15 | double fLeft, fTop, fRight, fBottom; |
| 16 | |
| 17 | void add(const SkDPoint& pt) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 18 | 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.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 22 | } |
| 23 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 24 | bool contains(const SkDPoint& pt) const { |
| 25 | return approximately_between(fLeft, pt.fX, fRight) |
| 26 | && approximately_between(fTop, pt.fY, fBottom); |
| 27 | } |
| 28 | |
caryclark | ed0935a | 2015-10-22 07:23:52 -0700 | [diff] [blame] | 29 | void debugInit(); |
| 30 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 31 | bool intersects(const SkDRect& r) const { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 32 | SkASSERT(fLeft <= fRight); |
| 33 | SkASSERT(fTop <= fBottom); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 34 | 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.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void set(const SkDPoint& pt) { |
| 40 | fLeft = fRight = pt.fX; |
| 41 | fTop = fBottom = pt.fY; |
| 42 | } |
| 43 | |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 44 | double width() const { |
| 45 | return fRight - fLeft; |
| 46 | } |
| 47 | |
| 48 | double height() const { |
| 49 | return fBottom - fTop; |
| 50 | } |
| 51 | |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 52 | 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); |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 69 | |
Cary Clark | 0a67198 | 2018-10-11 12:16:49 -0400 | [diff] [blame] | 70 | void setBounds(const SkTCurve& curve); |
| 71 | |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 72 | bool valid() const { |
| 73 | return fLeft <= fRight && fTop <= fBottom; |
| 74 | } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | #endif |