1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/2d/Matrix.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,106 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "Matrix.h" 1.10 +#include "Tools.h" 1.11 +#include <math.h> 1.12 + 1.13 +namespace mozilla { 1.14 +namespace gfx { 1.15 + 1.16 +Matrix 1.17 +Matrix::Rotation(Float aAngle) 1.18 +{ 1.19 + Matrix newMatrix; 1.20 + 1.21 + Float s = sin(aAngle); 1.22 + Float c = cos(aAngle); 1.23 + 1.24 + newMatrix._11 = c; 1.25 + newMatrix._12 = s; 1.26 + newMatrix._21 = -s; 1.27 + newMatrix._22 = c; 1.28 + 1.29 + return newMatrix; 1.30 +} 1.31 + 1.32 +Rect 1.33 +Matrix::TransformBounds(const Rect &aRect) const 1.34 +{ 1.35 + int i; 1.36 + Point quad[4]; 1.37 + Float min_x, max_x; 1.38 + Float min_y, max_y; 1.39 + 1.40 + quad[0] = *this * aRect.TopLeft(); 1.41 + quad[1] = *this * aRect.TopRight(); 1.42 + quad[2] = *this * aRect.BottomLeft(); 1.43 + quad[3] = *this * aRect.BottomRight(); 1.44 + 1.45 + min_x = max_x = quad[0].x; 1.46 + min_y = max_y = quad[0].y; 1.47 + 1.48 + for (i = 1; i < 4; i++) { 1.49 + if (quad[i].x < min_x) 1.50 + min_x = quad[i].x; 1.51 + if (quad[i].x > max_x) 1.52 + max_x = quad[i].x; 1.53 + 1.54 + if (quad[i].y < min_y) 1.55 + min_y = quad[i].y; 1.56 + if (quad[i].y > max_y) 1.57 + max_y = quad[i].y; 1.58 + } 1.59 + 1.60 + return Rect(min_x, min_y, max_x - min_x, max_y - min_y); 1.61 +} 1.62 + 1.63 +void 1.64 +Matrix::NudgeToIntegers() 1.65 +{ 1.66 + NudgeToInteger(&_11); 1.67 + NudgeToInteger(&_12); 1.68 + NudgeToInteger(&_21); 1.69 + NudgeToInteger(&_22); 1.70 + NudgeToInteger(&_31); 1.71 + NudgeToInteger(&_32); 1.72 +} 1.73 + 1.74 +Rect 1.75 +Matrix4x4::TransformBounds(const Rect& aRect) const 1.76 +{ 1.77 + Point quad[4]; 1.78 + Float min_x, max_x; 1.79 + Float min_y, max_y; 1.80 + 1.81 + quad[0] = *this * aRect.TopLeft(); 1.82 + quad[1] = *this * aRect.TopRight(); 1.83 + quad[2] = *this * aRect.BottomLeft(); 1.84 + quad[3] = *this * aRect.BottomRight(); 1.85 + 1.86 + min_x = max_x = quad[0].x; 1.87 + min_y = max_y = quad[0].y; 1.88 + 1.89 + for (int i = 1; i < 4; i++) { 1.90 + if (quad[i].x < min_x) { 1.91 + min_x = quad[i].x; 1.92 + } 1.93 + if (quad[i].x > max_x) { 1.94 + max_x = quad[i].x; 1.95 + } 1.96 + 1.97 + if (quad[i].y < min_y) { 1.98 + min_y = quad[i].y; 1.99 + } 1.100 + if (quad[i].y > max_y) { 1.101 + max_y = quad[i].y; 1.102 + } 1.103 + } 1.104 + 1.105 + return Rect(min_x, min_y, max_x - min_x, max_y - min_y); 1.106 +} 1.107 + 1.108 +} 1.109 +}