aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pathops/SkPathOpsRect.cpp
blob: 2ceed32900a3f3b97c329696e854e5b0aca735f0 (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
63
64
65
/*
 * 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 "SkPathOpsCubic.h"
#include "SkPathOpsLine.h"
#include "SkPathOpsQuad.h"
#include "SkPathOpsRect.h"

void SkDRect::setBounds(const SkDLine& line) {
    set(line[0]);
    add(line[1]);
}

void SkDRect::setBounds(const SkDQuad& quad) {
    set(quad[0]);
    add(quad[2]);
    double tValues[2];
    int roots = 0;
    if (!between(quad[0].fX, quad[1].fX, quad[2].fX)) {
        roots = SkDQuad::FindExtrema(quad[0].fX, quad[1].fX, quad[2].fX, tValues);
    }
    if (!between(quad[0].fY, quad[1].fY, quad[2].fY)) {
        roots += SkDQuad::FindExtrema(quad[0].fY, quad[1].fY, quad[2].fY, &tValues[roots]);
    }
    for (int x = 0; x < roots; ++x) {
        add(quad.ptAtT(tValues[x]));
    }
}

void SkDRect::setRawBounds(const SkDQuad& quad) {
    set(quad[0]);
    for (int x = 1; x < 3; ++x) {
        add(quad[x]);
    }
}

static bool is_bounded_by_end_points(double a, double b, double c, double d) {
    return between(a, b, d) && between(a, c, d);
}

void SkDRect::setBounds(const SkDCubic& c) {
    set(c[0]);
    add(c[3]);
    double tValues[4];
    int roots = 0;
    if (!is_bounded_by_end_points(c[0].fX, c[1].fX, c[2].fX, c[3].fX)) {
        roots = SkDCubic::FindExtrema(c[0].fX, c[1].fX, c[2].fX, c[3].fX, tValues);
    }
    if (!is_bounded_by_end_points(c[0].fY, c[1].fY, c[2].fY, c[3].fY)) {
        roots += SkDCubic::FindExtrema(c[0].fY, c[1].fY, c[2].fY, c[3].fY, &tValues[roots]);
    }
    for (int x = 0; x < roots; ++x) {
        add(c.ptAtT(tValues[x]));
    }
}

void SkDRect::setRawBounds(const SkDCubic& cubic) {
    set(cubic[0]);
    for (int x = 1; x < 4; ++x) {
        add(cubic[x]);
    }
}