@tscircuit/math-utils 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-LL3GOPYX.js +49 -0
- package/dist/chunk-LL3GOPYX.js.map +1 -0
- package/dist/grid.d.ts +2 -1
- package/dist/grid.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-AXPIDNML.js +0 -42
- package/dist/chunk-AXPIDNML.js.map +0 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/grid.ts
|
|
2
|
+
function grid({
|
|
3
|
+
rows,
|
|
4
|
+
cols,
|
|
5
|
+
xSpacing,
|
|
6
|
+
ySpacing,
|
|
7
|
+
width,
|
|
8
|
+
height,
|
|
9
|
+
offsetX = 0,
|
|
10
|
+
offsetY = 0,
|
|
11
|
+
yDirection = "cartesian",
|
|
12
|
+
centered = true
|
|
13
|
+
}) {
|
|
14
|
+
const effectiveXSpacing = xSpacing ?? 1;
|
|
15
|
+
const effectiveYSpacing = ySpacing ?? 1;
|
|
16
|
+
const totalWidth = width ?? cols * effectiveXSpacing;
|
|
17
|
+
const totalHeight = height ?? rows * effectiveYSpacing;
|
|
18
|
+
const centeringOffsetX = centered ? -totalWidth / 2 : 0;
|
|
19
|
+
const centeringOffsetY = centered ? -totalHeight / 2 : 0;
|
|
20
|
+
const cellWidth = width ? width / cols : effectiveXSpacing;
|
|
21
|
+
const cellHeight = height ? height / rows : effectiveYSpacing;
|
|
22
|
+
const cells = [];
|
|
23
|
+
for (let row = 0; row < rows; row++) {
|
|
24
|
+
for (let col = 0; col < cols; col++) {
|
|
25
|
+
const index = row * cols + col;
|
|
26
|
+
const centerX = offsetX + centeringOffsetX + col * cellWidth + cellWidth / 2;
|
|
27
|
+
const rawCenterY = offsetY + row * cellHeight + cellHeight / 2;
|
|
28
|
+
const centerY = yDirection === "cartesian" ? offsetY + centeringOffsetY + (rows - 1 - row) * cellHeight + cellHeight / 2 : offsetY + centeringOffsetY + row * cellHeight + cellHeight / 2;
|
|
29
|
+
cells.push({
|
|
30
|
+
index,
|
|
31
|
+
center: { x: centerX, y: centerY },
|
|
32
|
+
topLeft: {
|
|
33
|
+
x: centerX - cellWidth / 2,
|
|
34
|
+
y: centerY + cellHeight / 2
|
|
35
|
+
},
|
|
36
|
+
bottomRight: {
|
|
37
|
+
x: centerX + cellWidth / 2,
|
|
38
|
+
y: centerY - cellHeight / 2
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return cells;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
grid
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=chunk-LL3GOPYX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/grid.ts"],"sourcesContent":["import type { Point } from \"./common\"\n\nexport type GridCellPositions = {\n index: number\n center: Point\n topLeft: Point\n bottomRight: Point\n}\n\nexport type GridOptions = {\n rows: number\n cols: number\n xSpacing?: number\n ySpacing?: number\n width?: number\n height?: number\n offsetX?: number\n offsetY?: number\n yDirection?: \"cartesian\" | \"up-is-negative\"\n centered?: boolean\n}\n\nexport function grid({\n rows,\n cols,\n xSpacing,\n ySpacing,\n width,\n height,\n offsetX = 0,\n offsetY = 0,\n yDirection = \"cartesian\",\n centered = true,\n}: GridOptions): GridCellPositions[] {\n // Set default spacing if neither spacing nor dimensions are specified\n const effectiveXSpacing = xSpacing ?? 1\n const effectiveYSpacing = ySpacing ?? 1\n\n // Calculate cell dimensions\n const totalWidth = width ?? cols * effectiveXSpacing\n const totalHeight = height ?? rows * effectiveYSpacing\n\n // Calculate centering offsets if needed\n const centeringOffsetX = centered ? -totalWidth / 2 : 0\n const centeringOffsetY = centered ? -totalHeight / 2 : 0\n\n const cellWidth = width ? width / cols : effectiveXSpacing\n const cellHeight = height ? height / rows : effectiveYSpacing\n\n const cells: GridCellPositions[] = []\n\n for (let row = 0; row < rows; row++) {\n for (let col = 0; col < cols; col++) {\n const index = row * cols + col\n\n // Calculate center position\n const centerX =\n offsetX + centeringOffsetX + col * cellWidth + cellWidth / 2\n const rawCenterY = offsetY + row * cellHeight + cellHeight / 2\n\n // Adjust Y coordinate based on yDirection\n const centerY =\n yDirection === \"cartesian\"\n ? offsetY +\n centeringOffsetY +\n (rows - 1 - row) * cellHeight +\n cellHeight / 2\n : offsetY + centeringOffsetY + row * cellHeight + cellHeight / 2\n\n cells.push({\n index,\n center: { x: centerX, y: centerY },\n topLeft: {\n x: centerX - cellWidth / 2,\n y: centerY + cellHeight / 2,\n },\n bottomRight: {\n x: centerX + cellWidth / 2,\n y: centerY - cellHeight / 2,\n },\n })\n }\n }\n\n return cells\n}\n"],"mappings":";AAsBO,SAAS,KAAK;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,UAAU;AAAA,EACV,aAAa;AAAA,EACb,WAAW;AACb,GAAqC;AAEnC,QAAM,oBAAoB,YAAY;AACtC,QAAM,oBAAoB,YAAY;AAGtC,QAAM,aAAa,SAAS,OAAO;AACnC,QAAM,cAAc,UAAU,OAAO;AAGrC,QAAM,mBAAmB,WAAW,CAAC,aAAa,IAAI;AACtD,QAAM,mBAAmB,WAAW,CAAC,cAAc,IAAI;AAEvD,QAAM,YAAY,QAAQ,QAAQ,OAAO;AACzC,QAAM,aAAa,SAAS,SAAS,OAAO;AAE5C,QAAM,QAA6B,CAAC;AAEpC,WAAS,MAAM,GAAG,MAAM,MAAM,OAAO;AACnC,aAAS,MAAM,GAAG,MAAM,MAAM,OAAO;AACnC,YAAM,QAAQ,MAAM,OAAO;AAG3B,YAAM,UACJ,UAAU,mBAAmB,MAAM,YAAY,YAAY;AAC7D,YAAM,aAAa,UAAU,MAAM,aAAa,aAAa;AAG7D,YAAM,UACJ,eAAe,cACX,UACA,oBACC,OAAO,IAAI,OAAO,aACnB,aAAa,IACb,UAAU,mBAAmB,MAAM,aAAa,aAAa;AAEnE,YAAM,KAAK;AAAA,QACT;AAAA,QACA,QAAQ,EAAE,GAAG,SAAS,GAAG,QAAQ;AAAA,QACjC,SAAS;AAAA,UACP,GAAG,UAAU,YAAY;AAAA,UACzB,GAAG,UAAU,aAAa;AAAA,QAC5B;AAAA,QACA,aAAa;AAAA,UACX,GAAG,UAAU,YAAY;AAAA,UACzB,GAAG,UAAU,aAAa;AAAA,QAC5B;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/grid.d.ts
CHANGED
|
@@ -16,7 +16,8 @@ type GridOptions = {
|
|
|
16
16
|
offsetX?: number;
|
|
17
17
|
offsetY?: number;
|
|
18
18
|
yDirection?: "cartesian" | "up-is-negative";
|
|
19
|
+
centered?: boolean;
|
|
19
20
|
};
|
|
20
|
-
declare function grid({ rows, cols, xSpacing, ySpacing, width, height, offsetX, offsetY, yDirection, }: GridOptions): GridCellPositions[];
|
|
21
|
+
declare function grid({ rows, cols, xSpacing, ySpacing, width, height, offsetX, offsetY, yDirection, centered, }: GridOptions): GridCellPositions[];
|
|
21
22
|
|
|
22
23
|
export { type GridCellPositions, type GridOptions, grid };
|
package/dist/grid.js
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
package/dist/chunk-AXPIDNML.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// src/grid.ts
|
|
2
|
-
function grid({
|
|
3
|
-
rows,
|
|
4
|
-
cols,
|
|
5
|
-
xSpacing,
|
|
6
|
-
ySpacing,
|
|
7
|
-
width,
|
|
8
|
-
height,
|
|
9
|
-
offsetX = 0,
|
|
10
|
-
offsetY = 0,
|
|
11
|
-
yDirection = "cartesian"
|
|
12
|
-
}) {
|
|
13
|
-
const cellWidth = width ? width / cols : xSpacing ?? 1;
|
|
14
|
-
const cellHeight = height ? height / rows : ySpacing ?? 1;
|
|
15
|
-
const cells = [];
|
|
16
|
-
for (let row = 0; row < rows; row++) {
|
|
17
|
-
for (let col = 0; col < cols; col++) {
|
|
18
|
-
const index = row * cols + col;
|
|
19
|
-
const centerX = offsetX + col * cellWidth + cellWidth / 2;
|
|
20
|
-
const rawCenterY = offsetY + row * cellHeight + cellHeight / 2;
|
|
21
|
-
const centerY = yDirection === "cartesian" ? offsetY + (rows - 1 - row) * cellHeight + cellHeight / 2 : rawCenterY;
|
|
22
|
-
cells.push({
|
|
23
|
-
index,
|
|
24
|
-
center: { x: centerX, y: centerY },
|
|
25
|
-
topLeft: {
|
|
26
|
-
x: centerX - cellWidth / 2,
|
|
27
|
-
y: centerY + cellHeight / 2
|
|
28
|
-
},
|
|
29
|
-
bottomRight: {
|
|
30
|
-
x: centerX + cellWidth / 2,
|
|
31
|
-
y: centerY - cellHeight / 2
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return cells;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export {
|
|
40
|
-
grid
|
|
41
|
-
};
|
|
42
|
-
//# sourceMappingURL=chunk-AXPIDNML.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/grid.ts"],"sourcesContent":["import type { Point } from \"./common\"\n\nexport type GridCellPositions = {\n index: number\n center: Point\n topLeft: Point\n bottomRight: Point\n}\n\nexport type GridOptions = {\n rows: number\n cols: number\n xSpacing?: number\n ySpacing?: number\n width?: number\n height?: number\n offsetX?: number\n offsetY?: number\n yDirection?: \"cartesian\" | \"up-is-negative\"\n}\n\nexport function grid({\n rows,\n cols,\n xSpacing,\n ySpacing,\n width,\n height,\n offsetX = 0,\n offsetY = 0,\n yDirection = \"cartesian\",\n}: GridOptions): GridCellPositions[] {\n // Calculate cell dimensions\n const cellWidth = width ? width / cols : (xSpacing ?? 1)\n const cellHeight = height ? height / rows : (ySpacing ?? 1)\n\n const cells: GridCellPositions[] = []\n\n for (let row = 0; row < rows; row++) {\n for (let col = 0; col < cols; col++) {\n const index = row * cols + col\n\n // Calculate center position\n const centerX = offsetX + col * cellWidth + cellWidth / 2\n const rawCenterY = offsetY + row * cellHeight + cellHeight / 2\n\n // Adjust Y coordinate based on yDirection\n const centerY =\n yDirection === \"cartesian\"\n ? offsetY + (rows - 1 - row) * cellHeight + cellHeight / 2\n : rawCenterY\n\n cells.push({\n index,\n center: { x: centerX, y: centerY },\n topLeft: {\n x: centerX - cellWidth / 2,\n y: centerY + cellHeight / 2,\n },\n bottomRight: {\n x: centerX + cellWidth / 2,\n y: centerY - cellHeight / 2,\n },\n })\n }\n }\n\n return cells\n}\n"],"mappings":";AAqBO,SAAS,KAAK;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,UAAU;AAAA,EACV,aAAa;AACf,GAAqC;AAEnC,QAAM,YAAY,QAAQ,QAAQ,OAAQ,YAAY;AACtD,QAAM,aAAa,SAAS,SAAS,OAAQ,YAAY;AAEzD,QAAM,QAA6B,CAAC;AAEpC,WAAS,MAAM,GAAG,MAAM,MAAM,OAAO;AACnC,aAAS,MAAM,GAAG,MAAM,MAAM,OAAO;AACnC,YAAM,QAAQ,MAAM,OAAO;AAG3B,YAAM,UAAU,UAAU,MAAM,YAAY,YAAY;AACxD,YAAM,aAAa,UAAU,MAAM,aAAa,aAAa;AAG7D,YAAM,UACJ,eAAe,cACX,WAAW,OAAO,IAAI,OAAO,aAAa,aAAa,IACvD;AAEN,YAAM,KAAK;AAAA,QACT;AAAA,QACA,QAAQ,EAAE,GAAG,SAAS,GAAG,QAAQ;AAAA,QACjC,SAAS;AAAA,UACP,GAAG,UAAU,YAAY;AAAA,UACzB,GAAG,UAAU,aAAa;AAAA,QAC5B;AAAA,QACA,aAAa;AAAA,UACX,GAAG,UAAU,YAAY;AAAA,UACzB,GAAG,UAAU,aAAa;AAAA,QAC5B;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|