@biolibs/bionet-space 0.1.0 → 0.3.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.
- package/README.md +35 -0
- package/dist/arrange.d.ts +16 -0
- package/dist/arrange.d.ts.map +1 -1
- package/dist/arrange.js +22 -0
- package/dist/arrange.js.map +1 -1
- package/dist/build.d.ts +83 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +148 -0
- package/dist/build.js.map +1 -0
- package/dist/from.d.ts +81 -0
- package/dist/from.d.ts.map +1 -0
- package/dist/from.js +65 -0
- package/dist/from.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/arrange.ts +22 -0
- package/src/build.ts +167 -0
- package/src/from.ts +105 -0
- package/src/index.ts +4 -0
package/README.md
CHANGED
|
@@ -45,3 +45,38 @@ search(lab, "t7 promoter").length > 0; // true
|
|
|
45
45
|
## Positions in a box
|
|
46
46
|
|
|
47
47
|
`slotCenter`, `slotSize`, `slotName` (`A1`, `B7`) and `firstFreeSlot` work out a box's grid. `storedWithin` gives everything in a place however deep.
|
|
48
|
+
|
|
49
|
+
`slotFrom("C4")` reads a position the way it is written on a lid.
|
|
50
|
+
|
|
51
|
+
## From a lab's own record
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { layoutFrom } from "@biolibs/bionet-space";
|
|
55
|
+
|
|
56
|
+
const layout = layoutFrom({
|
|
57
|
+
places: [{ place: "f", kind: "freezer", name: "−80", parent: null, grid: null, standing: null, retired: false }],
|
|
58
|
+
items: [], parts: [],
|
|
59
|
+
});
|
|
60
|
+
layout.places.map((one) => [one.id, one.parent]); // [ [ "~room", null ], [ "f", "~room" ] ]
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`layoutFrom` takes a lab as `@biolibs/bionet` records it — millimetres, retired places, items that
|
|
64
|
+
may be nowhere — and gives a layout of what can be found. It asks for the lab by shape, so this
|
|
65
|
+
package still depends on nothing. Places standing in no room are put in one made up for the purpose.
|
|
66
|
+
|
|
67
|
+
## Arranging by hand
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { arrange, exampleLab, overlapping, standingAt, standingOf, sticking } from "@biolibs/bionet-space";
|
|
71
|
+
|
|
72
|
+
const arranged = arrange(exampleLab());
|
|
73
|
+
standingOf(arranged, "minus80")?.size; // [ 0.9, 2, 0.85 ]
|
|
74
|
+
standingAt(arranged, "minus80", [3.1, 2.2]); // the standing it would have with its base centred there
|
|
75
|
+
overlapping(arranged); // [] — pairs of places standing in each other
|
|
76
|
+
sticking(arranged); // [] — places stood partly outside what they are in
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`standingOf` is the inverse of `arrange`: where a place stands as the lab would say it, measured from
|
|
80
|
+
the place it is in, including for a place nobody has stood anywhere. `standingAt` is what a drag
|
|
81
|
+
becomes: settled every 5 cm and kept inside the parent. `quarterTurned` turns one. None of them
|
|
82
|
+
moves anything; they work out what would be said.
|
package/dist/arrange.d.ts
CHANGED
|
@@ -62,4 +62,20 @@ export declare function firstFreeSlot(box: Place, taken: readonly Slot[]): Slot
|
|
|
62
62
|
* @returns Something like `C4`.
|
|
63
63
|
*/
|
|
64
64
|
export declare function slotName(slot: Slot): string;
|
|
65
|
+
/**
|
|
66
|
+
* Read a position the way it is written on a box lid.
|
|
67
|
+
*
|
|
68
|
+
* @param name - Something like `C4` or `c4`.
|
|
69
|
+
* @returns The position, or `null` if that is not how one is written.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { slotFrom, slotName } from "@biolibs/bionet-space";
|
|
74
|
+
*
|
|
75
|
+
* slotFrom("C4"); // { row: 2, column: 3 }
|
|
76
|
+
* slotName(slotFrom("AB12")!); // "AB12"
|
|
77
|
+
* slotFrom("4C"); // null
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare function slotFrom(name: string): Slot | null;
|
|
65
81
|
//# sourceMappingURL=arrange.d.ts.map
|
package/dist/arrange.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrange.d.ts","sourceRoot":"","sources":["../src/arrange.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAkB,MAAM,YAAY,CAAC;AAEhF,uFAAuF;AACvF,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAOpF,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAMvF,CAAC;AAsFF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAE,CA8ClE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CASrF;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,CAK9C;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,IAAI,GAAG,IAAI,CAS7E;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAI3C"}
|
|
1
|
+
{"version":3,"file":"arrange.d.ts","sourceRoot":"","sources":["../src/arrange.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAkB,MAAM,YAAY,CAAC;AAEhF,uFAAuF;AACvF,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAOpF,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAMvF,CAAC;AAsFF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAE,CA8ClE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CASrF;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,CAK9C;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,IAAI,GAAG,IAAI,CAS7E;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAI3C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAKlD"}
|
package/dist/arrange.js
CHANGED
|
@@ -218,4 +218,26 @@ export function slotName(slot) {
|
|
|
218
218
|
row = String.fromCharCode(65 + (at % 26)) + row;
|
|
219
219
|
return `${row}${slot.column + 1}`;
|
|
220
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Read a position the way it is written on a box lid.
|
|
223
|
+
*
|
|
224
|
+
* @param name - Something like `C4` or `c4`.
|
|
225
|
+
* @returns The position, or `null` if that is not how one is written.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```ts
|
|
229
|
+
* import { slotFrom, slotName } from "@biolibs/bionet-space";
|
|
230
|
+
*
|
|
231
|
+
* slotFrom("C4"); // { row: 2, column: 3 }
|
|
232
|
+
* slotName(slotFrom("AB12")!); // "AB12"
|
|
233
|
+
* slotFrom("4C"); // null
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
export function slotFrom(name) {
|
|
237
|
+
const found = /^([A-Za-z]{1,2})([1-9][0-9]{0,2})$/.exec(name.trim());
|
|
238
|
+
if (found === null)
|
|
239
|
+
return null;
|
|
240
|
+
const row = [...found[1].toUpperCase()].reduce((sum, letter) => sum * 26 + (letter.charCodeAt(0) - 64), 0) - 1;
|
|
241
|
+
return { row, column: Number(found[2]) - 1 };
|
|
242
|
+
}
|
|
221
243
|
//# sourceMappingURL=arrange.js.map
|
package/dist/arrange.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrange.js","sourceRoot":"","sources":["../src/arrange.ts"],"names":[],"mappings":"AAcA,uFAAuF;AACvF,MAAM,CAAC,MAAM,YAAY,GAAgE;IACvF,IAAI,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACjB,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC;IACzB,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IACvB,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC;IACvB,UAAU,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IAC3B,GAAG,EAAE,CAAC,KAA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AI,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAU;IACjC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC;QAAE,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC;IAC/G,OAAO,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;AACpC,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,MAAM,KAAK,GAAG,oCAAoC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACrE,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,MAAM,GAAG,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;IAChH,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;AAC/C,CAAC"}
|
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The arithmetic of arranging a lab by hand.
|
|
3
|
+
*
|
|
4
|
+
* `arrange` goes from what a lab says to where things are. Arranging goes the other way: somebody
|
|
5
|
+
* drags a freezer across a floor, and that has to become something the lab can say — a position
|
|
6
|
+
* measured from the place the freezer is in, in that place's own facing. This is that inverse, with
|
|
7
|
+
* the checks a person arranging wants: has it left the room, is it standing in something else.
|
|
8
|
+
*
|
|
9
|
+
* Nothing here moves anything. It works out what would be said, and a caller says it.
|
|
10
|
+
*/
|
|
11
|
+
import type { Arranged, Standing } from "./model.js";
|
|
12
|
+
/** How finely a dragged place settles, in metres. */
|
|
13
|
+
export declare const SNAP = 0.05;
|
|
14
|
+
/**
|
|
15
|
+
* A length settled onto a grid.
|
|
16
|
+
*
|
|
17
|
+
* @param value - The length, in metres.
|
|
18
|
+
* @param step - The grid, in metres.
|
|
19
|
+
* @returns The nearest multiple of the step, to the millimetre.
|
|
20
|
+
*/
|
|
21
|
+
export declare function snapped(value: number, step?: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* Where a place stands, as the lab would say it: measured from the place it is in.
|
|
24
|
+
*
|
|
25
|
+
* It is the inverse of `arrange`, so it gives an answer for a place nobody has stood anywhere too:
|
|
26
|
+
* the standing that would leave it exactly where it is now.
|
|
27
|
+
*
|
|
28
|
+
* @param arranged - The lab, arranged.
|
|
29
|
+
* @param id - The place.
|
|
30
|
+
* @returns Its standing, or `null` if the lab has no such place.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { arrange, exampleLab, standingOf } from "@biolibs/bionet-space";
|
|
35
|
+
*
|
|
36
|
+
* const arranged = arrange(exampleLab());
|
|
37
|
+
* standingOf(arranged, "minus80")?.size; // [ 0.9, 2, 0.85 ]
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function standingOf(arranged: readonly Arranged[], id: string): Standing | null;
|
|
41
|
+
/**
|
|
42
|
+
* The standing a place would have if the centre of its base were moved to a point on the floor.
|
|
43
|
+
*
|
|
44
|
+
* The point is settled onto a grid and kept inside the place it is in, so a freezer cannot be
|
|
45
|
+
* dragged through a wall. Its height off the floor, its size and its turn stay as they are.
|
|
46
|
+
*
|
|
47
|
+
* @param arranged - The lab, arranged.
|
|
48
|
+
* @param id - The place being moved.
|
|
49
|
+
* @param to - Where the centre of its base should go, across and towards the front, in the lab's coordinates.
|
|
50
|
+
* @param options - `snap` is the grid to settle on, in metres; 0 for none.
|
|
51
|
+
* @returns The standing, or `null` if the lab has no such place.
|
|
52
|
+
*/
|
|
53
|
+
export declare function standingAt(arranged: readonly Arranged[], id: string, to: readonly [number, number], options?: {
|
|
54
|
+
snap?: number;
|
|
55
|
+
}): Standing | null;
|
|
56
|
+
/**
|
|
57
|
+
* A standing turned a quarter turn further.
|
|
58
|
+
*
|
|
59
|
+
* @param standing - The standing.
|
|
60
|
+
* @returns The same place, facing the next way round.
|
|
61
|
+
*/
|
|
62
|
+
export declare function quarterTurned(standing: Standing): Standing;
|
|
63
|
+
/**
|
|
64
|
+
* Places that are standing in each other.
|
|
65
|
+
*
|
|
66
|
+
* Only places in the same place are compared: a box is supposed to be inside its freezer. Two that
|
|
67
|
+
* touch are fine; two that share space are not, and both are named.
|
|
68
|
+
*
|
|
69
|
+
* @param arranged - The lab, arranged.
|
|
70
|
+
* @returns Each pair that shares space, once.
|
|
71
|
+
*/
|
|
72
|
+
export declare function overlapping(arranged: readonly Arranged[]): [string, string][];
|
|
73
|
+
/**
|
|
74
|
+
* Places somebody has stood partly outside the place they are in.
|
|
75
|
+
*
|
|
76
|
+
* Only places stood by hand are named. One that was never stood anywhere is where `arrange` put it,
|
|
77
|
+
* and if that is outside, the fault is not the lab's.
|
|
78
|
+
*
|
|
79
|
+
* @param arranged - The lab, arranged.
|
|
80
|
+
* @returns The ID of each such place.
|
|
81
|
+
*/
|
|
82
|
+
export declare function sticking(arranged: readonly Arranged[]): string[];
|
|
83
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAQ,MAAM,YAAY,CAAC;AAE3D,qDAAqD;AACrD,eAAO,MAAM,IAAI,OAAO,CAAC;AAOzB;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,MAAa,GAAG,MAAM,CAElE;AAoBD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,SAAS,QAAQ,EAAE,EAAE,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAerF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,SAAS,QAAQ,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,QAAQ,GAAG,IAAI,CAmBrJ;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAE1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,SAAS,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAY7E;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,SAAS,QAAQ,EAAE,GAAG,MAAM,EAAE,CAOhE"}
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/** How finely a dragged place settles, in metres. */
|
|
2
|
+
export const SNAP = 0.05;
|
|
3
|
+
/** How far two places may sink into each other before it counts, in metres. */
|
|
4
|
+
const SLACK = 0.001;
|
|
5
|
+
const round = (value) => Math.round(value * 1000) / 1000;
|
|
6
|
+
/**
|
|
7
|
+
* A length settled onto a grid.
|
|
8
|
+
*
|
|
9
|
+
* @param value - The length, in metres.
|
|
10
|
+
* @param step - The grid, in metres.
|
|
11
|
+
* @returns The nearest multiple of the step, to the millimetre.
|
|
12
|
+
*/
|
|
13
|
+
export function snapped(value, step = SNAP) {
|
|
14
|
+
return step <= 0 ? round(value) : round(Math.round(value / step) * step);
|
|
15
|
+
}
|
|
16
|
+
/** Undo a turn: an offset in the lab's directions, as measured inside a place turned that far. */
|
|
17
|
+
function unturned([x, y, z], turn) {
|
|
18
|
+
switch (turn) {
|
|
19
|
+
case 90: return [z, y, -x];
|
|
20
|
+
case 180: return [-x, y, -z];
|
|
21
|
+
case 270: return [-z, y, x];
|
|
22
|
+
default: return [x, y, z];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const base = (one) => [one.center[0], one.center[1] - one.size[1] / 2, one.center[2]];
|
|
26
|
+
/** The place something is in, arranged, or `null` for one that is in nothing. */
|
|
27
|
+
const parentOf = (arranged, one) => {
|
|
28
|
+
const id = one.path.at(-2);
|
|
29
|
+
return id === undefined ? null : arranged.find((each) => each.place.id === id) ?? null;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Where a place stands, as the lab would say it: measured from the place it is in.
|
|
33
|
+
*
|
|
34
|
+
* It is the inverse of `arrange`, so it gives an answer for a place nobody has stood anywhere too:
|
|
35
|
+
* the standing that would leave it exactly where it is now.
|
|
36
|
+
*
|
|
37
|
+
* @param arranged - The lab, arranged.
|
|
38
|
+
* @param id - The place.
|
|
39
|
+
* @returns Its standing, or `null` if the lab has no such place.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { arrange, exampleLab, standingOf } from "@biolibs/bionet-space";
|
|
44
|
+
*
|
|
45
|
+
* const arranged = arrange(exampleLab());
|
|
46
|
+
* standingOf(arranged, "minus80")?.size; // [ 0.9, 2, 0.85 ]
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function standingOf(arranged, id) {
|
|
50
|
+
const one = arranged.find((each) => each.place.id === id);
|
|
51
|
+
if (one === undefined)
|
|
52
|
+
return null;
|
|
53
|
+
const parent = parentOf(arranged, one);
|
|
54
|
+
const from = parent === null ? [0, 0, 0] : base(parent);
|
|
55
|
+
const at = base(one);
|
|
56
|
+
const inside = parent?.turn ?? 0;
|
|
57
|
+
const position = unturned([at[0] - from[0], at[1] - from[1], at[2] - from[2]], inside);
|
|
58
|
+
const [w, h, d] = one.size;
|
|
59
|
+
return {
|
|
60
|
+
position: [round(position[0]), round(position[1]), round(position[2])],
|
|
61
|
+
// The space it takes up was worked out after turning, so a quarter turn is undone here.
|
|
62
|
+
size: one.turn === 90 || one.turn === 270 ? [round(d), round(h), round(w)] : [round(w), round(h), round(d)],
|
|
63
|
+
turn: ((one.turn - inside + 360) % 360),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The standing a place would have if the centre of its base were moved to a point on the floor.
|
|
68
|
+
*
|
|
69
|
+
* The point is settled onto a grid and kept inside the place it is in, so a freezer cannot be
|
|
70
|
+
* dragged through a wall. Its height off the floor, its size and its turn stay as they are.
|
|
71
|
+
*
|
|
72
|
+
* @param arranged - The lab, arranged.
|
|
73
|
+
* @param id - The place being moved.
|
|
74
|
+
* @param to - Where the centre of its base should go, across and towards the front, in the lab's coordinates.
|
|
75
|
+
* @param options - `snap` is the grid to settle on, in metres; 0 for none.
|
|
76
|
+
* @returns The standing, or `null` if the lab has no such place.
|
|
77
|
+
*/
|
|
78
|
+
export function standingAt(arranged, id, to, options = {}) {
|
|
79
|
+
const one = arranged.find((each) => each.place.id === id);
|
|
80
|
+
const now = standingOf(arranged, id);
|
|
81
|
+
if (one === undefined || now === null)
|
|
82
|
+
return null;
|
|
83
|
+
const parent = parentOf(arranged, one);
|
|
84
|
+
const from = parent === null ? [0, 0, 0] : base(parent);
|
|
85
|
+
const [x, , z] = unturned([to[0] - from[0], 0, to[1] - from[2]], parent?.turn ?? 0);
|
|
86
|
+
let across = snapped(x, options.snap ?? SNAP);
|
|
87
|
+
let forward = snapped(z, options.snap ?? SNAP);
|
|
88
|
+
if (parent !== null) {
|
|
89
|
+
// How much room there is either side, in the parent's own facing.
|
|
90
|
+
const [pw, pd] = parent.turn === 90 || parent.turn === 270 ? [parent.size[2], parent.size[0]] : [parent.size[0], parent.size[2]];
|
|
91
|
+
const quarter = now.turn === 90 || now.turn === 270;
|
|
92
|
+
const [w, d] = quarter ? [now.size[2], now.size[0]] : [now.size[0], now.size[2]];
|
|
93
|
+
const within = (value, room, taken) => (taken >= room ? 0 : Math.min(Math.max(value, -(room - taken) / 2), (room - taken) / 2));
|
|
94
|
+
across = round(within(across, pw, w));
|
|
95
|
+
forward = round(within(forward, pd, d));
|
|
96
|
+
}
|
|
97
|
+
return { ...now, position: [across, now.position[1], forward] };
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A standing turned a quarter turn further.
|
|
101
|
+
*
|
|
102
|
+
* @param standing - The standing.
|
|
103
|
+
* @returns The same place, facing the next way round.
|
|
104
|
+
*/
|
|
105
|
+
export function quarterTurned(standing) {
|
|
106
|
+
return { ...standing, turn: (((standing.turn ?? 0) + 90) % 360) };
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Places that are standing in each other.
|
|
110
|
+
*
|
|
111
|
+
* Only places in the same place are compared: a box is supposed to be inside its freezer. Two that
|
|
112
|
+
* touch are fine; two that share space are not, and both are named.
|
|
113
|
+
*
|
|
114
|
+
* @param arranged - The lab, arranged.
|
|
115
|
+
* @returns Each pair that shares space, once.
|
|
116
|
+
*/
|
|
117
|
+
export function overlapping(arranged) {
|
|
118
|
+
const pairs = [];
|
|
119
|
+
const apart = (a, b, axis) => Math.abs(a.center[axis] - b.center[axis]) >= (a.size[axis] + b.size[axis]) / 2 - SLACK;
|
|
120
|
+
for (let first = 0; first < arranged.length; first++) {
|
|
121
|
+
for (let second = first + 1; second < arranged.length; second++) {
|
|
122
|
+
const [a, b] = [arranged[first], arranged[second]];
|
|
123
|
+
if (a.place.parent !== b.place.parent)
|
|
124
|
+
continue;
|
|
125
|
+
if (!apart(a, b, 0) && !apart(a, b, 1) && !apart(a, b, 2))
|
|
126
|
+
pairs.push([a.place.id, b.place.id]);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return pairs;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Places somebody has stood partly outside the place they are in.
|
|
133
|
+
*
|
|
134
|
+
* Only places stood by hand are named. One that was never stood anywhere is where `arrange` put it,
|
|
135
|
+
* and if that is outside, the fault is not the lab's.
|
|
136
|
+
*
|
|
137
|
+
* @param arranged - The lab, arranged.
|
|
138
|
+
* @returns The ID of each such place.
|
|
139
|
+
*/
|
|
140
|
+
export function sticking(arranged) {
|
|
141
|
+
return arranged.filter((one) => {
|
|
142
|
+
const parent = parentOf(arranged, one);
|
|
143
|
+
if (parent === null || one.placed !== "by hand")
|
|
144
|
+
return false;
|
|
145
|
+
return [0, 1, 2].some((axis) => Math.abs(one.center[axis] - parent.center[axis]) > (parent.size[axis] - one.size[axis]) / 2 + SLACK);
|
|
146
|
+
}).map((one) => one.place.id);
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAYA,qDAAqD;AACrD,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC;AAEzB,+EAA+E;AAC/E,MAAM,KAAK,GAAG,KAAK,CAAC;AAEpB,MAAM,KAAK,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;AAEzE;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,OAAe,IAAI;IACxD,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,C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,KAAK,CAAC,EAAE,CAAC,CAAC;AAChC,CAAC"}
|
package/dist/from.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A layout made from a lab's own record of itself.
|
|
3
|
+
*
|
|
4
|
+
* A lab's signed log says what places it has, which is inside which, and where each item was put.
|
|
5
|
+
* This turns that into a `Layout`. It asks for the lab structurally, by the few fields it reads, so
|
|
6
|
+
* this package still depends on nothing: `@biolibs/bionet`'s lab state fits, and so does anything
|
|
7
|
+
* else shaped like it.
|
|
8
|
+
*/
|
|
9
|
+
import type { Layout } from "./model.js";
|
|
10
|
+
/** A place, as a lab records it. Lengths are whole millimetres. */
|
|
11
|
+
export interface RecordedPlace {
|
|
12
|
+
place: string;
|
|
13
|
+
kind: string;
|
|
14
|
+
name: string;
|
|
15
|
+
parent: string | null;
|
|
16
|
+
grid: {
|
|
17
|
+
rows: number;
|
|
18
|
+
columns: number;
|
|
19
|
+
} | null;
|
|
20
|
+
standing: {
|
|
21
|
+
at: readonly number[];
|
|
22
|
+
size: readonly number[];
|
|
23
|
+
turn: number;
|
|
24
|
+
} | null;
|
|
25
|
+
retired: boolean;
|
|
26
|
+
fields?: Readonly<Record<string, string | number | null>>;
|
|
27
|
+
}
|
|
28
|
+
/** An item, as a lab records it. */
|
|
29
|
+
export interface RecordedItem {
|
|
30
|
+
item: string;
|
|
31
|
+
part: string;
|
|
32
|
+
unit: string | null;
|
|
33
|
+
amount: number;
|
|
34
|
+
retired: boolean;
|
|
35
|
+
needsRecount: boolean;
|
|
36
|
+
where: {
|
|
37
|
+
place: string;
|
|
38
|
+
slot: {
|
|
39
|
+
row: number;
|
|
40
|
+
column: number;
|
|
41
|
+
} | null;
|
|
42
|
+
} | null;
|
|
43
|
+
}
|
|
44
|
+
/** As much of a lab as a layout is made from. */
|
|
45
|
+
export interface RecordedLab {
|
|
46
|
+
places: readonly RecordedPlace[];
|
|
47
|
+
items: readonly RecordedItem[];
|
|
48
|
+
parts: readonly {
|
|
49
|
+
checksum: string;
|
|
50
|
+
name: string;
|
|
51
|
+
}[];
|
|
52
|
+
}
|
|
53
|
+
/** The ID of the room that is made up when a lab has places standing in no room. */
|
|
54
|
+
export declare const UNNAMED_ROOM = "~room";
|
|
55
|
+
/**
|
|
56
|
+
* Make a layout from a lab.
|
|
57
|
+
*
|
|
58
|
+
* Retired places are left out, with everything in them. Items that have been retired, or that
|
|
59
|
+
* nobody has put anywhere, are left out too: a layout is of what can be found. A place that stands
|
|
60
|
+
* in no room is put in one made up for the purpose, so that a lab which has only said "there is a
|
|
61
|
+
* freezer" can still be drawn.
|
|
62
|
+
*
|
|
63
|
+
* @param lab - The lab's places, items and parts.
|
|
64
|
+
* @param options - `room` is what to call the room that is made up if one is needed.
|
|
65
|
+
* @returns The layout.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { layoutFrom } from "@biolibs/bionet-space";
|
|
70
|
+
*
|
|
71
|
+
* const layout = layoutFrom({
|
|
72
|
+
* places: [{ place: "f", kind: "freezer", name: "−80", parent: null, grid: null, standing: null, retired: false }],
|
|
73
|
+
* items: [], parts: [],
|
|
74
|
+
* });
|
|
75
|
+
* layout.places.map((one) => [one.id, one.parent]); // [ [ "~room", null ], [ "f", "~room" ] ]
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function layoutFrom(lab: RecordedLab, options?: {
|
|
79
|
+
room?: string;
|
|
80
|
+
}): Layout;
|
|
81
|
+
//# sourceMappingURL=from.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"from.d.ts","sourceRoot":"","sources":["../src/from.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,MAAM,EAAuB,MAAM,YAAY,CAAC;AAE9D,mEAAmE;AACnE,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,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AG,EAAE,WAAW,EAAE,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,MAAM,CAoCpF"}
|
package/dist/from.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** The ID of the room that is made up when a lab has places standing in no room. */
|
|
2
|
+
export const UNNAMED_ROOM = "~room";
|
|
3
|
+
const metres = (list) => [list[0] / 1000, list[1] / 1000, list[2] / 1000];
|
|
4
|
+
/**
|
|
5
|
+
* Make a layout from a lab.
|
|
6
|
+
*
|
|
7
|
+
* Retired places are left out, with everything in them. Items that have been retired, or that
|
|
8
|
+
* nobody has put anywhere, are left out too: a layout is of what can be found. A place that stands
|
|
9
|
+
* in no room is put in one made up for the purpose, so that a lab which has only said "there is a
|
|
10
|
+
* freezer" can still be drawn.
|
|
11
|
+
*
|
|
12
|
+
* @param lab - The lab's places, items and parts.
|
|
13
|
+
* @param options - `room` is what to call the room that is made up if one is needed.
|
|
14
|
+
* @returns The layout.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { layoutFrom } from "@biolibs/bionet-space";
|
|
19
|
+
*
|
|
20
|
+
* const layout = layoutFrom({
|
|
21
|
+
* places: [{ place: "f", kind: "freezer", name: "−80", parent: null, grid: null, standing: null, retired: false }],
|
|
22
|
+
* items: [], parts: [],
|
|
23
|
+
* });
|
|
24
|
+
* layout.places.map((one) => [one.id, one.parent]); // [ [ "~room", null ], [ "f", "~room" ] ]
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function layoutFrom(lab, options = {}) {
|
|
28
|
+
const byId = new Map(lab.places.map((one) => [one.place, one]));
|
|
29
|
+
/** Whether a place, and everything it is inside, is still in use. */
|
|
30
|
+
const kept = (id) => {
|
|
31
|
+
const passed = new Set();
|
|
32
|
+
for (let at = id; at !== null; at = byId.get(at).parent) {
|
|
33
|
+
const one = byId.get(at);
|
|
34
|
+
if (one === undefined || one.retired || passed.has(at))
|
|
35
|
+
return false;
|
|
36
|
+
passed.add(at);
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
40
|
+
const loose = lab.places.some((one) => one.parent === null && one.kind !== "room" && kept(one.place));
|
|
41
|
+
const places = loose ? [{ id: UNNAMED_ROOM, kind: "room", name: options.room ?? "Lab", parent: null }] : [];
|
|
42
|
+
for (const one of lab.places) {
|
|
43
|
+
if (!kept(one.place))
|
|
44
|
+
continue;
|
|
45
|
+
const model = one.fields?.["model"];
|
|
46
|
+
places.push({
|
|
47
|
+
id: one.place, kind: one.kind, name: one.name,
|
|
48
|
+
parent: one.parent ?? (one.kind === "room" ? null : UNNAMED_ROOM),
|
|
49
|
+
...(one.standing === null ? {} : { standing: { position: metres(one.standing.at), size: metres(one.standing.size), turn: one.standing.turn } }),
|
|
50
|
+
...(one.grid === null ? {} : { grid: { rows: one.grid.rows, columns: one.grid.columns } }),
|
|
51
|
+
...(typeof model === "string" ? { model } : {}),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const names = new Map(lab.parts.map((part) => [part.checksum, part.name]));
|
|
55
|
+
const stored = [];
|
|
56
|
+
for (const item of lab.items) {
|
|
57
|
+
if (item.retired || item.where === null || !byId.has(item.where.place) || !kept(item.where.place))
|
|
58
|
+
continue;
|
|
59
|
+
stored.push({ item: item.item, place: item.where.place, slot: item.where.slot, part: item.part,
|
|
60
|
+
name: names.get(item.part) ?? "A part the lab no longer lists", amount: item.amount, unit: item.unit,
|
|
61
|
+
needsRecount: item.needsRecount });
|
|
62
|
+
}
|
|
63
|
+
return { places, stored };
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=from.js.map
|
package/dist/from.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"from.js","sourceRoot":"","sources":["../src/from.ts"],"names":[],"mappings":"AAwCA,oFAAoF;AACpF,MAAM,CAAC,MAAM,YAAY,GAAG,OAAO,CAAC;AAEpC,MAAM,MAA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AAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChD,CAAC,CAAC;IACL,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC3E,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;QAC7B,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;YAAE,SAAS;QAC5G,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI;YAChF,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,gCAAgC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI;YACpG,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC5B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,10 +13,14 @@
|
|
|
13
13
|
* - `model.ts` — places, what is stored in them, and a place with somewhere to stand
|
|
14
14
|
* - `arrange.ts` — giving every place somewhere to stand, and the positions inside a box
|
|
15
15
|
* - `find.ts` — levels, bounds, camera poses, searching
|
|
16
|
+
* - `build.ts` — arranging by hand: what a drag would have the lab say, and what has gone wrong
|
|
17
|
+
* - `from.ts` — a layout made from a lab's own record of itself
|
|
16
18
|
* - `example.ts` — a lab to look at
|
|
17
19
|
*/
|
|
18
20
|
export * from "./model.js";
|
|
19
21
|
export * from "./arrange.js";
|
|
20
22
|
export * from "./find.js";
|
|
21
23
|
export * from "./example.js";
|
|
24
|
+
export * from "./from.js";
|
|
25
|
+
export * from "./build.js";
|
|
22
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,10 +13,14 @@
|
|
|
13
13
|
* - `model.ts` — places, what is stored in them, and a place with somewhere to stand
|
|
14
14
|
* - `arrange.ts` — giving every place somewhere to stand, and the positions inside a box
|
|
15
15
|
* - `find.ts` — levels, bounds, camera poses, searching
|
|
16
|
+
* - `build.ts` — arranging by hand: what a drag would have the lab say, and what has gone wrong
|
|
17
|
+
* - `from.ts` — a layout made from a lab's own record of itself
|
|
16
18
|
* - `example.ts` — a lab to look at
|
|
17
19
|
*/
|
|
18
20
|
export * from "./model.js";
|
|
19
21
|
export * from "./arrange.js";
|
|
20
22
|
export * from "./find.js";
|
|
21
23
|
export * from "./example.js";
|
|
24
|
+
export * from "./from.js";
|
|
25
|
+
export * from "./build.js";
|
|
22
26
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
package/package.json
CHANGED
package/src/arrange.ts
CHANGED
|
@@ -239,3 +239,25 @@ export function slotName(slot: Slot): string {
|
|
|
239
239
|
for (let at = slot.row; at >= 0; at = Math.floor(at / 26) - 1) row = String.fromCharCode(65 + (at % 26)) + row;
|
|
240
240
|
return `${row}${slot.column + 1}`;
|
|
241
241
|
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Read a position the way it is written on a box lid.
|
|
245
|
+
*
|
|
246
|
+
* @param name - Something like `C4` or `c4`.
|
|
247
|
+
* @returns The position, or `null` if that is not how one is written.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* import { slotFrom, slotName } from "@biolibs/bionet-space";
|
|
252
|
+
*
|
|
253
|
+
* slotFrom("C4"); // { row: 2, column: 3 }
|
|
254
|
+
* slotName(slotFrom("AB12")!); // "AB12"
|
|
255
|
+
* slotFrom("4C"); // null
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
export function slotFrom(name: string): Slot | null {
|
|
259
|
+
const found = /^([A-Za-z]{1,2})([1-9][0-9]{0,2})$/.exec(name.trim());
|
|
260
|
+
if (found === null) return null;
|
|
261
|
+
const row = [...found[1]!.toUpperCase()].reduce((sum, letter) => sum * 26 + (letter.charCodeAt(0) - 64), 0) - 1;
|
|
262
|
+
return { row, column: Number(found[2]) - 1 };
|
|
263
|
+
}
|
package/src/build.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The arithmetic of arranging a lab by hand.
|
|
3
|
+
*
|
|
4
|
+
* `arrange` goes from what a lab says to where things are. Arranging goes the other way: somebody
|
|
5
|
+
* drags a freezer across a floor, and that has to become something the lab can say — a position
|
|
6
|
+
* measured from the place the freezer is in, in that place's own facing. This is that inverse, with
|
|
7
|
+
* the checks a person arranging wants: has it left the room, is it standing in something else.
|
|
8
|
+
*
|
|
9
|
+
* Nothing here moves anything. It works out what would be said, and a caller says it.
|
|
10
|
+
*/
|
|
11
|
+
import type { Arranged, Standing, Turn } from "./model.js";
|
|
12
|
+
|
|
13
|
+
/** How finely a dragged place settles, in metres. */
|
|
14
|
+
export const SNAP = 0.05;
|
|
15
|
+
|
|
16
|
+
/** How far two places may sink into each other before it counts, in metres. */
|
|
17
|
+
const SLACK = 0.001;
|
|
18
|
+
|
|
19
|
+
const round = (value: number): number => Math.round(value * 1000) / 1000;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A length settled onto a grid.
|
|
23
|
+
*
|
|
24
|
+
* @param value - The length, in metres.
|
|
25
|
+
* @param step - The grid, in metres.
|
|
26
|
+
* @returns The nearest multiple of the step, to the millimetre.
|
|
27
|
+
*/
|
|
28
|
+
export function snapped(value: number, step: number = SNAP): number {
|
|
29
|
+
return step <= 0 ? round(value) : round(Math.round(value / step) * step);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Undo a turn: an offset in the lab's directions, as measured inside a place turned that far. */
|
|
33
|
+
function unturned([x, y, z]: [number, number, number], turn: Turn): [number, number, number] {
|
|
34
|
+
switch (turn) {
|
|
35
|
+
case 90: return [z, y, -x];
|
|
36
|
+
case 180: return [-x, y, -z];
|
|
37
|
+
case 270: return [-z, y, x];
|
|
38
|
+
default: return [x, y, z];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const base = (one: Arranged): [number, number, number] => [one.center[0], one.center[1] - one.size[1] / 2, one.center[2]];
|
|
43
|
+
|
|
44
|
+
/** The place something is in, arranged, or `null` for one that is in nothing. */
|
|
45
|
+
const parentOf = (arranged: readonly Arranged[], one: Arranged): Arranged | null => {
|
|
46
|
+
const id = one.path.at(-2);
|
|
47
|
+
return id === undefined ? null : arranged.find((each) => each.place.id === id) ?? null;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Where a place stands, as the lab would say it: measured from the place it is in.
|
|
52
|
+
*
|
|
53
|
+
* It is the inverse of `arrange`, so it gives an answer for a place nobody has stood anywhere too:
|
|
54
|
+
* the standing that would leave it exactly where it is now.
|
|
55
|
+
*
|
|
56
|
+
* @param arranged - The lab, arranged.
|
|
57
|
+
* @param id - The place.
|
|
58
|
+
* @returns Its standing, or `null` if the lab has no such place.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { arrange, exampleLab, standingOf } from "@biolibs/bionet-space";
|
|
63
|
+
*
|
|
64
|
+
* const arranged = arrange(exampleLab());
|
|
65
|
+
* standingOf(arranged, "minus80")?.size; // [ 0.9, 2, 0.85 ]
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function standingOf(arranged: readonly Arranged[], id: string): Standing | null {
|
|
69
|
+
const one = arranged.find((each) => each.place.id === id);
|
|
70
|
+
if (one === undefined) return null;
|
|
71
|
+
const parent = parentOf(arranged, one);
|
|
72
|
+
const from: [number, number, number] = parent === null ? [0, 0, 0] : base(parent);
|
|
73
|
+
const at = base(one);
|
|
74
|
+
const inside = parent?.turn ?? 0;
|
|
75
|
+
const position = unturned([at[0] - from[0], at[1] - from[1], at[2] - from[2]], inside);
|
|
76
|
+
const [w, h, d] = one.size;
|
|
77
|
+
return {
|
|
78
|
+
position: [round(position[0]), round(position[1]), round(position[2])],
|
|
79
|
+
// The space it takes up was worked out after turning, so a quarter turn is undone here.
|
|
80
|
+
size: one.turn === 90 || one.turn === 270 ? [round(d), round(h), round(w)] : [round(w), round(h), round(d)],
|
|
81
|
+
turn: ((one.turn - inside + 360) % 360) as Turn,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The standing a place would have if the centre of its base were moved to a point on the floor.
|
|
87
|
+
*
|
|
88
|
+
* The point is settled onto a grid and kept inside the place it is in, so a freezer cannot be
|
|
89
|
+
* dragged through a wall. Its height off the floor, its size and its turn stay as they are.
|
|
90
|
+
*
|
|
91
|
+
* @param arranged - The lab, arranged.
|
|
92
|
+
* @param id - The place being moved.
|
|
93
|
+
* @param to - Where the centre of its base should go, across and towards the front, in the lab's coordinates.
|
|
94
|
+
* @param options - `snap` is the grid to settle on, in metres; 0 for none.
|
|
95
|
+
* @returns The standing, or `null` if the lab has no such place.
|
|
96
|
+
*/
|
|
97
|
+
export function standingAt(arranged: readonly Arranged[], id: string, to: readonly [number, number], options: { snap?: number } = {}): Standing | null {
|
|
98
|
+
const one = arranged.find((each) => each.place.id === id);
|
|
99
|
+
const now = standingOf(arranged, id);
|
|
100
|
+
if (one === undefined || now === null) return null;
|
|
101
|
+
const parent = parentOf(arranged, one);
|
|
102
|
+
const from: [number, number, number] = parent === null ? [0, 0, 0] : base(parent);
|
|
103
|
+
const [x, , z] = unturned([to[0] - from[0], 0, to[1] - from[2]], parent?.turn ?? 0);
|
|
104
|
+
let across = snapped(x, options.snap ?? SNAP);
|
|
105
|
+
let forward = snapped(z, options.snap ?? SNAP);
|
|
106
|
+
if (parent !== null) {
|
|
107
|
+
// How much room there is either side, in the parent's own facing.
|
|
108
|
+
const [pw, pd] = parent.turn === 90 || parent.turn === 270 ? [parent.size[2], parent.size[0]] : [parent.size[0], parent.size[2]];
|
|
109
|
+
const quarter = now.turn === 90 || now.turn === 270;
|
|
110
|
+
const [w, d] = quarter ? [now.size[2], now.size[0]] : [now.size[0], now.size[2]];
|
|
111
|
+
const within = (value: number, room: number, taken: number): number => (taken >= room ? 0 : Math.min(Math.max(value, -(room - taken) / 2), (room - taken) / 2));
|
|
112
|
+
across = round(within(across, pw, w));
|
|
113
|
+
forward = round(within(forward, pd, d));
|
|
114
|
+
}
|
|
115
|
+
return { ...now, position: [across, now.position[1], forward] };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A standing turned a quarter turn further.
|
|
120
|
+
*
|
|
121
|
+
* @param standing - The standing.
|
|
122
|
+
* @returns The same place, facing the next way round.
|
|
123
|
+
*/
|
|
124
|
+
export function quarterTurned(standing: Standing): Standing {
|
|
125
|
+
return { ...standing, turn: ((((standing.turn ?? 0) + 90) % 360) as Turn) };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Places that are standing in each other.
|
|
130
|
+
*
|
|
131
|
+
* Only places in the same place are compared: a box is supposed to be inside its freezer. Two that
|
|
132
|
+
* touch are fine; two that share space are not, and both are named.
|
|
133
|
+
*
|
|
134
|
+
* @param arranged - The lab, arranged.
|
|
135
|
+
* @returns Each pair that shares space, once.
|
|
136
|
+
*/
|
|
137
|
+
export function overlapping(arranged: readonly Arranged[]): [string, string][] {
|
|
138
|
+
const pairs: [string, string][] = [];
|
|
139
|
+
const apart = (a: Arranged, b: Arranged, axis: 0 | 1 | 2): boolean =>
|
|
140
|
+
Math.abs(a.center[axis] - b.center[axis]) >= (a.size[axis] + b.size[axis]) / 2 - SLACK;
|
|
141
|
+
for (let first = 0; first < arranged.length; first++) {
|
|
142
|
+
for (let second = first + 1; second < arranged.length; second++) {
|
|
143
|
+
const [a, b] = [arranged[first]!, arranged[second]!];
|
|
144
|
+
if (a.place.parent !== b.place.parent) continue;
|
|
145
|
+
if (!apart(a, b, 0) && !apart(a, b, 1) && !apart(a, b, 2)) pairs.push([a.place.id, b.place.id]);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return pairs;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Places somebody has stood partly outside the place they are in.
|
|
153
|
+
*
|
|
154
|
+
* Only places stood by hand are named. One that was never stood anywhere is where `arrange` put it,
|
|
155
|
+
* and if that is outside, the fault is not the lab's.
|
|
156
|
+
*
|
|
157
|
+
* @param arranged - The lab, arranged.
|
|
158
|
+
* @returns The ID of each such place.
|
|
159
|
+
*/
|
|
160
|
+
export function sticking(arranged: readonly Arranged[]): string[] {
|
|
161
|
+
return arranged.filter((one) => {
|
|
162
|
+
const parent = parentOf(arranged, one);
|
|
163
|
+
if (parent === null || one.placed !== "by hand") return false;
|
|
164
|
+
return ([0, 1, 2] as const).some((axis) =>
|
|
165
|
+
Math.abs(one.center[axis] - parent.center[axis]) > (parent.size[axis] - one.size[axis]) / 2 + SLACK);
|
|
166
|
+
}).map((one) => one.place.id);
|
|
167
|
+
}
|
package/src/from.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A layout made from a lab's own record of itself.
|
|
3
|
+
*
|
|
4
|
+
* A lab's signed log says what places it has, which is inside which, and where each item was put.
|
|
5
|
+
* This turns that into a `Layout`. It asks for the lab structurally, by the few fields it reads, so
|
|
6
|
+
* this package still depends on nothing: `@biolibs/bionet`'s lab state fits, and so does anything
|
|
7
|
+
* else shaped like it.
|
|
8
|
+
*/
|
|
9
|
+
import type { Layout, Place, Stored, Turn } from "./model.js";
|
|
10
|
+
|
|
11
|
+
/** A place, as a lab records it. Lengths are whole millimetres. */
|
|
12
|
+
export interface RecordedPlace {
|
|
13
|
+
place: string;
|
|
14
|
+
kind: string;
|
|
15
|
+
name: string;
|
|
16
|
+
parent: string | null;
|
|
17
|
+
grid: { rows: number; columns: number } | null;
|
|
18
|
+
standing: { at: readonly number[]; size: readonly number[]; turn: number } | null;
|
|
19
|
+
retired: boolean;
|
|
20
|
+
fields?: Readonly<Record<string, string | number | null>>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** An item, as a lab records it. */
|
|
24
|
+
export interface RecordedItem {
|
|
25
|
+
item: string;
|
|
26
|
+
part: string;
|
|
27
|
+
unit: string | null;
|
|
28
|
+
amount: number;
|
|
29
|
+
retired: boolean;
|
|
30
|
+
needsRecount: boolean;
|
|
31
|
+
where: { place: string; slot: { row: number; column: number } | null } | null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** As much of a lab as a layout is made from. */
|
|
35
|
+
export interface RecordedLab {
|
|
36
|
+
places: readonly RecordedPlace[];
|
|
37
|
+
items: readonly RecordedItem[];
|
|
38
|
+
parts: readonly { checksum: string; name: string }[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The ID of the room that is made up when a lab has places standing in no room. */
|
|
42
|
+
export const UNNAMED_ROOM = "~room";
|
|
43
|
+
|
|
44
|
+
const metres = (list: readonly number[]): [number, number, number] => [list[0]! / 1000, list[1]! / 1000, list[2]! / 1000];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Make a layout from a lab.
|
|
48
|
+
*
|
|
49
|
+
* Retired places are left out, with everything in them. Items that have been retired, or that
|
|
50
|
+
* nobody has put anywhere, are left out too: a layout is of what can be found. A place that stands
|
|
51
|
+
* in no room is put in one made up for the purpose, so that a lab which has only said "there is a
|
|
52
|
+
* freezer" can still be drawn.
|
|
53
|
+
*
|
|
54
|
+
* @param lab - The lab's places, items and parts.
|
|
55
|
+
* @param options - `room` is what to call the room that is made up if one is needed.
|
|
56
|
+
* @returns The layout.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { layoutFrom } from "@biolibs/bionet-space";
|
|
61
|
+
*
|
|
62
|
+
* const layout = layoutFrom({
|
|
63
|
+
* places: [{ place: "f", kind: "freezer", name: "−80", parent: null, grid: null, standing: null, retired: false }],
|
|
64
|
+
* items: [], parts: [],
|
|
65
|
+
* });
|
|
66
|
+
* layout.places.map((one) => [one.id, one.parent]); // [ [ "~room", null ], [ "f", "~room" ] ]
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function layoutFrom(lab: RecordedLab, options: { room?: string } = {}): Layout {
|
|
70
|
+
const byId = new Map(lab.places.map((one) => [one.place, one]));
|
|
71
|
+
/** Whether a place, and everything it is inside, is still in use. */
|
|
72
|
+
const kept = (id: string): boolean => {
|
|
73
|
+
const passed = new Set<string>();
|
|
74
|
+
for (let at: string | null = id; at !== null; at = byId.get(at)!.parent) {
|
|
75
|
+
const one = byId.get(at);
|
|
76
|
+
if (one === undefined || one.retired || passed.has(at)) return false;
|
|
77
|
+
passed.add(at);
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const loose = lab.places.some((one) => one.parent === null && one.kind !== "room" && kept(one.place));
|
|
83
|
+
const places: Place[] = loose ? [{ id: UNNAMED_ROOM, kind: "room", name: options.room ?? "Lab", parent: null }] : [];
|
|
84
|
+
for (const one of lab.places) {
|
|
85
|
+
if (!kept(one.place)) continue;
|
|
86
|
+
const model = one.fields?.["model"];
|
|
87
|
+
places.push({
|
|
88
|
+
id: one.place, kind: one.kind, name: one.name,
|
|
89
|
+
parent: one.parent ?? (one.kind === "room" ? null : UNNAMED_ROOM),
|
|
90
|
+
...(one.standing === null ? {} : { standing: { position: metres(one.standing.at), size: metres(one.standing.size), turn: one.standing.turn as Turn } }),
|
|
91
|
+
...(one.grid === null ? {} : { grid: { rows: one.grid.rows, columns: one.grid.columns } }),
|
|
92
|
+
...(typeof model === "string" ? { model } : {}),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const names = new Map(lab.parts.map((part) => [part.checksum, part.name]));
|
|
97
|
+
const stored: Stored[] = [];
|
|
98
|
+
for (const item of lab.items) {
|
|
99
|
+
if (item.retired || item.where === null || !byId.has(item.where.place) || !kept(item.where.place)) continue;
|
|
100
|
+
stored.push({ item: item.item, place: item.where.place, slot: item.where.slot, part: item.part,
|
|
101
|
+
name: names.get(item.part) ?? "A part the lab no longer lists", amount: item.amount, unit: item.unit,
|
|
102
|
+
needsRecount: item.needsRecount });
|
|
103
|
+
}
|
|
104
|
+
return { places, stored };
|
|
105
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -13,9 +13,13 @@
|
|
|
13
13
|
* - `model.ts` — places, what is stored in them, and a place with somewhere to stand
|
|
14
14
|
* - `arrange.ts` — giving every place somewhere to stand, and the positions inside a box
|
|
15
15
|
* - `find.ts` — levels, bounds, camera poses, searching
|
|
16
|
+
* - `build.ts` — arranging by hand: what a drag would have the lab say, and what has gone wrong
|
|
17
|
+
* - `from.ts` — a layout made from a lab's own record of itself
|
|
16
18
|
* - `example.ts` — a lab to look at
|
|
17
19
|
*/
|
|
18
20
|
export * from "./model.js";
|
|
19
21
|
export * from "./arrange.js";
|
|
20
22
|
export * from "./find.js";
|
|
21
23
|
export * from "./example.js";
|
|
24
|
+
export * from "./from.js";
|
|
25
|
+
export * from "./build.js";
|