samengine 1.9.1 → 1.10.1

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 (89) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +168 -0
  3. package/dist/config/buildconfig.d.ts +146 -0
  4. package/dist/config/buildconfig.js +115 -0
  5. package/dist/config/index.d.ts +9 -0
  6. package/dist/config/index.js +1 -0
  7. package/dist/core.d.ts +17 -0
  8. package/dist/core.js +24 -0
  9. package/dist/html.d.ts +29 -0
  10. package/dist/html.js +20 -0
  11. package/dist/input.d.ts +51 -0
  12. package/dist/input.js +44 -3
  13. package/dist/keys.d.ts +6 -0
  14. package/dist/keys.js +6 -2
  15. package/dist/logger.d.ts +8 -0
  16. package/dist/logger.js +8 -1
  17. package/dist/nonbrowser/getversion.d.ts +13 -0
  18. package/dist/nonbrowser/getversion.js +35 -0
  19. package/dist/nonbrowser/ghresolver.d.ts +1 -0
  20. package/dist/nonbrowser/ghresolver.js +7 -0
  21. package/dist/nonbrowser/index.d.ts +9 -0
  22. package/dist/nonbrowser/index.js +9 -0
  23. package/dist/nonbrowser/internal/buildhelper.d.ts +42 -0
  24. package/dist/nonbrowser/internal/buildhelper.js +144 -0
  25. package/dist/nonbrowser/internal/cli/argparser.d.ts +18 -0
  26. package/dist/nonbrowser/internal/cli/argparser.js +36 -0
  27. package/dist/nonbrowser/internal/cli/main.d.ts +13 -0
  28. package/dist/nonbrowser/internal/cli/main.js +265 -0
  29. package/dist/nonbrowser/internal/config.d.ts +9 -0
  30. package/dist/nonbrowser/internal/config.js +40 -0
  31. package/dist/nonbrowser/internal/exporthtml.d.ts +37 -0
  32. package/dist/nonbrowser/internal/exporthtml.js +622 -0
  33. package/dist/nonbrowser/utils.d.ts +8 -0
  34. package/dist/nonbrowser/utils.js +18 -0
  35. package/dist/physics/collision.d.ts +33 -0
  36. package/dist/physics/collision.js +27 -0
  37. package/dist/physics/physicsEngine.d.ts +18 -0
  38. package/dist/physics/physicsEngine.js +18 -0
  39. package/dist/physics/physicsObject.d.ts +20 -0
  40. package/dist/physics/physicsObject.js +20 -0
  41. package/dist/renderer.d.ts +78 -0
  42. package/dist/renderer.js +72 -9
  43. package/dist/samegui/index.d.ts +29 -0
  44. package/dist/samegui/index.js +26 -0
  45. package/dist/save.d.ts +12 -0
  46. package/dist/save.js +10 -0
  47. package/dist/sound/audioplayer.d.ts +39 -0
  48. package/dist/sound/audioplayer.js +39 -5
  49. package/dist/storage/index.d.ts +40 -2
  50. package/dist/storage/index.js +34 -3
  51. package/dist/text/index.d.ts +14 -0
  52. package/dist/text/index.js +58 -0
  53. package/dist/texture.d.ts +100 -0
  54. package/dist/texture.js +75 -41
  55. package/dist/types/button.d.ts +25 -0
  56. package/dist/types/button.js +22 -0
  57. package/dist/types/circle.d.ts +26 -0
  58. package/dist/types/circle.js +21 -7
  59. package/dist/types/color.d.ts +17 -0
  60. package/dist/types/color.js +11 -1
  61. package/dist/types/index.d.ts +1 -1
  62. package/dist/types/index.js +1 -1
  63. package/dist/types/rectangle.d.ts +29 -0
  64. package/dist/types/rectangle.js +23 -7
  65. package/dist/types/triangle.d.ts +23 -0
  66. package/dist/types/triangle.js +20 -6
  67. package/dist/types/vector2d.d.ts +42 -0
  68. package/dist/types/vector2d.js +39 -11
  69. package/dist/types/vector3d.d.ts +38 -0
  70. package/dist/types/vector3d.js +35 -11
  71. package/dist/utils/index.d.ts +11 -4
  72. package/dist/utils/index.js +11 -4
  73. package/dist/utils/logger/index.d.ts +24 -0
  74. package/dist/utils/logger/index.js +44 -0
  75. package/dist/utils/math.d.ts +18 -0
  76. package/dist/utils/math.js +18 -4
  77. package/package.json +29 -11
  78. package/dist/utils/csv/index.d.ts +0 -3
  79. package/dist/utils/csv/index.js +0 -2
  80. package/dist/utils/csv/parser.d.ts +0 -25
  81. package/dist/utils/csv/parser.js +0 -212
  82. package/dist/utils/csv/stringifier.d.ts +0 -30
  83. package/dist/utils/csv/stringifier.js +0 -130
  84. package/dist/utils/csv/types.d.ts +0 -63
  85. package/dist/utils/csv/types.js +0 -1
  86. package/dist/utils/jsonc-parser.d.ts +0 -4
  87. package/dist/utils/jsonc-parser.js +0 -166
  88. package/dist/utils/markdown.d.ts +0 -41
  89. package/dist/utils/markdown.js +0 -699
@@ -1,14 +1,40 @@
1
1
  import { Mouse } from "../input.js";
2
2
  import { type Vector2d } from "./vector2d.js";
3
+ /**
4
+ * Circle shape used for drawing, hit tests, and simple collision checks.
5
+ *
6
+ * `x` and `y` are the center of the circle.
7
+ */
3
8
  export type Circle = {
4
9
  x: number;
5
10
  y: number;
6
11
  radius: number;
7
12
  };
13
+ /**
14
+ * Creates a circle object.
15
+ */
8
16
  export declare function makeCircle(x: number, y: number, radius: number): Circle;
17
+ /**
18
+ * Returns the center of the circle as a `Vector2d`.
19
+ */
9
20
  export declare function centerCircle(circle: Circle): Vector2d;
21
+ /**
22
+ * Checks whether a point is inside or on the border of a circle.
23
+ */
10
24
  export declare function isPointInCircle(x: number, y: number, circle: Circle): boolean;
25
+ /**
26
+ * Checks whether the current mouse position is inside a circle.
27
+ */
11
28
  export declare function isMouseInCircle(mouse: Mouse, circle: Circle): boolean;
29
+ /**
30
+ * Checks whether a circle was clicked during the current frame.
31
+ */
12
32
  export declare function isCircleClicked(mouse: Mouse, circle: Circle): boolean;
33
+ /**
34
+ * Checks whether two circles overlap or touch.
35
+ */
13
36
  export declare function isCircleColliding(circle1: Circle, circle2: Circle): boolean;
37
+ /**
38
+ * Returns the center-to-center distance between two circles.
39
+ */
14
40
  export declare function getCircleDistance(circle1: Circle, circle2: Circle): number;
@@ -1,5 +1,7 @@
1
1
  // Circle Type for Hitboxes
2
- // Function to create an Object of Type Circle
2
+ /**
3
+ * Creates a circle object.
4
+ */
3
5
  export function makeCircle(x, y, radius) {
4
6
  return {
5
7
  x: x,
@@ -7,31 +9,43 @@ export function makeCircle(x, y, radius) {
7
9
  radius: radius,
8
10
  };
9
11
  }
10
- // Function to get the Center of the Circle as Vector2d
12
+ /**
13
+ * Returns the center of the circle as a `Vector2d`.
14
+ */
11
15
  export function centerCircle(circle) {
12
16
  return { x: circle.x, y: circle.y };
13
17
  }
14
- // Check if a Point is in the Circle
18
+ /**
19
+ * Checks whether a point is inside or on the border of a circle.
20
+ */
15
21
  export function isPointInCircle(x, y, circle) {
16
22
  const distance = Math.sqrt((x - circle.x) * (x - circle.x) +
17
23
  (y - circle.y) * (y - circle.y));
18
24
  return distance <= circle.radius;
19
25
  }
20
- // Check if Mouse is in the Circle
26
+ /**
27
+ * Checks whether the current mouse position is inside a circle.
28
+ */
21
29
  export function isMouseInCircle(mouse, circle) {
22
30
  return isPointInCircle(mouse.x, mouse.y, circle);
23
31
  }
24
- // Function to check if a Circle is clicked
32
+ /**
33
+ * Checks whether a circle was clicked during the current frame.
34
+ */
25
35
  export function isCircleClicked(mouse, circle) {
26
36
  return isMouseInCircle(mouse, circle) && mouse.justPressed;
27
37
  }
28
- // Check if two Circles collide
38
+ /**
39
+ * Checks whether two circles overlap or touch.
40
+ */
29
41
  export function isCircleColliding(circle1, circle2) {
30
42
  const distance = Math.sqrt((circle1.x - circle2.x) * (circle1.x - circle2.x) +
31
43
  (circle1.y - circle2.y) * (circle1.y - circle2.y));
32
44
  return distance <= (circle1.radius + circle2.radius);
33
45
  }
34
- // Check if Circle collides with Rectangle (imported from rectangle.ts would cause circular dependency)
46
+ /**
47
+ * Returns the center-to-center distance between two circles.
48
+ */
35
49
  export function getCircleDistance(circle1, circle2) {
36
50
  return Math.sqrt((circle1.x - circle2.x) * (circle1.x - circle2.x) +
37
51
  (circle1.y - circle2.y) * (circle1.y - circle2.y));
@@ -1,9 +1,26 @@
1
+ /**
2
+ * RGBA color object.
3
+ *
4
+ * `r`, `g`, and `b` are expected in the 0-255 range. `a` is optional and can be
5
+ * used by callers as an alpha channel value.
6
+ */
1
7
  export type Color = {
2
8
  r: number;
3
9
  g: number;
4
10
  b: number;
5
11
  a?: number;
6
12
  };
13
+ /**
14
+ * Creates a color object.
15
+ */
7
16
  export declare function makeColor(r: number, g: number, b: number, a?: number): Color;
17
+ /**
18
+ * Returns the RGB inverse of a color while preserving alpha if it exists.
19
+ */
8
20
  export declare function invertcolor(color: Color): Color;
21
+ /**
22
+ * Inverts a hex color in `#rrggbb` or `rrggbb` format.
23
+ *
24
+ * The returned value always starts with `#`.
25
+ */
9
26
  export declare function invertHexColor(hex: string): string;
@@ -1,4 +1,6 @@
1
- // Function to create an Object of Type Color
1
+ /**
2
+ * Creates a color object.
3
+ */
2
4
  export function makeColor(r, g, b, a) {
3
5
  return {
4
6
  r: r,
@@ -7,6 +9,9 @@ export function makeColor(r, g, b, a) {
7
9
  a: a
8
10
  };
9
11
  }
12
+ /**
13
+ * Returns the RGB inverse of a color while preserving alpha if it exists.
14
+ */
10
15
  export function invertcolor(color) {
11
16
  return {
12
17
  r: 255 - color.r,
@@ -15,6 +20,11 @@ export function invertcolor(color) {
15
20
  ...(color.a !== undefined ? { a: color.a } : {}) // optional alpha behalten
16
21
  };
17
22
  }
23
+ /**
24
+ * Inverts a hex color in `#rrggbb` or `rrggbb` format.
25
+ *
26
+ * The returned value always starts with `#`.
27
+ */
18
28
  export function invertHexColor(hex) {
19
29
  // Entferne das führende #
20
30
  const cleanHex = hex.replace('#', '');
@@ -4,4 +4,4 @@ export { type Color, makeColor, invertcolor, invertHexColor } from "./color.js";
4
4
  export { type Rect, makeRect, centerRectX, centerRectY, centerRect, isPointInRect, isMouseInRect, isRectClicked } from "./rectangle.js";
5
5
  export { type Circle, makeCircle, centerCircle, isPointInCircle, isMouseInCircle, isCircleClicked, isCircleColliding, getCircleDistance } from "./circle.js";
6
6
  export { type Triangle, makeTriangle, centerTriangle, isPointInTriangle, isMouseInTriangle, isTriangleClicked, getTrianglePerimeter, } from "./triangle.js";
7
- export { type Button, makeButton, clickedButton, drawButton } from "./button.js";
7
+ export { type Button, makeButton, clickedButton, drawButton, isButtonhovered, isButtonpressed } from "./button.js";
@@ -12,4 +12,4 @@ export { makeCircle, centerCircle, isPointInCircle, isMouseInCircle, isCircleCli
12
12
  // Triangle Type
13
13
  export { makeTriangle, centerTriangle, isPointInTriangle, isMouseInTriangle, isTriangleClicked, getTrianglePerimeter, } from "./triangle.js";
14
14
  // Button Type
15
- export { makeButton, clickedButton, drawButton } from "./button.js";
15
+ export { makeButton, clickedButton, drawButton, isButtonhovered, isButtonpressed } from "./button.js";
@@ -1,5 +1,11 @@
1
1
  import { type Mouse } from "../input.js";
2
2
  import { type Vector2d } from "./vector2d.js";
3
+ /**
4
+ * Axis-aligned rectangle used for drawing, UI, and simple hit tests.
5
+ *
6
+ * `x` and `y` describe the top-left corner. `width` and `height` extend to the
7
+ * right and downward in normal canvas coordinates.
8
+ */
3
9
  export type Rect = {
4
10
  x: number;
5
11
  y: number;
@@ -7,10 +13,33 @@ export type Rect = {
7
13
  height: number;
8
14
  borderRadius?: number;
9
15
  };
16
+ /**
17
+ * Creates a rectangle object.
18
+ */
10
19
  export declare function makeRect(x: number, y: number, width: number, height: number, borderRadius?: number): Rect;
20
+ /**
21
+ * Returns the horizontal center coordinate of a rectangle.
22
+ */
11
23
  export declare function centerRectX(rect: Rect): number;
24
+ /**
25
+ * Returns the vertical center coordinate of a rectangle.
26
+ */
12
27
  export declare function centerRectY(rect: Rect): number;
28
+ /**
29
+ * Returns the rectangle center as a `Vector2d`.
30
+ */
13
31
  export declare function centerRect(rect: Rect): Vector2d;
32
+ /**
33
+ * Checks whether a point is inside or on the border of a rectangle.
34
+ */
14
35
  export declare function isPointInRect(x: number, y: number, rect: Rect): boolean;
36
+ /**
37
+ * Checks whether the current mouse position is inside a rectangle.
38
+ */
15
39
  export declare function isMouseInRect(mouse: Mouse, rect: Rect): boolean;
40
+ /**
41
+ * Checks whether a rectangle was clicked during the current frame.
42
+ *
43
+ * This depends on `mouse.justPressed`, so call it before `resetInput()`.
44
+ */
16
45
  export declare function isRectClicked(mouse: Mouse, rect: Rect): boolean;
@@ -1,5 +1,7 @@
1
1
  // Rectangle Type for Hitboxes
2
- // Function to create an Object of Type rect
2
+ /**
3
+ * Creates a rectangle object.
4
+ */
3
5
  export function makeRect(x, y, width, height, borderRadius = 0) {
4
6
  return {
5
7
  x: x,
@@ -9,34 +11,48 @@ export function makeRect(x, y, width, height, borderRadius = 0) {
9
11
  borderRadius: borderRadius
10
12
  };
11
13
  }
12
- // Function to get the Center of the Width of the Object
14
+ /**
15
+ * Returns the horizontal center coordinate of a rectangle.
16
+ */
13
17
  export function centerRectX(rect) {
14
18
  return (rect.x + (rect.width / 2));
15
19
  }
16
- // Function to get the Center of the Height of the Object
20
+ /**
21
+ * Returns the vertical center coordinate of a rectangle.
22
+ */
17
23
  export function centerRectY(rect) {
18
24
  return (rect.y + (rect.height / 2));
19
25
  }
20
- // Get the Center of a Rectangle
26
+ /**
27
+ * Returns the rectangle center as a `Vector2d`.
28
+ */
21
29
  export function centerRect(rect) {
22
30
  let vector = { x: centerRectX(rect), y: centerRectY(rect) };
23
31
  return vector;
24
32
  }
25
- // Check if a Point in the Rectangle
33
+ /**
34
+ * Checks whether a point is inside or on the border of a rectangle.
35
+ */
26
36
  export function isPointInRect(x, y, rect) {
27
37
  return (x >= rect.x &&
28
38
  x <= rect.x + rect.width &&
29
39
  y >= rect.y &&
30
40
  y <= rect.y + rect.height);
31
41
  }
32
- // Is Rectangle Hovered
42
+ /**
43
+ * Checks whether the current mouse position is inside a rectangle.
44
+ */
33
45
  export function isMouseInRect(mouse, rect) {
34
46
  return (mouse.x >= rect.x &&
35
47
  mouse.x <= rect.x + rect.width &&
36
48
  mouse.y >= rect.y &&
37
49
  mouse.y <= rect.y + rect.height);
38
50
  }
39
- // Function to check if a Rectangle is clicked
51
+ /**
52
+ * Checks whether a rectangle was clicked during the current frame.
53
+ *
54
+ * This depends on `mouse.justPressed`, so call it before `resetInput()`.
55
+ */
40
56
  export function isRectClicked(mouse, rect) {
41
57
  return isMouseInRect(mouse, rect) && mouse.justPressed;
42
58
  }
@@ -1,5 +1,8 @@
1
1
  import { Mouse } from "../input.js";
2
2
  import { type Vector2d } from "./vector2d.js";
3
+ /**
4
+ * Triangle shape represented by three points.
5
+ */
3
6
  export type Triangle = {
4
7
  x1: number;
5
8
  y1: number;
@@ -8,9 +11,29 @@ export type Triangle = {
8
11
  x3: number;
9
12
  y3: number;
10
13
  };
14
+ /**
15
+ * Creates a triangle from three points.
16
+ */
11
17
  export declare function makeTriangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number): Triangle;
18
+ /**
19
+ * Returns the centroid of the triangle.
20
+ */
12
21
  export declare function centerTriangle(triangle: Triangle): Vector2d;
22
+ /**
23
+ * Checks whether a point lies inside the triangle.
24
+ *
25
+ * Uses an area comparison with a small tolerance to avoid floating point noise.
26
+ */
13
27
  export declare function isPointInTriangle(x: number, y: number, triangle: Triangle): boolean;
28
+ /**
29
+ * Checks whether the current mouse position is inside the triangle.
30
+ */
14
31
  export declare function isMouseInTriangle(mouse: Mouse, triangle: Triangle): boolean;
32
+ /**
33
+ * Checks whether the triangle was clicked during the current frame.
34
+ */
15
35
  export declare function isTriangleClicked(mouse: Mouse, triangle: Triangle): boolean;
36
+ /**
37
+ * Returns the perimeter length of the triangle.
38
+ */
16
39
  export declare function getTrianglePerimeter(triangle: Triangle): number;
@@ -1,5 +1,7 @@
1
1
  // Triangle Type for Hitboxes
2
- // Function to create an Object of Type triangle
2
+ /**
3
+ * Creates a triangle from three points.
4
+ */
3
5
  export function makeTriangle(x1, y1, x2, y2, x3, y3) {
4
6
  return {
5
7
  x1: x1,
@@ -14,14 +16,20 @@ export function makeTriangle(x1, y1, x2, y2, x3, y3) {
14
16
  function getTriangleArea(x1, y1, x2, y2, x3, y3) {
15
17
  return Math.abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0);
16
18
  }
17
- // Function to get the Center of the Triangle
19
+ /**
20
+ * Returns the centroid of the triangle.
21
+ */
18
22
  export function centerTriangle(triangle) {
19
23
  return {
20
24
  x: (triangle.x1 + triangle.x2 + triangle.x3) / 3,
21
25
  y: (triangle.y1 + triangle.y2 + triangle.y3) / 3
22
26
  };
23
27
  }
24
- // Check if a Point is in the Triangle using barycentric coordinates
28
+ /**
29
+ * Checks whether a point lies inside the triangle.
30
+ *
31
+ * Uses an area comparison with a small tolerance to avoid floating point noise.
32
+ */
25
33
  export function isPointInTriangle(x, y, triangle) {
26
34
  const areaTriangle = getTriangleArea(triangle.x1, triangle.y1, triangle.x2, triangle.y2, triangle.x3, triangle.y3);
27
35
  const area1 = getTriangleArea(x, y, triangle.x2, triangle.y2, triangle.x3, triangle.y3);
@@ -29,15 +37,21 @@ export function isPointInTriangle(x, y, triangle) {
29
37
  const area3 = getTriangleArea(triangle.x1, triangle.y1, triangle.x2, triangle.y2, x, y);
30
38
  return Math.abs(areaTriangle - (area1 + area2 + area3)) < 0.01;
31
39
  }
32
- // Check if Mouse is in the Triangle
40
+ /**
41
+ * Checks whether the current mouse position is inside the triangle.
42
+ */
33
43
  export function isMouseInTriangle(mouse, triangle) {
34
44
  return isPointInTriangle(mouse.x, mouse.y, triangle);
35
45
  }
36
- // Function to check if a Triangle is clicked
46
+ /**
47
+ * Checks whether the triangle was clicked during the current frame.
48
+ */
37
49
  export function isTriangleClicked(mouse, triangle) {
38
50
  return isMouseInTriangle(mouse, triangle) && mouse.justPressed;
39
51
  }
40
- // Get the Perimeter of the Triangle
52
+ /**
53
+ * Returns the perimeter length of the triangle.
54
+ */
41
55
  export function getTrianglePerimeter(triangle) {
42
56
  const side1 = Math.sqrt((triangle.x2 - triangle.x1) * (triangle.x2 - triangle.x1) +
43
57
  (triangle.y2 - triangle.y1) * (triangle.y2 - triangle.y1));
@@ -1,15 +1,57 @@
1
+ /**
2
+ * Two-dimensional vector for positions, directions, velocities, and sizes.
3
+ */
1
4
  export type Vector2d = {
2
5
  x: number;
3
6
  y: number;
4
7
  };
8
+ /**
9
+ * Creates a new 2D vector.
10
+ */
5
11
  export declare function makeVector2d(x: number, y: number): Vector2d;
12
+ /**
13
+ * Adds two vectors and returns a new vector.
14
+ */
6
15
  export declare function add2d(vector1: Vector2d, vector2: Vector2d): Vector2d;
16
+ /**
17
+ * Subtracts `vector2` from `vector1` and returns a new vector.
18
+ */
7
19
  export declare function subtract2d(vector1: Vector2d, vector2: Vector2d): Vector2d;
20
+ /**
21
+ * Returns the Euclidean length/magnitude of a vector.
22
+ */
8
23
  export declare function length2d(vector: Vector2d): number;
24
+ /**
25
+ * Normalizes a vector to length `1`.
26
+ *
27
+ * Important: this function mutates and returns the original vector object. Zero
28
+ * vectors are returned unchanged.
29
+ */
9
30
  export declare function normalize2d(vector: Vector2d): Vector2d;
31
+ /**
32
+ * Returns the dot product of two vectors.
33
+ */
10
34
  export declare function dot2d(v1: Vector2d, v2: Vector2d): number;
35
+ /**
36
+ * Returns the distance between two vector positions.
37
+ */
11
38
  export declare function distance2d(v1: Vector2d, v2: Vector2d): number;
39
+ /**
40
+ * Clamps each component of `vector` between the matching `min` and `max`
41
+ * component.
42
+ */
12
43
  export declare function clamp2d(vector: Vector2d, min: Vector2d, max: Vector2d): Vector2d;
44
+ /**
45
+ * Linearly interpolates each component from `start` to `end`.
46
+ *
47
+ * `t.x` controls x interpolation and `t.y` controls y interpolation.
48
+ */
13
49
  export declare function lerp2d(start: Vector2d, end: Vector2d, t: Vector2d): Vector2d;
50
+ /**
51
+ * Maps each vector component from one numeric range into another range.
52
+ */
14
53
  export declare function map2d(value: Vector2d, inMin: Vector2d, inMax: Vector2d, outMin: Vector2d, outMax: Vector2d): Vector2d;
54
+ /**
55
+ * Multiplies both vector components by a scalar.
56
+ */
15
57
  export declare function scale2d(value: Vector2d, vscale: number): Vector2d;
@@ -1,33 +1,46 @@
1
1
  // 2 Dimensional Vector Type
2
2
  import { clamp, lerp, map, scale } from "../utils/math.js";
3
- // Function to create an Object of Type Vector2D
3
+ /**
4
+ * Creates a new 2D vector.
5
+ */
4
6
  export function makeVector2d(x, y) {
5
7
  return {
6
8
  x: x,
7
9
  y: y
8
10
  };
9
11
  }
10
- // Function to add 2 Vectors together
12
+ /**
13
+ * Adds two vectors and returns a new vector.
14
+ */
11
15
  export function add2d(vector1, vector2) {
12
16
  return {
13
17
  x: vector1.x + vector2.x,
14
18
  y: vector1.y + vector2.y,
15
19
  };
16
20
  }
17
- // Function to subtract 2 Vectors from each other
21
+ /**
22
+ * Subtracts `vector2` from `vector1` and returns a new vector.
23
+ */
18
24
  export function subtract2d(vector1, vector2) {
19
25
  return {
20
26
  x: vector1.x - vector2.x,
21
27
  y: vector1.y - vector2.y,
22
28
  };
23
29
  }
24
- // Function to get the length from an Vector
30
+ /**
31
+ * Returns the Euclidean length/magnitude of a vector.
32
+ */
25
33
  export function length2d(vector) {
26
34
  let produkt = vector.x * vector.x + vector.y * vector.y;
27
35
  let root = Math.sqrt(produkt);
28
36
  return root;
29
37
  }
30
- // Function to normalize a Vector 2d
38
+ /**
39
+ * Normalizes a vector to length `1`.
40
+ *
41
+ * Important: this function mutates and returns the original vector object. Zero
42
+ * vectors are returned unchanged.
43
+ */
31
44
  export function normalize2d(vector) {
32
45
  // Check if the Vector is zero because then you dont need to
33
46
  // calculate sth
@@ -39,38 +52,53 @@ export function normalize2d(vector) {
39
52
  vector.y = vector.y / root;
40
53
  return vector;
41
54
  }
42
- // Function to make scalar produkt from an Vector
55
+ /**
56
+ * Returns the dot product of two vectors.
57
+ */
43
58
  export function dot2d(v1, v2) {
44
59
  return (v1.x * v2.x + v1.y * v2.y);
45
60
  }
46
61
  // crossprodukt (only for 3 Dimensinal Vectors)
47
- // Calculate the Distance between 2 Vectors
62
+ /**
63
+ * Returns the distance between two vector positions.
64
+ */
48
65
  export function distance2d(v1, v2) {
49
66
  let tmp = subtract2d(v1, v2);
50
67
  return length2d(tmp);
51
68
  }
52
- // Function to clamp a Vector 2d
69
+ /**
70
+ * Clamps each component of `vector` between the matching `min` and `max`
71
+ * component.
72
+ */
53
73
  export function clamp2d(vector, min, max) {
54
74
  return {
55
75
  x: clamp(vector.x, min.x, max.x),
56
76
  y: clamp(vector.y, min.y, max.y),
57
77
  };
58
78
  }
59
- // Lerp for a 2d Vector
79
+ /**
80
+ * Linearly interpolates each component from `start` to `end`.
81
+ *
82
+ * `t.x` controls x interpolation and `t.y` controls y interpolation.
83
+ */
60
84
  export function lerp2d(start, end, t) {
61
85
  return {
62
86
  x: lerp(start.x, end.x, t.x),
63
87
  y: lerp(start.y, end.y, t.y),
64
88
  };
65
89
  }
66
- // Map Function for a 2d Vector
90
+ /**
91
+ * Maps each vector component from one numeric range into another range.
92
+ */
67
93
  export function map2d(value, inMin, inMax, outMin, outMax) {
68
94
  return {
69
95
  x: map(value.x, inMin.x, inMax.x, outMin.x, outMax.x),
70
96
  y: map(value.y, inMin.y, inMax.y, outMin.y, outMax.y),
71
97
  };
72
98
  }
73
- // Function to scale a Vector
99
+ /**
100
+ * Multiplies both vector components by a scalar.
101
+ */
74
102
  export function scale2d(value, vscale) {
75
103
  return {
76
104
  x: scale(value.x, vscale),
@@ -1,16 +1,54 @@
1
+ /**
2
+ * Three-dimensional vector for positions, directions, and velocities.
3
+ */
1
4
  export type Vector3d = {
2
5
  x: number;
3
6
  y: number;
4
7
  z: number;
5
8
  };
9
+ /**
10
+ * Creates a new 3D vector.
11
+ */
6
12
  export declare function makeVector3d(x: number, y: number, z: number): Vector3d;
13
+ /**
14
+ * Adds two vectors and returns a new vector.
15
+ */
7
16
  export declare function add3d(vector1: Vector3d, vector2: Vector3d): Vector3d;
17
+ /**
18
+ * Subtracts `vector2` from `vector1` and returns a new vector.
19
+ */
8
20
  export declare function subtract3d(vector1: Vector3d, vector2: Vector3d): Vector3d;
21
+ /**
22
+ * Returns the Euclidean length/magnitude of a 3D vector.
23
+ */
9
24
  export declare function length3d(vector: Vector3d): number;
25
+ /**
26
+ * Normalizes a vector to length `1`.
27
+ *
28
+ * Important: this function mutates and returns the original vector object.
29
+ */
10
30
  export declare function normalize3d(vector: Vector3d): Vector3d;
31
+ /**
32
+ * Returns the dot product of two vectors.
33
+ */
11
34
  export declare function dot3d(v1: Vector3d, v2: Vector3d): number;
35
+ /**
36
+ * Returns the cross product of two 3D vectors.
37
+ */
12
38
  export declare function crossprodukt3d(v1: Vector3d, v2: Vector3d): Vector3d;
39
+ /**
40
+ * Returns the distance between two 3D vector positions.
41
+ */
13
42
  export declare function distance3d(v1: Vector3d, v2: Vector3d): number;
43
+ /**
44
+ * Clamps vector components between the matching `min` and `max` components.
45
+ */
14
46
  export declare function clamp3d(vector: Vector3d, min: Vector3d, max: Vector3d): Vector3d;
47
+ /**
48
+ * Linearly interpolates each component from `start` to `end`.
49
+ */
15
50
  export declare function lerp3d(start: Vector3d, end: Vector3d, t: Vector3d): Vector3d;
51
+ /**
52
+ * Maps each vector component from one numeric range into another range.
53
+ */
16
54
  export declare function map3d(value: Vector3d, inMin: Vector3d, inMax: Vector3d, outMin: Vector3d, outMax: Vector3d): Vector3d;