Bug 1492908 [wpt PR 13122] - Update wpt metadata, a=testonly
[gecko.git] / gfx / src / nsTransform2D.h
blob94a58c2114ee8fd562eb4bc7232ef2f31e4ddd7e
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___
10 #include "nsCoord.h"
12 class nsTransform2D
14 private:
15 /**
16 * This represents the following matrix (note that the order of row/column
17 * indices is opposite to usual notation)
19 * / m00 0 m20 \
20 * M = | 0 m11 m21 |
21 * \ 0 0 1 /
23 * Transformation of a coordinate (x, y) is obtained by setting
24 * v = (x, y, 1)^T and evaluating M . v
25 **/
27 float m00, m11, m20, m21;
29 public:
30 nsTransform2D(void) { m20 = m21 = 0.0f; m00 = m11 = 1.0f; }
32 ~nsTransform2D(void) { }
34 /**
35 * set this transform to a translation
37 * @param tx, x translation
38 * @param ty, y translation
39 **/
41 void SetToTranslate(float tx, float ty) { m00 = m11 = 1.0f; m20 = tx; m21 = ty; }
43 /**
44 * get the translation portion of this transform
46 * @param pt, Point to return translation values in
47 **/
49 void GetTranslationCoord(nscoord *ptX, nscoord *ptY) const { *ptX = NSToCoordRound(m20); *ptY = NSToCoordRound(m21); }
51 /**
52 * apply matrix to vector
54 * @param pt Point to transform
55 **/
57 void TransformCoord(nscoord *ptX, nscoord *ptY) const;
59 /**
60 * apply matrix to rect
62 * @param rect Rect to transform
63 **/
65 void TransformCoord(nscoord *aX, nscoord *aY, nscoord *aWidth, nscoord *aHeight) const;
67 /**
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
72 **/
74 void AddScale(float ptX, float ptY) { m00 *= ptX; m11 *= ptY; }
76 /**
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
82 **/
84 void SetScale(float ptX, float ptY) { m00 = ptX; m11 = ptY; }
87 #endif