blob: 540db16a0ee0d1f3a4ba89ed7d23000058e348ff [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 */
caryclark1049f122015-04-20 08:31:59 -07007#include "SkPathOpsConic.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +00008#include "SkPathOpsCubic.h"
9#include "SkPathOpsLine.h"
10#include "SkPathOpsQuad.h"
11#include "SkPathOpsRect.h"
12
caryclark@google.com07393ca2013-04-08 11:47:37 +000013void SkDRect::setBounds(const SkDQuad& quad) {
14 set(quad[0]);
15 add(quad[2]);
16 double tValues[2];
17 int roots = 0;
18 if (!between(quad[0].fX, quad[1].fX, quad[2].fX)) {
19 roots = SkDQuad::FindExtrema(quad[0].fX, quad[1].fX, quad[2].fX, tValues);
20 }
21 if (!between(quad[0].fY, quad[1].fY, quad[2].fY)) {
22 roots += SkDQuad::FindExtrema(quad[0].fY, quad[1].fY, quad[2].fY, &tValues[roots]);
23 }
24 for (int x = 0; x < roots; ++x) {
caryclark@google.com4fdbb222013-07-23 15:27:41 +000025 add(quad.ptAtT(tValues[x]));
caryclark@google.com07393ca2013-04-08 11:47:37 +000026 }
27}
28
caryclark1049f122015-04-20 08:31:59 -070029void 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[roots]);
39 }
40 for (int x = 0; x < roots; ++x) {
41 add(conic.ptAtT(tValues[x]));
42 }
43}
44
caryclark@google.com07393ca2013-04-08 11:47:37 +000045static bool is_bounded_by_end_points(double a, double b, double c, double d) {
46 return between(a, b, d) && between(a, c, d);
47}
48
49void SkDRect::setBounds(const SkDCubic& c) {
50 set(c[0]);
51 add(c[3]);
52 double tValues[4];
53 int roots = 0;
54 if (!is_bounded_by_end_points(c[0].fX, c[1].fX, c[2].fX, c[3].fX)) {
55 roots = SkDCubic::FindExtrema(c[0].fX, c[1].fX, c[2].fX, c[3].fX, tValues);
56 }
57 if (!is_bounded_by_end_points(c[0].fY, c[1].fY, c[2].fY, c[3].fY)) {
58 roots += SkDCubic::FindExtrema(c[0].fY, c[1].fY, c[2].fY, c[3].fY, &tValues[roots]);
59 }
60 for (int x = 0; x < roots; ++x) {
caryclark@google.com4fdbb222013-07-23 15:27:41 +000061 add(c.ptAtT(tValues[x]));
caryclark@google.com07393ca2013-04-08 11:47:37 +000062 }
63}