michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "Matrix.h" michael@0: #include "Tools.h" michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: Matrix michael@0: Matrix::Rotation(Float aAngle) michael@0: { michael@0: Matrix newMatrix; michael@0: michael@0: Float s = sin(aAngle); michael@0: Float c = cos(aAngle); michael@0: michael@0: newMatrix._11 = c; michael@0: newMatrix._12 = s; michael@0: newMatrix._21 = -s; michael@0: newMatrix._22 = c; michael@0: michael@0: return newMatrix; michael@0: } michael@0: michael@0: Rect michael@0: Matrix::TransformBounds(const Rect &aRect) const michael@0: { michael@0: int i; michael@0: Point quad[4]; michael@0: Float min_x, max_x; michael@0: Float min_y, max_y; michael@0: michael@0: quad[0] = *this * aRect.TopLeft(); michael@0: quad[1] = *this * aRect.TopRight(); michael@0: quad[2] = *this * aRect.BottomLeft(); michael@0: quad[3] = *this * aRect.BottomRight(); michael@0: michael@0: min_x = max_x = quad[0].x; michael@0: min_y = max_y = quad[0].y; michael@0: michael@0: for (i = 1; i < 4; i++) { michael@0: if (quad[i].x < min_x) michael@0: min_x = quad[i].x; michael@0: if (quad[i].x > max_x) michael@0: max_x = quad[i].x; michael@0: michael@0: if (quad[i].y < min_y) michael@0: min_y = quad[i].y; michael@0: if (quad[i].y > max_y) michael@0: max_y = quad[i].y; michael@0: } michael@0: michael@0: return Rect(min_x, min_y, max_x - min_x, max_y - min_y); michael@0: } michael@0: michael@0: void michael@0: Matrix::NudgeToIntegers() michael@0: { michael@0: NudgeToInteger(&_11); michael@0: NudgeToInteger(&_12); michael@0: NudgeToInteger(&_21); michael@0: NudgeToInteger(&_22); michael@0: NudgeToInteger(&_31); michael@0: NudgeToInteger(&_32); michael@0: } michael@0: michael@0: Rect michael@0: Matrix4x4::TransformBounds(const Rect& aRect) const michael@0: { michael@0: Point quad[4]; michael@0: Float min_x, max_x; michael@0: Float min_y, max_y; michael@0: michael@0: quad[0] = *this * aRect.TopLeft(); michael@0: quad[1] = *this * aRect.TopRight(); michael@0: quad[2] = *this * aRect.BottomLeft(); michael@0: quad[3] = *this * aRect.BottomRight(); michael@0: michael@0: min_x = max_x = quad[0].x; michael@0: min_y = max_y = quad[0].y; michael@0: michael@0: for (int i = 1; i < 4; i++) { michael@0: if (quad[i].x < min_x) { michael@0: min_x = quad[i].x; michael@0: } michael@0: if (quad[i].x > max_x) { michael@0: max_x = quad[i].x; michael@0: } michael@0: michael@0: if (quad[i].y < min_y) { michael@0: min_y = quad[i].y; michael@0: } michael@0: if (quad[i].y > max_y) { michael@0: max_y = quad[i].y; michael@0: } michael@0: } michael@0: michael@0: return Rect(min_x, min_y, max_x - min_x, max_y - min_y); michael@0: } michael@0: michael@0: } michael@0: }