caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 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" |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 8 | #include "SkPathOpsBounds.h" |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 9 | #include "SkPathOpsCubic.h" |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 10 | #include "SkPathOpsLine.h" |
| 11 | #include "SkPathOpsQuad.h" |
| 12 | #include "SkPathOpsTriangle.h" |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 13 | |
caryclark@google.com | d892bd8 | 2013-06-17 14:10:36 +0000 | [diff] [blame] | 14 | void CubicToQuads(const SkDCubic& cubic, double precision, SkTArray<SkDQuad, true>& quads) { |
| 15 | SkTArray<double, true> ts; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 16 | cubic.toQuadraticTs(precision, &ts); |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 17 | if (ts.count() <= 0) { |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 18 | SkDQuad quad = cubic.toQuad(); |
caryclark@google.com | d892bd8 | 2013-06-17 14:10:36 +0000 | [diff] [blame] | 19 | quads.push_back(quad); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 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(); |
caryclark@google.com | d892bd8 | 2013-06-17 14:10:36 +0000 | [diff] [blame] | 27 | quads.push_back(quad); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 28 | tStart = tEnd; |
| 29 | } |
| 30 | } |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 31 | |
| 32 | static bool SkDoubleIsNaN(double x) { |
| 33 | return x != x; |
| 34 | } |
| 35 | |
| 36 | bool 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 | |
| 49 | bool 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 | |
| 58 | bool 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 | |
| 67 | bool ValidPoint(const SkDPoint& pt) { |
| 68 | if (SkDoubleIsNaN(pt.fX)) { |
| 69 | return false; |
| 70 | } |
skia.committer@gmail.com | eebe6f4 | 2013-07-17 07:01:13 +0000 | [diff] [blame] | 71 | return !SkDoubleIsNaN(pt.fY); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | bool 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 | |
| 86 | bool 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 | |
| 95 | bool 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 | |
| 104 | bool ValidVector(const SkDVector& v) { |
| 105 | if (SkDoubleIsNaN(v.fX)) { |
| 106 | return false; |
| 107 | } |
skia.committer@gmail.com | eebe6f4 | 2013-07-17 07:01:13 +0000 | [diff] [blame] | 108 | return !SkDoubleIsNaN(v.fY); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 109 | } |