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 | */ |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame^] | 7 | #include "SkPathOpsConic.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 8 | #include "SkPathOpsCubic.h" |
| 9 | #include "SkPathOpsLine.h" |
| 10 | #include "SkPathOpsQuad.h" |
| 11 | #include "SkPathOpsRect.h" |
| 12 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 13 | void SkDRect::setBounds(const SkDQuad& quad) { |
| 14 | set(quad[0]); |
| 15 | add(quad[2]); |
| 16 | double tValues[2]; |
| 17 | int roots = 0; |
| 18 | if (!between(quad[0].fX, quad[1].fX, quad[2].fX)) { |
| 19 | roots = SkDQuad::FindExtrema(quad[0].fX, quad[1].fX, quad[2].fX, tValues); |
| 20 | } |
| 21 | if (!between(quad[0].fY, quad[1].fY, quad[2].fY)) { |
| 22 | roots += SkDQuad::FindExtrema(quad[0].fY, quad[1].fY, quad[2].fY, &tValues[roots]); |
| 23 | } |
| 24 | for (int x = 0; x < roots; ++x) { |
caryclark@google.com | 4fdbb22 | 2013-07-23 15:27:41 +0000 | [diff] [blame] | 25 | add(quad.ptAtT(tValues[x])); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 26 | } |
| 27 | } |
| 28 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame^] | 29 | void SkDRect::setBounds(const SkDConic& conic) { |
| 30 | set(conic[0]); |
| 31 | add(conic[2]); |
| 32 | double tValues[2]; |
| 33 | int roots = 0; |
| 34 | if (!between(conic[0].fX, conic[1].fX, conic[2].fX)) { |
| 35 | roots = SkDConic::FindExtrema(&conic[0].fX, conic.fWeight, tValues); |
| 36 | } |
| 37 | if (!between(conic[0].fY, conic[1].fY, conic[2].fY)) { |
| 38 | roots += SkDConic::FindExtrema(&conic[0].fY, conic.fWeight, &tValues[roots]); |
| 39 | } |
| 40 | for (int x = 0; x < roots; ++x) { |
| 41 | add(conic.ptAtT(tValues[x])); |
| 42 | } |
| 43 | } |
| 44 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 45 | static bool is_bounded_by_end_points(double a, double b, double c, double d) { |
| 46 | return between(a, b, d) && between(a, c, d); |
| 47 | } |
| 48 | |
| 49 | void SkDRect::setBounds(const SkDCubic& c) { |
| 50 | set(c[0]); |
| 51 | add(c[3]); |
| 52 | double tValues[4]; |
| 53 | int roots = 0; |
| 54 | if (!is_bounded_by_end_points(c[0].fX, c[1].fX, c[2].fX, c[3].fX)) { |
| 55 | roots = SkDCubic::FindExtrema(c[0].fX, c[1].fX, c[2].fX, c[3].fX, tValues); |
| 56 | } |
| 57 | if (!is_bounded_by_end_points(c[0].fY, c[1].fY, c[2].fY, c[3].fY)) { |
| 58 | roots += SkDCubic::FindExtrema(c[0].fY, c[1].fY, c[2].fY, c[3].fY, &tValues[roots]); |
| 59 | } |
| 60 | for (int x = 0; x < roots; ++x) { |
caryclark@google.com | 4fdbb22 | 2013-07-23 15:27:41 +0000 | [diff] [blame] | 61 | add(c.ptAtT(tValues[x])); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 62 | } |
| 63 | } |