| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | */ |
| tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame^] | 7 | |
| reed@android.com | d8730ea | 2009-02-27 22:06:06 +0000 | [diff] [blame] | 8 | #include "Test.h" |
| tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame^] | 9 | #include "TestClassDef.h" |
| reed@android.com | d8730ea | 2009-02-27 22:06:06 +0000 | [diff] [blame] | 10 | #include "SkGeometry.h" |
| 11 | |
| reed@google.com | 6fc321a | 2011-07-27 13:54:36 +0000 | [diff] [blame] | 12 | static bool nearly_equal(const SkPoint& a, const SkPoint& b) { |
| 13 | return SkScalarNearlyEqual(a.fX, b.fX) && SkScalarNearlyEqual(a.fY, b.fY); |
| 14 | } |
| 15 | |
| reed@google.com | 087d5aa | 2012-02-29 20:59:24 +0000 | [diff] [blame] | 16 | static void testChopCubic(skiatest::Reporter* reporter) { |
| 17 | /* |
| 18 | Inspired by this test, which used to assert that the tValues had dups |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 19 | |
| reed@google.com | 087d5aa | 2012-02-29 20:59:24 +0000 | [diff] [blame] | 20 | <path stroke="#202020" d="M0,0 C0,0 1,1 2190,5130 C2190,5070 2220,5010 2205,4980" /> |
| 21 | */ |
| 22 | const SkPoint src[] = { |
| 23 | { SkIntToScalar(2190), SkIntToScalar(5130) }, |
| 24 | { SkIntToScalar(2190), SkIntToScalar(5070) }, |
| 25 | { SkIntToScalar(2220), SkIntToScalar(5010) }, |
| 26 | { SkIntToScalar(2205), SkIntToScalar(4980) }, |
| 27 | }; |
| 28 | SkPoint dst[13]; |
| 29 | SkScalar tValues[3]; |
| reed@google.com | c256cd1 | 2012-02-29 21:57:36 +0000 | [diff] [blame] | 30 | // make sure we don't assert internally |
| reed@google.com | 087d5aa | 2012-02-29 20:59:24 +0000 | [diff] [blame] | 31 | int count = SkChopCubicAtMaxCurvature(src, dst, tValues); |
| caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 32 | if (false) { // avoid bit rot, suppress warning |
| 33 | REPORTER_ASSERT(reporter, count); |
| 34 | } |
| reed@google.com | 087d5aa | 2012-02-29 20:59:24 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame^] | 37 | DEF_TEST(Geometry, reporter) { |
| reed@android.com | d8730ea | 2009-02-27 22:06:06 +0000 | [diff] [blame] | 38 | SkPoint pts[3], dst[5]; |
| 39 | |
| 40 | pts[0].set(0, 0); |
| 41 | pts[1].set(100, 50); |
| 42 | pts[2].set(0, 100); |
| 43 | |
| 44 | int count = SkChopQuadAtMaxCurvature(pts, dst); |
| 45 | REPORTER_ASSERT(reporter, count == 1 || count == 2); |
| reed@google.com | 6fc321a | 2011-07-27 13:54:36 +0000 | [diff] [blame] | 46 | |
| 47 | pts[0].set(0, 0); |
| 48 | pts[1].set(SkIntToScalar(3), 0); |
| 49 | pts[2].set(SkIntToScalar(3), SkIntToScalar(3)); |
| 50 | SkConvertQuadToCubic(pts, dst); |
| 51 | const SkPoint cubic[] = { |
| tomhudson@google.com | 221db3c | 2011-07-28 21:10:29 +0000 | [diff] [blame] | 52 | { 0, 0, }, |
| 53 | { SkIntToScalar(2), 0, }, |
| 54 | { SkIntToScalar(3), SkIntToScalar(1), }, |
| 55 | { SkIntToScalar(3), SkIntToScalar(3) }, |
| reed@google.com | 6fc321a | 2011-07-27 13:54:36 +0000 | [diff] [blame] | 56 | }; |
| 57 | for (int i = 0; i < 4; ++i) { |
| 58 | REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i])); |
| 59 | } |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 60 | |
| reed@google.com | 087d5aa | 2012-02-29 20:59:24 +0000 | [diff] [blame] | 61 | testChopCubic(reporter); |
| reed@android.com | d8730ea | 2009-02-27 22:06:06 +0000 | [diff] [blame] | 62 | } |