Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(827)

Side by Side Diff: tests/PointTest.cpp

Issue 85463005: remove SkFloatToScalar macro (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: add flag to expose SkFloatToScalar to chromium Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/PathTest.cpp ('k') | tests/RoundRectTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Unit tests for src/core/SkPoint.cpp and its header 8 // Unit tests for src/core/SkPoint.cpp and its header
9 9
10 #include "SkPoint.h" 10 #include "SkPoint.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 if (NULL == reporter) { 77 if (NULL == reporter) {
78 storage = ~storage; 78 storage = ~storage;
79 } 79 }
80 memcpy(&value, &storage, 4); 80 memcpy(&value, &storage, 4);
81 return value; 81 return value;
82 } 82 }
83 83
84 // test that we handle very large values correctly. i.e. that we can 84 // test that we handle very large values correctly. i.e. that we can
85 // successfully normalize something whose mag overflows a float. 85 // successfully normalize something whose mag overflows a float.
86 static void test_overflow(skiatest::Reporter* reporter) { 86 static void test_overflow(skiatest::Reporter* reporter) {
87 SkScalar bigFloat = get_value(reporter, SkFloatToScalar(3.4e38f)); 87 SkScalar bigFloat = get_value(reporter, 3.4e38f);
88 SkPoint pt = { bigFloat, bigFloat }; 88 SkPoint pt = { bigFloat, bigFloat };
89 89
90 SkScalar length = pt.length(); 90 SkScalar length = pt.length();
91 length = force_as_float(reporter, length); 91 length = force_as_float(reporter, length);
92 92
93 // expect this to be non-finite, but dump the results if not. 93 // expect this to be non-finite, but dump the results if not.
94 if (SkScalarIsFinite(length)) { 94 if (SkScalarIsFinite(length)) {
95 SkDebugf("length(%g, %g) == %g\n", pt.fX, pt.fY, length); 95 SkDebugf("length(%g, %g) == %g\n", pt.fX, pt.fY, length);
96 REPORTER_ASSERT(reporter, !SkScalarIsFinite(length)); 96 REPORTER_ASSERT(reporter, !SkScalarIsFinite(length));
97 } 97 }
98 98
99 // this should succeed, even though we can't represent length 99 // this should succeed, even though we can't represent length
100 REPORTER_ASSERT(reporter, pt.setLength(SK_Scalar1)); 100 REPORTER_ASSERT(reporter, pt.setLength(SK_Scalar1));
101 101
102 // now that pt is normalized, we check its length 102 // now that pt is normalized, we check its length
103 length = pt.length(); 103 length = pt.length();
104 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(length, SK_Scalar1)); 104 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(length, SK_Scalar1));
105 } 105 }
106 106
107 // test that we handle very small values correctly. i.e. that we can 107 // test that we handle very small values correctly. i.e. that we can
108 // report failure if we try to normalize them. 108 // report failure if we try to normalize them.
109 static void test_underflow(skiatest::Reporter* reporter) { 109 static void test_underflow(skiatest::Reporter* reporter) {
110 SkPoint pt = { SkFloatToScalar(1.0e-37f), SkFloatToScalar(1.0e-37f) }; 110 SkPoint pt = { 1.0e-37f, 1.0e-37f };
111 SkPoint copy = pt; 111 SkPoint copy = pt;
112 112
113 REPORTER_ASSERT(reporter, 0 == SkPoint::Normalize(&pt)); 113 REPORTER_ASSERT(reporter, 0 == SkPoint::Normalize(&pt));
114 REPORTER_ASSERT(reporter, pt == copy); // pt is unchanged 114 REPORTER_ASSERT(reporter, pt == copy); // pt is unchanged
115 115
116 REPORTER_ASSERT(reporter, !pt.setLength(SK_Scalar1)); 116 REPORTER_ASSERT(reporter, !pt.setLength(SK_Scalar1));
117 REPORTER_ASSERT(reporter, pt == copy); // pt is unchanged 117 REPORTER_ASSERT(reporter, pt == copy); // pt is unchanged
118 } 118 }
119 119
120 #include "TestClassDef.h" 120 #include "TestClassDef.h"
121 DEF_TEST(Point, reporter) { 121 DEF_TEST(Point, reporter) {
122 test_casts(reporter); 122 test_casts(reporter);
123 123
124 static const struct { 124 static const struct {
125 SkScalar fX; 125 SkScalar fX;
126 SkScalar fY; 126 SkScalar fY;
127 SkScalar fLength; 127 SkScalar fLength;
128 } gRec[] = { 128 } gRec[] = {
129 { SkIntToScalar(3), SkIntToScalar(4), SkIntToScalar(5) }, 129 { SkIntToScalar(3), SkIntToScalar(4), SkIntToScalar(5) },
130 { SkFloatToScalar(0.6f), SkFloatToScalar(0.8f), SK_Scalar1 }, 130 { 0.6f, 0.8f, SK_Scalar1 },
131 }; 131 };
132 132
133 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { 133 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
134 test_length(reporter, gRec[i].fX, gRec[i].fY, gRec[i].fLength); 134 test_length(reporter, gRec[i].fX, gRec[i].fY, gRec[i].fLength);
135 } 135 }
136 136
137 test_underflow(reporter); 137 test_underflow(reporter);
138 test_overflow(reporter); 138 test_overflow(reporter);
139 } 139 }
140 140
141 DEF_TEST(Point_setLengthFast, reporter) { 141 DEF_TEST(Point_setLengthFast, reporter) {
142 // Scale a (1,1) point to a bunch of different lengths, 142 // Scale a (1,1) point to a bunch of different lengths,
143 // making sure the slow and fast paths are within 0.1%. 143 // making sure the slow and fast paths are within 0.1%.
144 const float tests[] = { 1.0f, 0.0f, 1.0e-37f, 3.4e38f, 42.0f, 0.00012f }; 144 const float tests[] = { 1.0f, 0.0f, 1.0e-37f, 3.4e38f, 42.0f, 0.00012f };
145 145
146 const SkPoint kOne = {1.0f, 1.0f}; 146 const SkPoint kOne = {1.0f, 1.0f};
147 for (unsigned i = 0; i < SK_ARRAY_COUNT(tests); i++) { 147 for (unsigned i = 0; i < SK_ARRAY_COUNT(tests); i++) {
148 SkPoint slow = kOne, fast = kOne; 148 SkPoint slow = kOne, fast = kOne;
149 149
150 slow.setLength(tests[i]); 150 slow.setLength(tests[i]);
151 fast.setLengthFast(tests[i]); 151 fast.setLengthFast(tests[i]);
152 152
153 if (slow.length() < FLT_MIN && fast.length() < FLT_MIN) continue; 153 if (slow.length() < FLT_MIN && fast.length() < FLT_MIN) continue;
154 154
155 SkScalar ratio = slow.length() / fast.length(); 155 SkScalar ratio = slow.length() / fast.length();
156 REPORTER_ASSERT(reporter, ratio > 0.999f); 156 REPORTER_ASSERT(reporter, ratio > 0.999f);
157 REPORTER_ASSERT(reporter, ratio < 1.001f); 157 REPORTER_ASSERT(reporter, ratio < 1.001f);
158 } 158 }
159 } 159 }
OLDNEW
« no previous file with comments | « tests/PathTest.cpp ('k') | tests/RoundRectTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698