OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
| 7 #include "SkPathOpsConic.h" |
7 #include "SkPathOpsCubic.h" | 8 #include "SkPathOpsCubic.h" |
8 #include "SkPathOpsLine.h" | 9 #include "SkPathOpsLine.h" |
9 #include "SkPathOpsQuad.h" | 10 #include "SkPathOpsQuad.h" |
10 #include "SkPathOpsRect.h" | 11 #include "SkPathOpsRect.h" |
11 | 12 |
12 void SkDRect::setBounds(const SkDQuad& quad) { | 13 void SkDRect::setBounds(const SkDQuad& quad) { |
13 set(quad[0]); | 14 set(quad[0]); |
14 add(quad[2]); | 15 add(quad[2]); |
15 double tValues[2]; | 16 double tValues[2]; |
16 int roots = 0; | 17 int roots = 0; |
17 if (!between(quad[0].fX, quad[1].fX, quad[2].fX)) { | 18 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 roots = SkDQuad::FindExtrema(quad[0].fX, quad[1].fX, quad[2].fX, tValues
); |
19 } | 20 } |
20 if (!between(quad[0].fY, quad[1].fY, quad[2].fY)) { | 21 if (!between(quad[0].fY, quad[1].fY, quad[2].fY)) { |
21 roots += SkDQuad::FindExtrema(quad[0].fY, quad[1].fY, quad[2].fY, &tValu
es[roots]); | 22 roots += SkDQuad::FindExtrema(quad[0].fY, quad[1].fY, quad[2].fY, &tValu
es[roots]); |
22 } | 23 } |
23 for (int x = 0; x < roots; ++x) { | 24 for (int x = 0; x < roots; ++x) { |
24 add(quad.ptAtT(tValues[x])); | 25 add(quad.ptAtT(tValues[x])); |
25 } | 26 } |
26 } | 27 } |
27 | 28 |
| 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[roo
ts]); |
| 39 } |
| 40 for (int x = 0; x < roots; ++x) { |
| 41 add(conic.ptAtT(tValues[x])); |
| 42 } |
| 43 } |
| 44 |
28 static bool is_bounded_by_end_points(double a, double b, double c, double d) { | 45 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); | 46 return between(a, b, d) && between(a, c, d); |
30 } | 47 } |
31 | 48 |
32 void SkDRect::setBounds(const SkDCubic& c) { | 49 void SkDRect::setBounds(const SkDCubic& c) { |
33 set(c[0]); | 50 set(c[0]); |
34 add(c[3]); | 51 add(c[3]); |
35 double tValues[4]; | 52 double tValues[4]; |
36 int roots = 0; | 53 int roots = 0; |
37 if (!is_bounded_by_end_points(c[0].fX, c[1].fX, c[2].fX, c[3].fX)) { | 54 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, tValue
s); | 55 roots = SkDCubic::FindExtrema(c[0].fX, c[1].fX, c[2].fX, c[3].fX, tValue
s); |
39 } | 56 } |
40 if (!is_bounded_by_end_points(c[0].fY, c[1].fY, c[2].fY, c[3].fY)) { | 57 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, &tVal
ues[roots]); | 58 roots += SkDCubic::FindExtrema(c[0].fY, c[1].fY, c[2].fY, c[3].fY, &tVal
ues[roots]); |
42 } | 59 } |
43 for (int x = 0; x < roots; ++x) { | 60 for (int x = 0; x < roots; ++x) { |
44 add(c.ptAtT(tValues[x])); | 61 add(c.ptAtT(tValues[x])); |
45 } | 62 } |
46 } | 63 } |
OLD | NEW |