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