@nakafa/aksara-contracts 8.0.2 → 8.0.4

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.
@@ -2,6 +2,7 @@ import { Array as Arr, Option, Result } from "effect";
2
2
  import { arcContained, axisContains, circleContained, cuboidContained, quadraticContained, } from "#contracts/math/extent";
3
3
  import { isPlaneFormulaPoint } from "#contracts/math/formula/field";
4
4
  import { planeFormulaGeometry, planeFormulaPoint, } from "#contracts/math/formula/plane";
5
+ import { regionFilled } from "#contracts/math/formula/region";
5
6
  import { geometryVisible } from "#contracts/math/formula/scope";
6
7
  import { spaceFormulaGeometry } from "#contracts/math/formula/space";
7
8
  import { infinitePathIntersectsBox } from "#contracts/math/intersection";
@@ -54,10 +55,13 @@ function planeObjectContained(frame, object, scope, labels) {
54
55
  object.kind === "marker" ||
55
56
  object.kind === "parametric" ||
56
57
  object.kind === "path" ||
57
- object.kind === "polar" ||
58
- object.kind === "region") {
58
+ object.kind === "polar") {
59
59
  return sampledVisible(planeFormulaGeometry(object, frame, scope), frame);
60
60
  }
61
+ if (object.kind === "region") {
62
+ const filled = regionFilled(object.inequalities, frame, scope);
63
+ return Result.isFailure(filled) || filled.success;
64
+ }
61
65
  if (object.kind === "line") {
62
66
  const [start, through] = object.through;
63
67
  return infinitePathIntersectsBox(object.kind, planeAxes(frame, start, through));
@@ -9,6 +9,14 @@ export declare const CONTOUR_CELLS = 240;
9
9
  * squares method, so an equation such as `x^2 + y^2 = 4` draws its circle.
10
10
  */
11
11
  export declare function contourLines(field: SampleField, box: SampleBox, cells?: number): readonly SampleBranch[];
12
+ /**
13
+ * Whether `contourFill` would draw anything, decided without drawing it. A cell
14
+ * fills when its four corners are finite and one of them is inside, because an
15
+ * inside corner and its two crossings already make an outline. The samples are
16
+ * read coarse to fine and kept, so a visible region costs a few hundred field
17
+ * reads instead of every cell of the grid.
18
+ */
19
+ export declare function contourFilled(field: SampleField, box: SampleBox, cells?: number): boolean;
12
20
  /**
13
21
  * Shades the part of the frame where a field is at least zero, one shape per
14
22
  * cell: the corners inside and the crossings between them, so a cell wholly
@@ -141,6 +141,49 @@ export function contourLines(field, box, cells = CONTOUR_CELLS) {
141
141
  const found = Arr.flatMap(squares, (cell) => cellSegments(field, cell));
142
142
  return join(Arr.map(found, ([from, to], index) => ({ from, index, to })));
143
143
  }
144
+ /** Grid strides from coarse to fine, so a filled region is usually found in a few samples. */
145
+ const FILL_STRIDES = [32, 16, 8, 4, 2, 1];
146
+ /**
147
+ * Whether `contourFill` would draw anything, decided without drawing it. A cell
148
+ * fills when its four corners are finite and one of them is inside, because an
149
+ * inside corner and its two crossings already make an outline. The samples are
150
+ * read coarse to fine and kept, so a visible region costs a few hundred field
151
+ * reads instead of every cell of the grid.
152
+ */
153
+ export function contourFilled(field, box, cells = CONTOUR_CELLS) {
154
+ const dx = (box.x.max - box.x.min) / cells;
155
+ const dy = (box.y.max - box.y.min) / cells;
156
+ const read = MutableHashMap.empty();
157
+ /** The field at one grid corner, sampled once and then read from memory. */
158
+ const value = (column, row) => {
159
+ const key = column * (cells + 1) + row;
160
+ return Option.getOrElse(MutableHashMap.get(read, key), () => {
161
+ const sample = field(box.x.min + column * dx, box.y.min + row * dy);
162
+ MutableHashMap.set(read, key, sample);
163
+ return sample;
164
+ });
165
+ };
166
+ /** Whether the cell lies on the grid and all four of its corners are finite. */
167
+ const finiteCell = (column, row) => column >= 0 &&
168
+ row >= 0 &&
169
+ column < cells &&
170
+ row < cells &&
171
+ Arr.every([
172
+ [column, row],
173
+ [column + 1, row],
174
+ [column + 1, row + 1],
175
+ [column, row + 1],
176
+ ], ([c, r]) => Number.isFinite(value(c, r)));
177
+ /** Whether this corner is inside and one finite cell touching it would fill. */
178
+ const fills = (column, row) => value(column, row) >= 0 &&
179
+ Arr.some([
180
+ [column, row],
181
+ [column - 1, row],
182
+ [column - 1, row - 1],
183
+ [column, row - 1],
184
+ ], ([c, r]) => finiteCell(c, r));
185
+ return Arr.some(FILL_STRIDES, (stride) => Arr.some(Arr.range(0, Math.floor(cells / stride)), (i) => Arr.some(Arr.range(0, Math.floor(cells / stride)), (j) => fills(i * stride, j * stride))));
186
+ }
144
187
  /**
145
188
  * Shades the part of the frame where a field is at least zero, one shape per
146
189
  * cell: the corners inside and the crossings between them, so a cell wholly
@@ -14,3 +14,9 @@ export declare function regionGeometry(inequalities: readonly [string, ...string
14
14
  fill: readonly import("./sample.js").SampleBranch[];
15
15
  kind: "region";
16
16
  }, import("./syntax.js").FormulaError>;
17
+ /**
18
+ * Whether the region where every inequality holds shows inside the box. It
19
+ * answers what `regionGeometry` would fill without tracing the outline, so a
20
+ * schema check stays cheap; drawing the region is the renderer's work.
21
+ */
22
+ export declare function regionFilled(inequalities: readonly [string, ...string[]], box: SampleBox, scope: FormulaScope): Result.Result<boolean, import("./syntax.js").FormulaError>;
@@ -1,7 +1,7 @@
1
1
  import { Array as Arr, MutableList, Option, Order, Result, Schema, } from "effect";
2
2
  import { SamplePointSchema, } from "#contracts/math/formula/box";
3
3
  import { compileFormula, } from "#contracts/math/formula/compile";
4
- import { contourFill, contourLines, } from "#contracts/math/formula/contour";
4
+ import { contourFill, contourFilled, contourLines, } from "#contracts/math/formula/contour";
5
5
  import { readRelation } from "#contracts/math/formula/parse";
6
6
  /** How far a boundary piece lies from one inequality's edge, and whether that edge is strict. */
7
7
  const ConstraintGapSchema = Schema.Struct({
@@ -92,3 +92,14 @@ export function regionGeometry(inequalities, box, scope) {
92
92
  };
93
93
  });
94
94
  }
95
+ /**
96
+ * Whether the region where every inequality holds shows inside the box. It
97
+ * answers what `regionGeometry` would fill without tracing the outline, so a
98
+ * schema check stays cheap; drawing the region is the renderer's work.
99
+ */
100
+ export function regionFilled(inequalities, box, scope) {
101
+ return Result.map(Result.all(Arr.map(inequalities, margin)), (margins) => {
102
+ const fields = Arr.map(margins, (each) => each.field(scope));
103
+ return contourFilled((x, y) => Math.min(...Arr.map(fields, (field) => field(x, y))), box);
104
+ });
105
+ }
@@ -21,10 +21,12 @@ export declare const MAX_PROJECTION_BATCH_COUNT = 64;
21
21
  /**
22
22
  * Maximum complete structured-snapshot batch sent to publication ingress. Nakafa
23
23
  * decodes, re-encodes, hashes and writes every row of a batch in one Convex
24
- * mutation, which may run one second: on 16 November 2026 the 7.0.0 assessment
25
- * rows filled 4 MiB batches and every stageSnapshotBatch timed out, so a batch
26
- * stays a quarter of that: still one Convex document's 1 MiB, which every row
27
- * already fits.
24
+ * mutation, which may run one second, and its cost grows with the batch's bytes.
25
+ * On 16 November 2026 the 7.0.0 assessment rows filled 4 MiB batches and every
26
+ * stageSnapshotBatch timed out; release catalog-20261116c then timed out on a
27
+ * 1 MiB batch of Quran rows after nineteen minutes of staging. A batch therefore
28
+ * stays at half of that, which still holds the largest snapshot row: a Quran row
29
+ * of 369 KiB, while no assessment row passes 34 KiB.
28
30
  */
29
31
  export declare const MAX_SNAPSHOT_BATCH_BYTES: number;
30
32
  /** Maximum structured snapshot rows accepted by one staging transaction, inside the same one-second mutation. */
@@ -21,12 +21,14 @@ export const MAX_PROJECTION_BATCH_COUNT = 64;
21
21
  /**
22
22
  * Maximum complete structured-snapshot batch sent to publication ingress. Nakafa
23
23
  * decodes, re-encodes, hashes and writes every row of a batch in one Convex
24
- * mutation, which may run one second: on 16 November 2026 the 7.0.0 assessment
25
- * rows filled 4 MiB batches and every stageSnapshotBatch timed out, so a batch
26
- * stays a quarter of that: still one Convex document's 1 MiB, which every row
27
- * already fits.
24
+ * mutation, which may run one second, and its cost grows with the batch's bytes.
25
+ * On 16 November 2026 the 7.0.0 assessment rows filled 4 MiB batches and every
26
+ * stageSnapshotBatch timed out; release catalog-20261116c then timed out on a
27
+ * 1 MiB batch of Quran rows after nineteen minutes of staging. A batch therefore
28
+ * stays at half of that, which still holds the largest snapshot row: a Quran row
29
+ * of 369 KiB, while no assessment row passes 34 KiB.
28
30
  */
29
- export const MAX_SNAPSHOT_BATCH_BYTES = 1024 * 1024;
31
+ export const MAX_SNAPSHOT_BATCH_BYTES = 512 * 1024;
30
32
  /** Maximum structured snapshot rows accepted by one staging transaction, inside the same one-second mutation. */
31
33
  export const MAX_SNAPSHOT_BATCH_COUNT = 16;
32
34
  /** Maximum complete grouped staging body below the Node action argument cap. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakafa/aksara-contracts",
3
- "version": "8.0.2",
3
+ "version": "8.0.4",
4
4
  "description": "Schemas and verification contracts for Nakafa content releases.",
5
5
  "homepage": "https://github.com/nakafaai/aksara#readme",
6
6
  "license": "SEE LICENSE IN LICENSE",