@mark1russell7/layout-contract 0.5.2 → 0.5.3
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/build/index.d.ts +4 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +6 -4
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/strategy-space.ts +13 -7
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/layout-contract",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.3",
|
|
5
5
|
"description": "The shared contract of the packing and highways layout engines: the input and record formats, the turn rule, margins, tolerances and hard rules.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"layout",
|
package/src/strategy-space.ts
CHANGED
|
@@ -42,7 +42,10 @@ export interface SpaceParam {
|
|
|
42
42
|
readonly when?: ParamWhen;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* The rule of the members of a meta option: a count from `min` to `max`. Members with `ordered: false` are sorted by their `configId`.
|
|
47
|
+
* With `min` and `max` 0, the option chooses its members from the input, so a config lists none. This form has no `pool` and no `view`.
|
|
48
|
+
*/
|
|
46
49
|
export interface MemberRule {
|
|
47
50
|
readonly min: number;
|
|
48
51
|
readonly max: number;
|
|
@@ -316,8 +319,11 @@ function optionProblems(stage: SpaceStage, o: StageOption): Problem[] {
|
|
|
316
319
|
if (o.supports !== undefined) out.push(...supportsProblems(o.supports, at));
|
|
317
320
|
if (o.members !== undefined) {
|
|
318
321
|
const { min, max, ordered } = o.members;
|
|
319
|
-
|
|
320
|
-
|
|
322
|
+
const noList = min === 0 && max === 0;
|
|
323
|
+
if (!Number.isInteger(min) || !Number.isInteger(max) || (!noList && (min < 1 || min > max)) || typeof ordered !== "boolean")
|
|
324
|
+
out.push(["members", `${at} has a member rule without whole counts 1 <= min <= max or min = max = 0, and a boolean ordered`]);
|
|
325
|
+
if (noList && (o.members.pool !== undefined || o.members.view !== undefined))
|
|
326
|
+
out.push(["members", `${at} has no member list, so its member rule cannot have a pool or a view`]);
|
|
321
327
|
const pool: unknown = o.members.pool;
|
|
322
328
|
if (pool !== undefined && (!Array.isArray(pool) || pool.length === 0 || !pool.every((entry: unknown) => Array.isArray(entry))))
|
|
323
329
|
out.push(["pool", `${at} has a pool that is not a list of one or more member lists`]);
|
|
@@ -838,7 +844,7 @@ const memberSpaces = /* @__PURE__ */ new WeakMap<StageOption, StrategySpace>();
|
|
|
838
844
|
* A different meta option has one when its members have a base config. `restrict` keeps only the pool entries that fit.
|
|
839
845
|
*/
|
|
840
846
|
const hasMembers = (space: StrategySpace, stage: string, o: StageOption): boolean =>
|
|
841
|
-
o.members === undefined || o.members.pool !== undefined || combos(memberSpaces.get(o) ?? partOf(space, stage).space, 1, false, 0n).length > 0;
|
|
847
|
+
o.members === undefined || o.members.max === 0 || o.members.pool !== undefined || combos(memberSpaces.get(o) ?? partOf(space, stage).space, 1, false, 0n).length > 0;
|
|
842
848
|
|
|
843
849
|
/** This function tells if a restricted space has a config. A base config counts. With `meta`, a meta config counts when each of its meta options has a member list. */
|
|
844
850
|
const hasConfig = (space: StrategySpace, meta: boolean): boolean =>
|
|
@@ -953,8 +959,8 @@ const subSeed = (seed: number, step: string): number => Math.floor(stepRandom(se
|
|
|
953
959
|
function sampleConfigs(space: StrategySpace, n: number, seed: number, meta: boolean, maxTries: number, canon: StrategySpace = space, walk = false): StrategyConfig[] {
|
|
954
960
|
const stages = space.stages;
|
|
955
961
|
const prefix = prefixes(space);
|
|
956
|
-
// A stage without options can stay empty in a part with a meta option of `view: "bounds"
|
|
957
|
-
const bounded = new Set(stages.filter((s) => meta && s.options.some((o) => memberSpaces.has(o))).map((s) => prefix.get(s.name)!));
|
|
962
|
+
// A stage without options can stay empty in a part with a meta option of `view: "bounds"` or with no member list, because that option replaces the stage.
|
|
963
|
+
const bounded = new Set(stages.filter((s) => meta && s.options.some((o) => memberSpaces.has(o) || o.members?.max === 0)).map((s) => prefix.get(s.name)!));
|
|
958
964
|
const lists = stages.map((s) => {
|
|
959
965
|
const list: (StageOption | null)[] = s.options.filter((o) => meta || o.members === undefined);
|
|
960
966
|
if (s.optional) list.push(null);
|
|
@@ -1006,7 +1012,7 @@ function sampleConfigs(space: StrategySpace, n: number, seed: number, meta: bool
|
|
|
1006
1012
|
values[active[j]!]![k]![p.name] = sampleValue(p, (stratum + r()) / active.length);
|
|
1007
1013
|
});
|
|
1008
1014
|
}
|
|
1009
|
-
if (o.members === undefined) continue;
|
|
1015
|
+
if (o.members === undefined || o.members.max === 0) continue;
|
|
1010
1016
|
const fixed = o.members.pool;
|
|
1011
1017
|
if (fixed !== undefined) {
|
|
1012
1018
|
const r = stepRandom(seed, `pool-entry:${s.name}:${o.id}`);
|