aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pathops/SkPathOpsRect.cpp
blob: 8c0115353298c039ee9ac1de2e41457764a8fd42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#include "SkPathOpsConic.h"
#include "SkPathOpsCubic.h"
#include "SkPathOpsLine.h"
#include "SkPathOpsQuad.h"
#include "SkPathOpsRect.h"

void SkDRect::setBounds(const SkDQuad& curve, const SkDQuad& sub, double startT, double endT) {
    set(sub[0]);
    add(sub[2]);
    double tValues[2];
    int roots = 0;
    if (!sub.monotonicInX()) {
        roots = SkDQuad::FindExtrema(&sub[0].fX, tValues);
    }
    if (!sub.monotonicInY()) {
        roots += SkDQuad::FindExtrema(&sub[0].fY, &tValues[roots]);
    }
    for (int index = 0; index < roots; ++index) {
        double t = startT + (endT - startT) * tValues[index];
        add(curve.ptAtT(t));
    }
}

void SkDRect::setBounds(const SkDConic& curve, const SkDConic& sub, double startT, double endT) {
    set(sub[0]);
    add(sub[2]);
    double tValues[2];
    int roots = 0;
    if (!sub.monotonicInX()) {
        roots = SkDConic::FindExtrema(&sub[0].fX, sub.fWeight, tValues);
    }
    if (!sub.monotonicInY()) {
        roots += SkDConic::FindExtrema(&sub[0].fY, sub.fWeight, &tValues[roots]);
    }
    for (int index = 0; index < roots; ++index) {
        double t = startT + (endT - startT) * tValues[index];
        add(curve.ptAtT(t));
    }
}

void SkDRect::setBounds(const SkDCubic& curve, const SkDCubic& sub, double startT, double endT) {
    set(sub[0]);
    add(sub[3]);
    double tValues[4];
    int roots = 0;
    if (!sub.monotonicInX()) {
        roots = SkDCubic::FindExtrema(&sub[0].fX, tValues);
    }
    if (!sub.monotonicInY()) {
        roots += SkDCubic::FindExtrema(&sub[0].fY, &tValues[roots]);
    }
    for (int index = 0; index < roots; ++index) {
        double t = startT + (endT - startT) * tValues[index];
        add(curve.ptAtT(t));
    }
}