blob: 8c0115353298c039ee9ac1de2e41457764a8fd42 [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
caryclarkaec25102015-04-29 08:28:30 -070013void SkDRect::setBounds(const SkDQuad& curve, const SkDQuad& sub, double startT, double endT) {
14 set(sub[0]);
15 add(sub[2]);
caryclark@google.com07393ca2013-04-08 11:47:37 +000016 double tValues[2];
17 int roots = 0;
caryclarkaec25102015-04-29 08:28:30 -070018 if (!sub.monotonicInX()) {
19 roots = SkDQuad::FindExtrema(&sub[0].fX, tValues);
caryclark@google.com07393ca2013-04-08 11:47:37 +000020 }
caryclarkaec25102015-04-29 08:28:30 -070021 if (!sub.monotonicInY()) {
22 roots += SkDQuad::FindExtrema(&sub[0].fY, &tValues[roots]);
caryclark@google.com07393ca2013-04-08 11:47:37 +000023 }
caryclarkaec25102015-04-29 08:28:30 -070024 for (int index = 0; index < roots; ++index) {
25 double t = startT + (endT - startT) * tValues[index];
26 add(curve.ptAtT(t));
caryclark@google.com07393ca2013-04-08 11:47:37 +000027 }
28}
29
caryclarkaec25102015-04-29 08:28:30 -070030void SkDRect::setBounds(const SkDConic& curve, const SkDConic& sub, double startT, double endT) {
31 set(sub[0]);
32 add(sub[2]);
caryclark1049f122015-04-20 08:31:59 -070033 double tValues[2];
34 int roots = 0;
caryclarkaec25102015-04-29 08:28:30 -070035 if (!sub.monotonicInX()) {
36 roots = SkDConic::FindExtrema(&sub[0].fX, sub.fWeight, tValues);
caryclark1049f122015-04-20 08:31:59 -070037 }
caryclarkaec25102015-04-29 08:28:30 -070038 if (!sub.monotonicInY()) {
39 roots += SkDConic::FindExtrema(&sub[0].fY, sub.fWeight, &tValues[roots]);
caryclark1049f122015-04-20 08:31:59 -070040 }
caryclarkaec25102015-04-29 08:28:30 -070041 for (int index = 0; index < roots; ++index) {
42 double t = startT + (endT - startT) * tValues[index];
43 add(curve.ptAtT(t));
caryclark1049f122015-04-20 08:31:59 -070044 }
45}
46
caryclarkaec25102015-04-29 08:28:30 -070047void SkDRect::setBounds(const SkDCubic& curve, const SkDCubic& sub, double startT, double endT) {
48 set(sub[0]);
49 add(sub[3]);
caryclark@google.com07393ca2013-04-08 11:47:37 +000050 double tValues[4];
51 int roots = 0;
caryclarkaec25102015-04-29 08:28:30 -070052 if (!sub.monotonicInX()) {
53 roots = SkDCubic::FindExtrema(&sub[0].fX, tValues);
caryclark@google.com07393ca2013-04-08 11:47:37 +000054 }
caryclarkaec25102015-04-29 08:28:30 -070055 if (!sub.monotonicInY()) {
56 roots += SkDCubic::FindExtrema(&sub[0].fY, &tValues[roots]);
caryclark@google.com07393ca2013-04-08 11:47:37 +000057 }
caryclarkaec25102015-04-29 08:28:30 -070058 for (int index = 0; index < roots; ++index) {
59 double t = startT + (endT - startT) * tValues[index];
60 add(curve.ptAtT(t));
caryclark@google.com07393ca2013-04-08 11:47:37 +000061 }
62}