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

Side by Side Diff: src/core/SkMatrix.cpp

Issue 13521006: First pass at Rect Effect (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: renamed isOrthogonal to preservesRightAngles Created 7 years, 8 months 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 | « include/gpu/GrAARectRenderer.h ('k') | src/gpu/GrAARectRenderer.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 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkMatrix.h" 8 #include "SkMatrix.h"
9 #include "Sk64.h" 9 #include "Sk64.h"
10 #include "SkFloatBits.h" 10 #include "SkFloatBits.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 SkScalar mx = fMat[kMScaleX]; 183 SkScalar mx = fMat[kMScaleX];
184 SkScalar my = fMat[kMScaleY]; 184 SkScalar my = fMat[kMScaleY];
185 // if no skew, can just compare scale factors 185 // if no skew, can just compare scale factors
186 if (!(mask & kAffine_Mask)) { 186 if (!(mask & kAffine_Mask)) {
187 return !SkScalarNearlyZero(mx) && SkScalarNearlyEqual(SkScalarAbs(mx), S kScalarAbs(my)); 187 return !SkScalarNearlyZero(mx) && SkScalarNearlyEqual(SkScalarAbs(mx), S kScalarAbs(my));
188 } 188 }
189 SkScalar sx = fMat[kMSkewX]; 189 SkScalar sx = fMat[kMSkewX];
190 SkScalar sy = fMat[kMSkewY]; 190 SkScalar sy = fMat[kMSkewY];
191 191
192 // TODO: I (rphillips) think there should be an || in here (see preservesRig htAngles)
192 // degenerate matrix, non-similarity 193 // degenerate matrix, non-similarity
193 if (SkScalarNearlyZero(mx) && SkScalarNearlyZero(my) 194 if (SkScalarNearlyZero(mx) && SkScalarNearlyZero(my)
194 && SkScalarNearlyZero(sx) && SkScalarNearlyZero(sy)) { 195 && SkScalarNearlyZero(sx) && SkScalarNearlyZero(sy)) {
195 return false; 196 return false;
196 } 197 }
197 198
198 // it has scales and skews, but it could also be rotation, check it out. 199 // it has scales and skews, but it could also be rotation, check it out.
199 SkVector vec[2]; 200 SkVector vec[2];
200 vec[0].set(mx, sx); 201 vec[0].set(mx, sx);
201 vec[1].set(sy, my); 202 vec[1].set(sy, my);
202 203
203 return SkScalarNearlyZero(vec[0].dot(vec[1]), SkScalarSquare(tol)) && 204 return SkScalarNearlyZero(vec[0].dot(vec[1]), SkScalarSquare(tol)) &&
204 SkScalarNearlyEqual(vec[0].lengthSqd(), vec[1].lengthSqd(), 205 SkScalarNearlyEqual(vec[0].lengthSqd(), vec[1].lengthSqd(),
205 SkScalarSquare(tol)); 206 SkScalarSquare(tol));
207 }
208
209 bool SkMatrix::preservesRightAngles(SkScalar tol) const {
210 TypeMask mask = this->getType();
211
212 if (mask <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) {
213 // identity, translate and/or scale
214 return true;
215 }
216 if (mask & kPerspective_Mask) {
217 return false;
218 }
219
220 SkASSERT(mask & kAffine_Mask);
221
222 SkScalar mx = fMat[kMScaleX];
223 SkScalar my = fMat[kMScaleY];
224 SkScalar sx = fMat[kMSkewX];
225 SkScalar sy = fMat[kMSkewY];
226
227 if ((SkScalarNearlyZero(mx) && SkScalarNearlyZero(sx)) ||
228 (SkScalarNearlyZero(my) && SkScalarNearlyZero(sy))) {
229 // degenerate matrix
230 return false;
231 }
232
233 // it has scales and skews, but it could also be rotation, check it out.
234 SkVector vec[2];
235 vec[0].set(mx, sx);
236 vec[1].set(sy, my);
237
238 return SkScalarNearlyZero(vec[0].dot(vec[1]), SkScalarSquare(tol)) &&
239 SkScalarNearlyEqual(vec[0].lengthSqd(), vec[1].lengthSqd(),
240 SkScalarSquare(tol));
206 } 241 }
207 242
208 /////////////////////////////////////////////////////////////////////////////// 243 ///////////////////////////////////////////////////////////////////////////////
209 244
210 void SkMatrix::setTranslate(SkScalar dx, SkScalar dy) { 245 void SkMatrix::setTranslate(SkScalar dx, SkScalar dy) {
211 if (SkScalarToCompareType(dx) || SkScalarToCompareType(dy)) { 246 if (SkScalarToCompareType(dx) || SkScalarToCompareType(dy)) {
212 fMat[kMTransX] = dx; 247 fMat[kMTransX] = dx;
213 fMat[kMTransY] = dy; 248 fMat[kMTransY] = dy;
214 249
215 fMat[kMScaleX] = fMat[kMScaleY] = SK_Scalar1; 250 fMat[kMScaleX] = fMat[kMScaleY] = SK_Scalar1;
(...skipping 1708 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 dst.fLeft *= scale; 1959 dst.fLeft *= scale;
1925 dst.fTop *= scale; 1960 dst.fTop *= scale;
1926 dst.fRight *= scale; 1961 dst.fRight *= scale;
1927 dst.fBottom *= scale; 1962 dst.fBottom *= scale;
1928 } 1963 }
1929 1964
1930 SkIRect idst; 1965 SkIRect idst;
1931 dst.round(&idst); 1966 dst.round(&idst);
1932 return isrc == idst; 1967 return isrc == idst;
1933 } 1968 }
OLDNEW
« no previous file with comments | « include/gpu/GrAARectRenderer.h ('k') | src/gpu/GrAARectRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698