forked from chrvadala/transformation-matrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransformation-matrix.d.ts
264 lines (226 loc) · 9.19 KB
/
transformation-matrix.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
declare module 'transformation-matrix' {
type Matrix = {
a: number;
b: number;
c: number;
d: number;
e: number;
f: number;
};
type MatrixDescriptor =
| { type: 'matrix', a: number, b: number, c: number, d: number, e: number, f: number }
| { type: 'translate', tx: number, ty: number }
| { type: 'scale', sx: number, sy: number }
| { type: 'rotate', angle: number, sx: number, sy: number }
| { type: 'skewX', angle: number }
| { type: 'skewY', angle: number }
| { type: 'shear', shx: number, shy: number}
type Point = { x: number; y: number } | [number, number];
export { Point, Matrix, MatrixDescriptor };
}
declare module 'transformation-matrix/applyToPoint' {
import { Point, Matrix } from 'transformation-matrix';
/** Calculate a point transformed with an affine matrix */
export function applyToPoint(matrix: Matrix, point: Point): Point;
/** Calculate an array of points transformed with an affine matrix */
export function applyToPoints(matrix: Matrix, points: Point[]): Point[];
}
declare module 'transformation-matrix/fromString' {
import { Matrix } from 'transformation-matrix';
/** Parse a string matrix formatted as `matrix(a,b,c,d,e,f)` */
export function fromString(str: string): Matrix;
}
declare module 'transformation-matrix/fromObject' {
import { Point, Matrix } from 'transformation-matrix';
/**
* Extract an affine matrix from an object that contains a,b,c,d,e,f keys.
* Each value could be a float or a string that contains a float
*/
export function fromObject(object: {
a: string | number;
b: string | number;
c: string | number;
d: string | number;
e: string | number;
f: string | number;
}): Matrix;
}
declare module 'transformation-matrix/identity' {
import { Matrix } from 'transformation-matrix';
/** Identity matrix */
export function identity(): Matrix;
}
declare module 'transformation-matrix/inverse' {
import { Matrix } from 'transformation-matrix';
/** Calculate a matrix that is the inverse of the provided matrix */
export function inverse(matrix: Matrix): Matrix;
}
declare module 'transformation-matrix/isAffineMatrix' {
import { Matrix } from 'transformation-matrix';
/** Check if the object contain an affine matrix */
export function isAffineMatrix(obj: object): boolean;
}
declare module 'transformation-matrix/rotate' {
import { Matrix } from 'transformation-matrix';
/**
* Calculate a rotation matrix
* @param angle Angle in radians
* @param cx If (cx,cy) are supplied the rotate is about this point
* @param cy If (cx,cy) are supplied the rotate is about this point
*/
export function rotate(angle: number, cx?: number, cy?: number): Matrix;
/** Calculate a rotation matrix with a DEG angle
* @param angle Angle in degree
* @param cx If (cx,cy) are supplied the rotate is about this point
* @param cy If (cx,cy) are supplied the rotate is about this point*/
export function rotateDEG(angle: number, cx?: number, cy?: number): Matrix;
}
declare module 'transformation-matrix/scale' {
import { Matrix } from 'transformation-matrix';
/**
* Calculate a scaling matrix
* @param sx Scaling on axis x
* @param sy Scaling on axis y (default `sx`)
*/
export function scale(sx: number, sy?: number): Matrix;
}
declare module 'transformation-matrix/shear' {
import { Matrix } from 'transformation-matrix';
/** Calculate a shear matrix */
export function shear(shx: number, shy: number): Matrix;
}
declare module 'transformation-matrix/skew' {
import { Matrix } from 'transformation-matrix';
/** Calculate a skew matrix */
export function skew(ax: number, ay: number): Matrix;
}
declare module 'transformation-matrix/toString' {
import { Matrix } from 'transformation-matrix';
/**
* Serialize the matrix to a string that can be used with CSS or SVG
* @returns {string} String that contains a matrix formatted as `matrix(a,b,c,d,e,f)`
*/
export function toSVG(matrix: Matrix): string;
/**
* Serialize the matrix to a string that can be used with CSS or SVG
* @returns {string} String that contains a matrix formatted as `matrix(a,b,c,d,e,f)`
*/
export function toCSS(matrix: Matrix): string;
/**
* Serialize the matrix to a string that can be used with CSS or SVG
* @returns {string} String that contains a matrix formatted as `matrix(a,b,c,d,e,f)`
*/
export function toString(matrix: Matrix): string;
}
declare module 'transformation-matrix/transform' {
import { Matrix } from 'transformation-matrix';
/** Merge multiple matrices into one */
export function transform(matrices: Matrix[]): Matrix;
export function transform(...matrices: Matrix[]): Matrix;
/** Merge multiple matrices into one */
export function compose(matrices: Matrix[]): Matrix;
export function compose(...matrices: Matrix[]): Matrix;
}
declare module 'transformation-matrix/translate' {
import { Matrix } from 'transformation-matrix';
/**
* Calculate a translate matrix
* @param tx Translation on axis x
* @param ty Translation on axis y (default `0`)
*/
export function translate(tx: number, ty?: number): Matrix;
}
declare module 'transformation-matrix/fromTriangles' {
import { Point, Matrix } from 'transformation-matrix';
/**
* Returns a matrix that transforms a triangle t1 into another triangle t2, or throws an exception if it is impossible.
* @param t1 an array of points containing the three points for the first triangle
* @param t2 an array of points containing the three points for the second triangle
* @returns Affine matrix which transforms t1 to t2
* @throws Exception if the matrix becomes not invertible
*/
export function fromTriangles(t1: Array<Point>, t2: Array<Point>): Matrix;
}
declare module 'transformation-matrix/smoothMatrix' {
import { Matrix } from 'transformation-matrix';
/**
* Rounds all elements of the given matrix using the given precision
* @param m a matrix to round
* @param precision precision to use for Math.round. Defaults to 10000000000 (meaning which rounds to the 10th digit after the comma).
* @returns the rounded matrix
*/
export function smoothMatrix (m : Matrix, precision? : number) : Matrix;
}
declare module 'transformation-matrix/fromDefinition' {
import { Point, Matrix, MatrixDescriptor } from 'transformation-matrix';
/**
* Converts array of matrix descriptor to array of matrix
* @param definitionOrArrayOfDefinition {Object[]} Array of object describing the matrix
* @returns {Matrix[]} Array of matrix
*
* @example
* > fromDefinition([
* { type: 'matrix', a:1, b:2, c:3, d:4, e:5, f:6 },
* { type: 'translate', tx: 10, ty: 20 },
* { type: 'scale', sx: 2, sy: 4 },
* { type: 'rotate', angle: 90, sx: 50, sy: 25 },
* { type: 'skewX', angle: 45 },
* { type: 'skewY', angle: 45 },
* { type: 'shear', shx: 10, shy: 20}
* ])
*
* [
* { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 },
* { a: 1, c: 0, e: 10, b: 0, d: 1, f: 20 },
* { a: 2, c: 0, e: 0, b: 0, d: 4, f: 0 },
* { a: 6.123, c: -1, e: 0, b: 1, d: 6.123, f: 0 },
* { a: 1, c: 0.99.., e: 0, b: 0, d: 1, f: 0 },
* { a: 1, c: 0, e: 0, b: 0.99, d: 1, f: 0 },
* { a: 1, c: 10, e: 0, b: 20, d: 1, f: 0 }
* ]
**/
export function fromDefinition(definition: MatrixDescriptor): Matrix;
export function fromDefinition(
arrayOfDefinition: MatrixDescriptor[]
): Matrix[];
}
declare module 'transformation-matrix/fromTransformAttribute' {
import { MatrixDescriptor } from 'transformation-matrix';
/**
* Parser for SVG Trasform Attribute http://www.w3.org/TR/SVG/coords.html#TransformAttribute <br/>
* Warning: This should be considered BETA until it is released a stable version of pegjs.
* @param transformString {string} Transform string as defined by w3 Consortium
* @returns {MatrixDescriptor[]} Array of MatrixDescriptor
*
* @example
* > fromTransformAttribute('translate(-10,-10) scale(2,2) translate(10,10)')
* [
* { type: 'translate', tx: -10, ty: -10},
* { type: 'scale', sx: 2, sy: 2 },
* { type: 'translate', tx: 10, ty: 10}
* ]
*
* > compose(fromDefinition(fromTransformAttribute('translate(-10, -10) scale(10, 10)')))
* { a: 10, c: 0, e: -10, b: 0, d: 10, f: -10 }
*/
export function fromTransformAttribute(transformString: string): MatrixDescriptor[];
}
declare module 'transformation-matrix' {
export * from 'transformation-matrix/applyToPoint';
export * from 'transformation-matrix/fromObject';
export * from 'transformation-matrix/fromString';
export * from 'transformation-matrix/identity';
export * from 'transformation-matrix/inverse';
export * from 'transformation-matrix/isAffineMatrix';
export * from 'transformation-matrix/rotate';
export * from 'transformation-matrix/scale';
export * from 'transformation-matrix/skew';
export * from 'transformation-matrix/shear';
export * from 'transformation-matrix/toString';
export * from 'transformation-matrix/transform';
export * from 'transformation-matrix/translate';
export * from 'transformation-matrix/fromTriangles';
export * from 'transformation-matrix/smoothMatrix';
export * from 'transformation-matrix/fromDefinition';
export * from 'transformation-matrix/fromTransformAttribute';
}