blob: e7bda028ee9f3b7f7a2eade2409a607c59c2b6da [file] [log] [blame]
caryclark@google.comc6825902012-02-03 22:07:47 +00001#include "DataTypes.h"
2#include "Extrema.h"
3
4void _Rect::setBounds(const Cubic& cubic) {
5 set(cubic[0]);
6 add(cubic[3]);
7 double tValues[4];
8 int roots = SkFindCubicExtrema(cubic[0].x, cubic[1].x, cubic[2].x,
9 cubic[3].x, tValues);
10 roots += SkFindCubicExtrema(cubic[0].y, cubic[1].y, cubic[2].y, cubic[3].y,
11 &tValues[roots]);
12 for (int x = 0; x < roots; ++x) {
13 _Point result;
14 xy_at_t(cubic, tValues[x], result.x, result.y);
15 add(result);
16 }
17}
18
19void _Rect::setRawBounds(const Cubic& cubic) {
20 set(cubic[0]);
21 for (int x = 1; x < 4; ++x) {
22 add(cubic[x]);
23 }
24}
25
26void _Rect::setBounds(const Quadratic& quad) {
27 set(quad[0]);
28 add(quad[2]);
29 double tValues[2];
30 int roots = SkFindQuadExtrema(quad[0].x, quad[1].x, quad[2].x, tValues);
31 roots += SkFindQuadExtrema(quad[0].y, quad[1].y, quad[2].y, &tValues[roots]);
32 for (int x = 0; x < roots; ++x) {
33 _Point result;
34 xy_at_t(quad, tValues[x], result.x, result.y);
35 add(result);
36 }
37}
38
39void _Rect::setRawBounds(const Quadratic& quad) {
40 set(quad[0]);
41 for (int x = 1; x < 3; ++x) {
42 add(quad[x]);
43 }
44}