@wentools/spatial 0.1.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 (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +119 -0
  3. package/esm/bounding_box.d.ts +12 -0
  4. package/esm/bounding_box.d.ts.map +1 -0
  5. package/esm/bounding_box.js +24 -0
  6. package/esm/circle.d.ts +47 -0
  7. package/esm/circle.d.ts.map +1 -0
  8. package/esm/circle.js +55 -0
  9. package/esm/distance.d.ts +31 -0
  10. package/esm/distance.d.ts.map +1 -0
  11. package/esm/distance.js +36 -0
  12. package/esm/intersection.d.ts +32 -0
  13. package/esm/intersection.d.ts.map +1 -0
  14. package/esm/intersection.js +77 -0
  15. package/esm/line.d.ts +39 -0
  16. package/esm/line.d.ts.map +1 -0
  17. package/esm/line.js +71 -0
  18. package/esm/mod.d.ts +18 -0
  19. package/esm/mod.d.ts.map +1 -0
  20. package/esm/mod.js +12 -0
  21. package/esm/package.json +3 -0
  22. package/esm/point/mod.d.ts +6 -0
  23. package/esm/point/mod.d.ts.map +1 -0
  24. package/esm/point/mod.js +4 -0
  25. package/esm/point/point.d.ts +54 -0
  26. package/esm/point/point.d.ts.map +1 -0
  27. package/esm/point/point.js +61 -0
  28. package/esm/rectangle.d.ts +125 -0
  29. package/esm/rectangle.d.ts.map +1 -0
  30. package/esm/rectangle.js +142 -0
  31. package/esm/vector/mod.d.ts +6 -0
  32. package/esm/vector/mod.d.ts.map +1 -0
  33. package/esm/vector/mod.js +4 -0
  34. package/esm/vector/vector.d.ts +69 -0
  35. package/esm/vector/vector.d.ts.map +1 -0
  36. package/esm/vector/vector.js +84 -0
  37. package/package.json +33 -0
  38. package/script/bounding_box.d.ts +12 -0
  39. package/script/bounding_box.d.ts.map +1 -0
  40. package/script/bounding_box.js +27 -0
  41. package/script/circle.d.ts +47 -0
  42. package/script/circle.d.ts.map +1 -0
  43. package/script/circle.js +65 -0
  44. package/script/distance.d.ts +31 -0
  45. package/script/distance.d.ts.map +1 -0
  46. package/script/distance.js +43 -0
  47. package/script/intersection.d.ts +32 -0
  48. package/script/intersection.d.ts.map +1 -0
  49. package/script/intersection.js +83 -0
  50. package/script/line.d.ts +39 -0
  51. package/script/line.d.ts.map +1 -0
  52. package/script/line.js +79 -0
  53. package/script/mod.d.ts +18 -0
  54. package/script/mod.d.ts.map +1 -0
  55. package/script/mod.js +79 -0
  56. package/script/package.json +3 -0
  57. package/script/point/mod.d.ts +6 -0
  58. package/script/point/mod.d.ts.map +1 -0
  59. package/script/point/mod.js +15 -0
  60. package/script/point/point.d.ts +54 -0
  61. package/script/point/point.d.ts.map +1 -0
  62. package/script/point/point.js +71 -0
  63. package/script/rectangle.d.ts +125 -0
  64. package/script/rectangle.d.ts.map +1 -0
  65. package/script/rectangle.js +162 -0
  66. package/script/vector/mod.d.ts +6 -0
  67. package/script/vector/mod.d.ts.map +1 -0
  68. package/script/vector/mod.js +20 -0
  69. package/script/vector/vector.d.ts +69 -0
  70. package/script/vector/vector.d.ts.map +1 -0
  71. package/script/vector/vector.js +99 -0
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Circle entity - represents a circle in 2D space.
3
+ */
4
+ import type { Point2D } from './point/mod.js';
5
+ /**
6
+ * A circle defined by center position and radius.
7
+ */
8
+ type Circle = {
9
+ x: number;
10
+ y: number;
11
+ radius: number;
12
+ };
13
+ /**
14
+ * Creates a circle from center position and radius.
15
+ */
16
+ declare const createCircle: (x: number, y: number, radius: number) => Circle;
17
+ /**
18
+ * Creates a circle from a center point and radius.
19
+ */
20
+ declare const createCircleFromPoint: (center: Point2D, radius: number) => Circle;
21
+ /**
22
+ * Gets the area of a circle.
23
+ */
24
+ declare const getCircleArea: (circle: Circle) => number;
25
+ /**
26
+ * Gets the circumference of a circle.
27
+ */
28
+ declare const getCircleCircumference: (circle: Circle) => number;
29
+ /**
30
+ * Gets the center point of a circle.
31
+ */
32
+ declare const getCircleCenter: (circle: Circle) => Point2D;
33
+ /**
34
+ * Checks if a point is inside a circle.
35
+ */
36
+ declare const isPointInCircle: (point: Point2D, circle: Circle) => boolean;
37
+ /**
38
+ * Checks if two circles overlap.
39
+ */
40
+ declare const circlesOverlap: (a: Circle, b: Circle) => boolean;
41
+ /**
42
+ * Checks if circle a fully contains circle b.
43
+ */
44
+ declare const circleContains: (outer: Circle, inner: Circle) => boolean;
45
+ export type { Circle };
46
+ export { createCircle, createCircleFromPoint, getCircleArea, getCircleCircumference, getCircleCenter, isPointInCircle, circlesOverlap, circleContains, };
47
+ //# sourceMappingURL=circle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circle.d.ts","sourceRoot":"","sources":["../src/circle.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAE7C;;GAEG;AACH,KAAK,MAAM,GAAG;IACb,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,MAAM,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;GAEG;AACH,QAAA,MAAM,YAAY,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,QAAQ,MAAM,KAAG,MAA4B,CAAA;AAEzF;;GAEG;AACH,QAAA,MAAM,qBAAqB,GAAI,QAAQ,OAAO,EAAE,QAAQ,MAAM,KAAG,MAI/D,CAAA;AAEF;;GAEG;AACH,QAAA,MAAM,aAAa,GAAI,QAAQ,MAAM,KAAG,MAAiD,CAAA;AAEzF;;GAEG;AACH,QAAA,MAAM,sBAAsB,GAAI,QAAQ,MAAM,KAAG,MAAqC,CAAA;AAEtF;;GAEG;AACH,QAAA,MAAM,eAAe,GAAI,QAAQ,MAAM,KAAG,OAAyC,CAAA;AAEnF;;GAEG;AACH,QAAA,MAAM,eAAe,GAAI,OAAO,OAAO,EAAE,QAAQ,MAAM,KAAG,OAIzD,CAAA;AAED;;GAEG;AACH,QAAA,MAAM,cAAc,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,OAM9C,CAAA;AAED;;GAEG;AACH,QAAA,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,OAAO,MAAM,KAAG,OAKtD,CAAA;AAED,YAAY,EAAE,MAAM,EAAE,CAAA;AACtB,OAAO,EACN,YAAY,EACZ,qBAAqB,EACrB,aAAa,EACb,sBAAsB,EACtB,eAAe,EACf,eAAe,EACf,cAAc,EACd,cAAc,GACd,CAAA"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ /**
3
+ * Circle entity - represents a circle in 2D space.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.circleContains = exports.circlesOverlap = exports.isPointInCircle = exports.getCircleCenter = exports.getCircleCircumference = exports.getCircleArea = exports.createCircleFromPoint = exports.createCircle = void 0;
7
+ /**
8
+ * Creates a circle from center position and radius.
9
+ */
10
+ const createCircle = (x, y, radius) => ({ x, y, radius });
11
+ exports.createCircle = createCircle;
12
+ /**
13
+ * Creates a circle from a center point and radius.
14
+ */
15
+ const createCircleFromPoint = (center, radius) => ({
16
+ x: center.x,
17
+ y: center.y,
18
+ radius,
19
+ });
20
+ exports.createCircleFromPoint = createCircleFromPoint;
21
+ /**
22
+ * Gets the area of a circle.
23
+ */
24
+ const getCircleArea = (circle) => Math.PI * circle.radius * circle.radius;
25
+ exports.getCircleArea = getCircleArea;
26
+ /**
27
+ * Gets the circumference of a circle.
28
+ */
29
+ const getCircleCircumference = (circle) => 2 * Math.PI * circle.radius;
30
+ exports.getCircleCircumference = getCircleCircumference;
31
+ /**
32
+ * Gets the center point of a circle.
33
+ */
34
+ const getCircleCenter = (circle) => ({ x: circle.x, y: circle.y });
35
+ exports.getCircleCenter = getCircleCenter;
36
+ /**
37
+ * Checks if a point is inside a circle.
38
+ */
39
+ const isPointInCircle = (point, circle) => {
40
+ const dx = point.x - circle.x;
41
+ const dy = point.y - circle.y;
42
+ return dx * dx + dy * dy <= circle.radius * circle.radius;
43
+ };
44
+ exports.isPointInCircle = isPointInCircle;
45
+ /**
46
+ * Checks if two circles overlap.
47
+ */
48
+ const circlesOverlap = (a, b) => {
49
+ const dx = b.x - a.x;
50
+ const dy = b.y - a.y;
51
+ const distanceSquared = dx * dx + dy * dy;
52
+ const radiusSum = a.radius + b.radius;
53
+ return distanceSquared <= radiusSum * radiusSum;
54
+ };
55
+ exports.circlesOverlap = circlesOverlap;
56
+ /**
57
+ * Checks if circle a fully contains circle b.
58
+ */
59
+ const circleContains = (outer, inner) => {
60
+ const dx = inner.x - outer.x;
61
+ const dy = inner.y - outer.y;
62
+ const distance = Math.sqrt(dx * dx + dy * dy);
63
+ return distance + inner.radius <= outer.radius;
64
+ };
65
+ exports.circleContains = circleContains;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Distance calculation functions for 2D space.
3
+ */
4
+ import type { Point2D } from './point/mod.js';
5
+ /**
6
+ * Calculates Manhattan distance (L1 norm) between two points.
7
+ * Distance is sum of absolute differences of coordinates.
8
+ */
9
+ declare const manhattanDistance: (a: Point2D, b: Point2D) => number;
10
+ /**
11
+ * Calculates Euclidean distance (L2 norm) between two points.
12
+ * Standard straight-line distance.
13
+ */
14
+ declare const euclideanDistance: (a: Point2D, b: Point2D) => number;
15
+ /**
16
+ * Calculates squared Euclidean distance between two points.
17
+ * Avoids sqrt for performance when only comparing distances.
18
+ */
19
+ declare const euclideanDistanceSquared: (a: Point2D, b: Point2D) => number;
20
+ /**
21
+ * Calculates Chebyshev distance (L∞ norm) between two points.
22
+ * Maximum of absolute differences (king move in chess).
23
+ */
24
+ declare const chebyshevDistance: (a: Point2D, b: Point2D) => number;
25
+ /**
26
+ * Creates a distance checker function using partial application.
27
+ * Returns a function that checks if two points are within threshold distance.
28
+ */
29
+ declare const createDistanceChecker: (threshold: number, metric?: "manhattan" | "euclidean" | "chebyshev") => (a: Point2D, b: Point2D) => boolean;
30
+ export { manhattanDistance, euclideanDistance, euclideanDistanceSquared, chebyshevDistance, createDistanceChecker, };
31
+ //# sourceMappingURL=distance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"distance.d.ts","sourceRoot":"","sources":["../src/distance.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAE7C;;;GAGG;AACH,QAAA,MAAM,iBAAiB,GAAI,GAAG,OAAO,EAAE,GAAG,OAAO,KAAG,MACV,CAAA;AAE1C;;;GAGG;AACH,QAAA,MAAM,iBAAiB,GAAI,GAAG,OAAO,EAAE,GAAG,OAAO,KAAG,MACO,CAAA;AAE3D;;;GAGG;AACH,QAAA,MAAM,wBAAwB,GAAI,GAAG,OAAO,EAAE,GAAG,OAAO,KAAG,MACX,CAAA;AAEhD;;;GAGG;AACH,QAAA,MAAM,iBAAiB,GAAI,GAAG,OAAO,EAAE,GAAG,OAAO,KAAG,MACD,CAAA;AAEnD;;;GAGG;AACH,QAAA,MAAM,qBAAqB,GACzB,WAAW,MAAM,EAAE,SAAQ,WAAW,GAAG,WAAW,GAAG,WAAyB,MAChF,GAAG,OAAO,EAAE,GAAG,OAAO,KAAG,OAQzB,CAAA;AAEF,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,GACrB,CAAA"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ /**
3
+ * Distance calculation functions for 2D space.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createDistanceChecker = exports.chebyshevDistance = exports.euclideanDistanceSquared = exports.euclideanDistance = exports.manhattanDistance = void 0;
7
+ /**
8
+ * Calculates Manhattan distance (L1 norm) between two points.
9
+ * Distance is sum of absolute differences of coordinates.
10
+ */
11
+ const manhattanDistance = (a, b) => Math.abs(b.x - a.x) + Math.abs(b.y - a.y);
12
+ exports.manhattanDistance = manhattanDistance;
13
+ /**
14
+ * Calculates Euclidean distance (L2 norm) between two points.
15
+ * Standard straight-line distance.
16
+ */
17
+ const euclideanDistance = (a, b) => Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));
18
+ exports.euclideanDistance = euclideanDistance;
19
+ /**
20
+ * Calculates squared Euclidean distance between two points.
21
+ * Avoids sqrt for performance when only comparing distances.
22
+ */
23
+ const euclideanDistanceSquared = (a, b) => Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2);
24
+ exports.euclideanDistanceSquared = euclideanDistanceSquared;
25
+ /**
26
+ * Calculates Chebyshev distance (L∞ norm) between two points.
27
+ * Maximum of absolute differences (king move in chess).
28
+ */
29
+ const chebyshevDistance = (a, b) => Math.max(Math.abs(b.x - a.x), Math.abs(b.y - a.y));
30
+ exports.chebyshevDistance = chebyshevDistance;
31
+ /**
32
+ * Creates a distance checker function using partial application.
33
+ * Returns a function that checks if two points are within threshold distance.
34
+ */
35
+ const createDistanceChecker = (threshold, metric = 'euclidean') => (a, b) => {
36
+ const distance = metric === 'manhattan'
37
+ ? manhattanDistance(a, b)
38
+ : metric === 'chebyshev'
39
+ ? chebyshevDistance(a, b)
40
+ : euclideanDistance(a, b);
41
+ return distance <= threshold;
42
+ };
43
+ exports.createDistanceChecker = createDistanceChecker;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Cross-shape intersection functions — operations that span multiple geometry types.
3
+ */
4
+ import type { Point2D } from './point/mod.js';
5
+ import type { Circle } from './circle.js';
6
+ import type { Rectangle } from './rectangle.js';
7
+ import type { Line } from './line.js';
8
+ /**
9
+ * Checks if a circle and rectangle overlap.
10
+ * Finds the closest point on the rectangle to the circle center,
11
+ * then checks if the distance is within the radius.
12
+ */
13
+ declare const circleRectangleOverlap: (circle: Circle, rect: Rectangle) => boolean;
14
+ /**
15
+ * Finds the intersection point of two line segments.
16
+ * Returns null if segments are parallel, coincident, or don't intersect within their bounds.
17
+ */
18
+ declare const lineLineIntersection: (a: Line, b: Line) => Point2D | null;
19
+ /**
20
+ * Finds the closest point on a line segment to a given point.
21
+ * Projects the point onto the line and clamps to the segment bounds.
22
+ * Returns the start point for degenerate (zero-length) segments.
23
+ */
24
+ declare const closestPointOnLine: (point: Point2D, line: Line) => Point2D;
25
+ /**
26
+ * Finds the closest point on a rectangle's boundary to a given point.
27
+ * For points outside, clamps to the nearest edge. For points inside,
28
+ * snaps to the nearest edge.
29
+ */
30
+ declare const closestPointOnRectangle: (point: Point2D, rect: Rectangle) => Point2D;
31
+ export { circleRectangleOverlap, lineLineIntersection, closestPointOnLine, closestPointOnRectangle, };
32
+ //# sourceMappingURL=intersection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intersection.d.ts","sourceRoot":"","sources":["../src/intersection.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAGrC;;;;GAIG;AACH,QAAA,MAAM,sBAAsB,GAAI,QAAQ,MAAM,EAAE,MAAM,SAAS,KAAG,OAMjE,CAAA;AAED;;;GAGG;AACH,QAAA,MAAM,oBAAoB,GAAI,GAAG,IAAI,EAAE,GAAG,IAAI,KAAG,OAAO,GAAG,IAe1D,CAAA;AAED;;;;GAIG;AACH,QAAA,MAAM,kBAAkB,GAAI,OAAO,OAAO,EAAE,MAAM,IAAI,KAAG,OAOxD,CAAA;AAED;;;;GAIG;AACH,QAAA,MAAM,uBAAuB,GAAI,OAAO,OAAO,EAAE,MAAM,SAAS,KAAG,OAgBlE,CAAA;AAED,OAAO,EACN,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,GACvB,CAAA"}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ /**
3
+ * Cross-shape intersection functions — operations that span multiple geometry types.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.closestPointOnRectangle = exports.closestPointOnLine = exports.lineLineIntersection = exports.circleRectangleOverlap = void 0;
7
+ const mod_js_1 = require("./point/mod.js");
8
+ /**
9
+ * Checks if a circle and rectangle overlap.
10
+ * Finds the closest point on the rectangle to the circle center,
11
+ * then checks if the distance is within the radius.
12
+ */
13
+ const circleRectangleOverlap = (circle, rect) => {
14
+ const closestX = Math.max(rect.x, Math.min(circle.x, rect.x + rect.width));
15
+ const closestY = Math.max(rect.y, Math.min(circle.y, rect.y + rect.height));
16
+ const dx = circle.x - closestX;
17
+ const dy = circle.y - closestY;
18
+ return dx * dx + dy * dy <= circle.radius * circle.radius;
19
+ };
20
+ exports.circleRectangleOverlap = circleRectangleOverlap;
21
+ /**
22
+ * Finds the intersection point of two line segments.
23
+ * Returns null if segments are parallel, coincident, or don't intersect within their bounds.
24
+ */
25
+ const lineLineIntersection = (a, b) => {
26
+ const dx1 = a.end.x - a.start.x;
27
+ const dy1 = a.end.y - a.start.y;
28
+ const dx2 = b.end.x - b.start.x;
29
+ const dy2 = b.end.y - b.start.y;
30
+ const d = dx1 * dy2 - dy1 * dx2;
31
+ if (d === 0)
32
+ return null;
33
+ const dx3 = b.start.x - a.start.x;
34
+ const dy3 = b.start.y - a.start.y;
35
+ const t = (dx3 * dy2 - dy3 * dx2) / d;
36
+ const u = (dx3 * dy1 - dy3 * dx1) / d;
37
+ if (t >= 0 && t <= 1 && u >= 0 && u <= 1) {
38
+ return (0, mod_js_1.createPoint)(a.start.x + t * dx1, a.start.y + t * dy1);
39
+ }
40
+ return null;
41
+ };
42
+ exports.lineLineIntersection = lineLineIntersection;
43
+ /**
44
+ * Finds the closest point on a line segment to a given point.
45
+ * Projects the point onto the line and clamps to the segment bounds.
46
+ * Returns the start point for degenerate (zero-length) segments.
47
+ */
48
+ const closestPointOnLine = (point, line) => {
49
+ const dx = line.end.x - line.start.x;
50
+ const dy = line.end.y - line.start.y;
51
+ const lengthSquared = dx * dx + dy * dy;
52
+ if (lengthSquared === 0)
53
+ return (0, mod_js_1.createPoint)(line.start.x, line.start.y);
54
+ const t = Math.max(0, Math.min(1, ((point.x - line.start.x) * dx + (point.y - line.start.y) * dy) / lengthSquared));
55
+ return (0, mod_js_1.createPoint)(line.start.x + t * dx, line.start.y + t * dy);
56
+ };
57
+ exports.closestPointOnLine = closestPointOnLine;
58
+ /**
59
+ * Finds the closest point on a rectangle's boundary to a given point.
60
+ * For points outside, clamps to the nearest edge. For points inside,
61
+ * snaps to the nearest edge.
62
+ */
63
+ const closestPointOnRectangle = (point, rect) => {
64
+ const clampedX = Math.max(rect.x, Math.min(point.x, rect.x + rect.width));
65
+ const clampedY = Math.max(rect.y, Math.min(point.y, rect.y + rect.height));
66
+ if (clampedX !== point.x || clampedY !== point.y) {
67
+ return (0, mod_js_1.createPoint)(clampedX, clampedY);
68
+ }
69
+ // Inside — snap to nearest edge
70
+ const distToLeft = point.x - rect.x;
71
+ const distToRight = (rect.x + rect.width) - point.x;
72
+ const distToTop = point.y - rect.y;
73
+ const distToBottom = (rect.y + rect.height) - point.y;
74
+ const minDist = Math.min(distToLeft, distToRight, distToTop, distToBottom);
75
+ if (minDist === distToLeft)
76
+ return (0, mod_js_1.createPoint)(rect.x, point.y);
77
+ if (minDist === distToRight)
78
+ return (0, mod_js_1.createPoint)(rect.x + rect.width, point.y);
79
+ if (minDist === distToTop)
80
+ return (0, mod_js_1.createPoint)(point.x, rect.y);
81
+ return (0, mod_js_1.createPoint)(point.x, rect.y + rect.height);
82
+ };
83
+ exports.closestPointOnRectangle = closestPointOnRectangle;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Line entity - represents a line segment in 2D space.
3
+ */
4
+ import type { Point2D } from './point/mod.js';
5
+ /**
6
+ * A line segment defined by start and end points.
7
+ */
8
+ type Line = {
9
+ start: Point2D;
10
+ end: Point2D;
11
+ };
12
+ /**
13
+ * Creates a line from start and end points.
14
+ */
15
+ declare const createLine: (start: Point2D, end: Point2D) => Line;
16
+ /**
17
+ * Creates a line from coordinate values.
18
+ */
19
+ declare const createLineFromCoords: (x1: number, y1: number, x2: number, y2: number) => Line;
20
+ /**
21
+ * Gets the length of a line segment.
22
+ */
23
+ declare const getLineLength: (line: Line) => number;
24
+ /**
25
+ * Gets the midpoint of a line segment.
26
+ */
27
+ declare const getLineMidpoint: (line: Line) => Point2D;
28
+ /**
29
+ * Gets the slope of a line segment.
30
+ * Returns Infinity for vertical lines.
31
+ */
32
+ declare const getLineSlope: (line: Line) => number;
33
+ /**
34
+ * Checks if a point lies on a line segment (within tolerance).
35
+ */
36
+ declare const isPointOnLine: (point: Point2D, line: Line, tolerance?: number) => boolean;
37
+ export type { Line };
38
+ export { createLine, createLineFromCoords, getLineLength, getLineMidpoint, getLineSlope, isPointOnLine, };
39
+ //# sourceMappingURL=line.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"line.d.ts","sourceRoot":"","sources":["../src/line.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAE7C;;GAEG;AACH,KAAK,IAAI,GAAG;IACX,KAAK,EAAE,OAAO,CAAA;IACd,GAAG,EAAE,OAAO,CAAA;CACZ,CAAA;AAED;;GAEG;AACH,QAAA,MAAM,UAAU,GAAI,OAAO,OAAO,EAAE,KAAK,OAAO,KAAG,IAAwB,CAAA;AAE3E;;GAEG;AACH,QAAA,MAAM,oBAAoB,GAAI,IAAI,MAAM,EAAE,IAAI,MAAM,EAAE,IAAI,MAAM,EAAE,IAAI,MAAM,KAAG,IAG7E,CAAA;AAEF;;GAEG;AACH,QAAA,MAAM,aAAa,GAAI,MAAM,IAAI,KAAG,MAInC,CAAA;AAED;;GAEG;AACH,QAAA,MAAM,eAAe,GAAI,MAAM,IAAI,KAAG,OAGpC,CAAA;AAEF;;;GAGG;AACH,QAAA,MAAM,YAAY,GAAI,MAAM,IAAI,KAAG,MAKlC,CAAA;AAED;;GAEG;AACH,QAAA,MAAM,aAAa,GAAI,OAAO,OAAO,EAAE,MAAM,IAAI,EAAE,YAAW,MAAc,KAAG,OAiC9E,CAAA;AAED,YAAY,EAAE,IAAI,EAAE,CAAA;AACpB,OAAO,EACN,UAAU,EACV,oBAAoB,EACpB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,aAAa,GACb,CAAA"}
package/script/line.js ADDED
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ /**
3
+ * Line entity - represents a line segment in 2D space.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isPointOnLine = exports.getLineSlope = exports.getLineMidpoint = exports.getLineLength = exports.createLineFromCoords = exports.createLine = void 0;
7
+ /**
8
+ * Creates a line from start and end points.
9
+ */
10
+ const createLine = (start, end) => ({ start, end });
11
+ exports.createLine = createLine;
12
+ /**
13
+ * Creates a line from coordinate values.
14
+ */
15
+ const createLineFromCoords = (x1, y1, x2, y2) => ({
16
+ start: { x: x1, y: y1 },
17
+ end: { x: x2, y: y2 },
18
+ });
19
+ exports.createLineFromCoords = createLineFromCoords;
20
+ /**
21
+ * Gets the length of a line segment.
22
+ */
23
+ const getLineLength = (line) => {
24
+ const dx = line.end.x - line.start.x;
25
+ const dy = line.end.y - line.start.y;
26
+ return Math.sqrt(dx * dx + dy * dy);
27
+ };
28
+ exports.getLineLength = getLineLength;
29
+ /**
30
+ * Gets the midpoint of a line segment.
31
+ */
32
+ const getLineMidpoint = (line) => ({
33
+ x: (line.start.x + line.end.x) / 2,
34
+ y: (line.start.y + line.end.y) / 2,
35
+ });
36
+ exports.getLineMidpoint = getLineMidpoint;
37
+ /**
38
+ * Gets the slope of a line segment.
39
+ * Returns Infinity for vertical lines.
40
+ */
41
+ const getLineSlope = (line) => {
42
+ const dx = line.end.x - line.start.x;
43
+ const dy = line.end.y - line.start.y;
44
+ if (dx === 0)
45
+ return Infinity;
46
+ return dy / dx;
47
+ };
48
+ exports.getLineSlope = getLineSlope;
49
+ /**
50
+ * Checks if a point lies on a line segment (within tolerance).
51
+ */
52
+ const isPointOnLine = (point, line, tolerance = 0.001) => {
53
+ // Check if point is within bounding box first
54
+ const minX = Math.min(line.start.x, line.end.x);
55
+ const maxX = Math.max(line.start.x, line.end.x);
56
+ const minY = Math.min(line.start.y, line.end.y);
57
+ const maxY = Math.max(line.start.y, line.end.y);
58
+ if (point.x < minX - tolerance ||
59
+ point.x > maxX + tolerance ||
60
+ point.y < minY - tolerance ||
61
+ point.y > maxY + tolerance) {
62
+ return false;
63
+ }
64
+ // Calculate distance from point to line
65
+ const dx = line.end.x - line.start.x;
66
+ const dy = line.end.y - line.start.y;
67
+ const length = Math.sqrt(dx * dx + dy * dy);
68
+ if (length === 0) {
69
+ // Line is a point, check if points are equal
70
+ const pointDx = point.x - line.start.x;
71
+ const pointDy = point.y - line.start.y;
72
+ return Math.sqrt(pointDx * pointDx + pointDy * pointDy) <= tolerance;
73
+ }
74
+ // Distance from point to line
75
+ const distance = Math.abs(dy * point.x - dx * point.y + line.end.x * line.start.y - line.end.y * line.start.x) /
76
+ length;
77
+ return distance <= tolerance;
78
+ };
79
+ exports.isPointOnLine = isPointOnLine;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Spatial library - 2D coordinate system operations.
3
+ * All operations in continuous 2D coordinate space.
4
+ */
5
+ export type { Point2D } from './point/mod.js';
6
+ export { createPoint, createOrigin, translatePoint, pointsEqual, lerpPoint, midpoint, rotatePoint, clampPoint } from './point/mod.js';
7
+ export type { Vector2D } from './vector/mod.js';
8
+ export { createVector, createZeroVector, vectorMagnitude, addVectors, subtractVectors, scaleVector, normalizeVector, dotProduct, crossProduct2D, perpendicular, vectorFromAngle, vectorToAngle, rotateVector, } from './vector/mod.js';
9
+ export type { Rectangle } from './rectangle.js';
10
+ export { createRectangle, createRectangleFromPoints, getRectangleArea, getRectanglePerimeter, getRectangleCenter, isPointInRectangle, rectanglesOverlap, rectangleContains, rectangleIntersection, rectangleUnion, centerRectangleInContainer, centerHorizontally, centerVertically, translateRectangle, expandRectangle, insetRectangle, scaleRectangle, getRectangleCorners, } from './rectangle.js';
11
+ export type { Circle } from './circle.js';
12
+ export { createCircle, createCircleFromPoint, getCircleArea, getCircleCircumference, getCircleCenter, isPointInCircle, circlesOverlap, circleContains, } from './circle.js';
13
+ export type { Line } from './line.js';
14
+ export { createLine, createLineFromCoords, getLineLength, getLineMidpoint, getLineSlope, isPointOnLine, } from './line.js';
15
+ export { manhattanDistance, euclideanDistance, euclideanDistanceSquared, chebyshevDistance, createDistanceChecker, } from './distance.js';
16
+ export { circleRectangleOverlap, lineLineIntersection, closestPointOnLine, closestPointOnRectangle, } from './intersection.js';
17
+ export { getBoundingBox } from './bounding_box.js';
18
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAErI,YAAY,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EACN,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,eAAe,EACf,WAAW,EACX,eAAe,EACf,UAAU,EACV,cAAc,EACd,aAAa,EACb,eAAe,EACf,aAAa,EACb,YAAY,GACZ,MAAM,iBAAiB,CAAA;AAExB,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EACN,eAAe,EACf,yBAAyB,EACzB,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,0BAA0B,EAC1B,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,cAAc,EACd,mBAAmB,GACnB,MAAM,gBAAgB,CAAA;AAEvB,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EACN,YAAY,EACZ,qBAAqB,EACrB,aAAa,EACb,sBAAsB,EACtB,eAAe,EACf,eAAe,EACf,cAAc,EACd,cAAc,GACd,MAAM,aAAa,CAAA;AAEpB,YAAY,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EACN,UAAU,EACV,oBAAoB,EACpB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,aAAa,GACb,MAAM,WAAW,CAAA;AAElB,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,GACrB,MAAM,eAAe,CAAA;AAEtB,OAAO,EACN,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,GACvB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA"}
package/script/mod.js ADDED
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ /**
3
+ * Spatial library - 2D coordinate system operations.
4
+ * All operations in continuous 2D coordinate space.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.getLineLength = exports.createLineFromCoords = exports.createLine = exports.circleContains = exports.circlesOverlap = exports.isPointInCircle = exports.getCircleCenter = exports.getCircleCircumference = exports.getCircleArea = exports.createCircleFromPoint = exports.createCircle = exports.getRectangleCorners = exports.scaleRectangle = exports.insetRectangle = exports.expandRectangle = exports.translateRectangle = exports.centerVertically = exports.centerHorizontally = exports.centerRectangleInContainer = exports.rectangleUnion = exports.rectangleIntersection = exports.rectangleContains = exports.rectanglesOverlap = exports.isPointInRectangle = exports.getRectangleCenter = exports.getRectanglePerimeter = exports.getRectangleArea = exports.createRectangleFromPoints = exports.createRectangle = exports.rotateVector = exports.vectorToAngle = exports.vectorFromAngle = exports.perpendicular = exports.crossProduct2D = exports.dotProduct = exports.normalizeVector = exports.scaleVector = exports.subtractVectors = exports.addVectors = exports.vectorMagnitude = exports.createZeroVector = exports.createVector = exports.clampPoint = exports.rotatePoint = exports.midpoint = exports.lerpPoint = exports.pointsEqual = exports.translatePoint = exports.createOrigin = exports.createPoint = void 0;
8
+ exports.getBoundingBox = exports.closestPointOnRectangle = exports.closestPointOnLine = exports.lineLineIntersection = exports.circleRectangleOverlap = exports.createDistanceChecker = exports.chebyshevDistance = exports.euclideanDistanceSquared = exports.euclideanDistance = exports.manhattanDistance = exports.isPointOnLine = exports.getLineSlope = exports.getLineMidpoint = void 0;
9
+ var mod_js_1 = require("./point/mod.js");
10
+ Object.defineProperty(exports, "createPoint", { enumerable: true, get: function () { return mod_js_1.createPoint; } });
11
+ Object.defineProperty(exports, "createOrigin", { enumerable: true, get: function () { return mod_js_1.createOrigin; } });
12
+ Object.defineProperty(exports, "translatePoint", { enumerable: true, get: function () { return mod_js_1.translatePoint; } });
13
+ Object.defineProperty(exports, "pointsEqual", { enumerable: true, get: function () { return mod_js_1.pointsEqual; } });
14
+ Object.defineProperty(exports, "lerpPoint", { enumerable: true, get: function () { return mod_js_1.lerpPoint; } });
15
+ Object.defineProperty(exports, "midpoint", { enumerable: true, get: function () { return mod_js_1.midpoint; } });
16
+ Object.defineProperty(exports, "rotatePoint", { enumerable: true, get: function () { return mod_js_1.rotatePoint; } });
17
+ Object.defineProperty(exports, "clampPoint", { enumerable: true, get: function () { return mod_js_1.clampPoint; } });
18
+ var mod_js_2 = require("./vector/mod.js");
19
+ Object.defineProperty(exports, "createVector", { enumerable: true, get: function () { return mod_js_2.createVector; } });
20
+ Object.defineProperty(exports, "createZeroVector", { enumerable: true, get: function () { return mod_js_2.createZeroVector; } });
21
+ Object.defineProperty(exports, "vectorMagnitude", { enumerable: true, get: function () { return mod_js_2.vectorMagnitude; } });
22
+ Object.defineProperty(exports, "addVectors", { enumerable: true, get: function () { return mod_js_2.addVectors; } });
23
+ Object.defineProperty(exports, "subtractVectors", { enumerable: true, get: function () { return mod_js_2.subtractVectors; } });
24
+ Object.defineProperty(exports, "scaleVector", { enumerable: true, get: function () { return mod_js_2.scaleVector; } });
25
+ Object.defineProperty(exports, "normalizeVector", { enumerable: true, get: function () { return mod_js_2.normalizeVector; } });
26
+ Object.defineProperty(exports, "dotProduct", { enumerable: true, get: function () { return mod_js_2.dotProduct; } });
27
+ Object.defineProperty(exports, "crossProduct2D", { enumerable: true, get: function () { return mod_js_2.crossProduct2D; } });
28
+ Object.defineProperty(exports, "perpendicular", { enumerable: true, get: function () { return mod_js_2.perpendicular; } });
29
+ Object.defineProperty(exports, "vectorFromAngle", { enumerable: true, get: function () { return mod_js_2.vectorFromAngle; } });
30
+ Object.defineProperty(exports, "vectorToAngle", { enumerable: true, get: function () { return mod_js_2.vectorToAngle; } });
31
+ Object.defineProperty(exports, "rotateVector", { enumerable: true, get: function () { return mod_js_2.rotateVector; } });
32
+ var rectangle_js_1 = require("./rectangle.js");
33
+ Object.defineProperty(exports, "createRectangle", { enumerable: true, get: function () { return rectangle_js_1.createRectangle; } });
34
+ Object.defineProperty(exports, "createRectangleFromPoints", { enumerable: true, get: function () { return rectangle_js_1.createRectangleFromPoints; } });
35
+ Object.defineProperty(exports, "getRectangleArea", { enumerable: true, get: function () { return rectangle_js_1.getRectangleArea; } });
36
+ Object.defineProperty(exports, "getRectanglePerimeter", { enumerable: true, get: function () { return rectangle_js_1.getRectanglePerimeter; } });
37
+ Object.defineProperty(exports, "getRectangleCenter", { enumerable: true, get: function () { return rectangle_js_1.getRectangleCenter; } });
38
+ Object.defineProperty(exports, "isPointInRectangle", { enumerable: true, get: function () { return rectangle_js_1.isPointInRectangle; } });
39
+ Object.defineProperty(exports, "rectanglesOverlap", { enumerable: true, get: function () { return rectangle_js_1.rectanglesOverlap; } });
40
+ Object.defineProperty(exports, "rectangleContains", { enumerable: true, get: function () { return rectangle_js_1.rectangleContains; } });
41
+ Object.defineProperty(exports, "rectangleIntersection", { enumerable: true, get: function () { return rectangle_js_1.rectangleIntersection; } });
42
+ Object.defineProperty(exports, "rectangleUnion", { enumerable: true, get: function () { return rectangle_js_1.rectangleUnion; } });
43
+ Object.defineProperty(exports, "centerRectangleInContainer", { enumerable: true, get: function () { return rectangle_js_1.centerRectangleInContainer; } });
44
+ Object.defineProperty(exports, "centerHorizontally", { enumerable: true, get: function () { return rectangle_js_1.centerHorizontally; } });
45
+ Object.defineProperty(exports, "centerVertically", { enumerable: true, get: function () { return rectangle_js_1.centerVertically; } });
46
+ Object.defineProperty(exports, "translateRectangle", { enumerable: true, get: function () { return rectangle_js_1.translateRectangle; } });
47
+ Object.defineProperty(exports, "expandRectangle", { enumerable: true, get: function () { return rectangle_js_1.expandRectangle; } });
48
+ Object.defineProperty(exports, "insetRectangle", { enumerable: true, get: function () { return rectangle_js_1.insetRectangle; } });
49
+ Object.defineProperty(exports, "scaleRectangle", { enumerable: true, get: function () { return rectangle_js_1.scaleRectangle; } });
50
+ Object.defineProperty(exports, "getRectangleCorners", { enumerable: true, get: function () { return rectangle_js_1.getRectangleCorners; } });
51
+ var circle_js_1 = require("./circle.js");
52
+ Object.defineProperty(exports, "createCircle", { enumerable: true, get: function () { return circle_js_1.createCircle; } });
53
+ Object.defineProperty(exports, "createCircleFromPoint", { enumerable: true, get: function () { return circle_js_1.createCircleFromPoint; } });
54
+ Object.defineProperty(exports, "getCircleArea", { enumerable: true, get: function () { return circle_js_1.getCircleArea; } });
55
+ Object.defineProperty(exports, "getCircleCircumference", { enumerable: true, get: function () { return circle_js_1.getCircleCircumference; } });
56
+ Object.defineProperty(exports, "getCircleCenter", { enumerable: true, get: function () { return circle_js_1.getCircleCenter; } });
57
+ Object.defineProperty(exports, "isPointInCircle", { enumerable: true, get: function () { return circle_js_1.isPointInCircle; } });
58
+ Object.defineProperty(exports, "circlesOverlap", { enumerable: true, get: function () { return circle_js_1.circlesOverlap; } });
59
+ Object.defineProperty(exports, "circleContains", { enumerable: true, get: function () { return circle_js_1.circleContains; } });
60
+ var line_js_1 = require("./line.js");
61
+ Object.defineProperty(exports, "createLine", { enumerable: true, get: function () { return line_js_1.createLine; } });
62
+ Object.defineProperty(exports, "createLineFromCoords", { enumerable: true, get: function () { return line_js_1.createLineFromCoords; } });
63
+ Object.defineProperty(exports, "getLineLength", { enumerable: true, get: function () { return line_js_1.getLineLength; } });
64
+ Object.defineProperty(exports, "getLineMidpoint", { enumerable: true, get: function () { return line_js_1.getLineMidpoint; } });
65
+ Object.defineProperty(exports, "getLineSlope", { enumerable: true, get: function () { return line_js_1.getLineSlope; } });
66
+ Object.defineProperty(exports, "isPointOnLine", { enumerable: true, get: function () { return line_js_1.isPointOnLine; } });
67
+ var distance_js_1 = require("./distance.js");
68
+ Object.defineProperty(exports, "manhattanDistance", { enumerable: true, get: function () { return distance_js_1.manhattanDistance; } });
69
+ Object.defineProperty(exports, "euclideanDistance", { enumerable: true, get: function () { return distance_js_1.euclideanDistance; } });
70
+ Object.defineProperty(exports, "euclideanDistanceSquared", { enumerable: true, get: function () { return distance_js_1.euclideanDistanceSquared; } });
71
+ Object.defineProperty(exports, "chebyshevDistance", { enumerable: true, get: function () { return distance_js_1.chebyshevDistance; } });
72
+ Object.defineProperty(exports, "createDistanceChecker", { enumerable: true, get: function () { return distance_js_1.createDistanceChecker; } });
73
+ var intersection_js_1 = require("./intersection.js");
74
+ Object.defineProperty(exports, "circleRectangleOverlap", { enumerable: true, get: function () { return intersection_js_1.circleRectangleOverlap; } });
75
+ Object.defineProperty(exports, "lineLineIntersection", { enumerable: true, get: function () { return intersection_js_1.lineLineIntersection; } });
76
+ Object.defineProperty(exports, "closestPointOnLine", { enumerable: true, get: function () { return intersection_js_1.closestPointOnLine; } });
77
+ Object.defineProperty(exports, "closestPointOnRectangle", { enumerable: true, get: function () { return intersection_js_1.closestPointOnRectangle; } });
78
+ var bounding_box_js_1 = require("./bounding_box.js");
79
+ Object.defineProperty(exports, "getBoundingBox", { enumerable: true, get: function () { return bounding_box_js_1.getBoundingBox; } });
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Point2D entity exports.
3
+ */
4
+ export type { Point2D } from './point.js';
5
+ export { createPoint, createOrigin, translatePoint, pointsEqual, lerpPoint, midpoint, rotatePoint, clampPoint } from './point.js';
6
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/point/mod.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /**
3
+ * Point2D entity exports.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.clampPoint = exports.rotatePoint = exports.midpoint = exports.lerpPoint = exports.pointsEqual = exports.translatePoint = exports.createOrigin = exports.createPoint = void 0;
7
+ var point_js_1 = require("./point.js");
8
+ Object.defineProperty(exports, "createPoint", { enumerable: true, get: function () { return point_js_1.createPoint; } });
9
+ Object.defineProperty(exports, "createOrigin", { enumerable: true, get: function () { return point_js_1.createOrigin; } });
10
+ Object.defineProperty(exports, "translatePoint", { enumerable: true, get: function () { return point_js_1.translatePoint; } });
11
+ Object.defineProperty(exports, "pointsEqual", { enumerable: true, get: function () { return point_js_1.pointsEqual; } });
12
+ Object.defineProperty(exports, "lerpPoint", { enumerable: true, get: function () { return point_js_1.lerpPoint; } });
13
+ Object.defineProperty(exports, "midpoint", { enumerable: true, get: function () { return point_js_1.midpoint; } });
14
+ Object.defineProperty(exports, "rotatePoint", { enumerable: true, get: function () { return point_js_1.rotatePoint; } });
15
+ Object.defineProperty(exports, "clampPoint", { enumerable: true, get: function () { return point_js_1.clampPoint; } });
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Point2D entity - represents a point in 2D space.
3
+ * x typically represents horizontal position (column in grids)
4
+ * y typically represents vertical position (row in grids)
5
+ */
6
+ /**
7
+ * A point in 2D space using x/y coordinates.
8
+ */
9
+ type Point2D = {
10
+ x: number;
11
+ y: number;
12
+ };
13
+ /**
14
+ * Creates a point from x/y coordinates.
15
+ */
16
+ declare const createPoint: (x: number, y: number) => Point2D;
17
+ /**
18
+ * Creates a point at the origin (0, 0).
19
+ */
20
+ declare const createOrigin: () => Point2D;
21
+ /**
22
+ * Translates a point by the given offset.
23
+ */
24
+ declare const translatePoint: (point: Point2D, dx: number, dy: number) => Point2D;
25
+ /**
26
+ * Checks if two points are equal.
27
+ */
28
+ declare const pointsEqual: (a: Point2D, b: Point2D) => boolean;
29
+ /**
30
+ * Linearly interpolates between two points.
31
+ * t=0 returns a, t=1 returns b. Values outside [0,1] extrapolate.
32
+ */
33
+ declare const lerpPoint: (a: Point2D, b: Point2D, t: number) => Point2D;
34
+ /**
35
+ * Returns the midpoint between two points.
36
+ */
37
+ declare const midpoint: (a: Point2D, b: Point2D) => Point2D;
38
+ /**
39
+ * Rotates a point around an origin by the given angle in radians.
40
+ * Defaults to rotating around (0, 0).
41
+ */
42
+ declare const rotatePoint: (point: Point2D, angle: number, origin?: Point2D) => Point2D;
43
+ /**
44
+ * Clamps a point to be within the given rectangular bounds.
45
+ */
46
+ declare const clampPoint: (point: Point2D, bounds: {
47
+ x: number;
48
+ y: number;
49
+ width: number;
50
+ height: number;
51
+ }) => Point2D;
52
+ export type { Point2D };
53
+ export { createPoint, createOrigin, translatePoint, pointsEqual, lerpPoint, midpoint, rotatePoint, clampPoint };
54
+ //# sourceMappingURL=point.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"point.d.ts","sourceRoot":"","sources":["../../src/point/point.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,KAAK,OAAO,GAAG;IACd,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACT,CAAA;AAED;;GAEG;AACH,QAAA,MAAM,WAAW,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,OAAqB,CAAA;AAEjE;;GAEG;AACH,QAAA,MAAM,YAAY,QAAO,OAA2B,CAAA;AAEpD;;GAEG;AACH,QAAA,MAAM,cAAc,GAAI,OAAO,OAAO,EAAE,IAAI,MAAM,EAAE,IAAI,MAAM,KAAG,OAG/D,CAAA;AAEF;;GAEG;AACH,QAAA,MAAM,WAAW,GAAI,GAAG,OAAO,EAAE,GAAG,OAAO,KAAG,OAAqC,CAAA;AAEnF;;;GAGG;AACH,QAAA,MAAM,SAAS,GAAI,GAAG,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,KAAG,OAGrD,CAAA;AAEF;;GAEG;AACH,QAAA,MAAM,QAAQ,GAAI,GAAG,OAAO,EAAE,GAAG,OAAO,KAAG,OAGzC,CAAA;AAEF;;;GAGG;AACH,QAAA,MAAM,WAAW,GAAI,OAAO,OAAO,EAAE,OAAO,MAAM,EAAE,SAAQ,OAAwB,KAAG,OAStF,CAAA;AAED;;GAEG;AACH,QAAA,MAAM,UAAU,GACf,OAAO,OAAO,EACd,QAAQ;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,KAC7D,OAGD,CAAA;AAEF,YAAY,EAAE,OAAO,EAAE,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,CAAA"}