@tscircuit/math-utils 0.0.23 → 0.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -52,7 +52,7 @@ console.log("Lines intersect:", intersects)
52
52
  | [`distance(p1, p2)`](./src/line-intersections.ts) | Euclidean distance between two points. |
53
53
  | [`getSegmentIntersection(a, b, u, v)`](./src/line-intersections.ts) | Intersection point of two segments or `null` if none. |
54
54
  | [`getBoundingBox(box)`](./src/nearest-box.ts) | Compute the bounding box of a box. |
55
- | [`computeDistanceBetweenBoxes(boxA, boxB)`](./src/nearest-box.ts) | Minimum distance between two boxes and the nearest points. |
55
+ | [`computeManhattanDistanceBetweenBoxes(boxA, boxB)`](./src/nearest-box.ts) | Minimum Manhattan distance between two boxes and the nearest points. |
56
56
  | [`clamp(value, min, max)`](./src/nearest-box.ts) | Clamp a value between `min` and `max`. |
57
57
  | [`findNearestPointsBetweenBoxSets(setA, setB)`](./src/nearest-box.ts) | Find nearest points between two sets of boxes. |
58
58
  | [`getUnitVectorFromPointAToB(a, b)`](./src/get-unit-vector.ts) | Unit vector pointing from point A to B. |
@@ -0,0 +1,11 @@
1
+ import { Bounds } from './common.js';
2
+
3
+ /**
4
+ * Calculates the overlapping bounds of two rectangles
5
+ * @param bounds1 First bounding rectangle
6
+ * @param bounds2 Second bounding rectangle
7
+ * @returns The overlapping bounds or null if there is no overlap
8
+ */
9
+ declare const boundsIntersection: (bounds1: Bounds, bounds2: Bounds) => Bounds | null;
10
+
11
+ export { boundsIntersection };
@@ -0,0 +1,7 @@
1
+ import {
2
+ boundsIntersection
3
+ } from "./chunk-S7H7MIDL.js";
4
+ export {
5
+ boundsIntersection
6
+ };
7
+ //# sourceMappingURL=bounds-intersection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,9 +1,9 @@
1
- import {
2
- clamp
3
- } from "./chunk-KWIMOCAS.js";
4
1
  import {
5
2
  distance
6
3
  } from "./chunk-EFLPMB4J.js";
4
+ import {
5
+ clamp
6
+ } from "./chunk-DRDDWFOS.js";
7
7
 
8
8
  // src/point-distance.ts
9
9
  function pointToBoxDistance(p, box) {
@@ -46,4 +46,4 @@ export {
46
46
  midpoint,
47
47
  distSq
48
48
  };
49
- //# sourceMappingURL=chunk-G6ZGTC5I.js.map
49
+ //# sourceMappingURL=chunk-5J3PCV4D.js.map
@@ -9,7 +9,7 @@ function getBoundingBox(box) {
9
9
  maxY: box.center.y + halfHeight
10
10
  };
11
11
  }
12
- function computeDistanceBetweenBoxes(boxA, boxB) {
12
+ function computeManhattanDistanceBetweenBoxes(boxA, boxB) {
13
13
  const a = getBoundingBox(boxA);
14
14
  const b = getBoundingBox(boxB);
15
15
  const dx = Math.max(a.minX - b.maxX, b.minX - a.maxX, 0);
@@ -26,6 +26,9 @@ function computeDistanceBetweenBoxes(boxA, boxB) {
26
26
  const distance = Math.hypot(pointA.x - pointB.x, pointA.y - pointB.y);
27
27
  return { distance, pointA, pointB };
28
28
  }
29
+ function computeDistanceBetweenBoxes(boxA, boxB) {
30
+ return computeManhattanDistanceBetweenBoxes(boxA, boxB);
31
+ }
29
32
  function computeGapBetweenBoxes(boxA, boxB) {
30
33
  const a = getBoundingBox(boxA);
31
34
  const b = getBoundingBox(boxB);
@@ -43,7 +46,7 @@ function findNearestPointsBetweenBoxSets(boxSetA, boxSetB) {
43
46
  let nearestPointB = { x: 0, y: 0 };
44
47
  for (const boxA of boxSetA) {
45
48
  for (const boxB of boxSetB) {
46
- const { distance, pointA, pointB } = computeDistanceBetweenBoxes(
49
+ const { distance, pointA, pointB } = computeManhattanDistanceBetweenBoxes(
47
50
  boxA,
48
51
  boxB
49
52
  );
@@ -63,9 +66,10 @@ function findNearestPointsBetweenBoxSets(boxSetA, boxSetB) {
63
66
 
64
67
  export {
65
68
  getBoundingBox,
69
+ computeManhattanDistanceBetweenBoxes,
66
70
  computeDistanceBetweenBoxes,
67
71
  computeGapBetweenBoxes,
68
72
  clamp,
69
73
  findNearestPointsBetweenBoxSets
70
74
  };
71
- //# sourceMappingURL=chunk-KWIMOCAS.js.map
75
+ //# sourceMappingURL=chunk-DRDDWFOS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/nearest-box.ts"],"sourcesContent":["import type { Point } from \"./common\"\n\nexport type Box = { center: Point; width: number; height: number }\nexport type BoxSet = Box[]\n\nexport type GridCell = { boxes: Box[] }\n\nexport function getBoundingBox(box: Box) {\n const halfWidth = box.width / 2\n const halfHeight = box.height / 2\n return {\n minX: box.center.x - halfWidth,\n maxX: box.center.x + halfWidth,\n minY: box.center.y - halfHeight,\n maxY: box.center.y + halfHeight,\n }\n}\n\nexport function computeManhattanDistanceBetweenBoxes(\n boxA: Box,\n boxB: Box,\n): { distance: number; pointA: Point; pointB: Point } {\n const a = getBoundingBox(boxA)\n const b = getBoundingBox(boxB)\n\n const dx = Math.max(a.minX - b.maxX, b.minX - a.maxX, 0)\n const dy = Math.max(a.minY - b.maxY, b.minY - a.maxY, 0)\n\n const pointA: Point = { x: 0, y: 0 }\n const pointB: Point = { x: 0, y: 0 }\n\n if (dx === 0 && dy === 0) {\n // Boxes overlap\n return { distance: 0, pointA: boxA.center, pointB: boxB.center }\n }\n\n // Compute the closest points on the edges\n pointA.x = clamp(boxA.center.x, b.minX, b.maxX)\n pointA.y = clamp(boxA.center.y, b.minY, b.maxY)\n\n pointB.x = clamp(boxB.center.x, a.minX, a.maxX)\n pointB.y = clamp(boxB.center.y, a.minY, a.maxY)\n\n const distance = Math.hypot(pointA.x - pointB.x, pointA.y - pointB.y)\n return { distance, pointA, pointB }\n}\n\n/**\n * @deprecated Use {@link computeManhattanDistanceBetweenBoxes} instead.\n */\nexport function computeDistanceBetweenBoxes(\n boxA: Box,\n boxB: Box,\n): { distance: number; pointA: Point; pointB: Point } {\n return computeManhattanDistanceBetweenBoxes(boxA, boxB)\n}\n\nexport function computeGapBetweenBoxes(boxA: Box, boxB: Box): number {\n const a = getBoundingBox(boxA)\n const b = getBoundingBox(boxB)\n\n const dx = Math.max(a.minX - b.maxX, b.minX - a.maxX, 0)\n const dy = Math.max(a.minY - b.maxY, b.minY - a.maxY, 0)\n\n const distance = Math.hypot(dx, dy)\n return distance\n}\n\nexport function clamp(value: number, min: number, max: number): number {\n return Math.max(min, Math.min(max, value))\n}\n\nexport function findNearestPointsBetweenBoxSets(\n boxSetA: BoxSet,\n boxSetB: BoxSet,\n): { pointA: Point; pointB: Point; distance: number } {\n let minDistance = Number.POSITIVE_INFINITY\n let nearestPointA: Point = { x: 0, y: 0 }\n let nearestPointB: Point = { x: 0, y: 0 }\n\n for (const boxA of boxSetA) {\n for (const boxB of boxSetB) {\n const { distance, pointA, pointB } = computeManhattanDistanceBetweenBoxes(\n boxA,\n boxB,\n )\n if (distance < minDistance) {\n minDistance = distance\n nearestPointA = pointA\n nearestPointB = pointB\n }\n }\n }\n\n return {\n pointA: nearestPointA,\n pointB: nearestPointB,\n distance: minDistance,\n }\n}\n"],"mappings":";AAOO,SAAS,eAAe,KAAU;AACvC,QAAM,YAAY,IAAI,QAAQ;AAC9B,QAAM,aAAa,IAAI,SAAS;AAChC,SAAO;AAAA,IACL,MAAM,IAAI,OAAO,IAAI;AAAA,IACrB,MAAM,IAAI,OAAO,IAAI;AAAA,IACrB,MAAM,IAAI,OAAO,IAAI;AAAA,IACrB,MAAM,IAAI,OAAO,IAAI;AAAA,EACvB;AACF;AAEO,SAAS,qCACd,MACA,MACoD;AACpD,QAAM,IAAI,eAAe,IAAI;AAC7B,QAAM,IAAI,eAAe,IAAI;AAE7B,QAAM,KAAK,KAAK,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC;AACvD,QAAM,KAAK,KAAK,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC;AAEvD,QAAM,SAAgB,EAAE,GAAG,GAAG,GAAG,EAAE;AACnC,QAA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,eAAW,QAAQ,SAAS;AAC1B,YAAM,EAAE,UAAU,QAAQ,OAAO,IAAI;AAAA,QACnC;AAAA,QACA;AAAA,MACF;AACA,UAAI,WAAW,aAAa;AAC1B,sBAAc;AACd,wBAAgB;AAChB,wBAAgB;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,UAAU;AAAA,EACZ;AACF;","names":[]}
@@ -0,0 +1,16 @@
1
+ // src/bounds-intersection.ts
2
+ var boundsIntersection = (bounds1, bounds2) => {
3
+ const minX = Math.max(bounds1.minX, bounds2.minX);
4
+ const minY = Math.max(bounds1.minY, bounds2.minY);
5
+ const maxX = Math.min(bounds1.maxX, bounds2.maxX);
6
+ const maxY = Math.min(bounds1.maxY, bounds2.maxY);
7
+ if (minX > maxX || minY > maxY) {
8
+ return null;
9
+ }
10
+ return { minX, minY, maxX, maxY };
11
+ };
12
+
13
+ export {
14
+ boundsIntersection
15
+ };
16
+ //# sourceMappingURL=chunk-S7H7MIDL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/bounds-intersection.ts"],"sourcesContent":["import type { Bounds } from \"./common\"\n\n/**\n * Calculates the overlapping bounds of two rectangles\n * @param bounds1 First bounding rectangle\n * @param bounds2 Second bounding rectangle\n * @returns The overlapping bounds or null if there is no overlap\n */\nexport const boundsIntersection = (\n bounds1: Bounds,\n bounds2: Bounds,\n): Bounds | null => {\n const minX = Math.max(bounds1.minX, bounds2.minX)\n const minY = Math.max(bounds1.minY, bounds2.minY)\n const maxX = Math.min(bounds1.maxX, bounds2.maxX)\n const maxY = Math.min(bounds1.maxY, bounds2.maxY)\n\n if (minX > maxX || minY > maxY) {\n return null\n }\n\n return { minX, minY, maxX, maxY }\n}\n"],"mappings":";AAQO,IAAM,qBAAqB,CAChC,SACA,YACkB;AAClB,QAAM,OAAO,KAAK,IAAI,QAAQ,MAAM,QAAQ,IAAI;AAChD,QAAM,OAAO,KAAK,IAAI,QAAQ,MAAM,QAAQ,IAAI;AAChD,QAAM,OAAO,KAAK,IAAI,QAAQ,MAAM,QAAQ,IAAI;AAChD,QAAM,OAAO,KAAK,IAAI,QAAQ,MAAM,QAAQ,IAAI;AAEhD,MAAI,OAAO,QAAQ,OAAO,MAAM;AAC9B,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,MAAM,MAAM,MAAM,KAAK;AAClC;","names":[]}
@@ -1,11 +1,11 @@
1
- import {
2
- clamp
3
- } from "./chunk-KWIMOCAS.js";
4
1
  import {
5
2
  distance,
6
3
  doSegmentsIntersect,
7
4
  pointToSegmentDistance
8
5
  } from "./chunk-EFLPMB4J.js";
6
+ import {
7
+ clamp
8
+ } from "./chunk-DRDDWFOS.js";
9
9
 
10
10
  // src/segment-distance.ts
11
11
  function segmentToSegmentMinDistance(a, b, u, v) {
@@ -109,4 +109,4 @@ export {
109
109
  segmentToCircleMinDistance,
110
110
  pointToSegmentClosestPoint
111
111
  };
112
- //# sourceMappingURL=chunk-QE7MTLD2.js.map
112
+ //# sourceMappingURL=chunk-Y7G4VXR7.js.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { distance, doSegmentsIntersect, doesLineIntersectLine, doesSegmentIntersectRect, getSegmentIntersection, onSegment, orientation, pointToSegmentDistance } from './line-intersections.js';
2
- export { Box, BoxSet, GridCell, clamp, computeDistanceBetweenBoxes, computeGapBetweenBoxes, findNearestPointsBetweenBoxSets, getBoundingBox } from './nearest-box.js';
2
+ export { Box, BoxSet, GridCell, clamp, computeDistanceBetweenBoxes, computeGapBetweenBoxes, computeManhattanDistanceBetweenBoxes, findNearestPointsBetweenBoxSets, getBoundingBox } from './nearest-box.js';
3
3
  export { Bounds, Point } from './common.js';
4
4
  export { getUnitVectorFromDirection, getUnitVectorFromPointAToB } from './get-unit-vector.js';
5
5
  export { GridCellPositions, GridOptions, grid } from './grid.js';
@@ -10,3 +10,4 @@ export { range } from './range.js';
10
10
  export { doBoundsOverlap } from './bounds-overlap.js';
11
11
  export { boundsAreaOverlap } from './bounds-area-overlap.js';
12
12
  export { boundsDistance } from './bounds-distance.js';
13
+ export { boundsIntersection } from './bounds-intersection.js';
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  midpoint,
4
4
  pointToBoundsDistance,
5
5
  pointToBoxDistance
6
- } from "./chunk-G6ZGTC5I.js";
6
+ } from "./chunk-5J3PCV4D.js";
7
7
  import "./chunk-MTORG67J.js";
8
8
  import {
9
9
  range
@@ -14,20 +14,34 @@ import {
14
14
  segmentToBoxMinDistance,
15
15
  segmentToCircleMinDistance,
16
16
  segmentToSegmentMinDistance
17
- } from "./chunk-QE7MTLD2.js";
17
+ } from "./chunk-Y7G4VXR7.js";
18
+ import {
19
+ distance,
20
+ doSegmentsIntersect,
21
+ doesLineIntersectLine,
22
+ doesSegmentIntersectRect,
23
+ getSegmentIntersection,
24
+ onSegment,
25
+ orientation,
26
+ pointToSegmentDistance
27
+ } from "./chunk-EFLPMB4J.js";
18
28
  import {
19
29
  clamp,
20
30
  computeDistanceBetweenBoxes,
21
31
  computeGapBetweenBoxes,
32
+ computeManhattanDistanceBetweenBoxes,
22
33
  findNearestPointsBetweenBoxSets,
23
34
  getBoundingBox
24
- } from "./chunk-KWIMOCAS.js";
35
+ } from "./chunk-DRDDWFOS.js";
25
36
  import {
26
37
  boundsAreaOverlap
27
38
  } from "./chunk-YA3GC5BB.js";
28
39
  import {
29
40
  boundsDistance
30
41
  } from "./chunk-KVGAXIWH.js";
42
+ import {
43
+ boundsIntersection
44
+ } from "./chunk-S7H7MIDL.js";
31
45
  import {
32
46
  doBoundsOverlap
33
47
  } from "./chunk-CA5ORSO4.js";
@@ -39,22 +53,14 @@ import {
39
53
  import {
40
54
  grid
41
55
  } from "./chunk-U45EKA3R.js";
42
- import {
43
- distance,
44
- doSegmentsIntersect,
45
- doesLineIntersectLine,
46
- doesSegmentIntersectRect,
47
- getSegmentIntersection,
48
- onSegment,
49
- orientation,
50
- pointToSegmentDistance
51
- } from "./chunk-EFLPMB4J.js";
52
56
  export {
53
57
  boundsAreaOverlap,
54
58
  boundsDistance,
59
+ boundsIntersection,
55
60
  clamp,
56
61
  computeDistanceBetweenBoxes,
57
62
  computeGapBetweenBoxes,
63
+ computeManhattanDistanceBetweenBoxes,
58
64
  distSq,
59
65
  distance,
60
66
  doBoundsOverlap,
@@ -15,6 +15,14 @@ declare function getBoundingBox(box: Box): {
15
15
  minY: number;
16
16
  maxY: number;
17
17
  };
18
+ declare function computeManhattanDistanceBetweenBoxes(boxA: Box, boxB: Box): {
19
+ distance: number;
20
+ pointA: Point;
21
+ pointB: Point;
22
+ };
23
+ /**
24
+ * @deprecated Use {@link computeManhattanDistanceBetweenBoxes} instead.
25
+ */
18
26
  declare function computeDistanceBetweenBoxes(boxA: Box, boxB: Box): {
19
27
  distance: number;
20
28
  pointA: Point;
@@ -28,4 +36,4 @@ declare function findNearestPointsBetweenBoxSets(boxSetA: BoxSet, boxSetB: BoxSe
28
36
  distance: number;
29
37
  };
30
38
 
31
- export { type Box, type BoxSet, type GridCell, clamp, computeDistanceBetweenBoxes, computeGapBetweenBoxes, findNearestPointsBetweenBoxSets, getBoundingBox };
39
+ export { type Box, type BoxSet, type GridCell, clamp, computeDistanceBetweenBoxes, computeGapBetweenBoxes, computeManhattanDistanceBetweenBoxes, findNearestPointsBetweenBoxSets, getBoundingBox };
@@ -2,13 +2,15 @@ import {
2
2
  clamp,
3
3
  computeDistanceBetweenBoxes,
4
4
  computeGapBetweenBoxes,
5
+ computeManhattanDistanceBetweenBoxes,
5
6
  findNearestPointsBetweenBoxSets,
6
7
  getBoundingBox
7
- } from "./chunk-KWIMOCAS.js";
8
+ } from "./chunk-DRDDWFOS.js";
8
9
  export {
9
10
  clamp,
10
11
  computeDistanceBetweenBoxes,
11
12
  computeGapBetweenBoxes,
13
+ computeManhattanDistanceBetweenBoxes,
12
14
  findNearestPointsBetweenBoxSets,
13
15
  getBoundingBox
14
16
  };
@@ -3,9 +3,9 @@ import {
3
3
  midpoint,
4
4
  pointToBoundsDistance,
5
5
  pointToBoxDistance
6
- } from "./chunk-G6ZGTC5I.js";
7
- import "./chunk-KWIMOCAS.js";
6
+ } from "./chunk-5J3PCV4D.js";
8
7
  import "./chunk-EFLPMB4J.js";
8
+ import "./chunk-DRDDWFOS.js";
9
9
  export {
10
10
  distSq,
11
11
  midpoint,
@@ -4,9 +4,9 @@ import {
4
4
  segmentToBoxMinDistance,
5
5
  segmentToCircleMinDistance,
6
6
  segmentToSegmentMinDistance
7
- } from "./chunk-QE7MTLD2.js";
8
- import "./chunk-KWIMOCAS.js";
7
+ } from "./chunk-Y7G4VXR7.js";
9
8
  import "./chunk-EFLPMB4J.js";
9
+ import "./chunk-DRDDWFOS.js";
10
10
  export {
11
11
  pointToSegmentClosestPoint,
12
12
  segmentToBoundsMinDistance,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/math-utils",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.23",
4
+ "version": "0.0.25",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/nearest-box.ts"],"sourcesContent":["import type { Point } from \"./common\"\n\nexport type Box = { center: Point; width: number; height: number }\nexport type BoxSet = Box[]\n\nexport type GridCell = { boxes: Box[] }\n\nexport function getBoundingBox(box: Box) {\n const halfWidth = box.width / 2\n const halfHeight = box.height / 2\n return {\n minX: box.center.x - halfWidth,\n maxX: box.center.x + halfWidth,\n minY: box.center.y - halfHeight,\n maxY: box.center.y + halfHeight,\n }\n}\n\nexport function computeDistanceBetweenBoxes(\n boxA: Box,\n boxB: Box,\n): { distance: number; pointA: Point; pointB: Point } {\n const a = getBoundingBox(boxA)\n const b = getBoundingBox(boxB)\n\n const dx = Math.max(a.minX - b.maxX, b.minX - a.maxX, 0)\n const dy = Math.max(a.minY - b.maxY, b.minY - a.maxY, 0)\n\n const pointA: Point = { x: 0, y: 0 }\n const pointB: Point = { x: 0, y: 0 }\n\n if (dx === 0 && dy === 0) {\n // Boxes overlap\n return { distance: 0, pointA: boxA.center, pointB: boxB.center }\n }\n\n // Compute the closest points on the edges\n pointA.x = clamp(boxA.center.x, b.minX, b.maxX)\n pointA.y = clamp(boxA.center.y, b.minY, b.maxY)\n\n pointB.x = clamp(boxB.center.x, a.minX, a.maxX)\n pointB.y = clamp(boxB.center.y, a.minY, a.maxY)\n\n const distance = Math.hypot(pointA.x - pointB.x, pointA.y - pointB.y)\n return { distance, pointA, pointB }\n}\n\nexport function computeGapBetweenBoxes(boxA: Box, boxB: Box): number {\n const a = getBoundingBox(boxA)\n const b = getBoundingBox(boxB)\n\n const dx = Math.max(a.minX - b.maxX, b.minX - a.maxX, 0)\n const dy = Math.max(a.minY - b.maxY, b.minY - a.maxY, 0)\n\n const distance = Math.hypot(dx, dy)\n return distance\n}\n\nexport function clamp(value: number, min: number, max: number): number {\n return Math.max(min, Math.min(max, value))\n}\n\nexport function findNearestPointsBetweenBoxSets(\n boxSetA: BoxSet,\n boxSetB: BoxSet,\n): { pointA: Point; pointB: Point; distance: number } {\n let minDistance = Number.POSITIVE_INFINITY\n let nearestPointA: Point = { x: 0, y: 0 }\n let nearestPointB: Point = { x: 0, y: 0 }\n\n for (const boxA of boxSetA) {\n for (const boxB of boxSetB) {\n const { distance, pointA, pointB } = computeDistanceBetweenBoxes(\n boxA,\n boxB,\n )\n if (distance < minDistance) {\n minDistance = distance\n nearestPointA = pointA\n nearestPointB = pointB\n }\n }\n }\n\n return {\n pointA: nearestPointA,\n pointB: nearestPointB,\n distance: minDistance,\n }\n}\n"],"mappings":";AAOO,SAAS,eAAe,KAAU;AACvC,QAAM,YAAY,IAAI,QAAQ;AAC9B,QAAM,aAAa,IAAI,SAAS;AAChC,SAAO;AAAA,IACL,MAAM,IAAI,OAAO,IAAI;AAAA,IACrB,MAAM,IAAI,OAAO,IAAI;AAAA,I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