| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 | 7 |
| 8 #include "SkGeometry.h" | 8 #include "SkGeometry.h" |
| 9 #include "Test.h" | 9 #include "Test.h" |
| 10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 for (int j = 1; j < 128; ++j) { | 56 for (int j = 1; j < 128; ++j) { |
| 57 SkPoint r0; | 57 SkPoint r0; |
| 58 SkEvalQuadAt(pts, t, &r0); | 58 SkEvalQuadAt(pts, t, &r0); |
| 59 SkPoint r1 = SkEvalQuadAt(pts, t); | 59 SkPoint r1 = SkEvalQuadAt(pts, t); |
| 60 check_pairs(reporter, i, t, "quad-pos", r0.fX, r0.fY, r1.fX, r1.fY); | 60 check_pairs(reporter, i, t, "quad-pos", r0.fX, r0.fY, r1.fX, r1.fY); |
| 61 | 61 |
| 62 SkVector v0; | 62 SkVector v0; |
| 63 SkEvalQuadAt(pts, t, NULL, &v0); | 63 SkEvalQuadAt(pts, t, NULL, &v0); |
| 64 SkVector v1 = SkEvalQuadTangentAt(pts, t); | 64 SkVector v1 = SkEvalQuadTangentAt(pts, t); |
| 65 check_pairs(reporter, i, t, "quad-tan", v0.fX, v0.fY, v1.fX, v1.fY); | 65 check_pairs(reporter, i, t, "quad-tan", v0.fX, v0.fY, v1.fX, v1.fY); |
| 66 | 66 |
| 67 SkPoint dst0[5], dst1[5]; | |
| 68 SkChopQuadAt(pts, dst0, t); | |
| 69 SkChopQuadAt2(pts, dst1, t); | |
| 70 for (int k = 0; k < 5; ++k) { | |
| 71 check_pairs(reporter, i, t, "chop-quad", | |
| 72 dst0[k].fX, dst0[k].fY, dst1[k].fX, dst1[k].fY); | |
| 73 } | |
| 74 | |
| 75 t += dt; | 67 t += dt; |
| 76 } | 68 } |
| 77 } | 69 } |
| 78 } | |
| 79 | |
| 80 static void test_cubicat(skiatest::Reporter* reporter) { | |
| 81 SkRandom rand; | |
| 82 for (int i = 0; i < 1000; ++i) { | |
| 83 SkPoint pts[4]; | |
| 84 for (int j = 0; j < 4; ++j) { | |
| 85 pts[j].set(rand.nextSScalar1() * 100, rand.nextSScalar1() * 100); | |
| 86 } | |
| 87 const SkScalar dt = SK_Scalar1 / 128; | |
| 88 SkScalar t = dt; | |
| 89 for (int j = 1; j < 128; ++j) { | |
| 90 SkPoint dst0[7], dst1[7]; | |
| 91 SkChopCubicAt(pts, dst0, t); | |
| 92 SkChopCubicAt2(pts, dst1, t); | |
| 93 for (int k = 0; k < 7; ++k) { | |
| 94 check_pairs(reporter, i, t, "chop-cubic", | |
| 95 dst0[k].fX, dst0[k].fY, dst1[k].fX, dst1[k].fY); | |
| 96 } | |
| 97 | |
| 98 t += dt; | |
| 99 } | |
| 100 } | |
| 101 } | 70 } |
| 102 | 71 |
| 103 static void test_conic_eval_pos(skiatest::Reporter* reporter, const SkConic& con
ic, SkScalar t) { | 72 static void test_conic_eval_pos(skiatest::Reporter* reporter, const SkConic& con
ic, SkScalar t) { |
| 104 SkPoint p0, p1; | 73 SkPoint p0, p1; |
| 105 conic.evalAt(t, &p0, NULL); | 74 conic.evalAt(t, &p0, NULL); |
| 106 p1 = conic.evalAt(t); | 75 p1 = conic.evalAt(t); |
| 107 check_pairs(reporter, 0, t, "conic-pos", p0.fX, p0.fY, p1.fX, p1.fY); | 76 check_pairs(reporter, 0, t, "conic-pos", p0.fX, p0.fY, p1.fX, p1.fY); |
| 108 } | 77 } |
| 109 | 78 |
| 110 static void test_conic_eval_tan(skiatest::Reporter* reporter, const SkConic& con
ic, SkScalar t) { | 79 static void test_conic_eval_tan(skiatest::Reporter* reporter, const SkConic& con
ic, SkScalar t) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 { SkIntToScalar(3), SkIntToScalar(1), }, | 141 { SkIntToScalar(3), SkIntToScalar(1), }, |
| 173 { SkIntToScalar(3), SkIntToScalar(3) }, | 142 { SkIntToScalar(3), SkIntToScalar(3) }, |
| 174 }; | 143 }; |
| 175 for (int i = 0; i < 4; ++i) { | 144 for (int i = 0; i < 4; ++i) { |
| 176 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i])); | 145 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i])); |
| 177 } | 146 } |
| 178 | 147 |
| 179 testChopCubic(reporter); | 148 testChopCubic(reporter); |
| 180 test_evalquadat(reporter); | 149 test_evalquadat(reporter); |
| 181 test_conic(reporter); | 150 test_conic(reporter); |
| 182 test_cubicat(reporter); | |
| 183 } | 151 } |
| OLD | NEW |