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