blob: 5dd3d8def5d0c2d295408450d2d22aeb8f40bf48 [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
caryclark@google.com07393ca2013-04-08 11:47:37 +000012void 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.com4fdbb222013-07-23 15:27:41 +000024 add(quad.ptAtT(tValues[x]));
caryclark@google.com07393ca2013-04-08 11:47:37 +000025 }
26}
27
caryclark@google.com07393ca2013-04-08 11:47:37 +000028static 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
32void 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.com4fdbb222013-07-23 15:27:41 +000044 add(c.ptAtT(tValues[x]));
caryclark@google.com07393ca2013-04-08 11:47:37 +000045 }
46}