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 | |
| 12 | struct SkDRect { |
| 13 | double fLeft, fTop, fRight, fBottom; |
| 14 | |
| 15 | void add(const SkDPoint& pt) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 16 | 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.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 20 | } |
| 21 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 22 | bool contains(const SkDPoint& pt) const { |
| 23 | return approximately_between(fLeft, pt.fX, fRight) |
| 24 | && approximately_between(fTop, pt.fY, fBottom); |
| 25 | } |
| 26 | |
caryclark | ed0935a | 2015-10-22 07:23:52 -0700 | [diff] [blame] | 27 | void debugInit(); |
| 28 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 29 | bool intersects(const SkDRect& r) const { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 30 | SkASSERT(fLeft <= fRight); |
| 31 | SkASSERT(fTop <= fBottom); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 32 | 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.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | void set(const SkDPoint& pt) { |
| 38 | fLeft = fRight = pt.fX; |
| 39 | fTop = fBottom = pt.fY; |
| 40 | } |
| 41 | |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 42 | double width() const { |
| 43 | return fRight - fLeft; |
| 44 | } |
| 45 | |
| 46 | double height() const { |
| 47 | return fBottom - fTop; |
| 48 | } |
| 49 | |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 50 | 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 | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 67 | |
| 68 | bool valid() const { |
| 69 | return fLeft <= fRight && fTop <= fBottom; |
| 70 | } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | #endif |