@vpmedia/phaser 1.95.0 → 1.97.0
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/CHANGELOG.md +51 -0
- package/package.json +10 -10
- package/src/phaser/core/animation.js +61 -56
- package/src/phaser/core/animation_manager.js +55 -55
- package/src/phaser/core/cache.js +154 -154
- package/src/phaser/core/device.js +2 -1
- package/src/phaser/core/device_util.js +27 -27
- package/src/phaser/core/dom.js +43 -43
- package/src/phaser/core/event_manager.js +63 -63
- package/src/phaser/core/factory.js +47 -47
- package/src/phaser/core/frame.js +30 -30
- package/src/phaser/core/frame_data.js +30 -28
- package/src/phaser/core/frame_util.js +8 -8
- package/src/phaser/core/game.js +34 -18
- package/src/phaser/core/loader.js +170 -170
- package/src/phaser/core/loader_parser.js +22 -22
- package/src/phaser/core/raf.js +1 -1
- package/src/phaser/core/scene.js +16 -10
- package/src/phaser/core/scene_manager.js +51 -43
- package/src/phaser/core/signal.js +68 -52
- package/src/phaser/core/signal.test.js +37 -0
- package/src/phaser/core/sound.js +54 -54
- package/src/phaser/core/sound_manager.js +49 -49
- package/src/phaser/core/stage.js +16 -16
- package/src/phaser/core/time.js +30 -30
- package/src/phaser/core/timer.js +79 -64
- package/src/phaser/core/timer_event.js +9 -9
- package/src/phaser/core/tween.js +90 -90
- package/src/phaser/core/tween_data.js +30 -30
- package/src/phaser/core/tween_manager.js +29 -24
- package/src/phaser/core/world.js +4 -3
- package/src/phaser/display/bitmap_text.js +61 -54
- package/src/phaser/display/button.js +48 -47
- package/src/phaser/display/canvas/buffer.js +8 -8
- package/src/phaser/display/canvas/graphics.js +8 -8
- package/src/phaser/display/canvas/masker.js +5 -5
- package/src/phaser/display/canvas/pool.js +18 -18
- package/src/phaser/display/canvas/renderer.js +16 -16
- package/src/phaser/display/canvas/tinter.js +22 -22
- package/src/phaser/display/canvas/util.js +42 -42
- package/src/phaser/display/display_object.js +119 -108
- package/src/phaser/display/graphics.js +112 -112
- package/src/phaser/display/graphics_data.js +10 -10
- package/src/phaser/display/graphics_data_util.js +3 -3
- package/src/phaser/display/group.js +50 -50
- package/src/phaser/display/image.js +54 -50
- package/src/phaser/display/sprite_batch.js +2 -2
- package/src/phaser/display/sprite_util.js +19 -19
- package/src/phaser/display/text.js +212 -187
- package/src/phaser/display/webgl/abstract_filter.js +4 -4
- package/src/phaser/display/webgl/base_texture.js +9 -9
- package/src/phaser/display/webgl/blend_manager.js +7 -7
- package/src/phaser/display/webgl/earcut.js +95 -95
- package/src/phaser/display/webgl/earcut_node.js +4 -4
- package/src/phaser/display/webgl/fast_sprite_batch.js +15 -15
- package/src/phaser/display/webgl/filter_manager.js +9 -9
- package/src/phaser/display/webgl/filter_texture.js +10 -10
- package/src/phaser/display/webgl/graphics.js +37 -37
- package/src/phaser/display/webgl/graphics_data.js +4 -4
- package/src/phaser/display/webgl/mask_manager.js +6 -6
- package/src/phaser/display/webgl/render_texture.js +16 -16
- package/src/phaser/display/webgl/renderer.js +20 -20
- package/src/phaser/display/webgl/shader/complex.js +4 -4
- package/src/phaser/display/webgl/shader/fast.js +4 -4
- package/src/phaser/display/webgl/shader/normal.js +8 -8
- package/src/phaser/display/webgl/shader/primitive.js +4 -4
- package/src/phaser/display/webgl/shader/strip.js +4 -4
- package/src/phaser/display/webgl/shader_manager.js +9 -9
- package/src/phaser/display/webgl/sprite_batch.js +18 -18
- package/src/phaser/display/webgl/stencil_manager.js +16 -16
- package/src/phaser/display/webgl/texture.js +13 -13
- package/src/phaser/display/webgl/texture_util.js +8 -8
- package/src/phaser/display/webgl/util.js +25 -25
- package/src/phaser/geom/circle.js +69 -69
- package/src/phaser/geom/circle.test.js +1 -0
- package/src/phaser/geom/ellipse.js +28 -28
- package/src/phaser/geom/ellipse.test.js +1 -0
- package/src/phaser/geom/line.js +93 -93
- package/src/phaser/geom/line.test.js +1 -0
- package/src/phaser/geom/matrix.js +54 -54
- package/src/phaser/geom/matrix.test.js +1 -0
- package/src/phaser/geom/point.js +96 -96
- package/src/phaser/geom/point.test.js +1 -0
- package/src/phaser/geom/polygon.js +22 -22
- package/src/phaser/geom/rectangle.js +132 -132
- package/src/phaser/geom/rectangle.test.js +1 -0
- package/src/phaser/geom/rounded_rectangle.js +12 -12
- package/src/phaser/geom/rounded_rectangle.test.js +1 -0
- package/src/phaser/geom/util/circle.js +33 -33
- package/src/phaser/geom/util/circle.test.js +1 -0
- package/src/phaser/geom/util/ellipse.js +5 -5
- package/src/phaser/geom/util/ellipse.test.js +1 -0
- package/src/phaser/geom/util/line.js +26 -26
- package/src/phaser/geom/util/line.test.js +1 -0
- package/src/phaser/geom/util/matrix.js +8 -8
- package/src/phaser/geom/util/matrix.test.js +1 -0
- package/src/phaser/geom/util/point.js +97 -97
- package/src/phaser/geom/util/point.test.js +1 -0
- package/src/phaser/geom/util/polygon.js +4 -4
- package/src/phaser/geom/util/polygon.test.js +1 -0
- package/src/phaser/geom/util/rectangle.js +74 -74
- package/src/phaser/geom/util/rectangle.test.js +1 -0
- package/src/phaser/geom/util/rounded_rectangle.js +4 -4
- package/src/phaser/geom/util/rounded_rectangle.test.js +1 -0
- package/src/phaser/util/math.js +81 -81
- package/src/phaser/util/math.test.js +1 -0
- package/types/phaser/core/animation.d.ts +61 -56
- package/types/phaser/core/animation.d.ts.map +1 -1
- package/types/phaser/core/animation_manager.d.ts +55 -55
- package/types/phaser/core/cache.d.ts +154 -154
- package/types/phaser/core/device.d.ts.map +1 -1
- package/types/phaser/core/dom.d.ts +43 -43
- package/types/phaser/core/event_manager.d.ts +63 -63
- package/types/phaser/core/factory.d.ts +47 -47
- package/types/phaser/core/frame.d.ts +30 -30
- package/types/phaser/core/frame_data.d.ts +28 -27
- package/types/phaser/core/frame_data.d.ts.map +1 -1
- package/types/phaser/core/game.d.ts +52 -19
- package/types/phaser/core/game.d.ts.map +1 -1
- package/types/phaser/core/loader.d.ts +170 -170
- package/types/phaser/core/loader_parser.d.ts.map +1 -1
- package/types/phaser/core/raf.d.ts +1 -1
- package/types/phaser/core/scene.d.ts +15 -9
- package/types/phaser/core/scene.d.ts.map +1 -1
- package/types/phaser/core/scene_manager.d.ts +51 -43
- package/types/phaser/core/scene_manager.d.ts.map +1 -1
- package/types/phaser/core/signal.d.ts +54 -51
- package/types/phaser/core/signal.d.ts.map +1 -1
- package/types/phaser/core/sound.d.ts +54 -54
- package/types/phaser/core/sound_manager.d.ts +49 -49
- package/types/phaser/core/stage.d.ts +10 -10
- package/types/phaser/core/time.d.ts +30 -30
- package/types/phaser/core/timer.d.ts +64 -64
- package/types/phaser/core/timer_event.d.ts +9 -9
- package/types/phaser/core/tween.d.ts +90 -90
- package/types/phaser/core/tween_data.d.ts +30 -30
- package/types/phaser/core/tween_manager.d.ts +29 -24
- package/types/phaser/core/tween_manager.d.ts.map +1 -1
- package/types/phaser/core/world.d.ts +4 -3
- package/types/phaser/core/world.d.ts.map +1 -1
- package/types/phaser/display/bitmap_text.d.ts +59 -52
- package/types/phaser/display/bitmap_text.d.ts.map +1 -1
- package/types/phaser/display/button.d.ts +47 -46
- package/types/phaser/display/button.d.ts.map +1 -1
- package/types/phaser/display/canvas/buffer.d.ts +8 -8
- package/types/phaser/display/canvas/renderer.d.ts +16 -16
- package/types/phaser/display/display_object.d.ts +119 -108
- package/types/phaser/display/display_object.d.ts.map +1 -1
- package/types/phaser/display/graphics.d.ts +101 -101
- package/types/phaser/display/graphics_data.d.ts +10 -10
- package/types/phaser/display/group.d.ts +47 -47
- package/types/phaser/display/image.d.ts +42 -40
- package/types/phaser/display/image.d.ts.map +1 -1
- package/types/phaser/display/text.d.ts +207 -184
- package/types/phaser/display/text.d.ts.map +1 -1
- package/types/phaser/display/webgl/abstract_filter.d.ts +4 -4
- package/types/phaser/display/webgl/base_texture.d.ts +9 -9
- package/types/phaser/display/webgl/blend_manager.d.ts +6 -6
- package/types/phaser/display/webgl/earcut.d.ts +95 -95
- package/types/phaser/display/webgl/earcut_node.d.ts +4 -4
- package/types/phaser/display/webgl/fast_sprite_batch.d.ts +15 -15
- package/types/phaser/display/webgl/filter_manager.d.ts +8 -8
- package/types/phaser/display/webgl/filter_texture.d.ts +10 -10
- package/types/phaser/display/webgl/graphics_data.d.ts +4 -4
- package/types/phaser/display/webgl/render_texture.d.ts +16 -16
- package/types/phaser/display/webgl/renderer.d.ts +20 -20
- package/types/phaser/display/webgl/shader/complex.d.ts +4 -4
- package/types/phaser/display/webgl/shader/fast.d.ts +4 -4
- package/types/phaser/display/webgl/shader/normal.d.ts +8 -8
- package/types/phaser/display/webgl/shader/primitive.d.ts +4 -4
- package/types/phaser/display/webgl/shader/strip.d.ts +4 -4
- package/types/phaser/display/webgl/shader_manager.d.ts +8 -8
- package/types/phaser/display/webgl/sprite_batch.d.ts +17 -17
- package/types/phaser/display/webgl/stencil_manager.d.ts +15 -15
- package/types/phaser/display/webgl/texture.d.ts +12 -12
- package/types/phaser/geom/circle.d.ts +69 -69
- package/types/phaser/geom/ellipse.d.ts +28 -28
- package/types/phaser/geom/line.d.ts +93 -93
- package/types/phaser/geom/matrix.d.ts +54 -54
- package/types/phaser/geom/point.d.ts +96 -96
- package/types/phaser/geom/polygon.d.ts +22 -22
- package/types/phaser/geom/rectangle.d.ts +132 -132
- package/types/phaser/geom/rounded_rectangle.d.ts +12 -12
- package/pnpm-workspace.yaml +0 -4
package/src/phaser/geom/line.js
CHANGED
|
@@ -5,11 +5,11 @@ import { GEOM_LINE } from '../core/const.js';
|
|
|
5
5
|
|
|
6
6
|
export class Line {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* @param {number} x1 -
|
|
10
|
-
* @param {number} y1 -
|
|
11
|
-
* @param {number} x2 -
|
|
12
|
-
* @param {number} y2 -
|
|
8
|
+
* Creates a new Line instance.
|
|
9
|
+
* @param {number} x1 - The x coordinate of the start point (default: 0).
|
|
10
|
+
* @param {number} y1 - The y coordinate of the start point (default: 0).
|
|
11
|
+
* @param {number} x2 - The x coordinate of the end point (default: 0).
|
|
12
|
+
* @param {number} y2 - The y coordinate of the end point (default: 0).
|
|
13
13
|
*/
|
|
14
14
|
constructor(x1 = 0, y1 = 0, x2 = 0, y2 = 0) {
|
|
15
15
|
/** @type {Point} */
|
|
@@ -21,12 +21,12 @@ export class Line {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
* @param {number} x1 -
|
|
26
|
-
* @param {number} y1 -
|
|
27
|
-
* @param {number} x2 -
|
|
28
|
-
* @param {number} y2 -
|
|
29
|
-
* @returns {Line}
|
|
24
|
+
* Sets the coordinates of this line to new values.
|
|
25
|
+
* @param {number} x1 - The new x coordinate of the start point.
|
|
26
|
+
* @param {number} y1 - The new y coordinate of the start point.
|
|
27
|
+
* @param {number} x2 - The new x coordinate of the end point.
|
|
28
|
+
* @param {number} y2 - The new y coordinate of the end point.
|
|
29
|
+
* @returns {Line} This line instance for chaining.
|
|
30
30
|
*/
|
|
31
31
|
setTo(x1, y1, x2, y2) {
|
|
32
32
|
this.start.setTo(x1, y1);
|
|
@@ -35,11 +35,11 @@ export class Line {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
39
|
-
* @param {object} startSprite -
|
|
40
|
-
* @param {object} endSprite -
|
|
41
|
-
* @param {boolean} useCenter -
|
|
42
|
-
* @returns {Line}
|
|
38
|
+
* Sets the coordinates of this line to match the positions of two sprites.
|
|
39
|
+
* @param {object} startSprite - The starting sprite to get the position from.
|
|
40
|
+
* @param {object} endSprite - The ending sprite to get the position from.
|
|
41
|
+
* @param {boolean} useCenter - Whether to use the center of the sprites (default: false).
|
|
42
|
+
* @returns {Line} This line instance for chaining.
|
|
43
43
|
*/
|
|
44
44
|
fromSprite(startSprite, endSprite, useCenter = false) {
|
|
45
45
|
if (useCenter) {
|
|
@@ -49,12 +49,12 @@ export class Line {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
53
|
-
* @param {number} x -
|
|
54
|
-
* @param {number} y -
|
|
55
|
-
* @param {number} angle -
|
|
56
|
-
* @param {number} length -
|
|
57
|
-
* @returns {Line}
|
|
52
|
+
* Sets the coordinates of this line to a point at a specific angle and distance.
|
|
53
|
+
* @param {number} x - The x coordinate of the starting point.
|
|
54
|
+
* @param {number} y - The y coordinate of the starting point.
|
|
55
|
+
* @param {number} angle - The angle in radians to set the line at.
|
|
56
|
+
* @param {number} length - The length of the line.
|
|
57
|
+
* @returns {Line} This line instance for chaining.
|
|
58
58
|
*/
|
|
59
59
|
fromAngle(x, y, angle, length) {
|
|
60
60
|
this.start.setTo(x, y);
|
|
@@ -63,10 +63,10 @@ export class Line {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
-
*
|
|
67
|
-
* @param {number} angle -
|
|
68
|
-
* @param {boolean} asDegrees -
|
|
69
|
-
* @returns {Line}
|
|
66
|
+
* Rotates this line around its center point by the specified angle.
|
|
67
|
+
* @param {number} angle - The angle in radians (or degrees if asDegrees is true) to rotate by.
|
|
68
|
+
* @param {boolean} asDegrees - Whether the angle is provided in degrees (default: false).
|
|
69
|
+
* @returns {Line} This line instance for chaining.
|
|
70
70
|
*/
|
|
71
71
|
rotate(angle, asDegrees = false) {
|
|
72
72
|
const cx = (this.start.x + this.end.x) / 2;
|
|
@@ -77,12 +77,12 @@ export class Line {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
*
|
|
81
|
-
* @param {number} x -
|
|
82
|
-
* @param {number} y -
|
|
83
|
-
* @param {number} angle -
|
|
84
|
-
* @param {boolean} asDegrees -
|
|
85
|
-
* @returns {Line}
|
|
80
|
+
* Rotates this line around a specific point by the specified angle.
|
|
81
|
+
* @param {number} x - The x coordinate of the center point to rotate around.
|
|
82
|
+
* @param {number} y - The y coordinate of the center point to rotate around.
|
|
83
|
+
* @param {number} angle - The angle in radians (or degrees if asDegrees is true) to rotate by.
|
|
84
|
+
* @param {boolean} asDegrees - Whether the angle is provided in degrees (default: false).
|
|
85
|
+
* @returns {Line} This line instance for chaining.
|
|
86
86
|
*/
|
|
87
87
|
rotateAround(x, y, angle, asDegrees = false) {
|
|
88
88
|
this.start.rotate(x, y, angle, asDegrees);
|
|
@@ -91,29 +91,29 @@ export class Line {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
|
-
*
|
|
95
|
-
* @param {Line} line -
|
|
96
|
-
* @param {boolean} asSegment -
|
|
97
|
-
* @param {Point} result -
|
|
98
|
-
* @returns {Point}
|
|
94
|
+
* Checks if this line intersects with another line.
|
|
95
|
+
* @param {Line} line - The other line to check for intersection with.
|
|
96
|
+
* @param {boolean} asSegment - Whether to treat the lines as segments (default: false).
|
|
97
|
+
* @param {Point} result - The point to store the intersection in (optional).
|
|
98
|
+
* @returns {Point} The intersection point, or null if no intersection occurs.
|
|
99
99
|
*/
|
|
100
100
|
intersects(line, asSegment, result) {
|
|
101
101
|
return intersectsPoints(this.start, this.end, line.start, line.end, asSegment, result);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
|
-
*
|
|
106
|
-
* @param {Line} line -
|
|
107
|
-
* @returns {number}
|
|
105
|
+
* Calculates the reflection of this line off another line.
|
|
106
|
+
* @param {Line} line - The line to reflect off.
|
|
107
|
+
* @returns {number} The angle of reflection in radians.
|
|
108
108
|
*/
|
|
109
109
|
reflect(line) {
|
|
110
110
|
return reflect(this, line);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
115
|
-
* @param {Point} output -
|
|
116
|
-
* @returns {Point}
|
|
114
|
+
* Returns the midpoint of this line.
|
|
115
|
+
* @param {Point} output - The point to store the result in (optional).
|
|
116
|
+
* @returns {Point} The midpoint of this line.
|
|
117
117
|
*/
|
|
118
118
|
midPoint(output = null) {
|
|
119
119
|
const result = output || new Point();
|
|
@@ -123,9 +123,9 @@ export class Line {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
|
-
*
|
|
127
|
-
* @param {number} x -
|
|
128
|
-
* @param {number} y -
|
|
126
|
+
* Centers this line on the specified point.
|
|
127
|
+
* @param {number} x - The x coordinate to center the line on.
|
|
128
|
+
* @param {number} y - The y coordinate to center the line on.
|
|
129
129
|
*/
|
|
130
130
|
centerOn(x, y) {
|
|
131
131
|
const cx = (this.start.x + this.end.x) / 2;
|
|
@@ -137,20 +137,20 @@ export class Line {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
/**
|
|
140
|
-
*
|
|
141
|
-
* @param {number} x -
|
|
142
|
-
* @param {number} y -
|
|
143
|
-
* @returns {boolean}
|
|
140
|
+
* Checks if the specified point lies on this line (not necessarily on the segment).
|
|
141
|
+
* @param {number} x - The x coordinate of the point to check.
|
|
142
|
+
* @param {number} y - The y coordinate of the point to check.
|
|
143
|
+
* @returns {boolean} True if the point lies on this line, false otherwise.
|
|
144
144
|
*/
|
|
145
145
|
pointOnLine(x, y) {
|
|
146
146
|
return (x - this.start.x) * (this.end.y - this.start.y) === (this.end.x - this.start.x) * (y - this.start.y);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
/**
|
|
150
|
-
*
|
|
151
|
-
* @param {number} x -
|
|
152
|
-
* @param {number} y -
|
|
153
|
-
* @returns {boolean}
|
|
150
|
+
* Checks if the specified point lies on this line segment.
|
|
151
|
+
* @param {number} x - The x coordinate of the point to check.
|
|
152
|
+
* @param {number} y - The y coordinate of the point to check.
|
|
153
|
+
* @returns {boolean} True if the point lies on this line segment, false otherwise.
|
|
154
154
|
*/
|
|
155
155
|
pointOnSegment(x, y) {
|
|
156
156
|
const xMin = Math.min(this.start.x, this.end.x);
|
|
@@ -161,9 +161,9 @@ export class Line {
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
|
-
*
|
|
165
|
-
* @param {Point} output -
|
|
166
|
-
* @returns {Point}
|
|
164
|
+
* Returns a random point on this line.
|
|
165
|
+
* @param {Point} output - The point to store the result in (optional).
|
|
166
|
+
* @returns {Point} A random point on this line.
|
|
167
167
|
*/
|
|
168
168
|
random(output = null) {
|
|
169
169
|
const result = output || new Point();
|
|
@@ -174,10 +174,10 @@ export class Line {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
/**
|
|
177
|
-
*
|
|
178
|
-
* @param {number} stepRate -
|
|
179
|
-
* @param {number[][]} results -
|
|
180
|
-
* @returns {number[][]}
|
|
177
|
+
* Gets coordinates of points along this line at regular intervals.
|
|
178
|
+
* @param {number} stepRate - The interval between points (default: 1).
|
|
179
|
+
* @param {number[][]} results - The array to store the results in (optional).
|
|
180
|
+
* @returns {number[][]} An array of coordinate pairs representing points along this line.
|
|
181
181
|
*/
|
|
182
182
|
coordinatesOnLine(stepRate = 1, results = []) {
|
|
183
183
|
let x1 = Math.round(this.start.x);
|
|
@@ -210,16 +210,16 @@ export class Line {
|
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
/**
|
|
213
|
-
*
|
|
214
|
-
* @returns {Line}
|
|
213
|
+
* Creates a clone of this line.
|
|
214
|
+
* @returns {Line} A new line with the same values as this one.
|
|
215
215
|
*/
|
|
216
216
|
clone() {
|
|
217
217
|
return clone(this);
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
/**
|
|
221
|
-
*
|
|
222
|
-
* @returns {number}
|
|
221
|
+
* Gets the length of this line.
|
|
222
|
+
* @returns {number} The length of this line.
|
|
223
223
|
*/
|
|
224
224
|
get length() {
|
|
225
225
|
return Math.sqrt(
|
|
@@ -229,112 +229,112 @@ export class Line {
|
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
/**
|
|
232
|
-
*
|
|
233
|
-
* @returns {number}
|
|
232
|
+
* Gets the angle of this line in radians.
|
|
233
|
+
* @returns {number} The angle of this line in radians.
|
|
234
234
|
*/
|
|
235
235
|
get angle() {
|
|
236
236
|
return Math.atan2(this.end.y - this.start.y, this.end.x - this.start.x);
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
/**
|
|
240
|
-
*
|
|
241
|
-
* @returns {number}
|
|
240
|
+
* Gets the slope of this line.
|
|
241
|
+
* @returns {number} The slope of this line.
|
|
242
242
|
*/
|
|
243
243
|
get slope() {
|
|
244
244
|
return (this.end.y - this.start.y) / (this.end.x - this.start.x);
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
/**
|
|
248
|
-
*
|
|
249
|
-
* @returns {number}
|
|
248
|
+
* Gets the perpendicular slope of this line.
|
|
249
|
+
* @returns {number} The perpendicular slope of this line.
|
|
250
250
|
*/
|
|
251
251
|
get perpSlope() {
|
|
252
252
|
return -((this.end.x - this.start.x) / (this.end.y - this.start.y));
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
/**
|
|
256
|
-
*
|
|
257
|
-
* @returns {number}
|
|
256
|
+
* Gets the x coordinate of the leftmost point on this line.
|
|
257
|
+
* @returns {number} The x coordinate of the leftmost point on this line.
|
|
258
258
|
*/
|
|
259
259
|
get x() {
|
|
260
260
|
return Math.min(this.start.x, this.end.x);
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
/**
|
|
264
|
-
*
|
|
265
|
-
* @returns {number}
|
|
264
|
+
* Gets the y coordinate of the topmost point on this line.
|
|
265
|
+
* @returns {number} The y coordinate of the topmost point on this line.
|
|
266
266
|
*/
|
|
267
267
|
get y() {
|
|
268
268
|
return Math.min(this.start.y, this.end.y);
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
/**
|
|
272
|
-
*
|
|
273
|
-
* @returns {number}
|
|
272
|
+
* Gets the x coordinate of the leftmost point on this line.
|
|
273
|
+
* @returns {number} The x coordinate of the leftmost point on this line.
|
|
274
274
|
*/
|
|
275
275
|
get left() {
|
|
276
276
|
return Math.min(this.start.x, this.end.x);
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
/**
|
|
280
|
-
*
|
|
281
|
-
* @returns {number}
|
|
280
|
+
* Gets the x coordinate of the rightmost point on this line.
|
|
281
|
+
* @returns {number} The x coordinate of the rightmost point on this line.
|
|
282
282
|
*/
|
|
283
283
|
get right() {
|
|
284
284
|
return Math.max(this.start.x, this.end.x);
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
/**
|
|
288
|
-
*
|
|
289
|
-
* @returns {number}
|
|
288
|
+
* Gets the y coordinate of the topmost point on this line.
|
|
289
|
+
* @returns {number} The y coordinate of the topmost point on this line.
|
|
290
290
|
*/
|
|
291
291
|
get top() {
|
|
292
292
|
return Math.min(this.start.y, this.end.y);
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
/**
|
|
296
|
-
*
|
|
297
|
-
* @returns {number}
|
|
296
|
+
* Gets the y coordinate of the bottommost point on this line.
|
|
297
|
+
* @returns {number} The y coordinate of the bottommost point on this line.
|
|
298
298
|
*/
|
|
299
299
|
get bottom() {
|
|
300
300
|
return Math.max(this.start.y, this.end.y);
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
/**
|
|
304
|
-
*
|
|
305
|
-
* @returns {number}
|
|
304
|
+
* Gets the width of this line (absolute difference between x coordinates).
|
|
305
|
+
* @returns {number} The width of this line.
|
|
306
306
|
*/
|
|
307
307
|
get width() {
|
|
308
308
|
return Math.abs(this.start.x - this.end.x);
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
/**
|
|
312
|
-
*
|
|
313
|
-
* @returns {number}
|
|
312
|
+
* Gets the height of this line (absolute difference between y coordinates).
|
|
313
|
+
* @returns {number} The height of this line.
|
|
314
314
|
*/
|
|
315
315
|
get height() {
|
|
316
316
|
return Math.abs(this.start.y - this.end.y);
|
|
317
317
|
}
|
|
318
318
|
|
|
319
319
|
/**
|
|
320
|
-
*
|
|
321
|
-
* @returns {number}
|
|
320
|
+
* Gets the normal vector x component of this line (perpendicular to the line).
|
|
321
|
+
* @returns {number} The normal vector x component of this line.
|
|
322
322
|
*/
|
|
323
323
|
get normalX() {
|
|
324
324
|
return Math.cos(this.angle - 1.5707963267948966);
|
|
325
325
|
}
|
|
326
326
|
|
|
327
327
|
/**
|
|
328
|
-
*
|
|
329
|
-
* @returns {number}
|
|
328
|
+
* Gets the normal vector y component of this line (perpendicular to the line).
|
|
329
|
+
* @returns {number} The normal vector y component of this line.
|
|
330
330
|
*/
|
|
331
331
|
get normalY() {
|
|
332
332
|
return Math.sin(this.angle - 1.5707963267948966);
|
|
333
333
|
}
|
|
334
334
|
|
|
335
335
|
/**
|
|
336
|
-
*
|
|
337
|
-
* @returns {number}
|
|
336
|
+
* Gets the angle of the normal vector of this line in radians.
|
|
337
|
+
* @returns {number} The angle of the normal vector of this line in radians.
|
|
338
338
|
*/
|
|
339
339
|
get normalAngle() {
|
|
340
340
|
return wrap(this.angle - 1.5707963267948966, -Math.PI, Math.PI);
|
|
@@ -4,13 +4,13 @@ import { GEOM_MATRIX } from '../core/const.js';
|
|
|
4
4
|
|
|
5
5
|
export class Matrix {
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @param {number} a -
|
|
9
|
-
* @param {number} b -
|
|
10
|
-
* @param {number} c -
|
|
11
|
-
* @param {number} d -
|
|
12
|
-
* @param {number} tx -
|
|
13
|
-
* @param {number} ty -
|
|
7
|
+
* Creates a new Matrix instance.
|
|
8
|
+
* @param {number} a - The a component of the matrix (default: 1).
|
|
9
|
+
* @param {number} b - The b component of the matrix (default: 0).
|
|
10
|
+
* @param {number} c - The c component of the matrix (default: 0).
|
|
11
|
+
* @param {number} d - The d component of the matrix (default: 1).
|
|
12
|
+
* @param {number} tx - The tx component of the matrix (default: 0).
|
|
13
|
+
* @param {number} ty - The ty component of the matrix (default: 0).
|
|
14
14
|
*/
|
|
15
15
|
constructor(a = 1, b = 0, c = 0, d = 1, tx = 0, ty = 0) {
|
|
16
16
|
/** @type {number} */
|
|
@@ -30,23 +30,23 @@ export class Matrix {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @param {number[]} array -
|
|
35
|
-
* @returns {Matrix}
|
|
33
|
+
* Sets the matrix components from an array.
|
|
34
|
+
* @param {number[]} array - The array to read the matrix components from (should have 6 elements).
|
|
35
|
+
* @returns {Matrix} This matrix instance for chaining.
|
|
36
36
|
*/
|
|
37
37
|
fromArray(array) {
|
|
38
38
|
return this.setTo(array[0], array[1], array[3], array[4], array[2], array[5]);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
* @param {number} a -
|
|
44
|
-
* @param {number} b -
|
|
45
|
-
* @param {number} c -
|
|
46
|
-
* @param {number} d -
|
|
47
|
-
* @param {number} tx -
|
|
48
|
-
* @param {number} ty -
|
|
49
|
-
* @returns {Matrix}
|
|
42
|
+
* Sets the matrix components to new values.
|
|
43
|
+
* @param {number} a - The new a component of the matrix.
|
|
44
|
+
* @param {number} b - The new b component of the matrix.
|
|
45
|
+
* @param {number} c - The new c component of the matrix.
|
|
46
|
+
* @param {number} d - The new d component of the matrix.
|
|
47
|
+
* @param {number} tx - The new tx component of the matrix.
|
|
48
|
+
* @param {number} ty - The new ty component of the matrix.
|
|
49
|
+
* @returns {Matrix} This matrix instance for chaining.
|
|
50
50
|
*/
|
|
51
51
|
setTo(a, b, c, d, tx, ty) {
|
|
52
52
|
this.a = a;
|
|
@@ -59,17 +59,17 @@ export class Matrix {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
63
|
-
* @returns {Matrix}
|
|
62
|
+
* Creates a clone of this matrix.
|
|
63
|
+
* @returns {Matrix} A new matrix with the same values as this one.
|
|
64
64
|
*/
|
|
65
65
|
clone() {
|
|
66
66
|
return clone(this);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
71
|
-
* @param {Matrix} matrix -
|
|
72
|
-
* @returns {Matrix}
|
|
70
|
+
* Copies the values of this matrix to another matrix.
|
|
71
|
+
* @param {Matrix} matrix - The matrix to copy values to.
|
|
72
|
+
* @returns {Matrix} The destination matrix.
|
|
73
73
|
*/
|
|
74
74
|
copyTo(matrix) {
|
|
75
75
|
matrix.copyFrom(this);
|
|
@@ -77,9 +77,9 @@ export class Matrix {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
*
|
|
81
|
-
* @param {Matrix} matrix -
|
|
82
|
-
* @returns {Matrix}
|
|
80
|
+
* Copies the values from another matrix to this matrix.
|
|
81
|
+
* @param {Matrix} matrix - The matrix to copy values from.
|
|
82
|
+
* @returns {Matrix} This matrix instance for chaining.
|
|
83
83
|
*/
|
|
84
84
|
copyFrom(matrix) {
|
|
85
85
|
this.a = matrix.a;
|
|
@@ -92,10 +92,10 @@ export class Matrix {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
96
|
-
* @param {boolean} transpose -
|
|
97
|
-
* @param {Float32Array} output -
|
|
98
|
-
* @returns {Float32Array}
|
|
95
|
+
* Converts this matrix to a Float32Array.
|
|
96
|
+
* @param {boolean} transpose - Whether to transpose the matrix (default: false).
|
|
97
|
+
* @param {Float32Array} output - The array to store the result in (optional).
|
|
98
|
+
* @returns {Float32Array} A Float32Array containing the matrix elements.
|
|
99
99
|
*/
|
|
100
100
|
toArray(transpose = false, output = null) {
|
|
101
101
|
const result = output || new Float32Array(9);
|
|
@@ -124,10 +124,10 @@ export class Matrix {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
|
-
*
|
|
128
|
-
* @param {Point} pos -
|
|
129
|
-
* @param {Point} output -
|
|
130
|
-
* @returns {Point}
|
|
127
|
+
* Applies this matrix to a point.
|
|
128
|
+
* @param {Point} pos - The point to apply the matrix to.
|
|
129
|
+
* @param {Point} output - The point to store the result in (optional).
|
|
130
|
+
* @returns {Point} The transformed point.
|
|
131
131
|
*/
|
|
132
132
|
apply(pos, output = null) {
|
|
133
133
|
const result = output || new Point();
|
|
@@ -137,10 +137,10 @@ export class Matrix {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
/**
|
|
140
|
-
*
|
|
141
|
-
* @param {Point} pos -
|
|
142
|
-
* @param {Point} output -
|
|
143
|
-
* @returns {Point}
|
|
140
|
+
* Applies the inverse of this matrix to a point.
|
|
141
|
+
* @param {Point} pos - The point to apply the inverse matrix to.
|
|
142
|
+
* @param {Point} output - The point to store the result in (optional).
|
|
143
|
+
* @returns {Point} The transformed point.
|
|
144
144
|
*/
|
|
145
145
|
applyInverse(pos, output = null) {
|
|
146
146
|
const result = output || new Point();
|
|
@@ -153,10 +153,10 @@ export class Matrix {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
|
-
*
|
|
157
|
-
* @param {number} x -
|
|
158
|
-
* @param {number} y -
|
|
159
|
-
* @returns {Matrix}
|
|
156
|
+
* Translates this matrix by the specified amounts.
|
|
157
|
+
* @param {number} x - The amount to translate in the x direction.
|
|
158
|
+
* @param {number} y - The amount to translate in the y direction.
|
|
159
|
+
* @returns {Matrix} This matrix instance for chaining.
|
|
160
160
|
*/
|
|
161
161
|
translate(x, y) {
|
|
162
162
|
this.tx += x;
|
|
@@ -165,10 +165,10 @@ export class Matrix {
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
/**
|
|
168
|
-
*
|
|
169
|
-
* @param {number} x -
|
|
170
|
-
* @param {number} y -
|
|
171
|
-
* @returns {Matrix}
|
|
168
|
+
* Scales this matrix by the specified amounts.
|
|
169
|
+
* @param {number} x - The amount to scale in the x direction.
|
|
170
|
+
* @param {number} y - The amount to scale in the y direction.
|
|
171
|
+
* @returns {Matrix} This matrix instance for chaining.
|
|
172
172
|
*/
|
|
173
173
|
scale(x, y) {
|
|
174
174
|
this.a *= x;
|
|
@@ -181,9 +181,9 @@ export class Matrix {
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
/**
|
|
184
|
-
*
|
|
185
|
-
* @param {number} angle -
|
|
186
|
-
* @returns {Matrix}
|
|
184
|
+
* Rotates this matrix by the specified angle.
|
|
185
|
+
* @param {number} angle - The angle in radians to rotate by.
|
|
186
|
+
* @returns {Matrix} This matrix instance for chaining.
|
|
187
187
|
*/
|
|
188
188
|
rotate(angle) {
|
|
189
189
|
const cos = Math.cos(angle);
|
|
@@ -201,9 +201,9 @@ export class Matrix {
|
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
/**
|
|
204
|
-
*
|
|
205
|
-
* @param {Matrix} matrix -
|
|
206
|
-
* @returns {Matrix}
|
|
204
|
+
* Appends another matrix to this matrix (multiplying matrices).
|
|
205
|
+
* @param {Matrix} matrix - The matrix to append.
|
|
206
|
+
* @returns {Matrix} This matrix instance for chaining.
|
|
207
207
|
*/
|
|
208
208
|
append(matrix) {
|
|
209
209
|
const a1 = this.a;
|
|
@@ -220,8 +220,8 @@ export class Matrix {
|
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
/**
|
|
223
|
-
*
|
|
224
|
-
* @returns {Matrix}
|
|
223
|
+
* Sets this matrix to an identity matrix (no transformation).
|
|
224
|
+
* @returns {Matrix} This matrix instance for chaining.
|
|
225
225
|
*/
|
|
226
226
|
identity() {
|
|
227
227
|
return this.setTo(1, 0, 0, 1, 0, 0);
|