epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@android.com | 5e5adfd | 2009-03-07 03:39:23 +0000 | [diff] [blame] | 8 | #include "Test.h" |
| 9 | #include "SkPathMeasure.h" |
| 10 | |
| 11 | static void TestPathMeasure(skiatest::Reporter* reporter) { |
| 12 | SkPath path; |
| 13 | |
| 14 | path.moveTo(0, 0); |
| 15 | path.lineTo(SK_Scalar1, 0); |
| 16 | path.lineTo(SK_Scalar1, SK_Scalar1); |
| 17 | path.lineTo(0, SK_Scalar1); |
| 18 | |
| 19 | SkPathMeasure meas(path, true); |
| 20 | SkScalar length = meas.getLength(); |
| 21 | SkASSERT(length == SK_Scalar1*4); |
| 22 | |
| 23 | path.reset(); |
| 24 | path.moveTo(0, 0); |
| 25 | path.lineTo(SK_Scalar1*3, SK_Scalar1*4); |
| 26 | meas.setPath(&path, false); |
| 27 | length = meas.getLength(); |
| 28 | REPORTER_ASSERT(reporter, length == SK_Scalar1*5); |
| 29 | |
| 30 | path.reset(); |
| 31 | path.addCircle(0, 0, SK_Scalar1); |
| 32 | meas.setPath(&path, true); |
| 33 | length = meas.getLength(); |
| 34 | // SkDebugf("circle arc-length = %g\n", length); |
| 35 | |
| 36 | for (int i = 0; i < 8; i++) { |
| 37 | SkScalar d = length * i / 8; |
| 38 | SkPoint p; |
| 39 | SkVector v; |
| 40 | meas.getPosTan(d, &p, &v); |
| 41 | #if 0 |
| 42 | SkDebugf("circle arc-length=%g, pos[%g %g] tan[%g %g]\n", |
| 43 | d, p.fX, p.fY, v.fX, v.fY); |
| 44 | #endif |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | #include "TestClassDef.h" |
| 49 | DEFINE_TESTCLASS("PathMeasure", PathMeasureTestClass, TestPathMeasure) |