OLD | NEW |
(Empty) | |
| 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 "SkPathOpsCubic.h" |
| 8 #include "SkPathOpsLine.h" |
| 9 #include "SkPathOpsQuad.h" |
| 10 #include "SkPathOpsRect.h" |
| 11 #include "Test.h" |
| 12 |
| 13 static const SkDLine lineTests[] = { |
| 14 {{{2, 1}, {2, 1}}}, |
| 15 {{{2, 1}, {1, 1}}}, |
| 16 {{{2, 1}, {2, 2}}}, |
| 17 {{{1, 1}, {2, 2}}}, |
| 18 {{{3, 0}, {2, 1}}}, |
| 19 {{{3, 2}, {1, 1}}}, |
| 20 }; |
| 21 |
| 22 static const SkDQuad quadTests[] = { |
| 23 {{{1, 1}, {2, 1}, {0, 2}}}, |
| 24 {{{0, 0}, {1, 1}, {3, 1}}}, |
| 25 {{{2, 0}, {1, 1}, {2, 2}}}, |
| 26 {{{4, 0}, {0, 1}, {4, 2}}}, |
| 27 {{{0, 0}, {0, 1}, {1, 1}}}, |
| 28 }; |
| 29 |
| 30 static const SkDCubic cubicTests[] = { |
| 31 {{{2, 0}, {3, 1}, {2, 2}, {1, 1}}}, |
| 32 {{{3, 1}, {2, 2}, {1, 1}, {2, 0}}}, |
| 33 {{{3, 0}, {2, 1}, {3, 2}, {1, 1}}}, |
| 34 }; |
| 35 |
| 36 static const size_t lineTests_count = sizeof(lineTests) / sizeof(lineTests[0]); |
| 37 static const size_t quadTests_count = sizeof(quadTests) / sizeof(quadTests[0]); |
| 38 static const size_t cubicTests_count = sizeof(cubicTests) / sizeof(cubicTests[0]
); |
| 39 |
| 40 static void DRectTest(skiatest::Reporter* reporter) { |
| 41 size_t index; |
| 42 SkDRect rect, rect2; |
| 43 for (index = 0; index < lineTests_count; ++index) { |
| 44 const SkDLine& line = lineTests[index]; |
| 45 rect.setBounds(line); |
| 46 REPORTER_ASSERT(reporter, rect.fLeft == SkTMin(line[0].fX, line[1].fX)); |
| 47 REPORTER_ASSERT(reporter, rect.fTop == SkTMin(line[0].fY, line[1].fY)); |
| 48 REPORTER_ASSERT(reporter, rect.fRight == SkTMax(line[0].fX, line[1].fX))
; |
| 49 REPORTER_ASSERT(reporter, rect.fBottom == SkTMax(line[0].fY, line[1].fY)
); |
| 50 rect2.set(line[0]); |
| 51 rect2.add(line[1]); |
| 52 REPORTER_ASSERT(reporter, rect2.fLeft == SkTMin(line[0].fX, line[1].fX))
; |
| 53 REPORTER_ASSERT(reporter, rect2.fTop == SkTMin(line[0].fY, line[1].fY)); |
| 54 REPORTER_ASSERT(reporter, rect2.fRight == SkTMax(line[0].fX, line[1].fX)
); |
| 55 REPORTER_ASSERT(reporter, rect2.fBottom == SkTMax(line[0].fY, line[1].fY
)); |
| 56 REPORTER_ASSERT(reporter, rect.contains(line[0])); |
| 57 REPORTER_ASSERT(reporter, rect.intersects(&rect2)); |
| 58 } |
| 59 for (index = 0; index < quadTests_count; ++index) { |
| 60 const SkDQuad& quad = quadTests[index]; |
| 61 rect.setRawBounds(quad); |
| 62 REPORTER_ASSERT(reporter, rect.fLeft == SkTMin(quad[0].fX, SkTMin(quad[1
].fX, quad[2].fX))); |
| 63 REPORTER_ASSERT(reporter, rect.fTop == SkTMin(quad[0].fY, SkTMin(quad[1]
.fY, quad[2].fY))); |
| 64 REPORTER_ASSERT(reporter, rect.fRight == SkTMax(quad[0].fX, |
| 65 SkTMax(quad[1].fX, quad[2].fX))); |
| 66 REPORTER_ASSERT(reporter, rect.fBottom == SkTMax(quad[0].fY, |
| 67 SkTMax(quad[1].fY, quad[2].fY))); |
| 68 rect2.setBounds(quad); |
| 69 REPORTER_ASSERT(reporter, rect.intersects(&rect2)); |
| 70 // FIXME: add a recursive box subdivision method to verify that tight bo
unds is correct |
| 71 SkDPoint leftTop = {rect2.fLeft, rect2.fTop}; |
| 72 REPORTER_ASSERT(reporter, rect.contains(leftTop)); |
| 73 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom}; |
| 74 REPORTER_ASSERT(reporter, rect.contains(rightBottom)); |
| 75 } |
| 76 for (index = 0; index < cubicTests_count; ++index) { |
| 77 const SkDCubic& cubic = cubicTests[index]; |
| 78 rect.setRawBounds(cubic); |
| 79 REPORTER_ASSERT(reporter, rect.fLeft == SkTMin(cubic[0].fX, SkTMin(cubic
[1].fX, |
| 80 SkTMin(cubic[2].fX, cubic[3].fX)))); |
| 81 REPORTER_ASSERT(reporter, rect.fTop == SkTMin(cubic[0].fY, SkTMin(cubic[
1].fY, |
| 82 SkTMin(cubic[2].fY, cubic[3].fY)))); |
| 83 REPORTER_ASSERT(reporter, rect.fRight == SkTMax(cubic[0].fX, SkTMax(cubi
c[1].fX, |
| 84 SkTMax(cubic[2].fX, cubic[3].fX)))); |
| 85 REPORTER_ASSERT(reporter, rect.fBottom == SkTMax(cubic[0].fY, SkTMax(cub
ic[1].fY, |
| 86 SkTMax(cubic[2].fY, cubic[3].fY)))); |
| 87 rect2.setBounds(cubic); |
| 88 REPORTER_ASSERT(reporter, rect.intersects(&rect2)); |
| 89 // FIXME: add a recursive box subdivision method to verify that tight bo
unds is correct |
| 90 SkDPoint leftTop = {rect2.fLeft, rect2.fTop}; |
| 91 REPORTER_ASSERT(reporter, rect.contains(leftTop)); |
| 92 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom}; |
| 93 REPORTER_ASSERT(reporter, rect.contains(rightBottom)); |
| 94 } |
| 95 } |
| 96 |
| 97 #include "TestClassDef.h" |
| 98 DEFINE_TESTCLASS("PathOpsDRect", PathOpsDRectClass, DRectTest) |
OLD | NEW |