1/* 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 */ 7#include "PathOpsTestCommon.h" 8#include "SkPathOpsBounds.h" 9#include "SkPathOpsCubic.h" 10#include "SkPathOpsLine.h" 11#include "SkPathOpsQuad.h" 12#include "SkPathOpsTriangle.h" 13 14void CubicToQuads(const SkDCubic& cubic, double precision, SkTArray<SkDQuad, true>& quads) { 15 SkTArray<double, true> ts; 16 cubic.toQuadraticTs(precision, &ts); 17 if (ts.count() <= 0) { 18 SkDQuad quad = cubic.toQuad(); 19 quads.push_back(quad); 20 return; 21 } 22 double tStart = 0; 23 for (int i1 = 0; i1 <= ts.count(); ++i1) { 24 const double tEnd = i1 < ts.count() ? ts[i1] : 1; 25 SkDCubic part = cubic.subDivide(tStart, tEnd); 26 SkDQuad quad = part.toQuad(); 27 quads.push_back(quad); 28 tStart = tEnd; 29 } 30} 31 32static bool SkDoubleIsNaN(double x) { 33 return x != x; 34} 35 36bool ValidBounds(const SkPathOpsBounds& bounds) { 37 if (SkScalarIsNaN(bounds.fLeft)) { 38 return false; 39 } 40 if (SkScalarIsNaN(bounds.fTop)) { 41 return false; 42 } 43 if (SkScalarIsNaN(bounds.fRight)) { 44 return false; 45 } 46 return !SkScalarIsNaN(bounds.fBottom); 47} 48 49bool ValidCubic(const SkDCubic& cubic) { 50 for (int index = 0; index < 4; ++index) { 51 if (!ValidPoint(cubic[index])) { 52 return false; 53 } 54 } 55 return true; 56} 57 58bool ValidLine(const SkDLine& line) { 59 for (int index = 0; index < 2; ++index) { 60 if (!ValidPoint(line[index])) { 61 return false; 62 } 63 } 64 return true; 65} 66 67bool ValidPoint(const SkDPoint& pt) { 68 if (SkDoubleIsNaN(pt.fX)) { 69 return false; 70 } 71 return !SkDoubleIsNaN(pt.fY); 72} 73 74bool ValidPoints(const SkPoint* pts, int count) { 75 for (int index = 0; index < count; ++index) { 76 if (SkScalarIsNaN(pts[index].fX)) { 77 return false; 78 } 79 if (SkScalarIsNaN(pts[index].fY)) { 80 return false; 81 } 82 } 83 return true; 84} 85 86bool ValidQuad(const SkDQuad& quad) { 87 for (int index = 0; index < 3; ++index) { 88 if (!ValidPoint(quad[index])) { 89 return false; 90 } 91 } 92 return true; 93} 94 95bool ValidTriangle(const SkDTriangle& triangle) { 96 for (int index = 0; index < 3; ++index) { 97 if (!ValidPoint(triangle.fPts[index])) { 98 return false; 99 } 100 } 101 return true; 102} 103 104bool ValidVector(const SkDVector& v) { 105 if (SkDoubleIsNaN(v.fX)) { 106 return false; 107 } 108 return !SkDoubleIsNaN(v.fY); 109} 110