| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #include "PathOpsTestCommon.h" | 7 #include "PathOpsTestCommon.h" |
| 8 #include "SkPathOpsBounds.h" | 8 #include "SkPathOpsBounds.h" |
| 9 #include "SkPathOpsCurve.h" | 9 #include "SkPathOpsCurve.h" |
| 10 #include "Test.h" | 10 #include "Test.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 static const size_t sectTestsCount = SK_ARRAY_COUNT(sectTests); | 23 static const size_t sectTestsCount = SK_ARRAY_COUNT(sectTests); |
| 24 | 24 |
| 25 static const SkRect noSectTests[][2] = { | 25 static const SkRect noSectTests[][2] = { |
| 26 {{2, 0, 4, 1}, {5, 0, 6, 1}}, | 26 {{2, 0, 4, 1}, {5, 0, 6, 1}}, |
| 27 {{2, 0, 4, 1}, {3, 2, 5, 2}}, | 27 {{2, 0, 4, 1}, {3, 2, 5, 2}}, |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 static const size_t noSectTestsCount = SK_ARRAY_COUNT(noSectTests); | 30 static const size_t noSectTestsCount = SK_ARRAY_COUNT(noSectTests); |
| 31 | 31 |
| 32 static const SkRect reallyEmpty[] = { | |
| 33 {0, 0, 0, 0}, | |
| 34 {1, 1, 1, 0}, | |
| 35 {1, 1, 0, 1}, | |
| 36 {1, 1, 0, 0}, | |
| 37 {1, 2, 3, SK_ScalarNaN}, | |
| 38 }; | |
| 39 | |
| 40 static const size_t emptyTestsCount = SK_ARRAY_COUNT(reallyEmpty); | |
| 41 | |
| 42 static const SkRect notReallyEmpty[] = { | |
| 43 {0, 0, 1, 0}, | |
| 44 {0, 0, 0, 1}, | |
| 45 {0, 0, 1, 1}, | |
| 46 }; | |
| 47 | |
| 48 static const size_t notEmptyTestsCount = SK_ARRAY_COUNT(notReallyEmpty); | |
| 49 | |
| 50 DEF_TEST(PathOpsBounds, reporter) { | 32 DEF_TEST(PathOpsBounds, reporter) { |
| 51 for (size_t index = 0; index < sectTestsCount; ++index) { | 33 for (size_t index = 0; index < sectTestsCount; ++index) { |
| 52 const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(sec
tTests[index][0]); | 34 const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(sec
tTests[index][0]); |
| 53 SkASSERT(ValidBounds(bounds1)); | 35 SkASSERT(ValidBounds(bounds1)); |
| 54 const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(sec
tTests[index][1]); | 36 const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(sec
tTests[index][1]); |
| 55 SkASSERT(ValidBounds(bounds2)); | 37 SkASSERT(ValidBounds(bounds2)); |
| 56 bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2); | 38 bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2); |
| 57 REPORTER_ASSERT(reporter, touches); | 39 REPORTER_ASSERT(reporter, touches); |
| 58 } | 40 } |
| 59 for (size_t index = 0; index < noSectTestsCount; ++index) { | 41 for (size_t index = 0; index < noSectTestsCount; ++index) { |
| 60 const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(noS
ectTests[index][0]); | 42 const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(noS
ectTests[index][0]); |
| 61 SkASSERT(ValidBounds(bounds1)); | 43 SkASSERT(ValidBounds(bounds1)); |
| 62 const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(noS
ectTests[index][1]); | 44 const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(noS
ectTests[index][1]); |
| 63 SkASSERT(ValidBounds(bounds2)); | 45 SkASSERT(ValidBounds(bounds2)); |
| 64 bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2); | 46 bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2); |
| 65 REPORTER_ASSERT(reporter, !touches); | 47 REPORTER_ASSERT(reporter, !touches); |
| 66 } | 48 } |
| 67 SkPathOpsBounds bounds; | 49 SkPathOpsBounds bounds; |
| 68 bounds.setEmpty(); | 50 bounds.setEmpty(); |
| 69 bounds.add(1, 2, 3, 4); | 51 bounds.add(1, 2, 3, 4); |
| 70 SkPathOpsBounds expected; | 52 SkPathOpsBounds expected; |
| 71 expected.set(0, 0, 3, 4); | 53 expected.set(0, 0, 3, 4); |
| 72 REPORTER_ASSERT(reporter, bounds == expected); | 54 REPORTER_ASSERT(reporter, bounds == expected); |
| 73 bounds.setEmpty(); | 55 bounds.setEmpty(); |
| 74 SkPathOpsBounds ordinal; | 56 SkPathOpsBounds ordinal; |
| 75 ordinal.set(1, 2, 3, 4); | 57 ordinal.set(1, 2, 3, 4); |
| 76 bounds.add(ordinal); | 58 bounds.add(ordinal); |
| 77 REPORTER_ASSERT(reporter, bounds == expected); | 59 REPORTER_ASSERT(reporter, bounds == expected); |
| 78 SkDPoint topLeft = {0, 0}; | 60 bounds.setEmpty(); |
| 79 bounds.setPointBounds(topLeft); | |
| 80 SkDPoint botRight = {3, 4}; | 61 SkDPoint botRight = {3, 4}; |
| 81 bounds.add(botRight); | 62 bounds.add(botRight); |
| 82 REPORTER_ASSERT(reporter, bounds == expected); | 63 REPORTER_ASSERT(reporter, bounds == expected); |
| 83 for (size_t index = 0; index < emptyTestsCount; ++index) { | |
| 84 const SkPathOpsBounds& bounds = static_cast<const SkPathOpsBounds&>(real
lyEmpty[index]); | |
| 85 // SkASSERT(ValidBounds(bounds)); // don't check because test may conta
in nan | |
| 86 bool empty = bounds.isReallyEmpty(); | |
| 87 REPORTER_ASSERT(reporter, empty); | |
| 88 } | |
| 89 for (size_t index = 0; index < notEmptyTestsCount; ++index) { | |
| 90 const SkPathOpsBounds& bounds = static_cast<const SkPathOpsBounds&>(notR
eallyEmpty[index]); | |
| 91 SkASSERT(ValidBounds(bounds)); | |
| 92 bool empty = bounds.isReallyEmpty(); | |
| 93 REPORTER_ASSERT(reporter, !empty); | |
| 94 } | |
| 95 const SkPoint curvePts[] = {{0, 0}, {1, 2}, {3, 4}, {5, 6}}; | 64 const SkPoint curvePts[] = {{0, 0}, {1, 2}, {3, 4}, {5, 6}}; |
| 96 SkDCurve curve; | 65 SkDCurve curve; |
| 97 curve.fLine.set(curvePts); | |
| 98 curve.setLineBounds(curvePts, 1, 0, 1, &bounds); | |
| 99 expected.set(0, 0, 1, 2); | |
| 100 REPORTER_ASSERT(reporter, bounds == expected); | |
| 101 (curve.*SetBounds[SkPath::kLine_Verb])(curvePts, 1, 0, 1, &bounds); | |
| 102 REPORTER_ASSERT(reporter, bounds == expected); | |
| 103 curve.fQuad.set(curvePts); | 66 curve.fQuad.set(curvePts); |
| 104 curve.setQuadBounds(curvePts, 1, 0, 1, &bounds); | 67 curve.setQuadBounds(curvePts, 1, 0, 1, &bounds); |
| 105 expected.set(0, 0, 3, 4); | 68 expected.set(0, 0, 3, 4); |
| 106 REPORTER_ASSERT(reporter, bounds == expected); | 69 REPORTER_ASSERT(reporter, bounds == expected); |
| 107 (curve.*SetBounds[SkPath::kQuad_Verb])(curvePts, 1, 0, 1, &bounds); | |
| 108 REPORTER_ASSERT(reporter, bounds == expected); | |
| 109 curve.fCubic.set(curvePts); | 70 curve.fCubic.set(curvePts); |
| 110 curve.setCubicBounds(curvePts, 1, 0, 1, &bounds); | 71 curve.setCubicBounds(curvePts, 1, 0, 1, &bounds); |
| 111 expected.set(0, 0, 5, 6); | 72 expected.set(0, 0, 5, 6); |
| 112 REPORTER_ASSERT(reporter, bounds == expected); | 73 REPORTER_ASSERT(reporter, bounds == expected); |
| 113 (curve.*SetBounds[SkPath::kCubic_Verb])(curvePts, 1, 0, 1, &bounds); | |
| 114 REPORTER_ASSERT(reporter, bounds == expected); | |
| 115 } | 74 } |
| OLD | NEW |