michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: #include "SkPathOpsCubic.h" michael@0: #include "SkPathOpsLine.h" michael@0: #include "SkPathOpsQuad.h" michael@0: #include "SkPathOpsRect.h" michael@0: michael@0: void SkDRect::setBounds(const SkDLine& line) { michael@0: set(line[0]); michael@0: add(line[1]); michael@0: } michael@0: michael@0: void SkDRect::setBounds(const SkDQuad& quad) { michael@0: set(quad[0]); michael@0: add(quad[2]); michael@0: double tValues[2]; michael@0: int roots = 0; michael@0: if (!between(quad[0].fX, quad[1].fX, quad[2].fX)) { michael@0: roots = SkDQuad::FindExtrema(quad[0].fX, quad[1].fX, quad[2].fX, tValues); michael@0: } michael@0: if (!between(quad[0].fY, quad[1].fY, quad[2].fY)) { michael@0: roots += SkDQuad::FindExtrema(quad[0].fY, quad[1].fY, quad[2].fY, &tValues[roots]); michael@0: } michael@0: for (int x = 0; x < roots; ++x) { michael@0: add(quad.ptAtT(tValues[x])); michael@0: } michael@0: } michael@0: michael@0: void SkDRect::setRawBounds(const SkDQuad& quad) { michael@0: set(quad[0]); michael@0: for (int x = 1; x < 3; ++x) { michael@0: add(quad[x]); michael@0: } michael@0: } michael@0: michael@0: static bool is_bounded_by_end_points(double a, double b, double c, double d) { michael@0: return between(a, b, d) && between(a, c, d); michael@0: } michael@0: michael@0: void SkDRect::setBounds(const SkDCubic& c) { michael@0: set(c[0]); michael@0: add(c[3]); michael@0: double tValues[4]; michael@0: int roots = 0; michael@0: if (!is_bounded_by_end_points(c[0].fX, c[1].fX, c[2].fX, c[3].fX)) { michael@0: roots = SkDCubic::FindExtrema(c[0].fX, c[1].fX, c[2].fX, c[3].fX, tValues); michael@0: } michael@0: if (!is_bounded_by_end_points(c[0].fY, c[1].fY, c[2].fY, c[3].fY)) { michael@0: roots += SkDCubic::FindExtrema(c[0].fY, c[1].fY, c[2].fY, c[3].fY, &tValues[roots]); michael@0: } michael@0: for (int x = 0; x < roots; ++x) { michael@0: add(c.ptAtT(tValues[x])); michael@0: } michael@0: } michael@0: michael@0: void SkDRect::setRawBounds(const SkDCubic& cubic) { michael@0: set(cubic[0]); michael@0: for (int x = 1; x < 4; ++x) { michael@0: add(cubic[x]); michael@0: } michael@0: }