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

Side by Side Diff: Source/platform/transforms/AffineTransform.cpp

Issue 166273019: Add rotateRadians function to AffineTransform (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 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
« no previous file with comments | « Source/platform/transforms/AffineTransform.h ('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 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
3 * 2010 Dirk Schulze <krit@webkit.org> 3 * 2010 Dirk Schulze <krit@webkit.org>
4 * Copyright (C) 2013 Google Inc. All rights reserved. 4 * Copyright (C) 2013 Google Inc. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 trans.m_transform[4] = other.m_transform[4] * m_transform[0] + other.m_trans form[5] * m_transform[2] + m_transform[4]; 127 trans.m_transform[4] = other.m_transform[4] * m_transform[0] + other.m_trans form[5] * m_transform[2] + m_transform[4];
128 trans.m_transform[5] = other.m_transform[4] * m_transform[1] + other.m_trans form[5] * m_transform[3] + m_transform[5]; 128 trans.m_transform[5] = other.m_transform[4] * m_transform[1] + other.m_trans form[5] * m_transform[3] + m_transform[5];
129 129
130 setMatrix(trans.m_transform); 130 setMatrix(trans.m_transform);
131 return *this; 131 return *this;
132 } 132 }
133 133
134 AffineTransform& AffineTransform::rotate(double a) 134 AffineTransform& AffineTransform::rotate(double a)
135 { 135 {
136 // angle is in degree. Switch to radian 136 // angle is in degree. Switch to radian
137 a = deg2rad(a); 137 return rotateRadians(deg2rad(a));
138 }
139
140 AffineTransform& AffineTransform::rotateRadians(double a)
141 {
138 double cosAngle = cos(a); 142 double cosAngle = cos(a);
139 double sinAngle = sin(a); 143 double sinAngle = sin(a);
140 AffineTransform rot(cosAngle, sinAngle, -sinAngle, cosAngle, 0, 0); 144 AffineTransform rot(cosAngle, sinAngle, -sinAngle, cosAngle, 0, 0);
141 145
142 multiply(rot); 146 multiply(rot);
143 return *this; 147 return *this;
144 } 148 }
145 149
146 AffineTransform& AffineTransform::scale(double s) 150 AffineTransform& AffineTransform::scale(double s)
147 { 151 {
(...skipping 23 matching lines...) Expand all
171 return *this; 175 return *this;
172 } 176 }
173 177
174 AffineTransform& AffineTransform::scaleNonUniform(double sx, double sy) 178 AffineTransform& AffineTransform::scaleNonUniform(double sx, double sy)
175 { 179 {
176 return scale(sx, sy); 180 return scale(sx, sy);
177 } 181 }
178 182
179 AffineTransform& AffineTransform::rotateFromVector(double x, double y) 183 AffineTransform& AffineTransform::rotateFromVector(double x, double y)
180 { 184 {
181 return rotate(rad2deg(atan2(y, x))); 185 return rotateRadians(atan2(y, x));
182 } 186 }
183 187
184 AffineTransform& AffineTransform::flipX() 188 AffineTransform& AffineTransform::flipX()
185 { 189 {
186 return scale(-1, 1); 190 return scale(-1, 1);
187 } 191 }
188 192
189 AffineTransform& AffineTransform::flipY() 193 AffineTransform& AffineTransform::flipY()
190 { 194 {
191 return scale(1, -1); 195 return scale(1, -1);
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 sy = -sy; 369 sy = -sy;
366 } 370 }
367 371
368 // Remove scale from matrix 372 // Remove scale from matrix
369 m.scale(1 / sx, 1 / sy); 373 m.scale(1 / sx, 1 / sy);
370 374
371 // Compute rotation 375 // Compute rotation
372 double angle = atan2(m.b(), m.a()); 376 double angle = atan2(m.b(), m.a());
373 377
374 // Remove rotation from matrix 378 // Remove rotation from matrix
375 m.rotate(rad2deg(-angle)); 379 m.rotateRadians(-angle);
376 380
377 // Return results 381 // Return results
378 decomp.scaleX = sx; 382 decomp.scaleX = sx;
379 decomp.scaleY = sy; 383 decomp.scaleY = sy;
380 decomp.angle = angle; 384 decomp.angle = angle;
381 decomp.remainderA = m.a(); 385 decomp.remainderA = m.a();
382 decomp.remainderB = m.b(); 386 decomp.remainderB = m.b();
383 decomp.remainderC = m.c(); 387 decomp.remainderC = m.c();
384 decomp.remainderD = m.d(); 388 decomp.remainderD = m.d();
385 decomp.translateX = m.e(); 389 decomp.translateX = m.e();
386 decomp.translateY = m.f(); 390 decomp.translateY = m.f();
387 391
388 return true; 392 return true;
389 } 393 }
390 394
391 void AffineTransform::recompose(const DecomposedType& decomp) 395 void AffineTransform::recompose(const DecomposedType& decomp)
392 { 396 {
393 this->setA(decomp.remainderA); 397 this->setA(decomp.remainderA);
394 this->setB(decomp.remainderB); 398 this->setB(decomp.remainderB);
395 this->setC(decomp.remainderC); 399 this->setC(decomp.remainderC);
396 this->setD(decomp.remainderD); 400 this->setD(decomp.remainderD);
397 this->setE(decomp.translateX); 401 this->setE(decomp.translateX);
398 this->setF(decomp.translateY); 402 this->setF(decomp.translateY);
399 this->rotate(rad2deg(decomp.angle)); 403 this->rotateRadians(decomp.angle);
400 this->scale(decomp.scaleX, decomp.scaleY); 404 this->scale(decomp.scaleX, decomp.scaleY);
401 } 405 }
402 406
403 } 407 }
OLDNEW
« no previous file with comments | « Source/platform/transforms/AffineTransform.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698