@vpmedia/phaser 1.0.1 → 1.0.3

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.
Files changed (112) hide show
  1. package/README.md +20 -3
  2. package/dist/phaser.cjs +1 -1
  3. package/dist/phaser.cjs.LICENSE.txt +1 -1
  4. package/dist/phaser.cjs.map +1 -1
  5. package/dist/phaser.js +1 -1
  6. package/dist/phaser.js.LICENSE.txt +1 -1
  7. package/dist/phaser.js.map +1 -1
  8. package/package.json +23 -17
  9. package/src/index.js +142 -0
  10. package/src/phaser/core/animation.js +355 -0
  11. package/src/phaser/core/animation_manager.js +238 -0
  12. package/src/phaser/core/animation_parser.js +133 -0
  13. package/src/phaser/core/array_set.js +107 -0
  14. package/src/phaser/core/cache.js +558 -0
  15. package/src/phaser/core/const.js +106 -0
  16. package/src/phaser/core/device.js +67 -0
  17. package/src/phaser/core/device_util.js +388 -0
  18. package/src/phaser/core/dom.js +207 -0
  19. package/src/phaser/core/event_manager.js +243 -0
  20. package/src/phaser/core/factory.js +74 -0
  21. package/src/phaser/core/frame.js +75 -0
  22. package/src/phaser/core/frame_data.js +84 -0
  23. package/src/phaser/core/frame_util.js +33 -0
  24. package/src/phaser/core/game.js +412 -0
  25. package/src/phaser/core/input.js +401 -0
  26. package/src/phaser/core/input_button.js +102 -0
  27. package/src/phaser/core/input_handler.js +687 -0
  28. package/src/phaser/core/input_mouse.js +289 -0
  29. package/src/phaser/core/input_mspointer.js +197 -0
  30. package/src/phaser/core/input_pointer.js +427 -0
  31. package/src/phaser/core/input_touch.js +157 -0
  32. package/src/phaser/core/loader.js +1057 -0
  33. package/src/phaser/core/loader_parser.js +109 -0
  34. package/src/phaser/core/raf.js +46 -0
  35. package/src/phaser/core/raf_fb.js +75 -0
  36. package/src/phaser/core/raf_to.js +34 -0
  37. package/src/phaser/core/scale_manager.js +806 -0
  38. package/src/phaser/core/scene.js +65 -0
  39. package/src/phaser/core/scene_manager.js +309 -0
  40. package/src/phaser/core/signal.js +175 -0
  41. package/src/phaser/core/signal_binding.js +69 -0
  42. package/src/phaser/core/sound.js +538 -0
  43. package/src/phaser/core/sound_manager.js +364 -0
  44. package/src/phaser/core/stage.js +108 -0
  45. package/src/phaser/core/time.js +203 -0
  46. package/src/phaser/core/timer.js +276 -0
  47. package/src/phaser/core/timer_event.js +21 -0
  48. package/src/phaser/core/tween.js +329 -0
  49. package/src/phaser/core/tween_data.js +258 -0
  50. package/src/phaser/core/tween_easing.js +341 -0
  51. package/src/phaser/core/tween_manager.js +185 -0
  52. package/src/phaser/core/world.js +18 -0
  53. package/src/phaser/display/bitmap_text.js +322 -0
  54. package/src/phaser/display/button.js +194 -0
  55. package/src/phaser/display/canvas/buffer.js +36 -0
  56. package/src/phaser/display/canvas/graphics.js +227 -0
  57. package/src/phaser/display/canvas/masker.js +39 -0
  58. package/src/phaser/display/canvas/pool.js +126 -0
  59. package/src/phaser/display/canvas/renderer.js +123 -0
  60. package/src/phaser/display/canvas/tinter.js +144 -0
  61. package/src/phaser/display/canvas/util.js +159 -0
  62. package/src/phaser/display/display_object.js +597 -0
  63. package/src/phaser/display/graphics.js +723 -0
  64. package/src/phaser/display/graphics_data.js +27 -0
  65. package/src/phaser/display/graphics_data_util.js +15 -0
  66. package/src/phaser/display/group.js +227 -0
  67. package/src/phaser/display/image.js +288 -0
  68. package/src/phaser/display/sprite_batch.js +15 -0
  69. package/src/phaser/display/sprite_util.js +250 -0
  70. package/src/phaser/display/text.js +1089 -0
  71. package/src/phaser/display/webgl/abstract_filter.js +25 -0
  72. package/src/phaser/display/webgl/base_texture.js +68 -0
  73. package/src/phaser/display/webgl/blend_manager.js +35 -0
  74. package/src/phaser/display/webgl/earcut.js +662 -0
  75. package/src/phaser/display/webgl/earcut_node.js +28 -0
  76. package/src/phaser/display/webgl/fast_sprite_batch.js +242 -0
  77. package/src/phaser/display/webgl/filter_manager.js +46 -0
  78. package/src/phaser/display/webgl/filter_texture.js +61 -0
  79. package/src/phaser/display/webgl/graphics.js +624 -0
  80. package/src/phaser/display/webgl/graphics_data.js +42 -0
  81. package/src/phaser/display/webgl/mask_manager.js +36 -0
  82. package/src/phaser/display/webgl/render_texture.js +81 -0
  83. package/src/phaser/display/webgl/renderer.js +234 -0
  84. package/src/phaser/display/webgl/shader/complex.js +74 -0
  85. package/src/phaser/display/webgl/shader/fast.js +97 -0
  86. package/src/phaser/display/webgl/shader/normal.js +225 -0
  87. package/src/phaser/display/webgl/shader/primitive.js +72 -0
  88. package/src/phaser/display/webgl/shader/strip.js +77 -0
  89. package/src/phaser/display/webgl/shader_manager.js +89 -0
  90. package/src/phaser/display/webgl/sprite_batch.js +320 -0
  91. package/src/phaser/display/webgl/stencil_manager.js +170 -0
  92. package/src/phaser/display/webgl/texture.js +117 -0
  93. package/src/phaser/display/webgl/texture_util.js +34 -0
  94. package/src/phaser/display/webgl/util.js +78 -0
  95. package/src/phaser/geom/circle.js +186 -0
  96. package/src/phaser/geom/ellipse.js +65 -0
  97. package/src/phaser/geom/line.js +190 -0
  98. package/src/phaser/geom/matrix.js +147 -0
  99. package/src/phaser/geom/point.js +164 -0
  100. package/src/phaser/geom/polygon.js +140 -0
  101. package/src/phaser/geom/rectangle.js +306 -0
  102. package/src/phaser/geom/rounded_rectangle.js +36 -0
  103. package/src/phaser/geom/util/circle.js +122 -0
  104. package/src/phaser/geom/util/ellipse.js +34 -0
  105. package/src/phaser/geom/util/line.js +135 -0
  106. package/src/phaser/geom/util/matrix.js +53 -0
  107. package/src/phaser/geom/util/point.js +296 -0
  108. package/src/phaser/geom/util/polygon.js +28 -0
  109. package/src/phaser/geom/util/rectangle.js +229 -0
  110. package/src/phaser/geom/util/rounded_rectangle.js +32 -0
  111. package/src/phaser/util/math.js +297 -0
  112. package/src/phaser/util/string.js +32 -0
@@ -0,0 +1,122 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ import Circle from '../circle';
7
+ import Point from '../point';
8
+ import { degToRad, distance } from '../../util/math';
9
+
10
+ /**
11
+ *
12
+ * @param {object} input TBD
13
+ * @param {object} output TBD
14
+ * @returns {object} TBD
15
+ */
16
+ export function clone(input, output = null) {
17
+ const result = output || new Circle();
18
+ result.x = input.x;
19
+ result.y = input.y;
20
+ result.diameter = input.diameter;
21
+ return result;
22
+ }
23
+
24
+ /**
25
+ *
26
+ * @param {object} a TBD
27
+ * @param {number} x TBD
28
+ * @param {number} y TBD
29
+ * @returns {boolean} TBD
30
+ */
31
+ export function contains(a, x, y) {
32
+ if (a.radius > 0 && x >= a.left && x <= a.right && y >= a.top && y <= a.bottom) {
33
+ const dx = (a.x - x) * (a.x - x);
34
+ const dy = (a.y - y) * (a.y - y);
35
+ return (dx + dy) <= (a.radius * a.radius);
36
+ }
37
+ return false;
38
+ }
39
+
40
+ /**
41
+ *
42
+ * @param {object} a TBD
43
+ * @param {object} b TBD
44
+ * @returns {boolean} TBD
45
+ */
46
+ export function equals(a, b) {
47
+ return (a.x === b.x && a.y === b.y && a.diameter === b.diameter);
48
+ }
49
+
50
+ /**
51
+ *
52
+ * @param {object} a TBD
53
+ * @param {object} b TBD
54
+ * @returns {boolean} TBD
55
+ */
56
+ export function intersects(a, b) {
57
+ return distance(a.x, a.y, b.x, b.y) <= (a.radius + b.radius);
58
+ }
59
+
60
+ /**
61
+ *
62
+ * @param {object} a TBD
63
+ * @param {number} angle TBD
64
+ * @param {boolean} asDegrees TBD
65
+ * @param {object} output TBD
66
+ * @returns {object} TBD
67
+ */
68
+ export function circumferencePoint(a, angle, asDegrees = false, output = null) {
69
+ const result = output || new Point();
70
+ if (asDegrees === true) {
71
+ angle = degToRad(angle);
72
+ }
73
+ result.x = a.x + a.radius * Math.cos(angle);
74
+ result.y = a.y + a.radius * Math.sin(angle);
75
+ return result;
76
+ }
77
+
78
+ /**
79
+ *
80
+ * @param {object} a TBD
81
+ * @param {number} angle TBD
82
+ * @param {boolean} asDegrees TBD
83
+ * @param {object} output TBD
84
+ * @returns {object} TBD
85
+ */
86
+ export function intersectsPoint(a, angle, asDegrees = false, output = null) {
87
+ const result = output || new Point();
88
+ if (asDegrees === true) {
89
+ angle = degToRad(angle);
90
+ }
91
+ result.x = a.x + a.radius * Math.cos(angle);
92
+ result.y = a.y + a.radius * Math.sin(angle);
93
+ return result;
94
+ }
95
+
96
+ /**
97
+ *
98
+ * @param {object} c TBD
99
+ * @param {object} r TBD
100
+ * @returns {boolean} TBD
101
+ */
102
+ export function intersectsRectangle(c, r) {
103
+ const cx = Math.abs(c.x - r.x - r.halfWidth);
104
+ const xDist = r.halfWidth + c.radius;
105
+ if (cx > xDist) {
106
+ return false;
107
+ }
108
+ const cy = Math.abs(c.y - r.y - r.halfHeight);
109
+ const yDist = r.halfHeight + c.radius;
110
+ if (cy > yDist) {
111
+ return false;
112
+ }
113
+ if (cx <= r.halfWidth || cy <= r.halfHeight) {
114
+ return true;
115
+ }
116
+ const xCornerDist = cx - r.halfWidth;
117
+ const yCornerDist = cy - r.halfHeight;
118
+ const xCornerDistSq = xCornerDist * xCornerDist;
119
+ const yCornerDistSq = yCornerDist * yCornerDist;
120
+ const maxCornerDistSq = c.radius * c.radius;
121
+ return xCornerDistSq + yCornerDistSq <= maxCornerDistSq;
122
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+
7
+ /**
8
+ * TBD
9
+ *
10
+ * @deprecated
11
+ * @returns {boolean} TBD
12
+ */
13
+ export default function () {
14
+ return true;
15
+ }
16
+
17
+ /**
18
+ *
19
+ * @param {object} a TBD
20
+ * @param {number} x TBD
21
+ * @param {number} y TBD
22
+ * @returns {boolean} TBD
23
+ */
24
+ export function contains(a, x, y) {
25
+ if (a.width <= 0 || a.height <= 0) {
26
+ return false;
27
+ }
28
+ // Normalize the coords to an ellipse with center 0,0 and a radius of 0.5
29
+ let normx = ((x - a.x) / a.width) - 0.5;
30
+ let normy = ((y - a.y) / a.height) - 0.5;
31
+ normx *= normx;
32
+ normy *= normy;
33
+ return (normx + normy < 0.25);
34
+ }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ import Point from '../point';
7
+ import Line from '../line';
8
+ import { intersects as intersectsRect } from './rectangle';
9
+
10
+ /**
11
+ *
12
+ * @param {object} input TBD
13
+ * @param {object} output TBD
14
+ * @returns {object} TBD
15
+ */
16
+ export function clone(input, output = null) {
17
+ const result = output || new Line();
18
+ result.start.x = input.start.x;
19
+ result.start.y = input.start.y;
20
+ result.end.x = input.end.x;
21
+ result.end.y = input.end.y;
22
+ return result;
23
+ }
24
+
25
+ /**
26
+ *
27
+ * @param {object} a TBD
28
+ * @param {object} b TBD
29
+ * @param {object} e TBD
30
+ * @param {object} f TBD
31
+ * @param {boolean} asSegment TBD
32
+ * @param {object} output TBD
33
+ * @returns {boolean} TBD
34
+ */
35
+ export function intersectsPoints(a, b, e, f, asSegment = true, output = null) {
36
+ const result = output || new Point();
37
+ const a1 = b.y - a.y;
38
+ const a2 = f.y - e.y;
39
+ const b1 = a.x - b.x;
40
+ const b2 = e.x - f.x;
41
+ const c1 = (b.x * a.y) - (a.x * b.y);
42
+ const c2 = (f.x * e.y) - (e.x * f.y);
43
+ const denom = (a1 * b2) - (a2 * b1);
44
+ if (denom === 0) {
45
+ return null;
46
+ }
47
+ result.x = ((b1 * c2) - (b2 * c1)) / denom;
48
+ result.y = ((a2 * c1) - (a1 * c2)) / denom;
49
+ if (asSegment) {
50
+ const uc = ((f.y - e.y) * (b.x - a.x) - (f.x - e.x) * (b.y - a.y));
51
+ const ua = (((f.x - e.x) * (a.y - e.y)) - (f.y - e.y) * (a.x - e.x)) / uc;
52
+ const ub = (((b.x - a.x) * (a.y - e.y)) - ((b.y - a.y) * (a.x - e.x))) / uc;
53
+ if (ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1) {
54
+ return result;
55
+ }
56
+ return null;
57
+ }
58
+ return result;
59
+ }
60
+
61
+ /**
62
+ *
63
+ * @param {object} a TBD
64
+ * @param {object} b TBD
65
+ * @param {boolean} asSegment TBD
66
+ * @param {object} result TBD
67
+ * @returns {boolean} TBD
68
+ */
69
+ export function intersects(a, b, asSegment, result) {
70
+ return intersectsPoints(a.start, a.end, b.start, b.end, asSegment, result);
71
+ }
72
+
73
+ /**
74
+ *
75
+ * @param {object} line TBD
76
+ * @param {object} rect TBD
77
+ * @returns {boolean} TBD
78
+ */
79
+ export function intersectsRectangle(line, rect) {
80
+ // Quick bail out of the Line and Rect bounds don't intersect
81
+ if (intersectsRect(line, rect)) {
82
+ return false;
83
+ }
84
+ const x1 = line.start.x;
85
+ const y1 = line.start.y;
86
+ const x2 = line.end.x;
87
+ const y2 = line.end.y;
88
+ const bx1 = rect.x;
89
+ const by1 = rect.y;
90
+ const bx2 = rect.right;
91
+ const by2 = rect.bottom;
92
+ let t = 0;
93
+ // If the start or end of the line is inside the rect then we assume
94
+ // collision, as rects are solid for our use-case.
95
+ if ((x1 >= bx1 && x1 <= bx2 && y1 >= by1 && y1 <= by2) || (x2 >= bx1 && x2 <= bx2 && y2 >= by1 && y2 <= by2)) {
96
+ return true;
97
+ }
98
+ if (x1 < bx1 && x2 >= bx1) {
99
+ // Left edge
100
+ t = y1 + (y2 - y1) * (bx1 - x1) / (x2 - x1);
101
+ if (t > by1 && t <= by2) {
102
+ return true;
103
+ }
104
+ } else if (x1 > bx2 && x2 <= bx2) {
105
+ // Right edge
106
+ t = y1 + (y2 - y1) * (bx2 - x1) / (x2 - x1);
107
+ if (t >= by1 && t <= by2) {
108
+ return true;
109
+ }
110
+ }
111
+ if (y1 < by1 && y2 >= by1) {
112
+ // Top edge
113
+ t = x1 + (x2 - x1) * (by1 - y1) / (y2 - y1);
114
+ if (t >= bx1 && t <= bx2) {
115
+ return true;
116
+ }
117
+ } else if (y1 > by2 && y2 <= by2) {
118
+ // Bottom edge
119
+ t = x1 + (x2 - x1) * (by2 - y1) / (y2 - y1);
120
+ if (t >= bx1 && t <= bx2) {
121
+ return true;
122
+ }
123
+ }
124
+ return false;
125
+ }
126
+
127
+ /**
128
+ *
129
+ * @param {object} a TBD
130
+ * @param {object} b TBD
131
+ * @returns {number} TBD
132
+ */
133
+ export function reflect(a, b) {
134
+ return 2 * b.normalAngle - 3.141592653589793 - a.angle;
135
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ import Matrix from '../matrix';
7
+
8
+ /**
9
+ *
10
+ * @param {object} input TBD
11
+ * @param {object} output TBD
12
+ * @returns {object} TBD
13
+ */
14
+ export function clone(input, output = null) {
15
+ const result = output || new Matrix();
16
+ result.a = input.a;
17
+ result.b = input.b;
18
+ result.c = input.c;
19
+ result.d = input.d;
20
+ result.tx = input.tx;
21
+ result.ty = input.ty;
22
+ return result;
23
+ }
24
+
25
+ /**
26
+ * TBD
27
+ *
28
+ * @returns {object} TBD
29
+ */
30
+ export function getIdentityMatrix() {
31
+ if (!window.PhaserRegistry) {
32
+ window.PhaserRegistry = {};
33
+ }
34
+ if (!window.PhaserRegistry.IDENTITY_MATRIX) {
35
+ window.PhaserRegistry.IDENTITY_MATRIX = new Matrix();
36
+ }
37
+ return window.PhaserRegistry.IDENTITY_MATRIX;
38
+ }
39
+
40
+ /**
41
+ * TBD
42
+ *
43
+ * @returns {object} TBD
44
+ */
45
+ export function getTempMatrix() {
46
+ if (!window.PhaserRegistry) {
47
+ window.PhaserRegistry = {};
48
+ }
49
+ if (!window.PhaserRegistry.TEMP_MATRIX) {
50
+ window.PhaserRegistry.TEMP_MATRIX = new Matrix();
51
+ }
52
+ return window.PhaserRegistry.TEMP_MATRIX;
53
+ }
@@ -0,0 +1,296 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ import Point from '../point';
7
+
8
+ /**
9
+ *
10
+ * @param {object} a TBD
11
+ * @param {object} b TBD
12
+ * @param {object} output TBD
13
+ * @returns {object} TBD
14
+ */
15
+ export function add(a, b, output = null) {
16
+ const result = output || new Point();
17
+ result.x = a.x + b.x;
18
+ result.y = a.y + b.y;
19
+ return result;
20
+ }
21
+
22
+ /**
23
+ *
24
+ * @param {object} a TBD
25
+ * @param {object} b TBD
26
+ * @param {object} output TBD
27
+ * @returns {object} TBD
28
+ */
29
+ export function subtract(a, b, output = null) {
30
+ const result = output || new Point();
31
+ result.x = a.x - b.x;
32
+ result.y = a.y - b.y;
33
+ return result;
34
+ }
35
+
36
+ /**
37
+ *
38
+ * @param {object} a TBD
39
+ * @param {object} b TBD
40
+ * @param {object} output TBD
41
+ * @returns {object} TBD
42
+ */
43
+ export function multiply(a, b, output = null) {
44
+ const result = output || new Point();
45
+ result.x = a.x * b.x;
46
+ result.y = a.y * b.y;
47
+ return result;
48
+ }
49
+
50
+ /**
51
+ *
52
+ * @param {object} a TBD
53
+ * @param {object} b TBD
54
+ * @param {object} output TBD
55
+ * @returns {object} TBD
56
+ */
57
+ export function divide(a, b, output = null) {
58
+ const result = output || new Point();
59
+ result.x = a.x / b.x;
60
+ result.y = a.y / b.y;
61
+ return result;
62
+ }
63
+
64
+ /**
65
+ *
66
+ * @param {object} a TBD
67
+ * @param {object} b TBD
68
+ * @returns {boolean} TBD
69
+ */
70
+ export function equals(a, b) {
71
+ return (a.x === b.x && a.y === b.y);
72
+ }
73
+
74
+ /**
75
+ *
76
+ * @param {object} a TBD
77
+ * @param {object} b TBD
78
+ * @returns {number} TBD
79
+ */
80
+ export function angle(a, b) {
81
+ return Math.atan2(a.y - b.y, a.x - b.x);
82
+ }
83
+
84
+ /**
85
+ *
86
+ * @param {object} a TBD
87
+ * @param {object} output TBD
88
+ * @returns {object} TBD
89
+ */
90
+ export function negative(a, output = null) {
91
+ const result = output || new Point();
92
+ return result.setTo(-a.x, -a.y);
93
+ }
94
+
95
+ /**
96
+ *
97
+ * @param {object} a TBD
98
+ * @param {object} b TBD
99
+ * @param {number} s TBD
100
+ * @param {object} output TBD
101
+ * @returns {object} TBD
102
+ */
103
+ export function multiplyAdd(a, b, s, output = null) {
104
+ const result = output || new Point();
105
+ return result.setTo(a.x + b.x * s, a.y + b.y * s);
106
+ }
107
+
108
+ /**
109
+ *
110
+ * @param {object} a TBD
111
+ * @param {object} b TBD
112
+ * @param {number} f TBD
113
+ * @param {object} output TBD
114
+ * @returns {object} TBD
115
+ */
116
+ export function interpolate(a, b, f, output = null) {
117
+ const result = output || new Point();
118
+ return result.setTo(a.x + (b.x - a.x) * f, a.y + (b.y - a.y) * f);
119
+ }
120
+
121
+ /**
122
+ *
123
+ * @param {object} a TBD
124
+ * @param {object} output TBD
125
+ * @returns {object} TBD
126
+ */
127
+ export function perp(a, output = null) {
128
+ const result = output || new Point();
129
+ return result.setTo(-a.y, a.x);
130
+ }
131
+
132
+ /**
133
+ *
134
+ * @param {object} a TBD
135
+ * @param {object} output TBD
136
+ * @returns {object} TBD
137
+ */
138
+ export function rperp(a, output = null) {
139
+ const result = output || new Point();
140
+ return result.setTo(a.y, -a.x);
141
+ }
142
+
143
+ /**
144
+ *
145
+ * @param {object} a TBD
146
+ * @param {object} b TBD
147
+ * @param {boolean} round TBD
148
+ * @returns {number} TBD
149
+ */
150
+ export function distance(a, b, round = false) {
151
+ const dx = a.x - b.x;
152
+ const dy = a.y - b.y;
153
+ const abDistance = Math.sqrt(dx * dx + dy * dy);
154
+ return round ? Math.round(abDistance) : abDistance;
155
+ }
156
+
157
+ /**
158
+ *
159
+ * @param {object} a TBD
160
+ * @param {object} b TBD
161
+ * @param {object} output TBD
162
+ * @returns {object} TBD
163
+ */
164
+ export function project(a, b, output = null) {
165
+ const result = output || new Point();
166
+ const amt = a.dot(b) / b.getMagnitudeSq();
167
+ if (amt !== 0) {
168
+ result.setTo(amt * b.x, amt * b.y);
169
+ }
170
+ return result;
171
+ }
172
+
173
+ /**
174
+ *
175
+ * @param {object} a TBD
176
+ * @param {object} b TBD
177
+ * @param {object} output TBD
178
+ * @returns {object} TBD
179
+ */
180
+ export function projectUnit(a, b, output = null) {
181
+ const result = output || new Point();
182
+ const amt = a.dot(b);
183
+ if (amt !== 0) {
184
+ result.setTo(amt * b.x, amt * b.y);
185
+ }
186
+ return result;
187
+ }
188
+
189
+ /**
190
+ *
191
+ * @param {object} a TBD
192
+ * @param {object} output TBD
193
+ * @returns {object} TBD
194
+ */
195
+ export function normalRightHand(a, output = null) {
196
+ const result = output || new Point();
197
+ return result.setTo(a.y * -1, a.x);
198
+ }
199
+
200
+ /**
201
+ *
202
+ * @param {object} a TBD
203
+ * @param {object} output TBD
204
+ * @returns {object} TBD
205
+ */
206
+ export function normalize(a, output = null) {
207
+ const result = output || new Point();
208
+ const m = a.getMagnitude();
209
+ if (m !== 0) {
210
+ result.setTo(a.x / m, a.y / m);
211
+ }
212
+ return result;
213
+ }
214
+
215
+ /**
216
+ *
217
+ * @param {object} a TBD
218
+ * @param {number} x TBD
219
+ * @param {number} y TBD
220
+ * @param {number} ang TBD
221
+ * @param {boolean} asDegrees TBD
222
+ * @param {number} dist TBD
223
+ * @returns {object} TBD
224
+ */
225
+ export function rotate(a, x, y, ang, asDegrees, dist) {
226
+ if (asDegrees) {
227
+ ang *= Math.PI / 180;
228
+ }
229
+ if (dist === undefined) {
230
+ a.subtract(x, y);
231
+ const s = Math.sin(ang);
232
+ const c = Math.cos(ang);
233
+ const tx = c * a.x - s * a.y;
234
+ const ty = s * a.x + c * a.y;
235
+ a.x = tx + x;
236
+ a.y = ty + y;
237
+ } else {
238
+ const t = ang + Math.atan2(a.y - y, a.x - x);
239
+ a.x = x + dist * Math.cos(t);
240
+ a.y = y + dist * Math.sin(t);
241
+ }
242
+ return a;
243
+ }
244
+
245
+ /**
246
+ *
247
+ * @param {object[]} points TBD
248
+ * @param {object} output TBD
249
+ * @returns {object} TBD
250
+ */
251
+ export function centroid(points, output = null) {
252
+ const result = output || new Point();
253
+ const pointsLen = points.length;
254
+ if (pointsLen < 1) {
255
+ throw new Error('Point(points) array must not be empty.');
256
+ }
257
+ if (pointsLen === 1) {
258
+ result.copyFrom(points[0]);
259
+ return result;
260
+ }
261
+ for (let i = 0; i < pointsLen; i += 1) {
262
+ add(result, points[i], result);
263
+ }
264
+ result.divide(pointsLen, pointsLen);
265
+ return result;
266
+ }
267
+
268
+ /**
269
+ *
270
+ * @param {object} obj TBD
271
+ * @param {string} xProp TBD
272
+ * @param {string} yProp TBD
273
+ * @returns {object} TBD
274
+ */
275
+ export function parse(obj, xProp = 'x', yProp = 'y') {
276
+ const point = new Point();
277
+ if (obj[xProp]) {
278
+ point.x = parseInt(obj[xProp], 10);
279
+ }
280
+ if (obj[yProp]) {
281
+ point.y = parseInt(obj[yProp], 10);
282
+ }
283
+ return point;
284
+ }
285
+
286
+ /**
287
+ *
288
+ * @param {object} input TBD
289
+ * @param {object} output TBD
290
+ * @returns {object} TBD
291
+ */
292
+ export function clone(input, output = null) {
293
+ const result = output || new Point();
294
+ result.setTo(input.x, input.y);
295
+ return result;
296
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ import Polygon from '../polygon';
7
+
8
+ /**
9
+ * TBD
10
+ *
11
+ * @deprecated
12
+ * @returns {boolean} TBD
13
+ */
14
+ export default function () {
15
+ return true;
16
+ }
17
+
18
+ /**
19
+ *
20
+ * @param {object} input TBD
21
+ * @param {object} output TBD
22
+ * @returns {object} TBD
23
+ */
24
+ export function clone(input, output = null) {
25
+ const result = output || new Polygon();
26
+ result.setTo(input._points.slice());
27
+ return result;
28
+ }