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

Side by Side Diff: ui/gfx/transform.cc

Issue 1883623002: Correct normal computation for inverted polygons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « ui/gfx/transform.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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // MSVC++ requires this to be set before any other includes to get M_PI. 5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 7
8 #include "ui/gfx/transform.h" 8 #include "ui/gfx/transform.h"
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 void Transform::TransformPoint(Point* point) const { 400 void Transform::TransformPoint(Point* point) const {
401 DCHECK(point); 401 DCHECK(point);
402 TransformPointInternal(matrix_, point); 402 TransformPointInternal(matrix_, point);
403 } 403 }
404 404
405 void Transform::TransformPoint(Point3F* point) const { 405 void Transform::TransformPoint(Point3F* point) const {
406 DCHECK(point); 406 DCHECK(point);
407 TransformPointInternal(matrix_, point); 407 TransformPointInternal(matrix_, point);
408 } 408 }
409 409
410 void Transform::TransformVector(Vector3dF* vector) const {
411 DCHECK(vector);
412 TransformVectorInternal(matrix_, vector);
413 }
414
410 bool Transform::TransformPointReverse(Point* point) const { 415 bool Transform::TransformPointReverse(Point* point) const {
411 DCHECK(point); 416 DCHECK(point);
412 417
413 // TODO(sad): Try to avoid trying to invert the matrix. 418 // TODO(sad): Try to avoid trying to invert the matrix.
414 SkMatrix44 inverse(SkMatrix44::kUninitialized_Constructor); 419 SkMatrix44 inverse(SkMatrix44::kUninitialized_Constructor);
415 if (!matrix_.invert(&inverse)) 420 if (!matrix_.invert(&inverse))
416 return false; 421 return false;
417 422
418 TransformPointInternal(inverse, point); 423 TransformPointInternal(inverse, point);
419 return true; 424 return true;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 xform.mapMScalars(p); 518 xform.mapMScalars(p);
514 519
515 if (p[3] != SK_MScalar1 && p[3] != 0.f) { 520 if (p[3] != SK_MScalar1 && p[3] != 0.f) {
516 float w_inverse = SK_MScalar1 / p[3]; 521 float w_inverse = SK_MScalar1 / p[3];
517 point->SetPoint(p[0] * w_inverse, p[1] * w_inverse, p[2] * w_inverse); 522 point->SetPoint(p[0] * w_inverse, p[1] * w_inverse, p[2] * w_inverse);
518 } else { 523 } else {
519 point->SetPoint(p[0], p[1], p[2]); 524 point->SetPoint(p[0], p[1], p[2]);
520 } 525 }
521 } 526 }
522 527
528 void Transform::TransformVectorInternal(const SkMatrix44& xform,
529 Vector3dF* vector) const {
530 if (xform.isIdentity())
531 return;
532
533 SkMScalar p[4] = {SkFloatToMScalar(vector->x()),
534 SkFloatToMScalar(vector->y()),
535 SkFloatToMScalar(vector->z()), 0};
536
537 xform.mapMScalars(p);
538
539 vector->set_x(p[0]);
540 vector->set_y(p[1]);
541 vector->set_z(p[2]);
542 }
543
523 void Transform::TransformPointInternal(const SkMatrix44& xform, 544 void Transform::TransformPointInternal(const SkMatrix44& xform,
524 Point* point) const { 545 Point* point) const {
525 if (xform.isIdentity()) 546 if (xform.isIdentity())
526 return; 547 return;
527 548
528 SkMScalar p[4] = {SkIntToMScalar(point->x()), SkIntToMScalar(point->y()), 549 SkMScalar p[4] = {SkIntToMScalar(point->x()), SkIntToMScalar(point->y()),
529 0, 1}; 550 0, 1};
530 551
531 xform.mapMScalars(p); 552 xform.mapMScalars(p);
532 553
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 matrix_.get(2, 1), 593 matrix_.get(2, 1),
573 matrix_.get(2, 2), 594 matrix_.get(2, 2),
574 matrix_.get(2, 3), 595 matrix_.get(2, 3),
575 matrix_.get(3, 0), 596 matrix_.get(3, 0),
576 matrix_.get(3, 1), 597 matrix_.get(3, 1),
577 matrix_.get(3, 2), 598 matrix_.get(3, 2),
578 matrix_.get(3, 3)); 599 matrix_.get(3, 3));
579 } 600 }
580 601
581 } // namespace gfx 602 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/transform.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698