blob: 2ceed32900a3f3b97c329696e854e5b0aca735f0 [file] [log] [blame]
caryclark@google.com07393ca2013-04-08 11:47:37 +00001/*
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
12void SkDRect::setBounds(const SkDLine& line) {
13 set(line[0]);
14 add(line[1]);
15}
16
17void SkDRect::setBounds(const SkDQuad& quad) {
18 set(quad[0]);
19 add(quad[2]);
20 double tValues[2];
21 int roots = 0;
22 if (!between(quad[0].fX, quad[1].fX, quad[2].fX)) {
23 roots = SkDQuad::FindExtrema(quad[0].fX, quad[1].fX, quad[2].fX, tValues);
24 }
25 if (!between(quad[0].fY, quad[1].fY, quad[2].fY)) {
26 roots += SkDQuad::FindExtrema(quad[0].fY, quad[1].fY, quad[2].fY, &tValues[roots]);
27 }
28 for (int x = 0; x < roots; ++x) {
caryclark@google.com4fdbb222013-07-23 15:27:41 +000029 add(quad.ptAtT(tValues[x]));
caryclark@google.com07393ca2013-04-08 11:47:37 +000030 }
31}
32
33void SkDRect::setRawBounds(const SkDQuad& quad) {
34 set(quad[0]);
35 for (int x = 1; x < 3; ++x) {
36 add(quad[x]);
37 }
38}
39
40static bool is_bounded_by_end_points(double a, double b, double c, double d) {
41 return between(a, b, d) && between(a, c, d);
42}
43
44void SkDRect::setBounds(const SkDCubic& c) {
45 set(c[0]);
46 add(c[3]);
47 double tValues[4];
48 int roots = 0;
49 if (!is_bounded_by_end_points(c[0].fX, c[1].fX, c[2].fX, c[3].fX)) {
50 roots = SkDCubic::FindExtrema(c[0].fX, c[1].fX, c[2].fX, c[3].fX, tValues);
51 }
52 if (!is_bounded_by_end_points(c[0].fY, c[1].fY, c[2].fY, c[3].fY)) {
53 roots += SkDCubic::FindExtrema(c[0].fY, c[1].fY, c[2].fY, c[3].fY, &tValues[roots]);
54 }
55 for (int x = 0; x < roots; ++x) {
caryclark@google.com4fdbb222013-07-23 15:27:41 +000056 add(c.ptAtT(tValues[x]));
caryclark@google.com07393ca2013-04-08 11:47:37 +000057 }
58}
59
60void SkDRect::setRawBounds(const SkDCubic& cubic) {
61 set(cubic[0]);
62 for (int x = 1; x < 4; ++x) {
63 add(cubic[x]);
64 }
65}