#ifndef AffineTransform_h
#define AffineTransform_h
#include "platform/transforms/TransformationMatrix.h"
#include <string.h>
#include "wtf/FastAllocBase.h"
namespace WebCore {
class FloatPoint;
class FloatQuad;
class FloatRect;
class IntPoint;
class IntRect;
class TransformationMatrix;
class PLATFORM_EXPORT AffineTransform {
WTF_MAKE_FAST_ALLOCATED;
public:
typedef double Transform[6];
AffineTransform();
AffineTransform(double a, double b, double c, double d, double e, double f);
void setMatrix(double a, double b, double c, double d, double e, double f);
void map(double x, double y, double& x2, double& y2) const;
IntPoint mapPoint(const IntPoint&) const;
FloatPoint mapPoint(const FloatPoint&) const;
IntSize mapSize(const IntSize&) const;
FloatSize mapSize(const FloatSize&) const;
IntRect mapRect(const IntRect&) const;
FloatRect mapRect(const FloatRect&) const;
FloatQuad mapQuad(const FloatQuad&) const;
bool isIdentity() const;
double a() const { return m_transform[0]; }
void setA(double a) { m_transform[0] = a; }
double b() const { return m_transform[1]; }
void setB(double b) { m_transform[1] = b; }
double c() const { return m_transform[2]; }
void setC(double c) { m_transform[2] = c; }
double d() const { return m_transform[3]; }
void setD(double d) { m_transform[3] = d; }
double e() const { return m_transform[4]; }
void setE(double e) { m_transform[4] = e; }
double f() const { return m_transform[5]; }
void setF(double f) { m_transform[5] = f; }
void makeIdentity();
AffineTransform& multiply(const AffineTransform& other);
AffineTransform& scale(double);
AffineTransform& scale(double sx, double sy);
AffineTransform& scaleNonUniform(double sx, double sy);
AffineTransform& rotate(double a);
AffineTransform& rotateRadians(double a);
AffineTransform& rotateFromVector(double x, double y);
AffineTransform& translate(double tx, double ty);
AffineTransform& shear(double sx, double sy);
AffineTransform& flipX();
AffineTransform& flipY();
AffineTransform& skew(double angleX, double angleY);
AffineTransform& skewX(double angle);
AffineTransform& skewY(double angle);
double xScale() const;
double yScale() const;
double det() const;
bool isInvertible() const;
AffineTransform inverse() const;
void blend(const AffineTransform& from, double progress);
TransformationMatrix toTransformationMatrix() const;
bool isIdentityOrTranslation() const
{
return m_transform[0] == 1 && m_transform[1] == 0 && m_transform[2] == 0 && m_transform[3] == 1;
}
bool isIdentityOrTranslationOrFlipped() const
{
return m_transform[0] == 1 && m_transform[1] == 0 && m_transform[2] == 0 && (m_transform[3] == 1 || m_transform[3] == -1);
}
bool preservesAxisAlignment() const
{
return (m_transform[1] == 0 && m_transform[2] == 0) || (m_transform[0] == 0 && m_transform[3] == 0);
}
bool operator== (const AffineTransform& m2) const
{
return (m_transform[0] == m2.m_transform[0]
&& m_transform[1] == m2.m_transform[1]
&& m_transform[2] == m2.m_transform[2]
&& m_transform[3] == m2.m_transform[3]
&& m_transform[4] == m2.m_transform[4]
&& m_transform[5] == m2.m_transform[5]);
}
bool operator!=(const AffineTransform& other) const { return !(*this == other); }
AffineTransform& operator*=(const AffineTransform& t)
{
return multiply(t);
}
AffineTransform operator*(const AffineTransform& t) const
{
AffineTransform result = *this;
result *= t;
return result;
}
static AffineTransform translation(double x, double y)
{
return AffineTransform(1, 0, 0, 1, x, y);
}
typedef struct {
double scaleX, scaleY;
double angle;
double remainderA, remainderB, remainderC, remainderD;
double translateX, translateY;
} DecomposedType;
bool decompose(DecomposedType&) const;
void recompose(const DecomposedType&);
private:
void setMatrix(const Transform m)
{
if (m && m != m_transform)
memcpy(m_transform, m, sizeof(Transform));
}
Transform m_transform;
};
PLATFORM_EXPORT AffineTransform makeMapBetweenRects(const FloatRect& source, const FloatRect& dest);
}
#endif