@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/Point.js ADDED
@@ -0,0 +1,274 @@
1
+ import { $Math, $clamp, $SHORT_INT_MIN, $SHORT_INT_MAX } from "@next2d/share";
2
+ /**
3
+ * Point オブジェクトは 2 次元の座標系の位置を表します。
4
+ * x は水平方向の軸を表し、y は垂直方向の軸を表します。
5
+ *
6
+ * The Point object represents a location in a two-dimensional coordinate system,
7
+ * where x represents the horizontal axis and y represents the vertical axis.
8
+ *
9
+ * @example <caption>Example usage of Point.</caption>
10
+ * // new Point
11
+ * const {Point} = next2d.geom;
12
+ * const point = new Point();
13
+ *
14
+ * @class
15
+ * @memberOf next2d.geom
16
+ */
17
+ export class Point {
18
+ /**
19
+ * @param {number} [x=0]
20
+ * @param {number} [y=0]
21
+ *
22
+ * @constructor
23
+ * @public
24
+ */
25
+ constructor(x = 0, y = 0) {
26
+ /**
27
+ * @type {number}
28
+ * @default 0
29
+ * @private
30
+ */
31
+ this._$x = 0;
32
+ /**
33
+ * @type {number}
34
+ * @default 0
35
+ * @private
36
+ */
37
+ this._$y = 0;
38
+ // setup
39
+ this.x = x;
40
+ this.y = y;
41
+ }
42
+ /**
43
+ * 指定されたクラスのストリングを返します。
44
+ * Returns the string representation of the specified class.
45
+ *
46
+ * @return {string}
47
+ * @default [class Point]
48
+ * @method
49
+ * @static
50
+ */
51
+ static toString() {
52
+ return "[class Point]";
53
+ }
54
+ /**
55
+ * @description 指定されたクラスの空間名を返します。
56
+ * Returns the space name of the specified class.
57
+ *
58
+ * @member {string}
59
+ * @default next2d.geom.Point
60
+ * @const
61
+ * @static
62
+ */
63
+ static get namespace() {
64
+ return "next2d.geom.Point";
65
+ }
66
+ /**
67
+ * @description 指定されたオブジェクトのストリングを返します。
68
+ * Returns the string representation of the specified object.
69
+ *
70
+ * @return {string}
71
+ * @method
72
+ * @public
73
+ */
74
+ toString() {
75
+ return `(x=${this.x}, y=${this.y})`;
76
+ }
77
+ /**
78
+ * @description 指定されたオブジェクトの空間名を返します。
79
+ * Returns the space name of the specified object.
80
+ *
81
+ * @member {string}
82
+ * @default next2d.geom.Point
83
+ * @const
84
+ * @public
85
+ */
86
+ get namespace() {
87
+ return "next2d.geom.Point";
88
+ }
89
+ /**
90
+ * @description (0,0) からこのポイントまでの線のセグメントの長さです。
91
+ * The length of the line segment from (0,0) to this point.
92
+ *
93
+ * @member {number}
94
+ * @default 0
95
+ * @readonly
96
+ * @public
97
+ */
98
+ get length() {
99
+ return $Math.sqrt($Math.pow(this.x, 2) + $Math.pow(this.y, 2));
100
+ }
101
+ /**
102
+ * @description ポイントの水平座標です。
103
+ * The horizontal coordinate of the point.
104
+ *
105
+ * @member {number}
106
+ * @default 0
107
+ * @public
108
+ */
109
+ get x() {
110
+ return this._$x;
111
+ }
112
+ set x(x) {
113
+ this._$x = $clamp(+x, $SHORT_INT_MIN, $SHORT_INT_MAX, 0);
114
+ }
115
+ /**
116
+ * @description ポイントの垂直座標です。
117
+ * The vertical coordinate of the point.
118
+ *
119
+ * @member {number}
120
+ * @default 0
121
+ * @public
122
+ */
123
+ get y() {
124
+ return this._$y;
125
+ }
126
+ set y(y) {
127
+ this._$y = $clamp(+y, $SHORT_INT_MIN, $SHORT_INT_MAX, 0);
128
+ }
129
+ /**
130
+ * @description このポイントの座標に他のポイントの座標を加算して、新しいポイントを作成します。
131
+ * Adds the coordinates of another point
132
+ * to the coordinates of this point to create a new point.
133
+ *
134
+ * @param {Point} v
135
+ * @returns {Point}
136
+ * @method
137
+ * @public
138
+ */
139
+ add(v) {
140
+ return new Point(this.x + v.x, this.y + v.y);
141
+ }
142
+ /**
143
+ * @description この Point オブジェクトのコピーを作成します。
144
+ * Creates a copy of this Point object.
145
+ *
146
+ * @returns {Point}
147
+ * @method
148
+ * @public
149
+ */
150
+ clone() {
151
+ return new Point(this.x, this.y);
152
+ }
153
+ /**
154
+ * @description すべてのポイントデータを、ソース Point オブジェクトから、
155
+ * 呼び出し元の Point オブジェクトにコピーします。
156
+ * Copies all of the point data from
157
+ * the source Point object into the calling Point object.
158
+ *
159
+ * @param {Point} source_point
160
+ * @returns void
161
+ * @public
162
+ */
163
+ copyFrom(source_point) {
164
+ this._$x = source_point._$x;
165
+ this._$y = source_point._$y;
166
+ }
167
+ /**
168
+ * @description point1 と point2 との距離を返します。
169
+ * Returns the distance between point1 and point2.
170
+ *
171
+ * @param {Point} point1
172
+ * @param {Point} point2
173
+ * @return {number}
174
+ * @method
175
+ * @static
176
+ */
177
+ static distance(point1, point2) {
178
+ return $Math.sqrt($Math.pow(point1._$x - point2._$x, 2)
179
+ + $Math.pow(point1._$y - point2._$y, 2));
180
+ }
181
+ /**
182
+ * @description 2 つのポイントが等しいかどうかを判別します。
183
+ * Determines whether two points are equal.
184
+ *
185
+ * @param {Point} to_compare
186
+ * @return {boolean}
187
+ * @method
188
+ * @public
189
+ */
190
+ equals(to_compare) {
191
+ return this._$x === to_compare._$x && this._$y === to_compare._$y;
192
+ }
193
+ /**
194
+ * @description 2 つの指定されたポイント間にあるポイントを判別します。
195
+ * Determines a point between two specified points.
196
+ *
197
+ * @param {Point} point1
198
+ * @param {Point} point2
199
+ * @param {number} f
200
+ * @return {Point}
201
+ * @static
202
+ */
203
+ static interpolate(point1, point2, f) {
204
+ return new Point(point1.x + (point2.x - point1.x) * (1 - f), point1.y + (point2.y - point1.y) * (1 - f));
205
+ }
206
+ /**
207
+ * @description (0,0) と現在のポイント間の線のセグメントを設定された長さに拡大 / 縮小します。
208
+ * Scales the line segment between (0,0) and the current point to a set length.
209
+ *
210
+ * @param {number} thickness
211
+ * @return {void}
212
+ * @method
213
+ * @public
214
+ */
215
+ normalize(thickness) {
216
+ const length = this.length;
217
+ this.x = this.x * thickness / length;
218
+ this.y = this.y * thickness / length;
219
+ }
220
+ /**
221
+ * @description Point オブジェクトを指定された量だけオフセットします。
222
+ * Offsets the Point object by the specified amount.
223
+ *
224
+ * @param {number} dx
225
+ * @param {number} dy
226
+ * @return {Point}
227
+ * @method
228
+ * @public
229
+ */
230
+ offset(dx, dy) {
231
+ this.x += dx;
232
+ this.y += dy;
233
+ }
234
+ /**
235
+ * @description 極座標ペアを直交点座標に変換します。
236
+ * Converts a pair of polar coordinates to a Cartesian point coordinate.
237
+ *
238
+ * @param {number} len
239
+ * @param {number} angle
240
+ * @return {Point}
241
+ * @method
242
+ * @static
243
+ */
244
+ static polar(len, angle) {
245
+ return new Point(len * $Math.cos(angle), len * $Math.sin(angle));
246
+ }
247
+ /**
248
+ * @description Point のメンバーを指定の値に設定します。
249
+ * Sets the members of Point to the specified values
250
+ *
251
+ * @param {number} xa
252
+ * @param {number} ya
253
+ * @return {void}
254
+ * @method
255
+ * @public
256
+ */
257
+ setTo(xa, ya) {
258
+ this.x = xa;
259
+ this.y = ya;
260
+ }
261
+ /**
262
+ * @description このポイントの座標から他のポイントの座標を減算して、新しいポイントを作成します。
263
+ * Subtracts the coordinates of another point
264
+ * from the coordinates of this point to create a new point.
265
+ *
266
+ * @param {Point} v
267
+ * @return {Point}
268
+ * @method
269
+ * @public
270
+ */
271
+ subtract(v) {
272
+ return new Point(this.x - v.x, this.y - v.y);
273
+ }
274
+ }
@@ -0,0 +1,364 @@
1
+ import { Point } from "./Point";
2
+ /**
3
+ * Rectangle オブジェクトは、その位置(左上隅のポイント (x, y) で示される)、および幅と高さで定義される領域です。
4
+ * Rectangle クラスの x、y、width、および height の各プロパティは、互いに独立しているため、
5
+ * あるプロパティの値を変更しても、他のプロパティに影響はありません。
6
+ * ただし、right プロパティと bottom プロパティはこれら 4 つのプロパティと不可分に関連しています。
7
+ * 例えば、right プロパティの値を変更すると width プロパティの値も変更されます。
8
+ * bottom プロパティの値を変更すると、height プロパティの値も変更されます。
9
+ *
10
+ * A Rectangle object is an area defined by its position,
11
+ * as indicated by its top-left corner point (x, y) and by its width and its height.
12
+ * The x, y, width, and height properties of the Rectangle class are independent of each other;
13
+ * changing the value of one property has no effect on the others. However,
14
+ * the right and bottom properties are integrally related to those four properties.
15
+ * For example, if you change the value of the right property, the value of the width property changes;
16
+ * if you change the bottom property, the value of the height property changes.
17
+ *
18
+ * @example <caption>Example usage of Rectangle.</caption>
19
+ * // new Rectangle
20
+ * const {Rectangle} = next2d.geom;
21
+ * const rectangle = new Rectangle(0, 0, 100, 100);
22
+ *
23
+ * @class
24
+ * @memberOf next2d.geom
25
+ */
26
+ export declare class Rectangle {
27
+ private _$x;
28
+ private _$y;
29
+ private _$width;
30
+ private _$height;
31
+ /**
32
+ * @param {number} [x=0]
33
+ * @param {number} [y=0]
34
+ * @param {number} [width=0]
35
+ * @param {number} [height=0]
36
+ *
37
+ * @constructor
38
+ * @public
39
+ */
40
+ constructor(x?: number, y?: number, width?: number, height?: number);
41
+ /**
42
+ * 指定されたクラスのストリングを返します。
43
+ * Returns the string representation of the specified class.
44
+ *
45
+ * @return {string}
46
+ * @default [class Rectangle]
47
+ * @method
48
+ * @static
49
+ */
50
+ static toString(): string;
51
+ /**
52
+ * @description 指定されたクラスの空間名を返します。
53
+ * Returns the space name of the specified class.
54
+ *
55
+ * @member {string}
56
+ * @default next2d.geom.Rectangle
57
+ * @const
58
+ * @static
59
+ */
60
+ static get namespace(): string;
61
+ /**
62
+ * @description 指定されたオブジェクトのストリングを返します。
63
+ * Returns the string representation of the specified object.
64
+ *
65
+ * @return {string}
66
+ * @method
67
+ * @public
68
+ */
69
+ toString(): string;
70
+ /**
71
+ * @description 指定されたオブジェクトの空間名を返します。
72
+ * Returns the space name of the specified object.
73
+ *
74
+ * @member {string}
75
+ * @default next2d.geom.Rectangle
76
+ * @const
77
+ * @public
78
+ */
79
+ get namespace(): string;
80
+ /**
81
+ * @description y プロパティと height プロパティの合計です。
82
+ * The sum of the y and height properties.
83
+ *
84
+ * @member {number}
85
+ * @public
86
+ */
87
+ get bottom(): number;
88
+ set bottom(bottom: number);
89
+ /**
90
+ * @description Rectangle オブジェクトの右下隅の位置で、
91
+ * right プロパティと bottom プロパティの値で決まります。
92
+ * The location of the Rectangle object's bottom-right corner,
93
+ * determined by the values of the right and bottom properties.
94
+ *
95
+ * @member {Point}
96
+ * @public
97
+ */
98
+ get bottomRight(): Point;
99
+ set bottomRight(point: Point);
100
+ /**
101
+ * @description 矩形の高さ(ピクセル単位)です。
102
+ * The height of the rectangle, in pixels.
103
+ *
104
+ * @member {number}
105
+ * @public
106
+ */
107
+ get height(): number;
108
+ set height(height: number);
109
+ /**
110
+ * @description 矩形の左上隅の x 座標です。
111
+ * The x coordinate of the top-left corner of the rectangle.
112
+ *
113
+ * @member {number}
114
+ * @public
115
+ */
116
+ get left(): number;
117
+ set left(left: number);
118
+ /**
119
+ * @description x プロパティと width プロパティの合計です。
120
+ * The sum of the x and width properties.
121
+ *
122
+ * @member {number}
123
+ * @public
124
+ */
125
+ get right(): number;
126
+ set right(right: number);
127
+ /**
128
+ * @description Rectangle オブジェクトのサイズで、
129
+ * width プロパティと height プロパティの値を持つ Point オブジェクトとして表現されます。
130
+ * The size of the Rectangle object,
131
+ * expressed as a Point object with the values of the width and height properties.
132
+ *
133
+ * @member {Point}
134
+ * @public
135
+ */
136
+ get size(): Point;
137
+ set size(point: Point);
138
+ /**
139
+ * @description 矩形の左上隅の y 座標です。
140
+ * The y coordinate of the top-left corner of the rectangle.
141
+ *
142
+ * @member {number}
143
+ * @public
144
+ */
145
+ get top(): number;
146
+ set top(top: number);
147
+ /**
148
+ * @description Rectangle オブジェクトの左上隅の位置で、
149
+ * そのポイントの x 座標と y 座標で決まります。
150
+ * The location of the Rectangle object's top-left corner,
151
+ * determined by the x and y coordinates of the point.
152
+ *
153
+ * @member {Point}
154
+ * @public
155
+ */
156
+ get topLeft(): Point;
157
+ set topLeft(point: Point);
158
+ /**
159
+ * @description 矩形の幅(ピクセル単位)です。
160
+ * The width of the rectangle, in pixels.
161
+ *
162
+ * @member {number}
163
+ * @public
164
+ */
165
+ get width(): number;
166
+ set width(width: number);
167
+ /**
168
+ * @description 矩形の左上隅の x 座標です。
169
+ * The x coordinate of the top-left corner of the rectangle.
170
+ *
171
+ * @member {number}
172
+ * @public
173
+ */
174
+ get x(): number;
175
+ set x(x: number);
176
+ /**
177
+ * @description 矩形の左上隅の y 座標です。
178
+ * The y coordinate of the top-left corner of the rectangle.
179
+ *
180
+ * @member {number}
181
+ * @public
182
+ */
183
+ get y(): number;
184
+ set y(y: number);
185
+ /**
186
+ * @description 元の Rectangle オブジェクトと x、y、width、および height の各プロパティの値が同じである、
187
+ * 新しい Rectangle オブジェクトを返します。
188
+ * Returns a new Rectangle object with the same values for the x, y, width,
189
+ * and height properties as the original Rectangle object.
190
+ *
191
+ * @return {Rectangle}
192
+ * @method
193
+ * @public
194
+ */
195
+ clone(): Rectangle;
196
+ /**
197
+ * @description 指定されたポイントがこの Rectangle オブジェクトで定義される矩形領域内にあるかどうかを判別します。
198
+ * Determines whether the specified point is contained within
199
+ * the rectangular region defined by this Rectangle object.
200
+ *
201
+ * @param {number} x
202
+ * @param {number} y
203
+ * @return {boolean}
204
+ * @method
205
+ * @public
206
+ */
207
+ contains(x: number, y: number): boolean;
208
+ /**
209
+ * @description 指定されたポイントがこの Rectangle オブジェクトで定義される矩形領域内にあるかどうかを判別します。
210
+ * Determines whether the specified point is contained within
211
+ * the rectangular region defined by this Rectangle object.
212
+ *
213
+ * @param {Point} point
214
+ * @return {boolean}
215
+ * @method
216
+ * @public
217
+ */
218
+ containsPoint(point: Point): boolean;
219
+ /**
220
+ * @description rect パラメーターで指定された Rectangle オブジェクトがこの Rectangle オブジェクト内にあるかどうかを判別します。
221
+ * Determines whether the Rectangle object specified by
222
+ * the rect parameter is contained within this Rectangle object.
223
+ *
224
+ * @param {Rectangle} rect
225
+ * @return {boolean}
226
+ * @method
227
+ * @public
228
+ */
229
+ containsRect(rect: Rectangle): boolean;
230
+ /**
231
+ * @description すべての矩形データを、ソース Rectangle オブジェクトから、
232
+ * 呼び出し元の Rectangle オブジェクトにコピーします。
233
+ * Copies all of rectangle data from
234
+ * the source Rectangle object into the calling Rectangle object.
235
+ *
236
+ * @param {Rectangle} source_rect
237
+ * @return {void}
238
+ * @method
239
+ * @public
240
+ */
241
+ copyFrom(source_rect: Rectangle): void;
242
+ /**
243
+ * @description toCompare パラメーターで指定されたオブジェクトが
244
+ * この Rectangle オブジェクトと等しいかどうかを判別します。
245
+ * Determines whether the object specified
246
+ * in the toCompare parameter is equal to this Rectangle object.
247
+ *
248
+ * @param {Rectangle} to_compare
249
+ * @return {boolean}
250
+ * @method
251
+ * @public
252
+ */
253
+ equals(to_compare: Rectangle): boolean;
254
+ /**
255
+ * @description Rectangle オブジェクトのサイズを、指定された量(ピクセル単位)だけ大きくします。
256
+ * Increases the size of the Rectangle object by the specified amounts, in pixels.
257
+ *
258
+ * @param {number} dx
259
+ * @param {number} dy
260
+ * @return void
261
+ * @method
262
+ * @public
263
+ */
264
+ inflate(dx: number, dy: number): void;
265
+ /**
266
+ * @description Rectangle オブジェクトのサイズを大きくします。
267
+ * Increases the size of the Rectangle object.
268
+ *
269
+ * @param {Point} point
270
+ * @return {void}
271
+ * @method
272
+ * @public
273
+ */
274
+ inflatePoint(point: Point): void;
275
+ /**
276
+ * @description toIntersect パラメーターで指定された Rectangle オブジェクトが
277
+ * この Rectangle オブジェクトと交差する場合に、交差領域を Rectangle オブジェクトとして返します。
278
+ * If the Rectangle object specified in the toIntersect parameter intersects
279
+ * with this Rectangle object, returns the area of intersection as a Rectangle object.
280
+ *
281
+ * @param {Rectangle} to_intersect
282
+ * @return {Rectangle}
283
+ * @method
284
+ * @public
285
+ */
286
+ intersection(to_intersect: Rectangle): Rectangle;
287
+ /**
288
+ * @description toIntersect パラメーターで指定されたオブジェクトが
289
+ * この Rectangle オブジェクトと交差するかどうかを判別します。
290
+ * Determines whether the object specified
291
+ * in the toIntersect parameter intersects with this Rectangle object.
292
+ *
293
+ * @param {Rectangle} to_intersect
294
+ * @return {boolean}
295
+ * @method
296
+ * @public
297
+ */
298
+ intersects(to_intersect: Rectangle): boolean;
299
+ /**
300
+ * @description この Rectangle オブジェクトが空かどうかを判別します。
301
+ * Determine if this Rectangle object is empty.
302
+ *
303
+ * @return {boolean}
304
+ * @method
305
+ * @public
306
+ */
307
+ isEmpty(): boolean;
308
+ /**
309
+ * @description Rectangle オブジェクトの位置(左上隅で決定される)を、指定された量だけ調整します。
310
+ * Adjusts the location of the Rectangle object,
311
+ * as determined by its top-left corner, by the specified amounts.
312
+ *
313
+ * @param {number} dx
314
+ * @param {number} dy
315
+ * @return {void}
316
+ * @method
317
+ * @public
318
+ */
319
+ offset(dx: number, dy: number): void;
320
+ /**
321
+ * @description Point オブジェクトをパラメーターとして使用して、Rectangle オブジェクトの位置を調整します。
322
+ * Adjusts the location of the Rectangle object using a Point object as a parameter.
323
+ *
324
+ * @param {Point} point
325
+ * @return {void}
326
+ * @method
327
+ * @public
328
+ */
329
+ offsetPoint(point: Point): void;
330
+ /**
331
+ * @description Rectangle オブジェクトのすべてのプロパティを 0 に設定します。
332
+ * Sets all properties of the Rectangle object to 0.
333
+ *
334
+ * @return {void}
335
+ * @method
336
+ * @public
337
+ */
338
+ setEmpty(): void;
339
+ /**
340
+ * @description Rectangle のメンバーを指定の値に設定します。
341
+ * Sets the members of Rectangle to the specified values
342
+ *
343
+ * @param {number} x
344
+ * @param {number} y
345
+ * @param {number} width
346
+ * @param {number} height
347
+ * @return {void}
348
+ * @method
349
+ * @public
350
+ */
351
+ setTo(x: number, y: number, width: number, height: number): void;
352
+ /**
353
+ * @description 2 つの矩形間の水平と垂直の空間を塗りつぶすことにより、
354
+ * 2 つの矩形を加算して新しい Rectangle オブジェクトを作成します。
355
+ * Adds two rectangles together to create a new Rectangle object,
356
+ * by filling in the horizontal and vertical space between the two rectangles.
357
+ *
358
+ * @param {Rectangle} to_union
359
+ * @return {Rectangle}
360
+ * @method
361
+ * @public
362
+ */
363
+ union(to_union: Rectangle): Rectangle;
364
+ }