| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkPathOpsCubic.h" | 8 #include "SkPathOpsCubic.h" |
| 9 #include "SkPathOpsLine.h" | 9 #include "SkPathOpsLine.h" |
| 10 #include "SkPathOpsQuad.h" | 10 #include "SkPathOpsQuad.h" |
| 11 #include "SkPathOpsRect.h" | 11 #include "SkPathOpsRect.h" |
| 12 #include "Test.h" | 12 #include "Test.h" |
| 13 | 13 |
| 14 static const SkDQuad quadTests[] = { | 14 static const QuadPts quadTests[] = { |
| 15 {{{1, 1}, {2, 1}, {0, 2}}}, | 15 {{{1, 1}, {2, 1}, {0, 2}}}, |
| 16 {{{0, 0}, {1, 1}, {3, 1}}}, | 16 {{{0, 0}, {1, 1}, {3, 1}}}, |
| 17 {{{2, 0}, {1, 1}, {2, 2}}}, | 17 {{{2, 0}, {1, 1}, {2, 2}}}, |
| 18 {{{4, 0}, {0, 1}, {4, 2}}}, | 18 {{{4, 0}, {0, 1}, {4, 2}}}, |
| 19 {{{0, 0}, {0, 1}, {1, 1}}}, | 19 {{{0, 0}, {0, 1}, {1, 1}}}, |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 static const SkDCubic cubicTests[] = { | 22 static const CubicPts cubicTests[] = { |
| 23 {{{2, 0}, {3, 1}, {2, 2}, {1, 1}}}, | 23 {{{2, 0}, {3, 1}, {2, 2}, {1, 1}}}, |
| 24 {{{3, 1}, {2, 2}, {1, 1}, {2, 0}}}, | 24 {{{3, 1}, {2, 2}, {1, 1}, {2, 0}}}, |
| 25 {{{3, 0}, {2, 1}, {3, 2}, {1, 1}}}, | 25 {{{3, 0}, {2, 1}, {3, 2}, {1, 1}}}, |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 static const size_t quadTests_count = SK_ARRAY_COUNT(quadTests); | 28 static const size_t quadTests_count = SK_ARRAY_COUNT(quadTests); |
| 29 static const size_t cubicTests_count = SK_ARRAY_COUNT(cubicTests); | 29 static const size_t cubicTests_count = SK_ARRAY_COUNT(cubicTests); |
| 30 | 30 |
| 31 static void setRawBounds(const SkDQuad& quad, SkDRect* rect) { | 31 static void setRawBounds(const SkDQuad& quad, SkDRect* rect) { |
| 32 rect->set(quad[0]); | 32 rect->set(quad[0]); |
| 33 rect->add(quad[1]); | 33 rect->add(quad[1]); |
| 34 rect->add(quad[2]); | 34 rect->add(quad[2]); |
| 35 } | 35 } |
| 36 | 36 |
| 37 static void setRawBounds(const SkDCubic& cubic, SkDRect* rect) { | 37 static void setRawBounds(const SkDCubic& cubic, SkDRect* rect) { |
| 38 rect->set(cubic[0]); | 38 rect->set(cubic[0]); |
| 39 rect->add(cubic[1]); | 39 rect->add(cubic[1]); |
| 40 rect->add(cubic[2]); | 40 rect->add(cubic[2]); |
| 41 rect->add(cubic[3]); | 41 rect->add(cubic[3]); |
| 42 } | 42 } |
| 43 | 43 |
| 44 DEF_TEST(PathOpsDRect, reporter) { | 44 DEF_TEST(PathOpsDRect, reporter) { |
| 45 size_t index; | 45 size_t index; |
| 46 SkDRect rect, rect2; | 46 SkDRect rect, rect2; |
| 47 for (index = 0; index < quadTests_count; ++index) { | 47 for (index = 0; index < quadTests_count; ++index) { |
| 48 const SkDQuad& quad = quadTests[index]; | 48 const QuadPts& q = quadTests[index]; |
| 49 SkDQuad quad; |
| 50 quad.debugSet(q.fPts); |
| 49 SkASSERT(ValidQuad(quad)); | 51 SkASSERT(ValidQuad(quad)); |
| 50 setRawBounds(quad, &rect); | 52 setRawBounds(quad, &rect); |
| 51 rect2.setBounds(quad); | 53 rect2.setBounds(quad); |
| 52 REPORTER_ASSERT(reporter, rect.intersects(rect2)); | 54 REPORTER_ASSERT(reporter, rect.intersects(rect2)); |
| 53 // FIXME: add a recursive box subdivision method to verify that tight bo
unds is correct | 55 // FIXME: add a recursive box subdivision method to verify that tight bo
unds is correct |
| 54 SkDPoint leftTop = {rect2.fLeft, rect2.fTop}; | 56 SkDPoint leftTop = {rect2.fLeft, rect2.fTop}; |
| 55 REPORTER_ASSERT(reporter, rect.contains(leftTop)); | 57 REPORTER_ASSERT(reporter, rect.contains(leftTop)); |
| 56 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom}; | 58 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom}; |
| 57 REPORTER_ASSERT(reporter, rect.contains(rightBottom)); | 59 REPORTER_ASSERT(reporter, rect.contains(rightBottom)); |
| 58 } | 60 } |
| 59 for (index = 0; index < cubicTests_count; ++index) { | 61 for (index = 0; index < cubicTests_count; ++index) { |
| 60 const SkDCubic& cubic = cubicTests[index]; | 62 const CubicPts& c = cubicTests[index]; |
| 63 SkDCubic cubic; |
| 64 cubic.debugSet(c.fPts); |
| 61 SkASSERT(ValidCubic(cubic)); | 65 SkASSERT(ValidCubic(cubic)); |
| 62 setRawBounds(cubic, &rect); | 66 setRawBounds(cubic, &rect); |
| 63 rect2.setBounds(cubic); | 67 rect2.setBounds(cubic); |
| 64 REPORTER_ASSERT(reporter, rect.intersects(rect2)); | 68 REPORTER_ASSERT(reporter, rect.intersects(rect2)); |
| 65 // FIXME: add a recursive box subdivision method to verify that tight bo
unds is correct | 69 // FIXME: add a recursive box subdivision method to verify that tight bo
unds is correct |
| 66 SkDPoint leftTop = {rect2.fLeft, rect2.fTop}; | 70 SkDPoint leftTop = {rect2.fLeft, rect2.fTop}; |
| 67 REPORTER_ASSERT(reporter, rect.contains(leftTop)); | 71 REPORTER_ASSERT(reporter, rect.contains(leftTop)); |
| 68 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom}; | 72 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom}; |
| 69 REPORTER_ASSERT(reporter, rect.contains(rightBottom)); | 73 REPORTER_ASSERT(reporter, rect.contains(rightBottom)); |
| 70 } | 74 } |
| 71 } | 75 } |
| OLD | NEW |