@vpmedia/phaser 1.15.0 → 1.17.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/README.md +3 -3
- package/package.json +6 -5
- package/src/index.js +15 -18
- package/src/phaser/core/animation.js +114 -6
- package/src/phaser/core/animation_manager.js +102 -10
- package/src/phaser/core/animation_parser.js +6 -19
- package/src/phaser/core/array_set.js +59 -5
- package/src/phaser/core/cache.js +307 -6
- package/src/phaser/core/const.js +107 -4
- package/src/phaser/core/device.js +3 -6
- package/src/phaser/core/device_util.js +3 -16
- package/src/phaser/core/dom.js +127 -29
- package/src/phaser/core/event_manager.js +128 -6
- package/src/phaser/core/factory.js +69 -34
- package/src/phaser/core/frame.js +43 -6
- package/src/phaser/core/frame_data.js +55 -5
- package/src/phaser/core/frame_util.js +7 -12
- package/src/phaser/core/game.js +35 -7
- package/src/phaser/core/input.js +133 -17
- package/src/phaser/core/input_handler.js +243 -43
- package/src/phaser/core/input_mouse.js +70 -5
- package/src/phaser/core/input_mspointer.js +40 -9
- package/src/phaser/core/input_pointer.js +88 -17
- package/src/phaser/core/input_touch.js +42 -5
- package/src/phaser/core/loader.js +303 -101
- package/src/phaser/core/loader_parser.js +2 -10
- package/src/phaser/core/raf.js +16 -5
- package/src/phaser/core/scale_manager.js +204 -39
- package/src/phaser/core/scene.js +24 -5
- package/src/phaser/core/scene_manager.js +81 -11
- package/src/phaser/core/signal.js +88 -11
- package/src/phaser/core/signal_binding.js +35 -15
- package/src/phaser/core/sound.js +99 -10
- package/src/phaser/core/sound_manager.js +89 -13
- package/src/phaser/core/sound_sprite.js +20 -5
- package/src/phaser/core/stage.js +43 -7
- package/src/phaser/core/time.js +67 -5
- package/src/phaser/core/timer.js +107 -30
- package/src/phaser/core/timer_event.js +11 -6
- package/src/phaser/core/tween.js +124 -30
- package/src/phaser/core/tween_data.js +42 -18
- package/src/phaser/core/tween_easing.js +1 -8
- package/src/phaser/core/tween_manager.js +47 -5
- package/src/phaser/core/world.js +9 -6
- package/src/phaser/display/bitmap_text.js +91 -10
- package/src/phaser/display/button.js +63 -12
- package/src/phaser/display/canvas/buffer.js +16 -6
- package/src/phaser/display/canvas/graphics.js +1 -13
- package/src/phaser/display/canvas/masker.js +0 -6
- package/src/phaser/display/canvas/pool.js +0 -7
- package/src/phaser/display/canvas/renderer.js +28 -8
- package/src/phaser/display/canvas/tinter.js +4 -43
- package/src/phaser/display/canvas/util.js +0 -6
- package/src/phaser/display/display_object.js +192 -20
- package/src/phaser/display/graphics.js +161 -26
- package/src/phaser/display/graphics_data.js +14 -6
- package/src/phaser/display/graphics_data_util.js +2 -8
- package/src/phaser/display/group.js +82 -9
- package/src/phaser/display/image.js +87 -9
- package/src/phaser/display/sprite_batch.js +3 -8
- package/src/phaser/display/sprite_util.js +3 -23
- package/src/phaser/display/text.js +331 -31
- package/src/phaser/display/webgl/abstract_filter.js +8 -7
- package/src/phaser/display/webgl/base_texture.js +20 -12
- package/src/phaser/display/webgl/blend_manager.js +14 -7
- package/src/phaser/display/webgl/earcut.js +4 -23
- package/src/phaser/display/webgl/earcut_node.js +6 -7
- package/src/phaser/display/webgl/fast_sprite_batch.js +34 -11
- package/src/phaser/display/webgl/filter_manager.js +25 -7
- package/src/phaser/display/webgl/filter_texture.js +21 -22
- package/src/phaser/display/webgl/graphics.js +5 -28
- package/src/phaser/display/webgl/graphics_data.js +10 -7
- package/src/phaser/display/webgl/mask_manager.js +0 -6
- package/src/phaser/display/webgl/render_texture.js +33 -21
- package/src/phaser/display/webgl/renderer.js +38 -11
- package/src/phaser/display/webgl/shader/complex.js +10 -6
- package/src/phaser/display/webgl/shader/fast.js +10 -6
- package/src/phaser/display/webgl/shader/normal.js +23 -32
- package/src/phaser/display/webgl/shader/primitive.js +10 -6
- package/src/phaser/display/webgl/shader/strip.js +10 -6
- package/src/phaser/display/webgl/shader_manager.js +18 -6
- package/src/phaser/display/webgl/sprite_batch.js +41 -8
- package/src/phaser/display/webgl/stencil_manager.js +28 -6
- package/src/phaser/display/webgl/texture.js +28 -15
- package/src/phaser/display/webgl/texture_util.js +0 -6
- package/src/phaser/display/webgl/util.js +0 -7
- package/src/phaser/geom/circle.js +123 -18
- package/src/phaser/geom/ellipse.js +39 -18
- package/src/phaser/geom/line.js +148 -16
- package/src/phaser/geom/matrix.js +73 -6
- package/src/phaser/geom/point.js +152 -6
- package/src/phaser/geom/polygon.js +42 -14
- package/src/phaser/geom/rectangle.js +233 -6
- package/src/phaser/geom/rounded_rectangle.js +10 -6
- package/src/phaser/geom/util/circle.js +3 -9
- package/src/phaser/geom/util/ellipse.js +0 -7
- package/src/phaser/geom/util/line.js +5 -14
- package/src/phaser/geom/util/matrix.js +1 -7
- package/src/phaser/geom/util/point.js +0 -6
- package/src/phaser/geom/util/polygon.js +1 -7
- package/src/phaser/geom/util/rectangle.js +1 -7
- package/src/phaser/geom/util/rounded_rectangle.js +1 -7
- package/src/phaser/util/math.js +3 -21
- package/types/index.d.ts +2 -1
- package/types/index.d.ts.map +1 -1
- package/types/phaser/core/animation.d.ts +126 -13
- package/types/phaser/core/animation.d.ts.map +1 -1
- package/types/phaser/core/animation_manager.d.ts +121 -19
- package/types/phaser/core/animation_manager.d.ts.map +1 -1
- package/types/phaser/core/animation_parser.d.ts +6 -5
- package/types/phaser/core/animation_parser.d.ts.map +1 -1
- package/types/phaser/core/array_set.d.ts +67 -13
- package/types/phaser/core/array_set.d.ts.map +1 -1
- package/types/phaser/core/cache.d.ts +365 -69
- package/types/phaser/core/cache.d.ts.map +1 -1
- package/types/phaser/core/const.d.ts +143 -40
- package/types/phaser/core/const.d.ts.map +1 -1
- package/types/phaser/core/device.d.ts +0 -5
- package/types/phaser/core/device.d.ts.map +1 -1
- package/types/phaser/core/device_util.d.ts +1 -1
- package/types/phaser/core/device_util.d.ts.map +1 -1
- package/types/phaser/core/dom.d.ts +119 -0
- package/types/phaser/core/dom.d.ts.map +1 -1
- package/types/phaser/core/event_manager.d.ts +127 -0
- package/types/phaser/core/event_manager.d.ts.map +1 -1
- package/types/phaser/core/factory.d.ts +75 -8
- package/types/phaser/core/factory.d.ts.map +1 -1
- package/types/phaser/core/frame.d.ts +64 -21
- package/types/phaser/core/frame.d.ts.map +1 -1
- package/types/phaser/core/frame_data.d.ts +61 -9
- package/types/phaser/core/frame_data.d.ts.map +1 -1
- package/types/phaser/core/frame_util.d.ts +10 -8
- package/types/phaser/core/frame_util.d.ts.map +1 -1
- package/types/phaser/core/game.d.ts +40 -6
- package/types/phaser/core/game.d.ts.map +1 -1
- package/types/phaser/core/input.d.ts +143 -15
- package/types/phaser/core/input.d.ts.map +1 -1
- package/types/phaser/core/input_handler.d.ts +258 -25
- package/types/phaser/core/input_handler.d.ts.map +1 -1
- package/types/phaser/core/input_mouse.d.ts +62 -14
- package/types/phaser/core/input_mouse.d.ts.map +1 -1
- package/types/phaser/core/input_mspointer.d.ts +51 -17
- package/types/phaser/core/input_mspointer.d.ts.map +1 -1
- package/types/phaser/core/input_pointer.d.ts +99 -14
- package/types/phaser/core/input_pointer.d.ts.map +1 -1
- package/types/phaser/core/input_touch.d.ts +53 -16
- package/types/phaser/core/input_touch.d.ts.map +1 -1
- package/types/phaser/core/loader.d.ts +299 -28
- package/types/phaser/core/loader.d.ts.map +1 -1
- package/types/phaser/core/loader_parser.d.ts.map +1 -1
- package/types/phaser/core/raf.d.ts +19 -9
- package/types/phaser/core/raf.d.ts.map +1 -1
- package/types/phaser/core/scale_manager.d.ts +208 -13
- package/types/phaser/core/scale_manager.d.ts.map +1 -1
- package/types/phaser/core/scene.d.ts +21 -5
- package/types/phaser/core/scene.d.ts.map +1 -1
- package/types/phaser/core/scene_manager.d.ts +90 -10
- package/types/phaser/core/scene_manager.d.ts.map +1 -1
- package/types/phaser/core/signal.d.ts +93 -9
- package/types/phaser/core/signal.d.ts.map +1 -1
- package/types/phaser/core/signal_binding.d.ts +34 -5
- package/types/phaser/core/signal_binding.d.ts.map +1 -1
- package/types/phaser/core/sound.d.ts +111 -14
- package/types/phaser/core/sound.d.ts.map +1 -1
- package/types/phaser/core/sound_manager.d.ts +97 -11
- package/types/phaser/core/sound_manager.d.ts.map +1 -1
- package/types/phaser/core/sound_sprite.d.ts +22 -8
- package/types/phaser/core/sound_sprite.d.ts.map +1 -1
- package/types/phaser/core/stage.d.ts +32 -3
- package/types/phaser/core/stage.d.ts.map +1 -1
- package/types/phaser/core/time.d.ts +73 -6
- package/types/phaser/core/time.d.ts.map +1 -1
- package/types/phaser/core/timer.d.ts +108 -7
- package/types/phaser/core/timer.d.ts.map +1 -1
- package/types/phaser/core/timer_event.d.ts +13 -7
- package/types/phaser/core/timer_event.d.ts.map +1 -1
- package/types/phaser/core/tween.d.ts +124 -4
- package/types/phaser/core/tween.d.ts.map +1 -1
- package/types/phaser/core/tween_data.d.ts +41 -2
- package/types/phaser/core/tween_data.d.ts.map +1 -1
- package/types/phaser/core/tween_easing.d.ts +0 -5
- package/types/phaser/core/tween_easing.d.ts.map +1 -1
- package/types/phaser/core/tween_manager.d.ts +49 -2
- package/types/phaser/core/tween_manager.d.ts.map +1 -1
- package/types/phaser/core/world.d.ts +9 -1
- package/types/phaser/core/world.d.ts.map +1 -1
- package/types/phaser/display/bitmap_text.d.ts +84 -7
- package/types/phaser/display/bitmap_text.d.ts.map +1 -1
- package/types/phaser/display/button.d.ts +65 -8
- package/types/phaser/display/button.d.ts.map +1 -1
- package/types/phaser/display/canvas/buffer.d.ts +20 -4
- package/types/phaser/display/canvas/buffer.d.ts.map +1 -1
- package/types/phaser/display/canvas/graphics.d.ts.map +1 -1
- package/types/phaser/display/canvas/masker.d.ts.map +1 -1
- package/types/phaser/display/canvas/pool.d.ts +0 -6
- package/types/phaser/display/canvas/pool.d.ts.map +1 -1
- package/types/phaser/display/canvas/renderer.d.ts +29 -2
- package/types/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/types/phaser/display/canvas/tinter.d.ts.map +1 -1
- package/types/phaser/display/canvas/util.d.ts.map +1 -1
- package/types/phaser/display/display_object.d.ts +195 -8
- package/types/phaser/display/display_object.d.ts.map +1 -1
- package/types/phaser/display/graphics.d.ts +132 -6
- package/types/phaser/display/graphics.d.ts.map +1 -1
- package/types/phaser/display/graphics_data.d.ts +15 -1
- package/types/phaser/display/graphics_data.d.ts.map +1 -1
- package/types/phaser/display/graphics_data_util.d.ts +3 -2
- package/types/phaser/display/graphics_data_util.d.ts.map +1 -1
- package/types/phaser/display/group.d.ts +80 -10
- package/types/phaser/display/group.d.ts.map +1 -1
- package/types/phaser/display/image.d.ts +72 -6
- package/types/phaser/display/image.d.ts.map +1 -1
- package/types/phaser/display/sprite_batch.d.ts +4 -3
- package/types/phaser/display/sprite_batch.d.ts.map +1 -1
- package/types/phaser/display/sprite_util.d.ts.map +1 -1
- package/types/phaser/display/text.d.ts +366 -46
- package/types/phaser/display/text.d.ts.map +1 -1
- package/types/phaser/display/webgl/abstract_filter.d.ts +8 -6
- package/types/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
- package/types/phaser/display/webgl/base_texture.d.ts +20 -1
- package/types/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/types/phaser/display/webgl/blend_manager.d.ts +11 -6
- package/types/phaser/display/webgl/blend_manager.d.ts.map +1 -1
- package/types/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/types/phaser/display/webgl/earcut_node.d.ts +9 -9
- package/types/phaser/display/webgl/earcut_node.d.ts.map +1 -1
- package/types/phaser/display/webgl/fast_sprite_batch.d.ts +33 -6
- package/types/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/types/phaser/display/webgl/filter_manager.d.ts +22 -6
- package/types/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/types/phaser/display/webgl/filter_texture.d.ts +21 -3
- package/types/phaser/display/webgl/filter_texture.d.ts.map +1 -1
- package/types/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/types/phaser/display/webgl/graphics_data.d.ts +10 -6
- package/types/phaser/display/webgl/graphics_data.d.ts.map +1 -1
- package/types/phaser/display/webgl/mask_manager.d.ts.map +1 -1
- package/types/phaser/display/webgl/render_texture.d.ts +30 -3
- package/types/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/types/phaser/display/webgl/renderer.d.ts +41 -4
- package/types/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/complex.d.ts +10 -0
- package/types/phaser/display/webgl/shader/complex.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/fast.d.ts +10 -0
- package/types/phaser/display/webgl/shader/fast.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/normal.d.ts +20 -0
- package/types/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/primitive.d.ts +10 -0
- package/types/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/strip.d.ts +10 -0
- package/types/phaser/display/webgl/shader/strip.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader_manager.d.ts +15 -0
- package/types/phaser/display/webgl/shader_manager.d.ts.map +1 -1
- package/types/phaser/display/webgl/sprite_batch.d.ts +37 -0
- package/types/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/types/phaser/display/webgl/stencil_manager.d.ts +25 -0
- package/types/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/types/phaser/display/webgl/texture.d.ts +21 -0
- package/types/phaser/display/webgl/texture.d.ts.map +1 -1
- package/types/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/types/phaser/display/webgl/util.d.ts +0 -6
- package/types/phaser/display/webgl/util.d.ts.map +1 -1
- package/types/phaser/geom/circle.d.ts +131 -9
- package/types/phaser/geom/circle.d.ts.map +1 -1
- package/types/phaser/geom/ellipse.d.ts +43 -5
- package/types/phaser/geom/ellipse.d.ts.map +1 -1
- package/types/phaser/geom/line.d.ts +159 -13
- package/types/phaser/geom/line.d.ts.map +1 -1
- package/types/phaser/geom/matrix.d.ts +85 -11
- package/types/phaser/geom/matrix.d.ts.map +1 -1
- package/types/phaser/geom/point.d.ts +170 -18
- package/types/phaser/geom/point.d.ts.map +1 -1
- package/types/phaser/geom/polygon.d.ts +45 -5
- package/types/phaser/geom/polygon.d.ts.map +1 -1
- package/types/phaser/geom/rectangle.d.ts +253 -20
- package/types/phaser/geom/rectangle.d.ts.map +1 -1
- package/types/phaser/geom/rounded_rectangle.d.ts +11 -1
- package/types/phaser/geom/rounded_rectangle.d.ts.map +1 -1
- package/types/phaser/geom/util/circle.d.ts +3 -3
- package/types/phaser/geom/util/circle.d.ts.map +1 -1
- package/types/phaser/geom/util/ellipse.d.ts +0 -6
- package/types/phaser/geom/util/ellipse.d.ts.map +1 -1
- package/types/phaser/geom/util/line.d.ts +5 -5
- package/types/phaser/geom/util/line.d.ts.map +1 -1
- package/types/phaser/geom/util/matrix.d.ts.map +1 -1
- package/types/phaser/geom/util/point.d.ts.map +1 -1
- package/types/phaser/geom/util/polygon.d.ts.map +1 -1
- package/types/phaser/geom/util/rectangle.d.ts.map +1 -1
- package/types/phaser/geom/util/rounded_rectangle.d.ts.map +1 -1
- package/types/phaser/util/math.d.ts +0 -5
- package/types/phaser/util/math.d.ts.map +1 -1
package/src/phaser/geom/line.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module geom/line
|
|
3
|
-
* @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
|
|
4
|
-
* @author Andras Csizmadia <andras@vpmedia.hu>
|
|
5
|
-
* @author Richard Davey <rich@photonstorm.com>
|
|
6
|
-
*/
|
|
7
1
|
import { Point } from './point';
|
|
8
2
|
import { clone, intersectsPoints, reflect } from './util/line';
|
|
9
3
|
import { wrap } from '../util/math';
|
|
@@ -23,30 +17,54 @@ export class Line {
|
|
|
23
17
|
this.type = GEOM_LINE;
|
|
24
18
|
}
|
|
25
19
|
|
|
20
|
+
/**
|
|
21
|
+
* TBD.
|
|
22
|
+
* @param {number} x1 - TBD.
|
|
23
|
+
* @param {number} y1 - TBD.
|
|
24
|
+
* @param {number} x2 - TBD.
|
|
25
|
+
* @param {number} y2 - TBD.
|
|
26
|
+
* @returns {Line} TBD.
|
|
27
|
+
*/
|
|
26
28
|
setTo(x1, y1, x2, y2) {
|
|
27
29
|
this.start.setTo(x1, y1);
|
|
28
30
|
this.end.setTo(x2, y2);
|
|
29
31
|
return this;
|
|
30
32
|
}
|
|
31
33
|
|
|
34
|
+
/**
|
|
35
|
+
* TBD.
|
|
36
|
+
* @param {object} startSprite - TBD.
|
|
37
|
+
* @param {object} endSprite - TBD.
|
|
38
|
+
* @param {boolean} useCenter - TBD.
|
|
39
|
+
* @returns {Line} TBD.
|
|
40
|
+
*/
|
|
32
41
|
fromSprite(startSprite, endSprite, useCenter = false) {
|
|
33
42
|
if (useCenter) {
|
|
34
|
-
return this.setTo(
|
|
35
|
-
startSprite.center.x,
|
|
36
|
-
startSprite.center.y,
|
|
37
|
-
endSprite.center.x,
|
|
38
|
-
endSprite.center.y
|
|
39
|
-
);
|
|
43
|
+
return this.setTo(startSprite.center.x, startSprite.center.y, endSprite.center.x, endSprite.center.y);
|
|
40
44
|
}
|
|
41
45
|
return this.setTo(startSprite.x, startSprite.y, endSprite.x, endSprite.y);
|
|
42
46
|
}
|
|
43
47
|
|
|
48
|
+
/**
|
|
49
|
+
* TBD.
|
|
50
|
+
* @param {number} x - TBD.
|
|
51
|
+
* @param {number} y - TBD.
|
|
52
|
+
* @param {number} angle - TBD.
|
|
53
|
+
* @param {number} length - TBD.
|
|
54
|
+
* @returns {Line} TBD.
|
|
55
|
+
*/
|
|
44
56
|
fromAngle(x, y, angle, length) {
|
|
45
57
|
this.start.setTo(x, y);
|
|
46
58
|
this.end.setTo(x + Math.cos(angle) * length, y + Math.sin(angle) * length);
|
|
47
59
|
return this;
|
|
48
60
|
}
|
|
49
61
|
|
|
62
|
+
/**
|
|
63
|
+
* TBD.
|
|
64
|
+
* @param {number} angle - TBD.
|
|
65
|
+
* @param {boolean} asDegrees - TBD.
|
|
66
|
+
* @returns {Line} TBD.
|
|
67
|
+
*/
|
|
50
68
|
rotate(angle, asDegrees = false) {
|
|
51
69
|
const cx = (this.start.x + this.end.x) / 2;
|
|
52
70
|
const cy = (this.start.y + this.end.y) / 2;
|
|
@@ -55,20 +73,45 @@ export class Line {
|
|
|
55
73
|
return this;
|
|
56
74
|
}
|
|
57
75
|
|
|
76
|
+
/**
|
|
77
|
+
* TBD.
|
|
78
|
+
* @param {number} x - TBD.
|
|
79
|
+
* @param {number} y - TBD.
|
|
80
|
+
* @param {number} angle - TBD.
|
|
81
|
+
* @param {boolean} asDegrees - TBD.
|
|
82
|
+
* @returns {Line} TBD.
|
|
83
|
+
*/
|
|
58
84
|
rotateAround(x, y, angle, asDegrees = false) {
|
|
59
85
|
this.start.rotate(x, y, angle, asDegrees);
|
|
60
86
|
this.end.rotate(x, y, angle, asDegrees);
|
|
61
87
|
return this;
|
|
62
88
|
}
|
|
63
89
|
|
|
90
|
+
/**
|
|
91
|
+
* TBD.
|
|
92
|
+
* @param {Line} line - TBD.
|
|
93
|
+
* @param {boolean} asSegment - TBD.
|
|
94
|
+
* @param {Point} result - TBD.
|
|
95
|
+
* @returns {Point} TBD.
|
|
96
|
+
*/
|
|
64
97
|
intersects(line, asSegment, result) {
|
|
65
98
|
return intersectsPoints(this.start, this.end, line.start, line.end, asSegment, result);
|
|
66
99
|
}
|
|
67
100
|
|
|
101
|
+
/**
|
|
102
|
+
* TBD.
|
|
103
|
+
* @param {Line} line - TBD.
|
|
104
|
+
* @returns {number} TBD.
|
|
105
|
+
*/
|
|
68
106
|
reflect(line) {
|
|
69
107
|
return reflect(this, line);
|
|
70
108
|
}
|
|
71
109
|
|
|
110
|
+
/**
|
|
111
|
+
* TBD.
|
|
112
|
+
* @param {Point} output - TBD.
|
|
113
|
+
* @returns {Point} TBD.
|
|
114
|
+
*/
|
|
72
115
|
midPoint(output = null) {
|
|
73
116
|
const result = output || new Point();
|
|
74
117
|
result.x = (this.start.x + this.end.x) / 2;
|
|
@@ -76,6 +119,11 @@ export class Line {
|
|
|
76
119
|
return result;
|
|
77
120
|
}
|
|
78
121
|
|
|
122
|
+
/**
|
|
123
|
+
* TBD.
|
|
124
|
+
* @param {number} x - TBD.
|
|
125
|
+
* @param {number} y - TBD.
|
|
126
|
+
*/
|
|
79
127
|
centerOn(x, y) {
|
|
80
128
|
const cx = (this.start.x + this.end.x) / 2;
|
|
81
129
|
const cy = (this.start.y + this.end.y) / 2;
|
|
@@ -85,13 +133,22 @@ export class Line {
|
|
|
85
133
|
this.end.add(tx, ty);
|
|
86
134
|
}
|
|
87
135
|
|
|
136
|
+
/**
|
|
137
|
+
* TBD.
|
|
138
|
+
* @param {number} x - TBD.
|
|
139
|
+
* @param {number} y - TBD.
|
|
140
|
+
* @returns {boolean} TBD.
|
|
141
|
+
*/
|
|
88
142
|
pointOnLine(x, y) {
|
|
89
|
-
return (
|
|
90
|
-
(x - this.start.x) * (this.end.y - this.start.y) ===
|
|
91
|
-
(this.end.x - this.start.x) * (y - this.start.y)
|
|
92
|
-
);
|
|
143
|
+
return (x - this.start.x) * (this.end.y - this.start.y) === (this.end.x - this.start.x) * (y - this.start.y);
|
|
93
144
|
}
|
|
94
145
|
|
|
146
|
+
/**
|
|
147
|
+
* TBD.
|
|
148
|
+
* @param {number} x - TBD.
|
|
149
|
+
* @param {number} y - TBD.
|
|
150
|
+
* @returns {boolean} TBD.
|
|
151
|
+
*/
|
|
95
152
|
pointOnSegment(x, y) {
|
|
96
153
|
const xMin = Math.min(this.start.x, this.end.x);
|
|
97
154
|
const xMax = Math.max(this.start.x, this.end.x);
|
|
@@ -100,6 +157,11 @@ export class Line {
|
|
|
100
157
|
return this.pointOnLine(x, y) && x >= xMin && x <= xMax && y >= yMin && y <= yMax;
|
|
101
158
|
}
|
|
102
159
|
|
|
160
|
+
/**
|
|
161
|
+
* TBD.
|
|
162
|
+
* @param {Point} output - TBD.
|
|
163
|
+
* @returns {Point} TBD.
|
|
164
|
+
*/
|
|
103
165
|
random(output = null) {
|
|
104
166
|
const result = output || new Point();
|
|
105
167
|
const t = Math.random();
|
|
@@ -108,6 +170,12 @@ export class Line {
|
|
|
108
170
|
return result;
|
|
109
171
|
}
|
|
110
172
|
|
|
173
|
+
/**
|
|
174
|
+
* TBD.
|
|
175
|
+
* @param {number} stepRate - TBD.
|
|
176
|
+
* @param {number[][]} results - TBD.
|
|
177
|
+
* @returns {number[][]} TBD.
|
|
178
|
+
*/
|
|
111
179
|
coordinatesOnLine(stepRate = 1, results = []) {
|
|
112
180
|
let x1 = Math.round(this.start.x);
|
|
113
181
|
let y1 = Math.round(this.start.y);
|
|
@@ -138,10 +206,18 @@ export class Line {
|
|
|
138
206
|
return results;
|
|
139
207
|
}
|
|
140
208
|
|
|
209
|
+
/**
|
|
210
|
+
* TBD.
|
|
211
|
+
* @returns {Line} TBD.
|
|
212
|
+
*/
|
|
141
213
|
clone() {
|
|
142
214
|
return clone(this);
|
|
143
215
|
}
|
|
144
216
|
|
|
217
|
+
/**
|
|
218
|
+
* TBD.
|
|
219
|
+
* @returns {number} TBD.
|
|
220
|
+
*/
|
|
145
221
|
get length() {
|
|
146
222
|
return Math.sqrt(
|
|
147
223
|
(this.end.x - this.start.x) * (this.end.x - this.start.x) +
|
|
@@ -149,58 +225,114 @@ export class Line {
|
|
|
149
225
|
);
|
|
150
226
|
}
|
|
151
227
|
|
|
228
|
+
/**
|
|
229
|
+
* TBD.
|
|
230
|
+
* @returns {number} TBD.
|
|
231
|
+
*/
|
|
152
232
|
get angle() {
|
|
153
233
|
return Math.atan2(this.end.y - this.start.y, this.end.x - this.start.x);
|
|
154
234
|
}
|
|
155
235
|
|
|
236
|
+
/**
|
|
237
|
+
* TBD.
|
|
238
|
+
* @returns {number} TBD.
|
|
239
|
+
*/
|
|
156
240
|
get slope() {
|
|
157
241
|
return (this.end.y - this.start.y) / (this.end.x - this.start.x);
|
|
158
242
|
}
|
|
159
243
|
|
|
244
|
+
/**
|
|
245
|
+
* TBD.
|
|
246
|
+
* @returns {number} TBD.
|
|
247
|
+
*/
|
|
160
248
|
get perpSlope() {
|
|
161
249
|
return -((this.end.x - this.start.x) / (this.end.y - this.start.y));
|
|
162
250
|
}
|
|
163
251
|
|
|
252
|
+
/**
|
|
253
|
+
* TBD.
|
|
254
|
+
* @returns {number} TBD.
|
|
255
|
+
*/
|
|
164
256
|
get x() {
|
|
165
257
|
return Math.min(this.start.x, this.end.x);
|
|
166
258
|
}
|
|
167
259
|
|
|
260
|
+
/**
|
|
261
|
+
* TBD.
|
|
262
|
+
* @returns {number} TBD.
|
|
263
|
+
*/
|
|
168
264
|
get y() {
|
|
169
265
|
return Math.min(this.start.y, this.end.y);
|
|
170
266
|
}
|
|
171
267
|
|
|
268
|
+
/**
|
|
269
|
+
* TBD.
|
|
270
|
+
* @returns {number} TBD.
|
|
271
|
+
*/
|
|
172
272
|
get left() {
|
|
173
273
|
return Math.min(this.start.x, this.end.x);
|
|
174
274
|
}
|
|
175
275
|
|
|
276
|
+
/**
|
|
277
|
+
* TBD.
|
|
278
|
+
* @returns {number} TBD.
|
|
279
|
+
*/
|
|
176
280
|
get right() {
|
|
177
281
|
return Math.max(this.start.x, this.end.x);
|
|
178
282
|
}
|
|
179
283
|
|
|
284
|
+
/**
|
|
285
|
+
* TBD.
|
|
286
|
+
* @returns {number} TBD.
|
|
287
|
+
*/
|
|
180
288
|
get top() {
|
|
181
289
|
return Math.min(this.start.y, this.end.y);
|
|
182
290
|
}
|
|
183
291
|
|
|
292
|
+
/**
|
|
293
|
+
* TBD.
|
|
294
|
+
* @returns {number} TBD.
|
|
295
|
+
*/
|
|
184
296
|
get bottom() {
|
|
185
297
|
return Math.max(this.start.y, this.end.y);
|
|
186
298
|
}
|
|
187
299
|
|
|
300
|
+
/**
|
|
301
|
+
* TBD.
|
|
302
|
+
* @returns {number} TBD.
|
|
303
|
+
*/
|
|
188
304
|
get width() {
|
|
189
305
|
return Math.abs(this.start.x - this.end.x);
|
|
190
306
|
}
|
|
191
307
|
|
|
308
|
+
/**
|
|
309
|
+
* TBD.
|
|
310
|
+
* @returns {number} TBD.
|
|
311
|
+
*/
|
|
192
312
|
get height() {
|
|
193
313
|
return Math.abs(this.start.y - this.end.y);
|
|
194
314
|
}
|
|
195
315
|
|
|
316
|
+
/**
|
|
317
|
+
* TBD.
|
|
318
|
+
* @returns {number} TBD.
|
|
319
|
+
*/
|
|
196
320
|
get normalX() {
|
|
197
321
|
return Math.cos(this.angle - 1.5707963267948966);
|
|
198
322
|
}
|
|
199
323
|
|
|
324
|
+
/**
|
|
325
|
+
* TBD.
|
|
326
|
+
* @returns {number} TBD.
|
|
327
|
+
*/
|
|
200
328
|
get normalY() {
|
|
201
329
|
return Math.sin(this.angle - 1.5707963267948966);
|
|
202
330
|
}
|
|
203
331
|
|
|
332
|
+
/**
|
|
333
|
+
* TBD.
|
|
334
|
+
* @returns {number} TBD.
|
|
335
|
+
*/
|
|
204
336
|
get normalAngle() {
|
|
205
337
|
return wrap(this.angle - 1.5707963267948966, -Math.PI, Math.PI);
|
|
206
338
|
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module geom/matrix
|
|
3
|
-
* @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
|
|
4
|
-
* @author Andras Csizmadia <andras@vpmedia.hu>
|
|
5
|
-
* @author Richard Davey <rich@photonstorm.com>
|
|
6
|
-
*/
|
|
7
1
|
import { Point } from './point';
|
|
8
2
|
import { clone } from './util/matrix';
|
|
9
3
|
import { GEOM_MATRIX } from '../core/const';
|
|
@@ -28,10 +22,25 @@ export class Matrix {
|
|
|
28
22
|
this.type = GEOM_MATRIX;
|
|
29
23
|
}
|
|
30
24
|
|
|
25
|
+
/**
|
|
26
|
+
* TBD.
|
|
27
|
+
* @param {number[]} array - TBD.
|
|
28
|
+
* @returns {Matrix} TBD.
|
|
29
|
+
*/
|
|
31
30
|
fromArray(array) {
|
|
32
31
|
return this.setTo(array[0], array[1], array[3], array[4], array[2], array[5]);
|
|
33
32
|
}
|
|
34
33
|
|
|
34
|
+
/**
|
|
35
|
+
* TBD.
|
|
36
|
+
* @param {number} a - TBD.
|
|
37
|
+
* @param {number} b - TBD.
|
|
38
|
+
* @param {number} c - TBD.
|
|
39
|
+
* @param {number} d - TBD.
|
|
40
|
+
* @param {number} tx - TBD.
|
|
41
|
+
* @param {number} ty - TBD.
|
|
42
|
+
* @returns {Matrix} TBD.
|
|
43
|
+
*/
|
|
35
44
|
setTo(a, b, c, d, tx, ty) {
|
|
36
45
|
this.a = a;
|
|
37
46
|
this.b = b;
|
|
@@ -42,15 +51,29 @@ export class Matrix {
|
|
|
42
51
|
return this;
|
|
43
52
|
}
|
|
44
53
|
|
|
54
|
+
/**
|
|
55
|
+
* TBD.
|
|
56
|
+
* @returns {Matrix} TBD.
|
|
57
|
+
*/
|
|
45
58
|
clone() {
|
|
46
59
|
return clone(this);
|
|
47
60
|
}
|
|
48
61
|
|
|
62
|
+
/**
|
|
63
|
+
* TBD.
|
|
64
|
+
* @param {Matrix} matrix - TBD.
|
|
65
|
+
* @returns {Matrix} TBD.
|
|
66
|
+
*/
|
|
49
67
|
copyTo(matrix) {
|
|
50
68
|
matrix.copyFrom(this);
|
|
51
69
|
return matrix;
|
|
52
70
|
}
|
|
53
71
|
|
|
72
|
+
/**
|
|
73
|
+
* TBD.
|
|
74
|
+
* @param {Matrix} matrix - TBD.
|
|
75
|
+
* @returns {Matrix} TBD.
|
|
76
|
+
*/
|
|
54
77
|
copyFrom(matrix) {
|
|
55
78
|
this.a = matrix.a;
|
|
56
79
|
this.b = matrix.b;
|
|
@@ -61,6 +84,12 @@ export class Matrix {
|
|
|
61
84
|
return this;
|
|
62
85
|
}
|
|
63
86
|
|
|
87
|
+
/**
|
|
88
|
+
* TBD.
|
|
89
|
+
* @param {boolean} transpose - TBD.
|
|
90
|
+
* @param {Float32Array} output - TBD.
|
|
91
|
+
* @returns {Float32Array} TBD.
|
|
92
|
+
*/
|
|
64
93
|
toArray(transpose = false, output = null) {
|
|
65
94
|
const result = output || new Float32Array(9);
|
|
66
95
|
if (transpose) {
|
|
@@ -87,6 +116,12 @@ export class Matrix {
|
|
|
87
116
|
return result;
|
|
88
117
|
}
|
|
89
118
|
|
|
119
|
+
/**
|
|
120
|
+
* TBD.
|
|
121
|
+
* @param {Point} pos - TBD.
|
|
122
|
+
* @param {Point} output - TBD.
|
|
123
|
+
* @returns {Point} TBD.
|
|
124
|
+
*/
|
|
90
125
|
apply(pos, output = null) {
|
|
91
126
|
const result = output || new Point();
|
|
92
127
|
result.x = this.a * pos.x + this.c * pos.y + this.tx;
|
|
@@ -94,6 +129,12 @@ export class Matrix {
|
|
|
94
129
|
return result;
|
|
95
130
|
}
|
|
96
131
|
|
|
132
|
+
/**
|
|
133
|
+
* TBD.
|
|
134
|
+
* @param {Point} pos - TBD.
|
|
135
|
+
* @param {Point} output - TBD.
|
|
136
|
+
* @returns {Point} TBD.
|
|
137
|
+
*/
|
|
97
138
|
applyInverse(pos, output = null) {
|
|
98
139
|
const result = output || new Point();
|
|
99
140
|
const id = 1 / (this.a * this.d + this.c * -this.b);
|
|
@@ -104,12 +145,24 @@ export class Matrix {
|
|
|
104
145
|
return result;
|
|
105
146
|
}
|
|
106
147
|
|
|
148
|
+
/**
|
|
149
|
+
* TBD.
|
|
150
|
+
* @param {number} x - TBD.
|
|
151
|
+
* @param {number} y - TBD.
|
|
152
|
+
* @returns {Matrix} TBD.
|
|
153
|
+
*/
|
|
107
154
|
translate(x, y) {
|
|
108
155
|
this.tx += x;
|
|
109
156
|
this.ty += y;
|
|
110
157
|
return this;
|
|
111
158
|
}
|
|
112
159
|
|
|
160
|
+
/**
|
|
161
|
+
* TBD.
|
|
162
|
+
* @param {number} x - TBD.
|
|
163
|
+
* @param {number} y - TBD.
|
|
164
|
+
* @returns {Matrix} TBD.
|
|
165
|
+
*/
|
|
113
166
|
scale(x, y) {
|
|
114
167
|
this.a *= x;
|
|
115
168
|
this.d *= y;
|
|
@@ -120,6 +173,11 @@ export class Matrix {
|
|
|
120
173
|
return this;
|
|
121
174
|
}
|
|
122
175
|
|
|
176
|
+
/**
|
|
177
|
+
* TBD.
|
|
178
|
+
* @param {number} angle - TBD.
|
|
179
|
+
* @returns {Matrix} TBD.
|
|
180
|
+
*/
|
|
123
181
|
rotate(angle) {
|
|
124
182
|
const cos = Math.cos(angle);
|
|
125
183
|
const sin = Math.sin(angle);
|
|
@@ -135,6 +193,11 @@ export class Matrix {
|
|
|
135
193
|
return this;
|
|
136
194
|
}
|
|
137
195
|
|
|
196
|
+
/**
|
|
197
|
+
* TBD.
|
|
198
|
+
* @param {Matrix} matrix - TBD.
|
|
199
|
+
* @returns {Matrix} TBD.
|
|
200
|
+
*/
|
|
138
201
|
append(matrix) {
|
|
139
202
|
const a1 = this.a;
|
|
140
203
|
const b1 = this.b;
|
|
@@ -149,6 +212,10 @@ export class Matrix {
|
|
|
149
212
|
return this;
|
|
150
213
|
}
|
|
151
214
|
|
|
215
|
+
/**
|
|
216
|
+
* TBD.
|
|
217
|
+
* @returns {Matrix} TBD.
|
|
218
|
+
*/
|
|
152
219
|
identity() {
|
|
153
220
|
return this.setTo(1, 0, 0, 1, 0, 0);
|
|
154
221
|
}
|