mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
9
This commit is contained in:
@ -29,36 +29,46 @@
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#include "Matrix.h"
|
||||
#include "Matrix_private.h"
|
||||
|
||||
namespace Aggplus
|
||||
{
|
||||
CMatrix::CMatrix(double m11, double m12, double m21, double m22, double dx, double dy) : m_agg_mtx(m11, m12, m21, m22, dx, dy)
|
||||
CMatrix::CMatrix(double m11, double m12, double m21, double m22, double dx, double dy)
|
||||
{
|
||||
m_internal = new CMatrix_private();
|
||||
m_internal->m_agg_mtx.sx = m11;
|
||||
m_internal->m_agg_mtx.shy = m12;
|
||||
m_internal->m_agg_mtx.shx = m21;
|
||||
m_internal->m_agg_mtx.sy = m22;
|
||||
m_internal->m_agg_mtx.tx = dx;
|
||||
m_internal->m_agg_mtx.ty = dy;
|
||||
}
|
||||
|
||||
CMatrix::CMatrix(const CMatrix& oSrc) : m_agg_mtx()
|
||||
CMatrix::CMatrix(const CMatrix& oSrc)
|
||||
{
|
||||
m_agg_mtx = oSrc.m_agg_mtx;
|
||||
m_internal = new CMatrix_private();
|
||||
m_internal->m_agg_mtx = oSrc.m_internal->m_agg_mtx;
|
||||
}
|
||||
|
||||
CMatrix::CMatrix() : m_agg_mtx()
|
||||
CMatrix::CMatrix()
|
||||
{
|
||||
m_internal = new CMatrix_private();
|
||||
}
|
||||
|
||||
CMatrix::~CMatrix()
|
||||
{
|
||||
RELEASEOBJECT(m_internal);
|
||||
}
|
||||
|
||||
void CMatrix::Translate(double offsetX, double offsetY, MatrixOrder order)
|
||||
{
|
||||
if (order == MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(agg::trans_affine_translation(offsetX, offsetY));
|
||||
m_internal->m_agg_mtx.premultiply(agg::trans_affine_translation(offsetX, offsetY));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(agg::trans_affine_translation(offsetX, offsetY));
|
||||
m_internal->m_agg_mtx.multiply(agg::trans_affine_translation(offsetX, offsetY));
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,11 +76,11 @@ namespace Aggplus
|
||||
{
|
||||
if (order == MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(agg::trans_affine_scaling(scaleX, scaleY));
|
||||
m_internal->m_agg_mtx.premultiply(agg::trans_affine_scaling(scaleX, scaleY));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(agg::trans_affine_scaling(scaleX, scaleY));
|
||||
m_internal->m_agg_mtx.multiply(agg::trans_affine_scaling(scaleX, scaleY));
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,36 +88,36 @@ namespace Aggplus
|
||||
{
|
||||
if (order == MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(agg::trans_affine_skewing(shearX, shearY));
|
||||
m_internal->m_agg_mtx.premultiply(agg::trans_affine_skewing(shearX, shearY));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(agg::trans_affine_skewing(shearX, shearY));
|
||||
m_internal->m_agg_mtx.multiply(agg::trans_affine_skewing(shearX, shearY));
|
||||
}
|
||||
}
|
||||
|
||||
void CMatrix::TransformVectors(PointF* pts, int count)
|
||||
{
|
||||
// Store matrix to an array [6] of double
|
||||
double M[6]; m_agg_mtx.store_to(M);
|
||||
double M[6]; m_internal->m_agg_mtx.store_to(M);
|
||||
|
||||
for(int i = 0; i < count; ++i)
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
double x =pts[i].X;
|
||||
double y =pts[i].Y;
|
||||
m_agg_mtx.transform(&x, &y);
|
||||
pts[i].X =(float)(x-M[4]);
|
||||
pts[i].Y =(float)(y-M[5]);
|
||||
double x = pts[i].X;
|
||||
double y = pts[i].Y;
|
||||
m_internal->m_agg_mtx.transform(&x, &y);
|
||||
pts[i].X = (float)(x-M[4]);
|
||||
pts[i].Y = (float)(y-M[5]);
|
||||
}
|
||||
}
|
||||
|
||||
void CMatrix::TransformPoints(PointF* pts, int count)
|
||||
{
|
||||
for(int i = 0; i < count; ++i)
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
double x = pts[i].X;
|
||||
double y = pts[i].Y;
|
||||
m_agg_mtx.transform(&x, &y);
|
||||
m_internal->m_agg_mtx.transform(&x, &y);
|
||||
pts[i].X = (float)x;
|
||||
pts[i].Y = (float)y;
|
||||
}
|
||||
@ -115,18 +125,18 @@ namespace Aggplus
|
||||
|
||||
void CMatrix::TransformPoint(double& x, double& y)
|
||||
{
|
||||
m_agg_mtx.transform(&x, &y);
|
||||
m_internal->m_agg_mtx.transform(&x, &y);
|
||||
}
|
||||
|
||||
void CMatrix::Rotate(double angle, MatrixOrder order)
|
||||
{
|
||||
if (order == MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
m_internal->m_agg_mtx.premultiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
m_internal->m_agg_mtx.multiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,11 +145,11 @@ namespace Aggplus
|
||||
Translate(-center.X, -center.Y, order);
|
||||
if(order == MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
m_internal->m_agg_mtx.premultiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
m_internal->m_agg_mtx.multiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
}
|
||||
Translate(center.X, center.Y, order);
|
||||
return;
|
||||
@ -150,11 +160,11 @@ namespace Aggplus
|
||||
Translate(-x, -y, order);
|
||||
if (order == MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
m_internal->m_agg_mtx.premultiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
m_internal->m_agg_mtx.multiply(agg::trans_affine_rotation(agg::deg2rad(angle)));
|
||||
}
|
||||
Translate(x, y, order);
|
||||
}
|
||||
@ -163,28 +173,26 @@ namespace Aggplus
|
||||
{
|
||||
if (order == MatrixOrderPrepend)
|
||||
{
|
||||
m_agg_mtx.premultiply(matrix->m_agg_mtx);
|
||||
m_internal->m_agg_mtx.premultiply(matrix->m_internal->m_agg_mtx);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_agg_mtx.multiply(matrix->m_agg_mtx);
|
||||
m_internal->m_agg_mtx.multiply(matrix->m_internal->m_agg_mtx);
|
||||
}
|
||||
}
|
||||
|
||||
double CMatrix::OffsetX() const
|
||||
{
|
||||
double M[6]; m_agg_mtx.store_to(M);
|
||||
return (M[4]);
|
||||
return m_internal->m_agg_mtx.tx;
|
||||
}
|
||||
double CMatrix::OffsetY() const
|
||||
{
|
||||
double M[6]; m_agg_mtx.store_to(M);
|
||||
return (M[5]);
|
||||
return m_internal->m_agg_mtx.ty;
|
||||
}
|
||||
|
||||
Status CMatrix::GetElements(REAL* m) const
|
||||
{
|
||||
double M[6]; m_agg_mtx.store_to(M);
|
||||
double M[6]; m_internal->m_agg_mtx.store_to(M);
|
||||
m[0]=(REAL)M[0];
|
||||
m[1]=(REAL)M[1];
|
||||
m[2]=(REAL)M[2];
|
||||
@ -196,28 +204,28 @@ namespace Aggplus
|
||||
|
||||
Status CMatrix::GetElements(double* m) const
|
||||
{
|
||||
m_agg_mtx.store_to(m);
|
||||
m_internal->m_agg_mtx.store_to(m);
|
||||
return Ok;
|
||||
}
|
||||
|
||||
void CMatrix::Reset()
|
||||
{
|
||||
m_agg_mtx.reset();
|
||||
m_internal->m_agg_mtx.reset();
|
||||
}
|
||||
|
||||
const CMatrix& CMatrix::operator=(const CMatrix& Src)
|
||||
{
|
||||
m_agg_mtx = Src.m_agg_mtx;
|
||||
return *this;
|
||||
m_internal->m_agg_mtx = Src.m_internal->m_agg_mtx;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Status CMatrix::Invert()
|
||||
{
|
||||
double d = m_agg_mtx.determinant();
|
||||
double d = m_internal->m_agg_mtx.determinant();
|
||||
if (0.0001 >= fabs(d))
|
||||
return InvalidParameter;
|
||||
|
||||
m_agg_mtx.invert();
|
||||
m_internal->m_agg_mtx.invert();
|
||||
return Ok;
|
||||
}
|
||||
|
||||
@ -225,15 +233,16 @@ namespace Aggplus
|
||||
//Used in X_BrushLinearGradient constructor
|
||||
double CMatrix::z_Rotation() const
|
||||
{
|
||||
return agg::rad2deg(m_agg_mtx.rotation());
|
||||
return agg::rad2deg(m_internal->m_agg_mtx.rotation());
|
||||
}
|
||||
|
||||
void CMatrix::TransformPoints( PointF* dst, const PointF* src, int count ) const
|
||||
void CMatrix::TransformPoints( PointF* dst, const PointF* src, int count )
|
||||
{
|
||||
agg::trans_affine& m = m_internal->m_agg_mtx;
|
||||
for(int i = 0; i < count; ++i)
|
||||
{
|
||||
double x = src[i].X * m_agg_mtx.sx + src[i].Y * m_agg_mtx.shx + m_agg_mtx.tx;
|
||||
double y = src[i].Y * m_agg_mtx.sy + src[i].X * m_agg_mtx.shy + m_agg_mtx.ty;
|
||||
double x = src[i].X * m.sx + src[i].Y * m.shx + m.tx;
|
||||
double y = src[i].Y * m.sy + src[i].X * m.shy + m.ty;
|
||||
|
||||
dst[i].X = (float)x;
|
||||
dst[i].Y = (float)y;
|
||||
@ -242,13 +251,14 @@ namespace Aggplus
|
||||
|
||||
bool CMatrix::IsIdentity() const
|
||||
{
|
||||
return m_agg_mtx.is_identity();
|
||||
return m_internal->m_agg_mtx.is_identity();
|
||||
}
|
||||
bool CMatrix::IsIdentity2() const
|
||||
{
|
||||
return agg::is_equal_eps(m_agg_mtx.sx, 1.0, agg::affine_epsilon) &&
|
||||
agg::is_equal_eps(m_agg_mtx.shy, 0.0, agg::affine_epsilon) &&
|
||||
agg::is_equal_eps(m_agg_mtx.shx, 0.0, agg::affine_epsilon) &&
|
||||
agg::is_equal_eps(m_agg_mtx.sy, 1.0, agg::affine_epsilon);
|
||||
agg::trans_affine& m = m_internal->m_agg_mtx;
|
||||
return agg::is_equal_eps(m.sx, 1.0, agg::affine_epsilon) &&
|
||||
agg::is_equal_eps(m.shy, 0.0, agg::affine_epsilon) &&
|
||||
agg::is_equal_eps(m.shx, 0.0, agg::affine_epsilon) &&
|
||||
agg::is_equal_eps(m.sy, 1.0, agg::affine_epsilon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user