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

Side by Side Diff: tests/PointTest.cpp

Issue 785933003: change SkPoint::setLength to set itself to (0,0) if it starting length is degenerate (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 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
« no previous file with comments | « src/core/SkPoint.cpp ('k') | no next file » | 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = { 1.0e-37f, 1.0e-37f }; 110 SkPoint pt = { 1.0e-37f, 1.0e-37f };
111 SkPoint copy = pt; 111 const SkPoint empty = { 0, 0 };
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 == empty);
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 == empty);
118 } 118 }
119 119
120 DEF_TEST(Point, reporter) { 120 DEF_TEST(Point, reporter) {
121 test_casts(reporter); 121 test_casts(reporter);
122 122
123 static const struct { 123 static const struct {
124 SkScalar fX; 124 SkScalar fX;
125 SkScalar fY; 125 SkScalar fY;
126 SkScalar fLength; 126 SkScalar fLength;
127 } gRec[] = { 127 } gRec[] = {
(...skipping 21 matching lines...) Expand all
149 slow.setLength(tests[i]); 149 slow.setLength(tests[i]);
150 fast.setLengthFast(tests[i]); 150 fast.setLengthFast(tests[i]);
151 151
152 if (slow.length() < FLT_MIN && fast.length() < FLT_MIN) continue; 152 if (slow.length() < FLT_MIN && fast.length() < FLT_MIN) continue;
153 153
154 SkScalar ratio = slow.length() / fast.length(); 154 SkScalar ratio = slow.length() / fast.length();
155 REPORTER_ASSERT(reporter, ratio > 0.999f); 155 REPORTER_ASSERT(reporter, ratio > 0.999f);
156 REPORTER_ASSERT(reporter, ratio < 1.001f); 156 REPORTER_ASSERT(reporter, ratio < 1.001f);
157 } 157 }
158 } 158 }
OLDNEW
« no previous file with comments | « src/core/SkPoint.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698