OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "Test.h" | 8 #include "Test.h" |
9 #include "SkPathMeasure.h" | 9 #include "SkPathMeasure.h" |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 meas.getLength(); | 44 meas.getLength(); |
45 #endif | 45 #endif |
46 } | 46 } |
47 | 47 |
48 static void test_small_segment() { | 48 static void test_small_segment() { |
49 #ifdef SK_SCALAR_IS_FLOAT | 49 #ifdef SK_SCALAR_IS_FLOAT |
50 SkPath path; | 50 SkPath path; |
51 const SkPoint pts[] = { | 51 const SkPoint pts[] = { |
52 { 100000, 100000}, | 52 { 100000, 100000}, |
53 // big jump between these points, makes a big segment | 53 // big jump between these points, makes a big segment |
54 { SkFloatToScalar(1.0005f), SkFloatToScalar(0.9999f) }, | 54 { 1.0005f, 0.9999f }, |
55 // tiny (non-zero) jump between these points | 55 // tiny (non-zero) jump between these points |
56 { SK_Scalar1, SK_Scalar1 }, | 56 { SK_Scalar1, SK_Scalar1 }, |
57 }; | 57 }; |
58 | 58 |
59 path.moveTo(pts[0]); | 59 path.moveTo(pts[0]); |
60 for (size_t i = 1; i < SK_ARRAY_COUNT(pts); ++i) { | 60 for (size_t i = 1; i < SK_ARRAY_COUNT(pts); ++i) { |
61 path.lineTo(pts[i]); | 61 path.lineTo(pts[i]); |
62 } | 62 } |
63 SkPathMeasure meas(path, false); | 63 SkPathMeasure meas(path, false); |
64 | 64 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 REPORTER_ASSERT(reporter, length == SK_Scalar1 * 4); | 116 REPORTER_ASSERT(reporter, length == SK_Scalar1 * 4); |
117 meas.nextContour(); | 117 meas.nextContour(); |
118 length = meas.getLength(); | 118 length = meas.getLength(); |
119 REPORTER_ASSERT(reporter, length == SK_Scalar1); | 119 REPORTER_ASSERT(reporter, length == SK_Scalar1); |
120 SkPoint position; | 120 SkPoint position; |
121 SkVector tangent; | 121 SkVector tangent; |
122 REPORTER_ASSERT(reporter, meas.getPosTan(SK_ScalarHalf, &position, &tangent)
); | 122 REPORTER_ASSERT(reporter, meas.getPosTan(SK_ScalarHalf, &position, &tangent)
); |
123 REPORTER_ASSERT(reporter, | 123 REPORTER_ASSERT(reporter, |
124 SkScalarNearlyEqual(position.fX, | 124 SkScalarNearlyEqual(position.fX, |
125 -SK_ScalarHalf, | 125 -SK_ScalarHalf, |
126 SkFloatToScalar(0.0001f))); | 126 0.0001f)); |
127 REPORTER_ASSERT(reporter, position.fY == 0); | 127 REPORTER_ASSERT(reporter, position.fY == 0); |
128 REPORTER_ASSERT(reporter, tangent.fX == -SK_Scalar1); | 128 REPORTER_ASSERT(reporter, tangent.fX == -SK_Scalar1); |
129 REPORTER_ASSERT(reporter, tangent.fY == 0); | 129 REPORTER_ASSERT(reporter, tangent.fY == 0); |
130 | 130 |
131 // Test degenerate paths | 131 // Test degenerate paths |
132 path.reset(); | 132 path.reset(); |
133 path.moveTo(0, 0); | 133 path.moveTo(0, 0); |
134 path.lineTo(0, 0); | 134 path.lineTo(0, 0); |
135 path.lineTo(SK_Scalar1, 0); | 135 path.lineTo(SK_Scalar1, 0); |
136 path.quadTo(SK_Scalar1, 0, SK_Scalar1, 0); | 136 path.quadTo(SK_Scalar1, 0, SK_Scalar1, 0); |
137 path.quadTo(SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1 * 2); | 137 path.quadTo(SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1 * 2); |
138 path.cubicTo(SK_Scalar1, SK_Scalar1 * 2, | 138 path.cubicTo(SK_Scalar1, SK_Scalar1 * 2, |
139 SK_Scalar1, SK_Scalar1 * 2, | 139 SK_Scalar1, SK_Scalar1 * 2, |
140 SK_Scalar1, SK_Scalar1 * 2); | 140 SK_Scalar1, SK_Scalar1 * 2); |
141 path.cubicTo(SK_Scalar1*2, SK_Scalar1 * 2, | 141 path.cubicTo(SK_Scalar1*2, SK_Scalar1 * 2, |
142 SK_Scalar1*3, SK_Scalar1 * 2, | 142 SK_Scalar1*3, SK_Scalar1 * 2, |
143 SK_Scalar1*4, SK_Scalar1 * 2); | 143 SK_Scalar1*4, SK_Scalar1 * 2); |
144 meas.setPath(&path, false); | 144 meas.setPath(&path, false); |
145 length = meas.getLength(); | 145 length = meas.getLength(); |
146 REPORTER_ASSERT(reporter, length == SK_Scalar1 * 6); | 146 REPORTER_ASSERT(reporter, length == SK_Scalar1 * 6); |
147 REPORTER_ASSERT(reporter, meas.getPosTan(SK_ScalarHalf, &position, &tangent)
); | 147 REPORTER_ASSERT(reporter, meas.getPosTan(SK_ScalarHalf, &position, &tangent)
); |
148 REPORTER_ASSERT(reporter, | 148 REPORTER_ASSERT(reporter, |
149 SkScalarNearlyEqual(position.fX, | 149 SkScalarNearlyEqual(position.fX, |
150 SK_ScalarHalf, | 150 SK_ScalarHalf, |
151 SkFloatToScalar(0.0001f))); | 151 0.0001f)); |
152 REPORTER_ASSERT(reporter, position.fY == 0); | 152 REPORTER_ASSERT(reporter, position.fY == 0); |
153 REPORTER_ASSERT(reporter, tangent.fX == SK_Scalar1); | 153 REPORTER_ASSERT(reporter, tangent.fX == SK_Scalar1); |
154 REPORTER_ASSERT(reporter, tangent.fY == 0); | 154 REPORTER_ASSERT(reporter, tangent.fY == 0); |
155 REPORTER_ASSERT(reporter, meas.getPosTan(SkFloatToScalar(2.5f), &position, &
tangent)); | 155 REPORTER_ASSERT(reporter, meas.getPosTan(2.5f, &position, &tangent)); |
156 REPORTER_ASSERT(reporter, | 156 REPORTER_ASSERT(reporter, |
157 SkScalarNearlyEqual(position.fX, SK_Scalar1, SkFloatToScalar(0.0001f))); | 157 SkScalarNearlyEqual(position.fX, SK_Scalar1, 0.0001f)); |
158 REPORTER_ASSERT(reporter, | 158 REPORTER_ASSERT(reporter, |
159 SkScalarNearlyEqual(position.fY, SkFloatToScalar(1.5f))); | 159 SkScalarNearlyEqual(position.fY, 1.5f)); |
160 REPORTER_ASSERT(reporter, tangent.fX == 0); | 160 REPORTER_ASSERT(reporter, tangent.fX == 0); |
161 REPORTER_ASSERT(reporter, tangent.fY == SK_Scalar1); | 161 REPORTER_ASSERT(reporter, tangent.fY == SK_Scalar1); |
162 REPORTER_ASSERT(reporter, meas.getPosTan(SkFloatToScalar(4.5f), &position, &
tangent)); | 162 REPORTER_ASSERT(reporter, meas.getPosTan(4.5f, &position, &tangent)); |
163 REPORTER_ASSERT(reporter, | 163 REPORTER_ASSERT(reporter, |
164 SkScalarNearlyEqual(position.fX, | 164 SkScalarNearlyEqual(position.fX, |
165 SkFloatToScalar(2.5f), | 165 2.5f, |
166 SkFloatToScalar(0.0001f))); | 166 0.0001f)); |
167 REPORTER_ASSERT(reporter, | 167 REPORTER_ASSERT(reporter, |
168 SkScalarNearlyEqual(position.fY, | 168 SkScalarNearlyEqual(position.fY, |
169 SkFloatToScalar(2.0f), | 169 2.0f, |
170 SkFloatToScalar(0.0001f))); | 170 0.0001f)); |
171 REPORTER_ASSERT(reporter, tangent.fX == SK_Scalar1); | 171 REPORTER_ASSERT(reporter, tangent.fX == SK_Scalar1); |
172 REPORTER_ASSERT(reporter, tangent.fY == 0); | 172 REPORTER_ASSERT(reporter, tangent.fY == 0); |
173 | 173 |
174 path.reset(); | 174 path.reset(); |
175 path.moveTo(0, 0); | 175 path.moveTo(0, 0); |
176 path.lineTo(SK_Scalar1, 0); | 176 path.lineTo(SK_Scalar1, 0); |
177 path.moveTo(SK_Scalar1, SK_Scalar1); | 177 path.moveTo(SK_Scalar1, SK_Scalar1); |
178 path.moveTo(SK_Scalar1 * 2, SK_Scalar1 * 2); | 178 path.moveTo(SK_Scalar1 * 2, SK_Scalar1 * 2); |
179 path.lineTo(SK_Scalar1, SK_Scalar1 * 2); | 179 path.lineTo(SK_Scalar1, SK_Scalar1 * 2); |
180 meas.setPath(&path, false); | 180 meas.setPath(&path, false); |
181 length = meas.getLength(); | 181 length = meas.getLength(); |
182 REPORTER_ASSERT(reporter, length == SK_Scalar1); | 182 REPORTER_ASSERT(reporter, length == SK_Scalar1); |
183 REPORTER_ASSERT(reporter, meas.getPosTan(SK_ScalarHalf, &position, &tangent)
); | 183 REPORTER_ASSERT(reporter, meas.getPosTan(SK_ScalarHalf, &position, &tangent)
); |
184 REPORTER_ASSERT(reporter, | 184 REPORTER_ASSERT(reporter, |
185 SkScalarNearlyEqual(position.fX, | 185 SkScalarNearlyEqual(position.fX, |
186 SK_ScalarHalf, | 186 SK_ScalarHalf, |
187 SkFloatToScalar(0.0001f))); | 187 0.0001f)); |
188 REPORTER_ASSERT(reporter, position.fY == 0); | 188 REPORTER_ASSERT(reporter, position.fY == 0); |
189 REPORTER_ASSERT(reporter, tangent.fX == SK_Scalar1); | 189 REPORTER_ASSERT(reporter, tangent.fX == SK_Scalar1); |
190 REPORTER_ASSERT(reporter, tangent.fY == 0); | 190 REPORTER_ASSERT(reporter, tangent.fY == 0); |
191 meas.nextContour(); | 191 meas.nextContour(); |
192 length = meas.getLength(); | 192 length = meas.getLength(); |
193 REPORTER_ASSERT(reporter, length == SK_Scalar1); | 193 REPORTER_ASSERT(reporter, length == SK_Scalar1); |
194 REPORTER_ASSERT(reporter, meas.getPosTan(SK_ScalarHalf, &position, &tangent)
); | 194 REPORTER_ASSERT(reporter, meas.getPosTan(SK_ScalarHalf, &position, &tangent)
); |
195 REPORTER_ASSERT(reporter, | 195 REPORTER_ASSERT(reporter, |
196 SkScalarNearlyEqual(position.fX, | 196 SkScalarNearlyEqual(position.fX, |
197 SkFloatToScalar(1.5f), | 197 1.5f, |
198 SkFloatToScalar(0.0001f))); | 198 0.0001f)); |
199 REPORTER_ASSERT(reporter, | 199 REPORTER_ASSERT(reporter, |
200 SkScalarNearlyEqual(position.fY, | 200 SkScalarNearlyEqual(position.fY, |
201 SkFloatToScalar(2.0f), | 201 2.0f, |
202 SkFloatToScalar(0.0001f))); | 202 0.0001f)); |
203 REPORTER_ASSERT(reporter, tangent.fX == -SK_Scalar1); | 203 REPORTER_ASSERT(reporter, tangent.fX == -SK_Scalar1); |
204 REPORTER_ASSERT(reporter, tangent.fY == 0); | 204 REPORTER_ASSERT(reporter, tangent.fY == 0); |
205 | 205 |
206 test_small_segment(); | 206 test_small_segment(); |
207 test_small_segment2(); | 207 test_small_segment2(); |
208 test_small_segment3(); | 208 test_small_segment3(); |
209 } | 209 } |
210 | 210 |
211 #include "TestClassDef.h" | 211 #include "TestClassDef.h" |
212 DEFINE_TESTCLASS("PathMeasure", PathMeasureTestClass, TestPathMeasure) | 212 DEFINE_TESTCLASS("PathMeasure", PathMeasureTestClass, TestPathMeasure) |
OLD | NEW |