1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsTransform2D_h___
8 #define nsTransform2D_h___
16 * This represents the following matrix (note that the order of row/column
17 * indices is opposite to usual notation)
23 * Transformation of a coordinate (x, y) is obtained by setting
24 * v = (x, y, 1)^T and evaluating M . v
27 float m00
, m11
, m20
, m21
;
30 nsTransform2D(void) { m20
= m21
= 0.0f
; m00
= m11
= 1.0f
; }
32 ~nsTransform2D(void) { }
35 * set this transform to a translation
37 * @param tx, x translation
38 * @param ty, y translation
41 void SetToTranslate(float tx
, float ty
) { m00
= m11
= 1.0f
; m20
= tx
; m21
= ty
; }
44 * get the translation portion of this transform
46 * @param pt, Point to return translation values in
49 void GetTranslationCoord(nscoord
*ptX
, nscoord
*ptY
) const { *ptX
= NSToCoordRound(m20
); *ptY
= NSToCoordRound(m21
); }
52 * apply matrix to vector
54 * @param pt Point to transform
57 void TransformCoord(nscoord
*ptX
, nscoord
*ptY
) const;
60 * apply matrix to rect
62 * @param rect Rect to transform
65 void TransformCoord(nscoord
*aX
, nscoord
*aY
, nscoord
*aWidth
, nscoord
*aHeight
) const;
68 * add a scale to a Transform via x, y pair
70 * @param ptX x value to add as x scale
71 * @param ptY y value to add as y scale
74 void AddScale(float ptX
, float ptY
) { m00
*= ptX
; m11
*= ptY
; }
77 * Set the scale (overriding any previous calls to AddScale, but leaving
78 * any existing translation).
80 * @param ptX x value to add as x scale
81 * @param ptY y value to add as y scale
84 void SetScale(float ptX
, float ptY
) { m00
= ptX
; m11
= ptY
; }