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