@next2d/geom 1.14.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Matrix.js ADDED
@@ -0,0 +1,454 @@
1
+ import { Point } from "./Point";
2
+ import { $getMatrix } from "@next2d/util";
3
+ import { $getFloat32Array6, $clamp, $Math, $SHORT_INT_MIN, $SHORT_INT_MAX } from "@next2d/share";
4
+ /**
5
+ * Matrix クラスは、2 つの座標空間の間におけるポイントのマッピング方法を決定する変換マトリックスを表します。
6
+ * Matrix オブジェクトのプロパティを設定し、Matrix オブジェクトを Transform オブジェクトの matrix プロパティに適用し、
7
+ * 次に Transform オブジェクトを表示オブジェクトの transform プロパティとして適用することで、表示オブジェクトに対する各種グラフィック変換を実行できます。
8
+ * これらの変換機能には、平行移動(x と y の位置変更)、回転、拡大 / 縮小、傾斜などが含まれます。
9
+ *
10
+ * The Matrix class represents a transformation matrix that determines how to map points from one coordinate space to another.
11
+ * You can perform various graphical transformations on a display object by setting the properties of a Matrix object,
12
+ * applying that Matrix object to the matrix property of a Transform object,
13
+ * and then applying that Transform object as the transform property of the display object.
14
+ * These transformation functions include translation (x and y repositioning), rotation, scaling, and skewing.
15
+ *
16
+ * @example <caption>Example usage of Matrix.</caption>
17
+ * // new Matrix
18
+ * const {Matrix} = next2d.geom;
19
+ * const matrix = new Matrix();
20
+ * // set new Matrix
21
+ * const {MovieClip} = next2d.display;
22
+ * const movieClip = new MovieClip();
23
+ * movieClip.transform.matrix = matrix;
24
+ *
25
+ * @class
26
+ * @memberOf next2d.geom
27
+ */
28
+ export class Matrix {
29
+ /**
30
+ * @param {number} [a=1]
31
+ * @param {number} [b=0]
32
+ * @param {number} [c=0]
33
+ * @param {number} [d=1]
34
+ * @param {number} [tx=0]
35
+ * @param {number} [ty=0]
36
+ *
37
+ * @constructor
38
+ * @public
39
+ */
40
+ constructor(a = 1, b = 0, c = 0, d = 1, tx = 0, ty = 0) {
41
+ /**
42
+ * @type {Float32Array}
43
+ * @private
44
+ */
45
+ this._$matrix = $getFloat32Array6(1, 0, 0, 1, 0, 0);
46
+ // setup
47
+ this.a = a;
48
+ this.b = b;
49
+ this.c = c;
50
+ this.d = d;
51
+ this.tx = tx;
52
+ this.ty = ty;
53
+ }
54
+ /**
55
+ * 指定されたクラスのストリングを返します。
56
+ * Returns the string representation of the specified class.
57
+ *
58
+ * @return {string}
59
+ * @default [class Matrix]
60
+ * @method
61
+ * @static
62
+ */
63
+ static toString() {
64
+ return "[class Matrix]";
65
+ }
66
+ /**
67
+ * @description 指定されたクラスの空間名を返します。
68
+ * Returns the space name of the specified class.
69
+ *
70
+ * @member {string}
71
+ * @default next2d.geom.Matrix
72
+ * @const
73
+ * @static
74
+ */
75
+ static get namespace() {
76
+ return "next2d.geom.Matrix";
77
+ }
78
+ /**
79
+ * @description 指定されたオブジェクトのストリングを返します。
80
+ * Returns the string representation of the specified object.
81
+ *
82
+ * @return {string}
83
+ * @method
84
+ * @public
85
+ */
86
+ toString() {
87
+ return `(a=${this.a}, b=${this.b}, c=${this.c}, d=${this.d}, tx=${this.tx}, ty=${this.ty})`;
88
+ }
89
+ /**
90
+ * @description 指定されたオブジェクトの空間名を返します。
91
+ * Returns the space name of the specified object.
92
+ *
93
+ * @member {string}
94
+ * @default next2d.geom.Matrix
95
+ * @const
96
+ * @public
97
+ */
98
+ get namespace() {
99
+ return "next2d.geom.Matrix";
100
+ }
101
+ /**
102
+ * @description イメージを拡大 / 縮小または回転するときに x 軸方向のピクセルの配置に影響を与える値です。
103
+ * The value that affects the positioning
104
+ * of pixels along the x axis when scaling or rotating an image.
105
+ *
106
+ * @member {number}
107
+ * @default 1
108
+ * @public
109
+ */
110
+ get a() {
111
+ return this._$matrix[0];
112
+ }
113
+ set a(a) {
114
+ this._$matrix[0] = $clamp(+a, $SHORT_INT_MIN, $SHORT_INT_MAX, 0);
115
+ }
116
+ /**
117
+ * @description イメージを回転または傾斜させるときに y 軸方向のピクセルの配置に影響を与える値です。
118
+ * The value that affects the positioning
119
+ * of pixels along the y axis when rotating or skewing an image.
120
+ *
121
+ * @member {number}
122
+ * @default 0
123
+ * @public
124
+ */
125
+ get b() {
126
+ return this._$matrix[1];
127
+ }
128
+ set b(b) {
129
+ this._$matrix[1] = $clamp(+b, $SHORT_INT_MIN, $SHORT_INT_MAX, 0);
130
+ }
131
+ /**
132
+ * @description イメージを回転または傾斜させるときに x 軸方向のピクセルの配置に影響を与える値です。
133
+ * The value that affects the positioning
134
+ * of pixels along the x axis when rotating or skewing an image.
135
+ *
136
+ * @member {number}
137
+ * @default 0
138
+ * @public
139
+ */
140
+ get c() {
141
+ return this._$matrix[2];
142
+ }
143
+ set c(c) {
144
+ this._$matrix[2] = $clamp(+c, $SHORT_INT_MIN, $SHORT_INT_MAX, 0);
145
+ }
146
+ /**
147
+ * @description イメージを拡大 / 縮小または回転するときに y 軸方向のピクセルの配置に影響を与える値です。
148
+ * The value that affects the positioning
149
+ * of pixels along the y axis when scaling or rotating an image.
150
+ *
151
+ * @member {number}
152
+ * @default 1
153
+ * @public
154
+ */
155
+ get d() {
156
+ return this._$matrix[3];
157
+ }
158
+ set d(d) {
159
+ this._$matrix[3] = $clamp(+d, $SHORT_INT_MIN, $SHORT_INT_MAX, 0);
160
+ }
161
+ /**
162
+ * @description x 軸方向に各ポイントを平行移動する距離です。
163
+ * The distance by which to translate each point along the x axis.
164
+ *
165
+ * @member {number}
166
+ * @default 0
167
+ * @public
168
+ */
169
+ get tx() {
170
+ return this._$matrix[4];
171
+ }
172
+ set tx(tx) {
173
+ this._$matrix[4] = $clamp(+tx, $SHORT_INT_MIN, $SHORT_INT_MAX, 0);
174
+ }
175
+ /**
176
+ * @description y 軸方向に各ポイントを平行移動する距離です。
177
+ * The distance by which to translate each point along the y axis.
178
+ *
179
+ * @member {number}
180
+ * @default 0
181
+ * @public
182
+ */
183
+ get ty() {
184
+ return this._$matrix[5];
185
+ }
186
+ set ty(ty) {
187
+ this._$matrix[5] = $clamp(+ty, $SHORT_INT_MIN, $SHORT_INT_MAX, 0);
188
+ }
189
+ /**
190
+ * @return {Matrix}
191
+ * @method
192
+ * @private
193
+ */
194
+ _$clone() {
195
+ return this.clone();
196
+ }
197
+ /**
198
+ * @description 新しい Matrix オブジェクトとして、このマトリックスのクローンを返します。
199
+ * 含まれるオブジェクトはまったく同じコピーになります。
200
+ * Returns a new Matrix object that is a clone of this matrix,
201
+ * with an exact copy of the contained object.
202
+ *
203
+ * @return {Matrix}
204
+ * @method
205
+ * @public
206
+ */
207
+ clone() {
208
+ return $getMatrix(this._$matrix[0], this._$matrix[1], this._$matrix[2], this._$matrix[3], this._$matrix[4], this._$matrix[5]);
209
+ }
210
+ /**
211
+ * @description マトリックスを現在のマトリックスと連結して、
212
+ * 2 つのマトリックスの図形効果を効果的に組み合わせます。
213
+ * Concatenates a matrix with the current matrix,
214
+ * effectively combining the geometric effects of the two.
215
+ *
216
+ * @param {Matrix} m
217
+ * @return {void}
218
+ * @method
219
+ * @public
220
+ */
221
+ concat(m) {
222
+ const matrix = this._$matrix;
223
+ const target = m._$matrix;
224
+ let a = matrix[0] * target[0];
225
+ let b = 0.0;
226
+ let c = 0.0;
227
+ let d = matrix[3] * target[3];
228
+ let tx = matrix[4] * target[0] + target[4];
229
+ let ty = matrix[5] * target[3] + target[5];
230
+ if (matrix[1] || matrix[2] || target[1] || target[2]) {
231
+ a += matrix[1] * target[2];
232
+ d += matrix[2] * target[1];
233
+ b += matrix[0] * target[1] + matrix[1] * target[3];
234
+ c += matrix[2] * target[0] + matrix[3] * target[2];
235
+ tx += matrix[5] * target[2];
236
+ ty += matrix[4] * target[1];
237
+ }
238
+ this.a = a;
239
+ this.b = b;
240
+ this.c = c;
241
+ this.d = d;
242
+ this.tx = tx;
243
+ this.ty = ty;
244
+ }
245
+ /**
246
+ * @description すべてのマトリックスデータを、ソース Matrix オブジェクトから、
247
+ * 呼び出し元の Matrix オブジェクトにコピーします。
248
+ *
249
+ * @param {Matrix} source_matrix
250
+ * @method
251
+ * @return {void}
252
+ */
253
+ copyFrom(source_matrix) {
254
+ this.a = source_matrix.a;
255
+ this.b = source_matrix.b;
256
+ this.c = source_matrix.c;
257
+ this.d = source_matrix.d;
258
+ this.tx = source_matrix.tx;
259
+ this.ty = source_matrix.ty;
260
+ }
261
+ /**
262
+ * @description 拡大 / 縮小、回転、平行移動に関するパラメーターなどがあります。
263
+ * Includes parameters for scaling, rotation, and translation.
264
+ *
265
+ * @param {number} scale_x
266
+ * @param {number} scale_y
267
+ * @param {number} [rotation=0]
268
+ * @param {number} [tx=0]
269
+ * @param {number} [ty=0]
270
+ * @return {void}
271
+ * @method
272
+ * @public
273
+ */
274
+ createBox(scale_x, scale_y, rotation = 0, tx = 0, ty = 0) {
275
+ this.identity();
276
+ this.rotate(rotation);
277
+ this.scale(scale_x, scale_y);
278
+ this.translate(tx, ty);
279
+ }
280
+ /**
281
+ * @description Graphics クラスの beginGradientFill() メソッドで使用する特定のスタイルを作成します。
282
+ * Creates the specific style of matrix expected
283
+ * by the beginGradientFill() and lineGradientStyle() methods of the Graphics class.
284
+ *
285
+ * @param {number} width
286
+ * @param {number} height
287
+ * @param {number} [rotation=0]
288
+ * @param {number} [tx=0]
289
+ * @param {number} [ty=0]
290
+ * @return {void}
291
+ * @method
292
+ * @public
293
+ */
294
+ createGradientBox(width, height, rotation = 0, tx = 0, ty = 0) {
295
+ this.createBox(width / 1638.4, height / 1638.4, rotation, tx + width / 2, ty + height / 2);
296
+ }
297
+ /**
298
+ * @description 変換前の座標空間内のポイントが指定されると、そのポイントの変換後の座標を返します。
299
+ * Given a point in the pretransform coordinate space,
300
+ * returns the coordinates of that point after the transformation occurs.
301
+ *
302
+ * @param {Point} point
303
+ * @return {Point}
304
+ * @method
305
+ * @public
306
+ */
307
+ deltaTransformPoint(point) {
308
+ return new Point(point.x * this._$matrix[0] + point.y * this._$matrix[2], point.x * this._$matrix[1] + point.y * this._$matrix[3]);
309
+ }
310
+ /**
311
+ * @description 各行列プロパティを null 変換になる値に設定します。
312
+ * Sets each matrix property to a value that causes a null transformation.
313
+ *
314
+ * @return {void}
315
+ * @method
316
+ * @public
317
+ */
318
+ identity() {
319
+ this._$matrix[0] = 1;
320
+ this._$matrix[1] = 0;
321
+ this._$matrix[2] = 0;
322
+ this._$matrix[3] = 1;
323
+ this._$matrix[4] = 0;
324
+ this._$matrix[5] = 0;
325
+ }
326
+ /**
327
+ * @description 元のマトリックスの逆の変換を実行します。
328
+ * Performs the opposite transformation of the original matrix.
329
+ *
330
+ * @return {void}
331
+ * @method
332
+ * @public
333
+ */
334
+ invert() {
335
+ const a = this._$matrix[0];
336
+ const b = this._$matrix[1];
337
+ const c = this._$matrix[2];
338
+ const d = this._$matrix[3];
339
+ const tx = this._$matrix[4];
340
+ const ty = this._$matrix[5];
341
+ if (b === 0 && c === 0) {
342
+ this.a = 1 / a;
343
+ this.b = 0;
344
+ this.c = 0;
345
+ this.d = 1 / d;
346
+ this.tx = -this.a * tx;
347
+ this.ty = -this.d * ty;
348
+ }
349
+ else {
350
+ const det = a * d - b * c;
351
+ if (det) {
352
+ const rdet = 1 / det;
353
+ this.a = d * rdet;
354
+ this.b = -b * rdet;
355
+ this.c = -c * rdet;
356
+ this.d = a * rdet;
357
+ this.tx = -(this.a * tx + this.c * ty);
358
+ this.ty = -(this.b * tx + this.d * ty);
359
+ }
360
+ }
361
+ }
362
+ /**
363
+ * @description Matrix オブジェクトに回転変換を適用します。
364
+ * Applies a rotation transformation to the Matrix object.
365
+ *
366
+ * @param {number} rotation
367
+ * @return {void}
368
+ * @method
369
+ * @public
370
+ */
371
+ rotate(rotation) {
372
+ const a = this._$matrix[0];
373
+ const b = this._$matrix[1];
374
+ const c = this._$matrix[2];
375
+ const d = this._$matrix[3];
376
+ const tx = this._$matrix[4];
377
+ const ty = this._$matrix[5];
378
+ this.a = a * $Math.cos(rotation) - b * $Math.sin(rotation);
379
+ this.b = a * $Math.sin(rotation) + b * $Math.cos(rotation);
380
+ this.c = c * $Math.cos(rotation) - d * $Math.sin(rotation);
381
+ this.d = c * $Math.sin(rotation) + d * $Math.cos(rotation);
382
+ this.tx = tx * $Math.cos(rotation) - ty * $Math.sin(rotation);
383
+ this.ty = tx * $Math.sin(rotation) + ty * $Math.cos(rotation);
384
+ }
385
+ /**
386
+ * @description 行列に拡大 / 縮小の変換を適用します。
387
+ * Applies a scaling transformation to the matrix.
388
+ *
389
+ * @param {number} sx
390
+ * @param {number} sy
391
+ * @return {void}
392
+ * @method
393
+ * @public
394
+ */
395
+ scale(sx, sy) {
396
+ this.a *= sx;
397
+ this.c *= sx;
398
+ this.tx *= sx;
399
+ this.b *= sy;
400
+ this.d *= sy;
401
+ this.ty *= sy;
402
+ }
403
+ /**
404
+ * @description Matrix のメンバーを指定の値に設定します。
405
+ * Sets the members of Matrix to the specified values
406
+ *
407
+ * @param {number} a
408
+ * @param {number} b
409
+ * @param {number} c
410
+ * @param {number} d
411
+ * @param {number} tx
412
+ * @param {number} ty
413
+ * @return {void}
414
+ * @method
415
+ * @public
416
+ */
417
+ setTo(a, b, c, d, tx, ty) {
418
+ this.a = a;
419
+ this.b = b;
420
+ this.c = c;
421
+ this.d = d;
422
+ this.tx = tx;
423
+ this.ty = ty;
424
+ }
425
+ /**
426
+ * @description Matrix オブジェクトで表現される図形変換を、指定されたポイントに適用した結果を返します。
427
+ * Returns the result of applying the geometric transformation represented
428
+ * by the Matrix object to the specified point.
429
+ *
430
+ * @param {Point} point
431
+ * @return {Point}
432
+ * @method
433
+ * @public
434
+ */
435
+ transformPoint(point) {
436
+ return new Point(point.x * this._$matrix[0] + point.y * this._$matrix[2] + this._$matrix[4], point.x * this._$matrix[1] + point.y * this._$matrix[3] + this._$matrix[5]);
437
+ }
438
+ /**
439
+ * @description 行列を x 軸と y 軸に沿って、
440
+ * dx パラメーターと dy パラメーターで指定された量だけ平行移動します。
441
+ * Translates the matrix along the x and y axes,
442
+ * as specified by the dx and dy parameters.
443
+ *
444
+ * @param {number} dx
445
+ * @param {number} dy
446
+ * @return {void}
447
+ * @method
448
+ * @public
449
+ */
450
+ translate(dx, dy) {
451
+ this.tx += dx;
452
+ this.ty += dy;
453
+ }
454
+ }
@@ -0,0 +1,213 @@
1
+ /**
2
+ * Point オブジェクトは 2 次元の座標系の位置を表します。
3
+ * x は水平方向の軸を表し、y は垂直方向の軸を表します。
4
+ *
5
+ * The Point object represents a location in a two-dimensional coordinate system,
6
+ * where x represents the horizontal axis and y represents the vertical axis.
7
+ *
8
+ * @example <caption>Example usage of Point.</caption>
9
+ * // new Point
10
+ * const {Point} = next2d.geom;
11
+ * const point = new Point();
12
+ *
13
+ * @class
14
+ * @memberOf next2d.geom
15
+ */
16
+ export declare class Point {
17
+ private _$x;
18
+ private _$y;
19
+ /**
20
+ * @param {number} [x=0]
21
+ * @param {number} [y=0]
22
+ *
23
+ * @constructor
24
+ * @public
25
+ */
26
+ constructor(x?: number, y?: number);
27
+ /**
28
+ * 指定されたクラスのストリングを返します。
29
+ * Returns the string representation of the specified class.
30
+ *
31
+ * @return {string}
32
+ * @default [class Point]
33
+ * @method
34
+ * @static
35
+ */
36
+ static toString(): string;
37
+ /**
38
+ * @description 指定されたクラスの空間名を返します。
39
+ * Returns the space name of the specified class.
40
+ *
41
+ * @member {string}
42
+ * @default next2d.geom.Point
43
+ * @const
44
+ * @static
45
+ */
46
+ static get namespace(): string;
47
+ /**
48
+ * @description 指定されたオブジェクトのストリングを返します。
49
+ * Returns the string representation of the specified object.
50
+ *
51
+ * @return {string}
52
+ * @method
53
+ * @public
54
+ */
55
+ toString(): string;
56
+ /**
57
+ * @description 指定されたオブジェクトの空間名を返します。
58
+ * Returns the space name of the specified object.
59
+ *
60
+ * @member {string}
61
+ * @default next2d.geom.Point
62
+ * @const
63
+ * @public
64
+ */
65
+ get namespace(): string;
66
+ /**
67
+ * @description (0,0) からこのポイントまでの線のセグメントの長さです。
68
+ * The length of the line segment from (0,0) to this point.
69
+ *
70
+ * @member {number}
71
+ * @default 0
72
+ * @readonly
73
+ * @public
74
+ */
75
+ get length(): number;
76
+ /**
77
+ * @description ポイントの水平座標です。
78
+ * The horizontal coordinate of the point.
79
+ *
80
+ * @member {number}
81
+ * @default 0
82
+ * @public
83
+ */
84
+ get x(): number;
85
+ set x(x: number);
86
+ /**
87
+ * @description ポイントの垂直座標です。
88
+ * The vertical coordinate of the point.
89
+ *
90
+ * @member {number}
91
+ * @default 0
92
+ * @public
93
+ */
94
+ get y(): number;
95
+ set y(y: number);
96
+ /**
97
+ * @description このポイントの座標に他のポイントの座標を加算して、新しいポイントを作成します。
98
+ * Adds the coordinates of another point
99
+ * to the coordinates of this point to create a new point.
100
+ *
101
+ * @param {Point} v
102
+ * @returns {Point}
103
+ * @method
104
+ * @public
105
+ */
106
+ add(v: Point): Point;
107
+ /**
108
+ * @description この Point オブジェクトのコピーを作成します。
109
+ * Creates a copy of this Point object.
110
+ *
111
+ * @returns {Point}
112
+ * @method
113
+ * @public
114
+ */
115
+ clone(): Point;
116
+ /**
117
+ * @description すべてのポイントデータを、ソース Point オブジェクトから、
118
+ * 呼び出し元の Point オブジェクトにコピーします。
119
+ * Copies all of the point data from
120
+ * the source Point object into the calling Point object.
121
+ *
122
+ * @param {Point} source_point
123
+ * @returns void
124
+ * @public
125
+ */
126
+ copyFrom(source_point: Point): void;
127
+ /**
128
+ * @description point1 と point2 との距離を返します。
129
+ * Returns the distance between point1 and point2.
130
+ *
131
+ * @param {Point} point1
132
+ * @param {Point} point2
133
+ * @return {number}
134
+ * @method
135
+ * @static
136
+ */
137
+ static distance(point1: Point, point2: Point): number;
138
+ /**
139
+ * @description 2 つのポイントが等しいかどうかを判別します。
140
+ * Determines whether two points are equal.
141
+ *
142
+ * @param {Point} to_compare
143
+ * @return {boolean}
144
+ * @method
145
+ * @public
146
+ */
147
+ equals(to_compare: Point): boolean;
148
+ /**
149
+ * @description 2 つの指定されたポイント間にあるポイントを判別します。
150
+ * Determines a point between two specified points.
151
+ *
152
+ * @param {Point} point1
153
+ * @param {Point} point2
154
+ * @param {number} f
155
+ * @return {Point}
156
+ * @static
157
+ */
158
+ static interpolate(point1: Point, point2: Point, f: number): Point;
159
+ /**
160
+ * @description (0,0) と現在のポイント間の線のセグメントを設定された長さに拡大 / 縮小します。
161
+ * Scales the line segment between (0,0) and the current point to a set length.
162
+ *
163
+ * @param {number} thickness
164
+ * @return {void}
165
+ * @method
166
+ * @public
167
+ */
168
+ normalize(thickness: number): void;
169
+ /**
170
+ * @description Point オブジェクトを指定された量だけオフセットします。
171
+ * Offsets the Point object by the specified amount.
172
+ *
173
+ * @param {number} dx
174
+ * @param {number} dy
175
+ * @return {Point}
176
+ * @method
177
+ * @public
178
+ */
179
+ offset(dx: number, dy: number): void;
180
+ /**
181
+ * @description 極座標ペアを直交点座標に変換します。
182
+ * Converts a pair of polar coordinates to a Cartesian point coordinate.
183
+ *
184
+ * @param {number} len
185
+ * @param {number} angle
186
+ * @return {Point}
187
+ * @method
188
+ * @static
189
+ */
190
+ static polar(len: number, angle: number): Point;
191
+ /**
192
+ * @description Point のメンバーを指定の値に設定します。
193
+ * Sets the members of Point to the specified values
194
+ *
195
+ * @param {number} xa
196
+ * @param {number} ya
197
+ * @return {void}
198
+ * @method
199
+ * @public
200
+ */
201
+ setTo(xa: number, ya: number): void;
202
+ /**
203
+ * @description このポイントの座標から他のポイントの座標を減算して、新しいポイントを作成します。
204
+ * Subtracts the coordinates of another point
205
+ * from the coordinates of this point to create a new point.
206
+ *
207
+ * @param {Point} v
208
+ * @return {Point}
209
+ * @method
210
+ * @public
211
+ */
212
+ subtract(v: Point): Point;
213
+ }