@vpmedia/phaser 1.74.0 → 1.76.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.
Files changed (142) hide show
  1. package/README.md +1 -1
  2. package/coverage/clover.xml +1089 -3
  3. package/coverage/coverage-final.json +19 -1
  4. package/coverage/lcov-report/core/const.js.html +901 -0
  5. package/coverage/lcov-report/core/index.html +116 -0
  6. package/coverage/lcov-report/geom/circle.js.html +1003 -0
  7. package/coverage/lcov-report/geom/ellipse.js.html +388 -0
  8. package/coverage/lcov-report/geom/index.html +221 -0
  9. package/coverage/lcov-report/geom/line.js.html +1102 -0
  10. package/coverage/lcov-report/geom/matrix.js.html +751 -0
  11. package/coverage/lcov-report/geom/point.js.html +1027 -0
  12. package/coverage/lcov-report/geom/polygon.js.html +604 -0
  13. package/coverage/lcov-report/geom/rectangle.js.html +1774 -0
  14. package/coverage/lcov-report/geom/rounded_rectangle.js.html +226 -0
  15. package/coverage/lcov-report/geom/util/circle.js.html +436 -0
  16. package/coverage/lcov-report/geom/util/ellipse.js.html +139 -0
  17. package/coverage/lcov-report/geom/util/index.html +221 -0
  18. package/coverage/lcov-report/geom/util/line.js.html +475 -0
  19. package/coverage/lcov-report/geom/util/matrix.js.html +223 -0
  20. package/coverage/lcov-report/geom/util/point.js.html +961 -0
  21. package/coverage/lcov-report/geom/util/polygon.js.html +124 -0
  22. package/coverage/lcov-report/geom/util/rectangle.js.html +784 -0
  23. package/coverage/lcov-report/geom/util/rounded_rectangle.js.html +136 -0
  24. package/coverage/lcov-report/index.html +70 -10
  25. package/coverage/lcov-report/util/index.html +116 -0
  26. package/coverage/lcov-report/util/math.js.html +958 -0
  27. package/coverage/lcov.info +2179 -0
  28. package/eslint.config.js +41 -0
  29. package/package.json +9 -9
  30. package/src/phaser/core/array_set.js +1 -1
  31. package/src/phaser/core/device_util.js +1 -0
  32. package/src/phaser/core/dom.js +1 -0
  33. package/src/phaser/core/factory.js +1 -1
  34. package/src/phaser/core/game.js +4 -1
  35. package/src/phaser/core/input_handler.js +2 -2
  36. package/src/phaser/core/scene.js +3 -1
  37. package/src/phaser/core/signal.js +2 -2
  38. package/src/phaser/core/time.js +2 -2
  39. package/src/phaser/core/timer.js +1 -1
  40. package/src/phaser/core/tween.js +2 -2
  41. package/src/phaser/display/button.js +6 -4
  42. package/src/phaser/display/canvas/util.js +1 -0
  43. package/src/phaser/display/display_object.js +2 -0
  44. package/src/phaser/display/graphics.js +1 -1
  45. package/src/phaser/display/group.js +1 -1
  46. package/src/phaser/display/webgl/render_texture.js +5 -4
  47. package/src/phaser/display/webgl/shader/complex.js +1 -0
  48. package/src/phaser/display/webgl/shader/fast.js +1 -0
  49. package/src/phaser/display/webgl/shader/normal.js +3 -0
  50. package/src/phaser/display/webgl/shader/primitive.js +1 -0
  51. package/src/phaser/display/webgl/shader/strip.js +1 -0
  52. package/src/phaser/display/webgl/shader_manager.js +1 -1
  53. package/src/phaser/display/webgl/texture.js +1 -1
  54. package/src/phaser/geom/circle.test.js +198 -0
  55. package/src/phaser/geom/ellipse.js +3 -3
  56. package/src/phaser/geom/ellipse.test.js +83 -0
  57. package/src/phaser/geom/line.test.js +112 -0
  58. package/src/phaser/geom/matrix.test.js +242 -0
  59. package/src/phaser/geom/point.test.js +209 -0
  60. package/src/phaser/geom/rectangle.test.js +460 -0
  61. package/src/phaser/geom/rounded_rectangle.test.js +63 -0
  62. package/src/phaser/geom/util/circle.test.js +29 -0
  63. package/src/phaser/geom/util/ellipse.js +1 -1
  64. package/src/phaser/geom/util/ellipse.test.js +8 -0
  65. package/src/phaser/geom/util/line.js +1 -1
  66. package/src/phaser/geom/util/line.test.js +11 -0
  67. package/src/phaser/geom/util/matrix.test.js +23 -0
  68. package/src/phaser/geom/util/point.js +1 -1
  69. package/src/phaser/geom/util/point.test.js +9 -0
  70. package/src/phaser/geom/util/polygon.test.js +13 -0
  71. package/src/phaser/geom/util/rectangle.test.js +11 -0
  72. package/src/phaser/geom/util/rounded_rectangle.test.js +12 -0
  73. package/src/phaser/util/math.test.js +187 -0
  74. package/types/phaser/core/animation.d.ts.map +1 -1
  75. package/types/phaser/core/animation_manager.d.ts.map +1 -1
  76. package/types/phaser/core/array_set.d.ts +2 -2
  77. package/types/phaser/core/array_set.d.ts.map +1 -1
  78. package/types/phaser/core/cache.d.ts.map +1 -1
  79. package/types/phaser/core/const.d.ts.map +1 -1
  80. package/types/phaser/core/device.d.ts +4 -0
  81. package/types/phaser/core/device.d.ts.map +1 -1
  82. package/types/phaser/core/device_util.d.ts.map +1 -1
  83. package/types/phaser/core/dom.d.ts.map +1 -1
  84. package/types/phaser/core/event_manager.d.ts.map +1 -1
  85. package/types/phaser/core/factory.d.ts +1 -1
  86. package/types/phaser/core/factory.d.ts.map +1 -1
  87. package/types/phaser/core/frame_data.d.ts.map +1 -1
  88. package/types/phaser/core/game.d.ts.map +1 -1
  89. package/types/phaser/core/input.d.ts.map +1 -1
  90. package/types/phaser/core/input_pointer.d.ts.map +1 -1
  91. package/types/phaser/core/loader.d.ts.map +1 -1
  92. package/types/phaser/core/scale_manager.d.ts +1 -1
  93. package/types/phaser/core/scale_manager.d.ts.map +1 -1
  94. package/types/phaser/core/scene.d.ts +3 -1
  95. package/types/phaser/core/scene.d.ts.map +1 -1
  96. package/types/phaser/core/scene_manager.d.ts.map +1 -1
  97. package/types/phaser/core/signal.d.ts +1 -1
  98. package/types/phaser/core/signal.d.ts.map +1 -1
  99. package/types/phaser/core/sound.d.ts.map +1 -1
  100. package/types/phaser/core/sound_manager.d.ts.map +1 -1
  101. package/types/phaser/core/stage.d.ts.map +1 -1
  102. package/types/phaser/core/time.d.ts.map +1 -1
  103. package/types/phaser/core/timer.d.ts +1 -1
  104. package/types/phaser/core/timer.d.ts.map +1 -1
  105. package/types/phaser/core/tween.d.ts.map +1 -1
  106. package/types/phaser/display/bitmap_text.d.ts.map +1 -1
  107. package/types/phaser/display/button.d.ts +3 -2
  108. package/types/phaser/display/button.d.ts.map +1 -1
  109. package/types/phaser/display/canvas/util.d.ts.map +1 -1
  110. package/types/phaser/display/display_object.d.ts +2 -0
  111. package/types/phaser/display/display_object.d.ts.map +1 -1
  112. package/types/phaser/display/group.d.ts.map +1 -1
  113. package/types/phaser/display/image.d.ts.map +1 -1
  114. package/types/phaser/display/text.d.ts.map +1 -1
  115. package/types/phaser/display/webgl/fast_sprite_batch.d.ts +2 -2
  116. package/types/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
  117. package/types/phaser/display/webgl/graphics_data.d.ts +2 -2
  118. package/types/phaser/display/webgl/graphics_data.d.ts.map +1 -1
  119. package/types/phaser/display/webgl/render_texture.d.ts.map +1 -1
  120. package/types/phaser/display/webgl/shader/complex.d.ts +1 -0
  121. package/types/phaser/display/webgl/shader/complex.d.ts.map +1 -1
  122. package/types/phaser/display/webgl/shader/fast.d.ts +1 -0
  123. package/types/phaser/display/webgl/shader/fast.d.ts.map +1 -1
  124. package/types/phaser/display/webgl/shader/normal.d.ts +3 -0
  125. package/types/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  126. package/types/phaser/display/webgl/shader/primitive.d.ts +1 -0
  127. package/types/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
  128. package/types/phaser/display/webgl/shader/strip.d.ts +1 -0
  129. package/types/phaser/display/webgl/shader/strip.d.ts.map +1 -1
  130. package/types/phaser/display/webgl/shader_manager.d.ts +7 -3
  131. package/types/phaser/display/webgl/shader_manager.d.ts.map +1 -1
  132. package/types/phaser/display/webgl/sprite_batch.d.ts +3 -3
  133. package/types/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
  134. package/types/phaser/display/webgl/util.d.ts.map +1 -1
  135. package/types/phaser/geom/circle.d.ts.map +1 -1
  136. package/types/phaser/geom/ellipse.d.ts.map +1 -1
  137. package/types/phaser/geom/line.d.ts.map +1 -1
  138. package/types/phaser/geom/polygon.d.ts +2 -2
  139. package/types/phaser/geom/polygon.d.ts.map +1 -1
  140. package/types/phaser/geom/rectangle.d.ts.map +1 -1
  141. package/types/phaser/geom/util/ellipse.d.ts +1 -1
  142. package/types/phaser/geom/util/ellipse.d.ts.map +1 -1
package/eslint.config.js CHANGED
@@ -50,9 +50,50 @@ export default [
50
50
  rules: {
51
51
  ...js.configs.recommended.rules,
52
52
  ...jsdocPlugin.configs['flat/recommended'].rules,
53
+ ...unicornPlugin.configs['flat/recommended'].rules,
53
54
  'no-unused-vars': 'off',
54
55
  'prefer-arrow-callback': 'warn',
55
56
  'prefer-template': 'warn',
57
+ 'unicorn/consistent-function-scoping': 'off',
58
+ 'unicorn/explicit-length-check': 'off',
59
+ 'unicorn/filename-case': 'off',
60
+ 'unicorn/no-array-for-each': 'off',
61
+ 'unicorn/no-array-push-push': 'off',
62
+ 'unicorn/no-for-loop': 'off',
63
+ 'unicorn/no-lonely-if': 'off',
64
+ 'unicorn/no-negated-condition': 'off',
65
+ 'unicorn/no-nested-ternary': 'off',
66
+ 'unicorn/no-null': 'off',
67
+ 'unicorn/no-this-assignment': 'off',
68
+ 'unicorn/no-typeof-undefined': 'off',
69
+ 'unicorn/no-undefined': 'off',
70
+ 'unicorn/no-useless-undefined': 'off',
71
+ 'unicorn/number-literal-case': 'off',
72
+ 'unicorn/numeric-separators-style': 'off',
73
+ 'unicorn/prefer-add-event-listener': 'off',
74
+ 'unicorn/prefer-at': 'off',
75
+ 'unicorn/prefer-code-point': 'off',
76
+ 'unicorn/prefer-default-parameters': 'off',
77
+ 'unicorn/prefer-dom-node-append': 'off',
78
+ 'unicorn/prefer-dom-node-remove': 'off',
79
+ 'unicorn/prefer-global-this': 'off',
80
+ 'unicorn/prefer-includes': 'off',
81
+ 'unicorn/prefer-logical-operator-over-ternary': 'off',
82
+ 'unicorn/prefer-math-min-max': 'off',
83
+ 'unicorn/prefer-math-trunc': 'off',
84
+ 'unicorn/prefer-modern-dom-apis': 'off',
85
+ 'unicorn/prefer-modern-math-apis': 'off',
86
+ 'unicorn/prefer-optional-catch-binding': 'off',
87
+ 'unicorn/prefer-query-selector': 'off',
88
+ 'unicorn/prefer-regexp-test': 'off',
89
+ 'unicorn/prefer-spread': 'off',
90
+ 'unicorn/prefer-string-replace-all': 'off',
91
+ 'unicorn/prefer-string-slice': 'off',
92
+ 'unicorn/prefer-structured-clone': 'off',
93
+ 'unicorn/prefer-switch': 'off',
94
+ 'unicorn/prefer-ternary': 'off',
95
+ 'unicorn/prevent-abbreviations': 'off',
96
+ 'unicorn/switch-case-braces': 'off',
56
97
  'jsdoc/require-jsdoc': [
57
98
  'warn',
58
99
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vpmedia/phaser",
3
- "version": "1.74.0",
3
+ "version": "1.76.0",
4
4
  "description": "@vpmedia/phaser is the modern ECMAScript port of the popular Phaser game engine v2.6.2",
5
5
  "author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
6
6
  "license": "MIT",
@@ -23,22 +23,22 @@
23
23
  "types": "./types/index.d.ts",
24
24
  "type": "module",
25
25
  "dependencies": {
26
- "@vpmedia/simplify": "^1.14.0",
26
+ "@vpmedia/simplify": "^1.16.0",
27
27
  "uuid": "^11.0.3"
28
28
  },
29
29
  "devDependencies": {
30
- "@eslint/js": "^9.15.0",
30
+ "@eslint/js": "^9.16.0",
31
31
  "@jest/globals": "^29.7.0",
32
32
  "@types/jest": "^29.5.14",
33
- "eslint": "^9.15.0",
34
- "eslint-plugin-jsdoc": "^50.5.0",
33
+ "eslint": "^9.16.0",
34
+ "eslint-plugin-jsdoc": "^50.6.0",
35
35
  "eslint-plugin-unicorn": "^56.0.1",
36
- "globals": "^15.12.0",
36
+ "globals": "^15.13.0",
37
37
  "jest": "^29.7.0",
38
38
  "jest-environment-jsdom": "^29.7.0",
39
- "lefthook": "^1.8.4",
40
- "prettier": "^3.3.3",
41
- "typescript": "^5.6.3"
39
+ "lefthook": "^1.8.5",
40
+ "prettier": "^3.4.1",
41
+ "typescript": "^5.7.2"
42
42
  },
43
43
  "scripts": {
44
44
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests",
@@ -69,7 +69,7 @@ export class ArraySet {
69
69
  */
70
70
  remove(item) {
71
71
  const idx = this.list.indexOf(item);
72
- if (idx > -1) {
72
+ if (idx !== -1) {
73
73
  this.list.splice(idx, 1);
74
74
  return item;
75
75
  }
@@ -110,6 +110,7 @@ export const checkFullScreenSupport = (device) => {
110
110
  break;
111
111
  }
112
112
  }
113
+ // @ts-ignore
113
114
  if (window.Element && Element.ALLOW_KEYBOARD_INPUT) {
114
115
  device.fullscreenKeyboard = true;
115
116
  }
@@ -257,6 +257,7 @@ export class DOM {
257
257
  */
258
258
  getScreenOrientation(primaryFallback) {
259
259
  const screen = window.screen;
260
+ // @ts-ignore
260
261
  const orientation = screen.orientation || screen.mozOrientation || screen.msOrientation;
261
262
  if (orientation && typeof orientation.type === 'string') {
262
263
  // Screen Orientation API specification
@@ -37,7 +37,7 @@ export class GameObjectFactory {
37
37
  * @param {boolean} addToStage - TBD.
38
38
  * @returns {Group} TBD.
39
39
  */
40
- group(parent, name, addToStage) {
40
+ group(parent = null, name = null, addToStage = false) {
41
41
  return new Group(this.game, parent, name, addToStage);
42
42
  }
43
43
 
@@ -126,7 +126,10 @@ export class Game {
126
126
  this.canvas = create(this, this.width, this.height, this.config.canvasID, true);
127
127
  }
128
128
  if (this.config.canvasStyle) {
129
- this.canvas.style = this.config.canvasStyle;
129
+ const properties = Object.keys(this.config.canvasStyle);
130
+ for (const property of properties) {
131
+ this.canvas.style[property] = this.config.canvasStyle[property];
132
+ }
130
133
  } else {
131
134
  this.canvas.style['-webkit-full-screen'] = 'width: 100%; height: 100%';
132
135
  }
@@ -284,7 +284,7 @@ export class InputHandler {
284
284
  if (!this.enabled) {
285
285
  return false;
286
286
  }
287
- if (pointerId === undefined) {
287
+ if (pointerId === undefined || pointerId === null) {
288
288
  for (let i = 0; i < 10; i += 1) {
289
289
  if (this._pointerData[i].isOver) {
290
290
  return true;
@@ -304,7 +304,7 @@ export class InputHandler {
304
304
  if (!this.enabled) {
305
305
  return false;
306
306
  }
307
- if (pointerId === undefined) {
307
+ if (pointerId === undefined || pointerId === null) {
308
308
  for (let i = 0; i < 10; i += 1) {
309
309
  if (this._pointerData[i].isOut) {
310
310
  return true;
@@ -37,8 +37,10 @@ export class Scene {
37
37
 
38
38
  /**
39
39
  * TBD.
40
+ * @param {number} width - TBD.
41
+ * @param {number} height - TBD.
40
42
  */
41
- resize() {
43
+ resize(width, height) {
42
44
  // inherit
43
45
  }
44
46
 
@@ -10,7 +10,7 @@ export class Signal {
10
10
  this.memorize = false;
11
11
  this._shouldPropagate = true;
12
12
  this.active = true;
13
- this._boundDispatch = false;
13
+ this._boundDispatch = null;
14
14
  }
15
15
 
16
16
  /**
@@ -21,7 +21,7 @@ export class Signal {
21
21
  */
22
22
  validateListener(listener, fnName) {
23
23
  if (typeof listener !== 'function') {
24
- throw new Error(
24
+ throw new TypeError(
25
25
  'Signal: listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName)
26
26
  );
27
27
  }
@@ -12,7 +12,7 @@ export class Time {
12
12
  this.now = 0;
13
13
  this.elapsed = 0;
14
14
  this.elapsedMS = 0;
15
- this.desiredFpsMult = 1.0 / 60;
15
+ this.desiredFpsMult = 1 / 60;
16
16
  this._desiredFps = 60;
17
17
  this.suggestedFps = this.desiredFps;
18
18
  this.advancedTiming = false;
@@ -242,6 +242,6 @@ export class Time {
242
242
  */
243
243
  set desiredFps(value) {
244
244
  this._desiredFps = value;
245
- this.desiredFpsMult = 1.0 / value;
245
+ this.desiredFpsMult = 1 / value;
246
246
  }
247
247
  }
@@ -96,7 +96,7 @@ export class Timer {
96
96
  * TBD.
97
97
  * @param {number} delay - TBD.
98
98
  */
99
- start(delay) {
99
+ start(delay = 0) {
100
100
  if (this.running) {
101
101
  return;
102
102
  }
@@ -107,7 +107,7 @@ export class Tween {
107
107
  this.properties[property] = this.target[property] || 0;
108
108
  if (!Array.isArray(this.properties[property])) {
109
109
  // Ensures we're using numbers, not strings
110
- this.properties[property] *= 1.0;
110
+ this.properties[property] *= 1;
111
111
  }
112
112
  }
113
113
  }
@@ -439,7 +439,7 @@ export class Tween {
439
439
  this.properties[property] = this.target[property] || 0;
440
440
  if (!Array.isArray(this.properties[property])) {
441
441
  // Ensures we're using numbers, not strings
442
- this.properties[property] *= 1.0;
442
+ this.properties[property] *= 1;
443
443
  }
444
444
  }
445
445
  }
@@ -22,6 +22,7 @@ export class Button extends Image {
22
22
  * @param {string} outFrame - TBD.
23
23
  * @param {string} downFrame - TBD.
24
24
  * @param {string} upFrame - TBD.
25
+ * @param {string} disabledFrame - TBD.
25
26
  */
26
27
  constructor(
27
28
  game,
@@ -33,7 +34,8 @@ export class Button extends Image {
33
34
  overFrame = null,
34
35
  outFrame = null,
35
36
  downFrame = null,
36
- upFrame = null
37
+ upFrame = null,
38
+ disabledFrame = null
37
39
  ) {
38
40
  super(game, x, y, key, outFrame);
39
41
  this.type = BUTTON;
@@ -53,7 +55,7 @@ export class Button extends Image {
53
55
  this.input = new InputHandler(this);
54
56
  this.input.start(0, true);
55
57
  this.input.useHandCursor = true;
56
- this.setFrames(overFrame, outFrame, downFrame, upFrame);
58
+ this.setFrames(overFrame, outFrame, downFrame, upFrame, disabledFrame);
57
59
  if (callback !== null) {
58
60
  this.onInputUp.add(callback, callbackContext);
59
61
  }
@@ -95,7 +97,7 @@ export class Button extends Image {
95
97
  * @param {boolean} isEnabled - TBD.
96
98
  * @param {boolean} isImmediate - TBD.
97
99
  */
98
- setEnabled(isEnabled, isImmediate) {
100
+ setEnabled(isEnabled, isImmediate = false) {
99
101
  this.input.enabled = isEnabled;
100
102
  if (isImmediate) {
101
103
  this.changeStateFrame(isEnabled ? STATE_UP : STATE_DISABLED);
@@ -110,7 +112,7 @@ export class Button extends Image {
110
112
  * TBD.
111
113
  */
112
114
  clearFrames() {
113
- this.setFrames(null, null, null, null);
115
+ this.setFrames(null, null, null, null, null);
114
116
  }
115
117
 
116
118
  /**
@@ -42,6 +42,7 @@ export const setBackgroundColor = (canvas, color) => {
42
42
  */
43
43
  export const setTouchAction = (canvas, value = 'none') => {
44
44
  value = value || 'none';
45
+ // @ts-ignore
45
46
  canvas.style.msTouchAction = value;
46
47
  canvas.style['ms-touch-action'] = value;
47
48
  canvas.style['touch-action'] = value;
@@ -32,6 +32,8 @@ export class DisplayObject {
32
32
  this.cachedBounds = new Rectangle(0, 0, 0, 0);
33
33
  this.currentBounds = null;
34
34
  this._mask = null;
35
+ this._filters = null;
36
+ this._filterBlock = null;
35
37
  this.children = [];
36
38
  this.ignoreChildInput = false;
37
39
  }
@@ -223,7 +223,7 @@ export class Graphics extends DisplayObject {
223
223
  const a2 = y2 - y1;
224
224
  const b2 = x2 - x1;
225
225
  const mm = Math.abs(a1 * b2 - b1 * a2);
226
- if (mm < 1.0e-8 || radius === 0) {
226
+ if (mm < 1e-8 || radius === 0) {
227
227
  if (points[points.length - 2] !== x1 || points[points.length - 1] !== y1) {
228
228
  points.push(x1, y1);
229
229
  }
@@ -14,7 +14,7 @@ export class Group extends DisplayObject {
14
14
  * @param {string} name - TBD.
15
15
  * @param {boolean} addToStage - TBD.
16
16
  */
17
- constructor(game, parent = null, name = 'group', addToStage = false) {
17
+ constructor(game, parent = null, name = null, addToStage = false) {
18
18
  super();
19
19
  this.game = game;
20
20
  this.type = GROUP;
@@ -1,10 +1,10 @@
1
- import { Rectangle } from '../../geom/rectangle.js';
1
+ import { RENDER_WEBGL } from '../../core/const.js';
2
2
  import { Point } from '../../geom/point.js';
3
- import { Texture } from './texture.js';
3
+ import { Rectangle } from '../../geom/rectangle.js';
4
+ import { CanvasBuffer } from '../canvas/buffer.js';
4
5
  import { BaseTexture } from './base_texture.js';
5
6
  import { FilterTexture } from './filter_texture.js';
6
- import { CanvasBuffer } from '../canvas/buffer.js';
7
- import { RENDER_WEBGL } from '../../core/const.js';
7
+ import { Texture } from './texture.js';
8
8
 
9
9
  export class RenderTexture extends Texture {
10
10
  /**
@@ -34,6 +34,7 @@ export class RenderTexture extends Texture {
34
34
  this.crop = new Rectangle(0, 0, this.width * this.resolution, this.height * this.resolution);
35
35
  this.renderer = renderer;
36
36
  if (this.renderer.type === RENDER_WEBGL) {
37
+ // @ts-ignore
37
38
  const gl = this.renderer.gl;
38
39
  this.baseTexture._dirty[gl.id] = false;
39
40
  this.textureBuffer = new FilterTexture(gl, this.width, this.height, this.baseTexture.scaleMode);
@@ -11,6 +11,7 @@ export class ComplexPrimitiveShader {
11
11
  constructor(gl) {
12
12
  this.gl = gl;
13
13
  this._UID = uuidv4();
14
+ /** @type {WebGLProgram} */
14
15
  this.program = null;
15
16
  this.fragmentSrc = [
16
17
  'precision mediump float;',
@@ -11,6 +11,7 @@ export class FastShader {
11
11
  constructor(gl) {
12
12
  this.gl = gl;
13
13
  this._UID = uuidv4();
14
+ /** @type {WebGLProgram} */
14
15
  this.program = null;
15
16
  this.textureCount = 0;
16
17
  this.fragmentSrc = [
@@ -31,6 +31,7 @@ export class NormalShader {
31
31
  constructor(gl) {
32
32
  this.gl = gl;
33
33
  this._UID = uuidv4();
34
+ /** @type {WebGLProgram} */
34
35
  this.program = null;
35
36
  this.fragmentSrc = [
36
37
  'precision lowp float;',
@@ -41,6 +42,8 @@ export class NormalShader {
41
42
  ' gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor ;',
42
43
  '}',
43
44
  ];
45
+ /** @type {string[]} */
46
+ this.vertexSrc = null;
44
47
  this.textureCount = 0;
45
48
  this.firstRun = true;
46
49
  this.dirty = true;
@@ -11,6 +11,7 @@ export class PrimitiveShader {
11
11
  constructor(gl) {
12
12
  this.gl = gl;
13
13
  this._UID = uuidv4();
14
+ /** @type {WebGLProgram} */
14
15
  this.program = null;
15
16
  this.fragmentSrc = [
16
17
  'precision mediump float;',
@@ -11,6 +11,7 @@ export class StripShader {
11
11
  constructor(gl) {
12
12
  this.gl = gl;
13
13
  this._UID = uuidv4();
14
+ /** @type {WebGLProgram} */
14
15
  this.program = null;
15
16
  this.fragmentSrc = [
16
17
  'precision mediump float;',
@@ -26,7 +26,7 @@ export class WebGLShaderManager {
26
26
 
27
27
  /**
28
28
  * TBD.
29
- * @param {WebGLRenderingContext} gl - TBD.
29
+ * @param {WebGLRenderingContext & { id: number }} gl - TBD.
30
30
  */
31
31
  setContext(gl) {
32
32
  this.gl = gl;
@@ -30,7 +30,7 @@ export class Texture {
30
30
  this.noFrame = true;
31
31
  frame = new Rectangle(0, 0, 1, 1);
32
32
  }
33
- if (baseTexture && baseTexture.baseTexture) {
33
+ if (baseTexture instanceof Texture) {
34
34
  baseTexture = baseTexture.baseTexture;
35
35
  }
36
36
  this.baseTexture = baseTexture;
@@ -0,0 +1,198 @@
1
+ import { Circle } from './circle.js';
2
+ import { Point } from './point.js';
3
+
4
+ describe('Circle', () => {
5
+ describe('constructor', () => {
6
+ it('should initialize properties correctly when no arguments are provided', () => {
7
+ const circle = new Circle();
8
+ expect(circle.x).toBe(0);
9
+ expect(circle.y).toBe(0);
10
+ expect(circle.diameter).toBe(0);
11
+ });
12
+
13
+ it('should initialize properties correctly when x, y, and diameter are provided', () => {
14
+ const circle = new Circle(10, 20, 30);
15
+ expect(circle.x).toBe(10);
16
+ expect(circle.y).toBe(20);
17
+ expect(circle.diameter).toBe(30);
18
+ });
19
+ });
20
+
21
+ describe('circumference', () => {
22
+ it('should calculate the circumference correctly when diameter is provided', () => {
23
+ const circle = new Circle(0, 0, 1);
24
+ expect(circle.circumference()).toBeCloseTo(Math.PI);
25
+ });
26
+
27
+ it('should return Infinity when diameter is 0', () => {
28
+ const circle = new Circle();
29
+ circle.diameter = 0;
30
+ expect(circle.circumference()).toBe(0);
31
+ });
32
+ });
33
+
34
+ describe('random', () => {
35
+ it('should generate a random point within the circle correctly', () => {
36
+ const circle = new Circle();
37
+ const output = new Point();
38
+ circle.random(output);
39
+ expect(output.x).toBeGreaterThan(-1);
40
+ expect(output.y).toBeGreaterThan(-1);
41
+ expect(Math.hypot(output.x, output.y)).toBe(0);
42
+ });
43
+
44
+ it('should generate a random point within the circle correctly when output is not provided', () => {
45
+ const circle = new Circle();
46
+ const output = new Point();
47
+ circle.random(output);
48
+ expect(output.x).toBeGreaterThan(-1);
49
+ expect(output.y).toBeGreaterThan(-1);
50
+ expect(Math.hypot(output.x, output.y)).toBe(0);
51
+ });
52
+ });
53
+
54
+ describe('getBounds', () => {
55
+ it('should calculate the bounds correctly when diameter is provided', () => {
56
+ const circle = new Circle(0, 0, 1);
57
+ const bounds = circle.getBounds();
58
+ expect(bounds.x).toBe(-0.5);
59
+ expect(bounds.y).toBe(-0.5);
60
+ expect(bounds.width).toBe(1);
61
+ expect(bounds.height).toBe(1);
62
+ });
63
+
64
+ it('should return empty rectangle when diameter is 0', () => {
65
+ const circle = new Circle();
66
+ circle.diameter = 0;
67
+ const bounds = circle.getBounds();
68
+ expect(bounds.x).toBe(0);
69
+ expect(bounds.y).toBe(0);
70
+ expect(bounds.width).toBe(0);
71
+ expect(bounds.height).toBe(0);
72
+ });
73
+ });
74
+
75
+ describe('setTo', () => {
76
+ it('should set properties correctly when x, y, and diameter are provided', () => {
77
+ const circle = new Circle();
78
+ circle.setTo(10, 20, 30);
79
+ expect(circle.x).toBe(10);
80
+ expect(circle.y).toBe(20);
81
+ expect(circle.diameter).toBe(30);
82
+ });
83
+
84
+ it('should set radius property correctly when diameter is changed', () => {
85
+ const circle = new Circle();
86
+ circle.diameter = 1;
87
+ expect(circle.radius).toBe(0.5);
88
+ });
89
+ });
90
+
91
+ describe('copyFrom', () => {
92
+ it('should copy properties correctly from another Circle instance', () => {
93
+ const source = new Circle(10, 20, 30);
94
+ const dest = new Circle();
95
+ dest.copyFrom(source);
96
+ expect(dest.x).toBe(source.x);
97
+ expect(dest.y).toBe(source.y);
98
+ expect(dest.diameter).toBe(source.diameter);
99
+ });
100
+ });
101
+
102
+ describe('copyTo', () => {
103
+ it('should copy properties correctly to another Circle instance', () => {
104
+ const source = new Circle(10, 20, 30);
105
+ const dest = new Circle();
106
+ source.copyTo(dest);
107
+ expect(dest.x).toBe(source.x);
108
+ expect(dest.y).toBe(source.y);
109
+ expect(dest.diameter).toBe(source.diameter);
110
+ });
111
+ });
112
+
113
+ describe('distance', () => {
114
+ it('should calculate the distance correctly between two points within a circle', () => {
115
+ const circle = new Circle();
116
+ const point = new Point(1, 1);
117
+ expect(circle.distance(point)).toBeCloseTo(Math.hypot(point.x, point.y));
118
+ });
119
+
120
+ it('should return Infinity when diameter is 0', () => {
121
+ const circle = new Circle();
122
+ circle.diameter = 0;
123
+ expect(circle.distance(new Point(1, 1))).toBeCloseTo(1.4142);
124
+ });
125
+ });
126
+
127
+ describe('clone', () => {
128
+ it('should create a deep copy of the Circle instance correctly', () => {
129
+ const source = new Circle(10, 20, 30);
130
+ const clone = source.clone();
131
+ expect(clone.x).toBe(source.x);
132
+ expect(clone.y).toBe(source.y);
133
+ expect(clone.diameter).toBe(source.diameter);
134
+ });
135
+ });
136
+
137
+ describe('contains', () => {
138
+ it('should determine if a point is within the circle correctly', () => {
139
+ const circle = new Circle();
140
+ const point = new Point(1, 1);
141
+ expect(circle.contains(point.x, point.y)).toBe(false);
142
+ });
143
+
144
+ it('should return false when diameter is 0', () => {
145
+ const circle = new Circle();
146
+ circle.diameter = 0;
147
+ expect(circle.contains(1, 1)).toBe(false);
148
+ });
149
+ });
150
+
151
+ describe('circumferencePoint', () => {
152
+ it('should generate a point on the circumference correctly', () => {
153
+ const circle = new Circle();
154
+ const output = new Point();
155
+ expect(circle.circumferencePoint(Math.PI / 2).x).toBeCloseTo(0.5 * circle.radius);
156
+ });
157
+
158
+ it('should return null when diameter is 0', () => {
159
+ const circle = new Circle();
160
+ circle.diameter = 0;
161
+ expect(circle.circumferencePoint(Math.PI / 2).type).toBe(25);
162
+ });
163
+ });
164
+
165
+ describe('offset', () => {
166
+ it('should offset the circle correctly by a point', () => {
167
+ const circle = new Circle();
168
+ const point = new Point(1, 1);
169
+ circle.offset(point.x, point.y);
170
+ expect(circle.x).toBeGreaterThan(0);
171
+ expect(circle.y).toBeGreaterThan(0);
172
+ });
173
+
174
+ it('should return the Circle instance itself', () => {
175
+ const circle = new Circle();
176
+ const point = new Point(1, 1);
177
+ circle.offset(point.x, point.y);
178
+ expect(circle).toBe(circle);
179
+ });
180
+ });
181
+
182
+ describe('offsetPoint', () => {
183
+ it('should offset the circle correctly by a point', () => {
184
+ const circle = new Circle();
185
+ const point = new Point(1, 1);
186
+ circle.offsetPoint(point);
187
+ expect(circle.x).toBeGreaterThan(0);
188
+ expect(circle.y).toBeGreaterThan(0);
189
+ });
190
+ });
191
+
192
+ describe('toString', () => {
193
+ it('should generate the correct string representation of the Circle instance', () => {
194
+ const circle = new Circle();
195
+ expect(circle.toString()).toBe('[{Circle (x=0 y=0 diameter=0 radius=0)}]');
196
+ });
197
+ });
198
+ });
@@ -1,7 +1,7 @@
1
+ import { GEOM_ELLIPSE } from '../core/const.js';
1
2
  import { Point } from './point.js';
2
3
  import { Rectangle } from './rectangle.js';
3
4
  import { contains } from './util/ellipse.js';
4
- import { GEOM_ELLIPSE } from '../core/const.js';
5
5
 
6
6
  export class Ellipse {
7
7
  /**
@@ -86,8 +86,8 @@ export class Ellipse {
86
86
  const r = Math.random();
87
87
  result.x = Math.sqrt(r) * Math.cos(p);
88
88
  result.y = Math.sqrt(r) * Math.sin(p);
89
- result.x = this.x + (result.x * this.width) / 2.0;
90
- result.y = this.y + (result.y * this.height) / 2.0;
89
+ result.x = this.x + (result.x * this.width) / 2;
90
+ result.y = this.y + (result.y * this.height) / 2;
91
91
  return result;
92
92
  }
93
93