@mark1russell7/room-view 0.3.0 → 0.3.2
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 +28 -0
- package/build/{check-DI_B57qy.js → check-lFfxIUS3.js} +3 -29
- package/build/check-lFfxIUS3.js.map +1 -0
- package/build/index.d.ts +4 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +5 -3
- package/build/index.js.map +1 -1
- package/build/{layers-CYZwt1bH.d.ts → layers-BiiyFJwZ.d.ts} +3 -2
- package/build/layers-BiiyFJwZ.d.ts.map +1 -0
- package/build/{layers-CDNFVXds.js → layers-DmTro5Ny.js} +5 -29
- package/build/layers-DmTro5Ny.js.map +1 -0
- package/build/{level-BERjgyrT.js → level-CvbiwvhH.js} +4 -3
- package/build/{level-BERjgyrT.js.map → level-CvbiwvhH.js.map} +1 -1
- package/build/{level-m-mJ_3Ok.d.ts → level-DmEftWYn.d.ts} +3 -3
- package/build/{level-m-mJ_3Ok.d.ts.map → level-DmEftWYn.d.ts.map} +1 -1
- package/build/marks.d.ts +2 -2
- package/build/marks.js +1 -1
- package/build/plan-import.d.ts +329 -0
- package/build/plan-import.d.ts.map +1 -0
- package/build/plan-import.js +864 -0
- package/build/plan-import.js.map +1 -0
- package/build/room-BQua5eSs.d.ts +124 -0
- package/build/room-BQua5eSs.d.ts.map +1 -0
- package/build/room-CiVZ_07s.js +29 -0
- package/build/room-CiVZ_07s.js.map +1 -0
- package/build/sample.d.ts +2 -2
- package/build/schema.d.ts +3 -3
- package/build/schema.js +4 -3
- package/build/schema.js.map +1 -1
- package/build/{solids-OiTlb_Pm.d.ts → solids-CdJf0U39.d.ts} +3 -123
- package/build/solids-CdJf0U39.d.ts.map +1 -0
- package/build/three.d.ts +2 -1
- package/build/three.d.ts.map +1 -1
- package/build/three.js +2 -1
- package/build/three.js.map +1 -1
- package/build/units-BZmvVyu4.js +30 -0
- package/build/units-BZmvVyu4.js.map +1 -0
- package/package.json +7 -1
- package/build/check-DI_B57qy.js.map +0 -1
- package/build/layers-CDNFVXds.js.map +0 -1
- package/build/layers-CYZwt1bH.d.ts.map +0 -1
- package/build/solids-OiTlb_Pm.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-import.js","names":[],"sources":["../src/plan-import/sheet.ts","../src/plan-import/walls.ts","../src/plan-import/bridges.ts","../src/plan-import/raster.ts","../src/plan-import/importer.ts"],"sourcesContent":["import type { Ring } from \"@mark1russell7/layout-contract\";\nimport type { PlanPoint } from \"../room.ts\";\nimport type { LengthUnit } from \"../units.ts\";\n\n/**\n * A line of a sheet: one straight piece of a stroked path, in the coordinates of the sheet.\n * The y axis of a sheet points down, as in a PDF page after the usual flip.\n */\nexport interface SheetLine {\n readonly from: PlanPoint;\n readonly to: PlanPoint;\n /** The width of the pen, in the units of the sheet. */\n readonly width: number;\n /** The color of the pen, for example `#000000`. */\n readonly color: string;\n /** This value is true when the line is one piece of a curve, for example of the swing of a door. */\n readonly curve?: boolean | undefined;\n}\n\n/** A filled path of a sheet. The rings use the even-odd rule. The sequence of the fills is the paint sequence. */\nexport interface SheetFill {\n readonly color: string;\n readonly rings: readonly Ring[];\n}\n\n/** A text of a sheet. The point `at` is the start of its base line. */\nexport interface SheetText {\n readonly text: string;\n readonly at: PlanPoint;\n /** The height of the text, in the units of the sheet. */\n readonly height: number;\n}\n\n/**\n * A sheet: the vector paths of one floor plan, for example from a page of a PDF file.\n * The scale is the number of units of the sheet for one `unit` of the building. A PDF page at 1/8 inch to the foot has the scale 9 with the unit `ft`.\n */\nexport interface Sheet {\n /** The width of the sheet, in the units of the sheet. */\n readonly width: number;\n /** The height of the sheet, in the units of the sheet. */\n readonly height: number;\n readonly scale: number;\n /** The unit of the building, and of each length of the result. */\n readonly unit: LengthUnit;\n readonly lines: readonly SheetLine[];\n readonly fills?: readonly SheetFill[] | undefined;\n readonly texts?: readonly SheetText[] | undefined;\n}\n\n/** This function gives the name of the pen of a line: its width, a bar, then its color. */\nexport function penOf(line: Pick<SheetLine, \"width\" | \"color\">): string {\n return `${line.width}|${line.color}`;\n}\n\n/** This function gives the length of a line. */\nexport function lineLength(line: Pick<SheetLine, \"from\" | \"to\">): number {\n return Math.hypot(line.to[0] - line.from[0], line.to[1] - line.from[1]);\n}\n\n/** A legend: the name of each fill color, and the fills that are the color samples of the legend. */\nexport interface Legend {\n /** The name of each color. A color with two or more names has the names with a slash between them. */\n readonly names: Readonly<Record<string, string>>;\n /** The position of each sample in the fills of the sheet. A sample is not a room. */\n readonly samples: readonly number[];\n}\n\n/** The options of `readLegend`. Each length is in the units of the sheet, and the defaults suit a sheet in points. */\nexport interface LegendOptions {\n /** The smallest side of a sample. The default is 4. */\n readonly smallest?: number | undefined;\n /** The largest side of a sample. The default is 30. */\n readonly largest?: number | undefined;\n /** The largest distance from the right side of a sample to the start of its text. The default is 12. */\n readonly reach?: number | undefined;\n /** The smallest height of a text of the legend. The default is 2. */\n readonly smallestText?: number | undefined;\n}\n\n/** This function gives the box of a fill: the smallest x, the smallest y, the largest x and the largest y. */\nexport function fillBox(fill: SheetFill): readonly [number, number, number, number] {\n let x0 = Infinity;\n let y0 = Infinity;\n let x1 = -Infinity;\n let y1 = -Infinity;\n for (const ring of fill.rings) {\n for (const [x, y] of ring) {\n x0 = Math.min(x0, x);\n y0 = Math.min(y0, y);\n x1 = Math.max(x1, x);\n y1 = Math.max(y1, y);\n }\n }\n return [x0, y0, x1, y1];\n}\n\n/**\n * This function reads the legend of a sheet. A sample is a small square fill with a text near its right side.\n * The text is the name of the color of the sample.\n */\nexport function readLegend(sheet: Pick<Sheet, \"fills\" | \"texts\">, options: LegendOptions = {}): Legend {\n const smallest = options.smallest ?? 4;\n const largest = options.largest ?? 30;\n const reach = options.reach ?? 12;\n const smallestText = options.smallestText ?? 2;\n const texts = sheet.texts ?? [];\n const names = new Map<string, string[]>();\n const samples: number[] = [];\n (sheet.fills ?? []).forEach((fill, index) => {\n const [x0, y0, x1, y1] = fillBox(fill);\n const w = x1 - x0;\n const h = y1 - y0;\n if (w < smallest || h < smallest || w > largest || h > largest || Math.abs(w - h) > 0.5 * Math.max(w, h)) return;\n const text = texts.find((item) => item.height > smallestText && item.at[0] > x1 && item.at[0] - x1 < reach && item.at[1] > y0 - 2 && item.at[1] < y1 + 4);\n if (text === undefined || /^\\W*$/.test(text.text)) return;\n samples.push(index);\n const list = names.get(fill.color) ?? [];\n const name = text.text.trim();\n if (!list.includes(name)) list.push(name);\n names.set(fill.color, list);\n });\n return { names: Object.fromEntries([...names].map(([color, list]) => [color, list.join(\"/\")])), samples };\n}\n","import type { PlanPoint } from \"../room.ts\";\nimport { lineLength, penOf, type SheetLine } from \"./sheet.ts\";\n\n/** Two parallel lines at a distance from each other. */\nexport interface LinePair {\n /** The position of the first line. */\n readonly a: number;\n /** The position of the second line. */\n readonly b: number;\n /** The distance between the two lines. */\n readonly distance: number;\n /** The length of the common part of the two lines, along their direction. */\n readonly overlap: number;\n}\n\n/** The pairs of `parallelPairs`, and the number of partners on each side of each line. */\nexport interface PairSearch {\n readonly pairs: readonly LinePair[];\n /** The partners of line `i` on its left side are at `2 * i`, and on its right side at `2 * i + 1`. */\n readonly sides: Int32Array;\n}\n\n/** This function gives the direction of a line, from 0 to pi. */\nfunction angleOf(line: SheetLine): number {\n let angle = Math.atan2(line.to[1] - line.from[1], line.to[0] - line.from[0]);\n if (angle < 0) angle += Math.PI;\n if (angle >= Math.PI) angle -= Math.PI;\n return angle;\n}\n\n/** The place of a line in the frame of a direction: its offset across the direction, and its range along it. */\ninterface Frame {\n readonly offset: number;\n readonly low: number;\n readonly high: number;\n}\n\n/** This function gives the place of a line in the frame of the unit direction (`ux`, `uy`). */\nfunction frameOf(line: SheetLine, ux: number, uy: number): Frame {\n const offset = (-uy * (line.from[0] + line.to[0])) / 2 + (ux * (line.from[1] + line.to[1])) / 2;\n const t0 = ux * line.from[0] + uy * line.from[1];\n const t1 = ux * line.to[0] + uy * line.to[1];\n return { offset, low: Math.min(t0, t1), high: Math.max(t0, t1) };\n}\n\n/**\n * This function finds the pairs of parallel lines with a distance from `nearest` to `farthest`, and a common part of `overlap` or more.\n * Two lines are parallel when their directions differ by `tolerance` radians or less. The lines go in buckets by direction, so the search is fast.\n */\nexport function parallelPairs(lines: readonly SheetLine[], nearest: number, farthest: number, overlap: number, tolerance = 0.0175): PairSearch {\n const count = Math.round(Math.PI / tolerance);\n const buckets = new Map<number, { index: number; angle: number; offset: number }[]>();\n lines.forEach((line, index) => {\n const angle = angleOf(line);\n const key = Math.round(angle / tolerance) % count;\n const theta = key * tolerance;\n const { offset } = frameOf(line, Math.cos(theta), Math.sin(theta));\n const bucket = buckets.get(key) ?? [];\n bucket.push({ index, angle, offset });\n buckets.set(key, bucket);\n });\n for (const bucket of buckets.values()) bucket.sort((p, q) => p.offset - q.offset);\n const pairs: LinePair[] = [];\n const sides = new Int32Array(lines.length * 2);\n const slack = 3;\n const lower = (list: readonly { offset: number }[], value: number): number => {\n let low = 0;\n let high = list.length;\n while (low < high) {\n const middle = (low + high) >> 1;\n if (list[middle]!.offset < value) low = middle + 1;\n else high = middle;\n }\n return low;\n };\n for (const [key, bucket] of buckets) {\n for (const next of [key, (key + 1) % count]) {\n const other = buckets.get(next);\n if (other === undefined || (next === key && count === 1)) continue;\n for (const p of bucket) {\n const ux = Math.cos(p.angle);\n const uy = Math.sin(p.angle);\n const pp = frameOf(lines[p.index]!, ux, uy);\n for (let j = lower(other, p.offset - farthest - slack); j < other.length && other[j]!.offset <= p.offset + farthest + slack; j++) {\n const q = other[j]!;\n if (next === key && q.index <= p.index) continue;\n let turn = Math.abs(q.angle - p.angle);\n if (turn > Math.PI / 2) turn = Math.PI - turn;\n if (turn > tolerance) continue;\n const qq = frameOf(lines[q.index]!, ux, uy);\n const across = qq.offset - pp.offset;\n const distance = Math.abs(across);\n if (distance < nearest || distance > farthest) continue;\n const common = Math.min(pp.high, qq.high) - Math.max(pp.low, qq.low);\n if (common < overlap) continue;\n pairs.push({ a: p.index, b: q.index, distance, overlap: common });\n sides[p.index * 2 + (across > 0 ? 0 : 1)]!++;\n sides[q.index * 2 + (across > 0 ? 1 : 0)]!++;\n }\n }\n }\n }\n return { pairs, sides };\n}\n\n/** The options of the search for walls. Each length is in the unit of the sheet. */\nexport interface WallOptions {\n /** The smallest thickness of a wall. The default is 0.25 ft. */\n readonly thinnest?: number | undefined;\n /** The largest thickness of a wall. The default is 1.5 ft. */\n readonly thickest?: number | undefined;\n /** The length of a long line of a pen. The pairs of the long lines tell if a pen is a wall pen. The default is 1.5 ft. */\n readonly longLine?: number | undefined;\n /** The smallest number of long lines of a wall pen. The default is 8. */\n readonly fewestLines?: number | undefined;\n /** The smallest sum of the lengths of the paired long lines of a wall pen. The default is 40 ft. */\n readonly leastLength?: number | undefined;\n /** The smallest common length of the two faces of one wall. The default is 1 ft. */\n readonly shortestWall?: number | undefined;\n}\n\n/** The read of one pen of a sheet. */\nexport interface PenRead {\n /** The name of the pen, as `penOf` gives it. */\n readonly pen: string;\n /** The number of long straight lines of the pen. */\n readonly lines: number;\n /** The part of the long lines with a parallel partner at the distance of a wall, from 0 to 1. */\n readonly paired: number;\n /** The part of the paired lines with partners on one side only, from 0 to 1. The face of a wall has a partner on one side. */\n readonly oneSide: number;\n /** The sum of the lengths of the paired lines, in the `unit` of the sheet. */\n readonly length: number;\n /** The part of the length of all the straight lines of the pen that is in the paired lines, from 0 to 1. A pen of short lines, as a hatch or text, has a small part. */\n readonly lengthShare: number;\n /** This value is true when the pen draws walls. */\n readonly wall: boolean;\n}\n\n/** The limits of the search for walls, in the units of the sheet. */\nexport interface WallLimits {\n readonly thinnest: number;\n readonly thickest: number;\n readonly longLine: number;\n readonly fewestLines: number;\n readonly leastLength: number;\n readonly shortestWall: number;\n}\n\n/**\n * This function reads each pen of the straight lines of a sheet.\n * A pen is a wall pen when most of its long lines have a parallel partner at the distance of a wall thickness.\n * Also, most of the paired lines of a wall pen have the partner on one side only.\n * Also, the paired lines hold most of the length of all the straight lines of the pen. Thus a hatch with some paired lines is not a wall pen.\n *\n * The limits are in the units of the sheet. The pens with the most lines come first.\n */\nexport function readPens(lines: readonly SheetLine[], limits: WallLimits, scale: number): readonly PenRead[] {\n const byPen = new Map<string, SheetLine[]>();\n const straight = new Map<string, number>();\n for (const line of lines) {\n if (line.curve === true) continue;\n const pen = penOf(line);\n straight.set(pen, (straight.get(pen) ?? 0) + lineLength(line));\n if (lineLength(line) < limits.longLine) continue;\n const list = byPen.get(pen) ?? [];\n list.push(line);\n byPen.set(pen, list);\n }\n const reads: PenRead[] = [];\n for (const [pen, list] of byPen) {\n if (list.length < limits.fewestLines) {\n reads.push({ pen, lines: list.length, paired: 0, oneSide: 0, length: 0, lengthShare: 0, wall: false });\n continue;\n }\n const { sides } = parallelPairs(list, limits.thinnest, limits.thickest, limits.longLine);\n let paired = 0;\n let oneSide = 0;\n let length = 0;\n list.forEach((line, index) => {\n const left = sides[2 * index]!;\n const right = sides[2 * index + 1]!;\n if (left === 0 && right === 0) return;\n paired++;\n length += lineLength(line);\n if (left === 0 || right === 0) oneSide++;\n });\n const share = paired / list.length;\n const single = paired === 0 ? 0 : oneSide / paired;\n const lengthShare = length / straight.get(pen)!;\n const wall = share >= 0.5 && single >= 0.6 && lengthShare >= 0.5 && length >= limits.leastLength;\n reads.push({ pen, lines: list.length, paired: share, oneSide: single, length: length / scale, lengthShare, wall });\n }\n return reads.sort((p, q) => q.lines - p.lines);\n}\n\n/** A wall from two parallel lines of a wall pen: the center line of the common part, in the coordinates of the sheet. */\nexport interface WallPair {\n readonly a: number;\n readonly b: number;\n readonly from: PlanPoint;\n readonly to: PlanPoint;\n /** The distance between the two faces, in the units of the sheet. */\n readonly thickness: number;\n}\n\n/**\n * This function gives the walls of the straight lines of the wall pens. Each line keeps its nearest partner, so a face has one wall.\n * The wall is the center line of the common part of the two faces.\n */\nexport function wallPairs(lines: readonly SheetLine[], limits: WallLimits): readonly WallPair[] {\n const { pairs } = parallelPairs(lines, limits.thinnest, limits.thickest, limits.shortestWall);\n const best = new Map<number, LinePair>();\n for (const pair of pairs) {\n for (const index of [pair.a, pair.b]) {\n const known = best.get(index);\n if (known === undefined || pair.distance < known.distance) best.set(index, pair);\n }\n }\n const used = new Set<string>();\n const walls: WallPair[] = [];\n for (const pair of best.values()) {\n const key = `${Math.min(pair.a, pair.b)}:${Math.max(pair.a, pair.b)}`;\n if (used.has(key)) continue;\n used.add(key);\n const a = lines[pair.a]!;\n const b = lines[pair.b]!;\n const length = lineLength(a);\n const ux = (a.to[0] - a.from[0]) / length;\n const uy = (a.to[1] - a.from[1]) / length;\n const nx = -uy;\n const ny = ux;\n const along = [(b.from[0] - a.from[0]) * ux + (b.from[1] - a.from[1]) * uy, (b.to[0] - a.from[0]) * ux + (b.to[1] - a.from[1]) * uy];\n const low = Math.max(0, Math.min(...along));\n const high = Math.min(length, Math.max(...along));\n if (!(high > low)) continue;\n const across = ((b.from[0] - a.from[0]) * nx + (b.from[1] - a.from[1]) * ny + (b.to[0] - a.from[0]) * nx + (b.to[1] - a.from[1]) * ny) / 2;\n const point = (t: number): PlanPoint => [a.from[0] + ux * t + (nx * across) / 2, a.from[1] + uy * t + (ny * across) / 2];\n walls.push({ a: pair.a, b: pair.b, from: point(low), to: point(high), thickness: pair.distance });\n }\n return walls;\n}\n","import type { PlanPoint } from \"../room.ts\";\nimport { lineLength, type SheetLine } from \"./sheet.ts\";\nimport { parallelPairs } from \"./walls.ts\";\n\n/** The options of the search for bridges. Each length is in the `unit` of the sheet. */\nexport interface BridgeOptions {\n /** The smallest width of a gap in a wall. The default is 1.5 ft. */\n readonly narrowest?: number | undefined;\n /** The largest width of a gap in a wall. The default is 4.5 ft. */\n readonly widest?: number | undefined;\n /** The smallest length of the end line of a wall. The default is 0.2 ft. */\n readonly shortestEnd?: number | undefined;\n /** The largest length of the end line of a wall. The default is 1.6 ft. */\n readonly longestEnd?: number | undefined;\n /** Two lines touch when the distance between them is this value or less. The default is 0.225 ft. */\n readonly touch?: number | undefined;\n /** The largest angle between the direction of an open end and the direction to the other end, in degrees. The default is 25. */\n readonly angle?: number | undefined;\n}\n\n/** The limits of the search for bridges, in the units of the sheet. */\nexport interface BridgeLimits {\n readonly narrowest: number;\n readonly widest: number;\n readonly shortestEnd: number;\n readonly longestEnd: number;\n readonly touch: number;\n readonly angle: number;\n}\n\n/** These are the sources of a bridge. `ends` is a pair of end lines of two walls. `open` is a pair of open ends of two lines. */\nexport const BRIDGE_SOURCES: readonly [\"ends\", \"open\"] = [\"ends\", \"open\"];\n\n/** A source of a bridge. */\nexport type BridgeSource = (typeof BRIDGE_SOURCES)[number];\n\n/** A bridge: a gap between two wall ends, in the coordinates of the sheet. A bridge closes a room, and the room record has it as an opening. */\nexport interface Bridge {\n readonly source: BridgeSource;\n /** The line of the bridge from the middle of one wall end to the middle of the other. */\n readonly from: PlanPoint;\n readonly to: PlanPoint;\n /** The thickness of the wall at the bridge. A bridge from open ends has no thickness. */\n readonly thickness: number | undefined;\n /** The lines that close the gap, as the barrier of the rooms. */\n readonly lines: readonly SheetLine[];\n}\n\n/**\n * This function finds the bridges across the gaps in the walls. A gap is from `narrowest` to `widest`.\n *\n * - Two short end lines of walls can be parallel and face each other across a gap. They give two lines, one along each face of the wall.\n * - An open end of a long line, with no other line near it, joins the nearest open end that faces it.\n */\nexport function findBridges(lines: readonly SheetLine[], limits: BridgeLimits): readonly Bridge[] {\n const bridges: Bridge[] = [];\n const ends = lines.filter((line) => {\n const length = lineLength(line);\n return length >= limits.shortestEnd && length <= limits.longestEnd;\n });\n const { pairs } = parallelPairs(ends, limits.narrowest, limits.widest, 0.6 * limits.shortestEnd, 0.06);\n for (const pair of pairs) {\n const a = ends[pair.a]!;\n const b = ends[pair.b]!;\n const width = Math.max(a.width, b.width);\n const color = a.color;\n const straight = Math.hypot(a.from[0] - b.from[0], a.from[1] - b.from[1]) + Math.hypot(a.to[0] - b.to[0], a.to[1] - b.to[1]);\n const crossed = Math.hypot(a.from[0] - b.to[0], a.from[1] - b.to[1]) + Math.hypot(a.to[0] - b.from[0], a.to[1] - b.from[1]);\n const [b0, b1] = straight <= crossed ? [b.from, b.to] : [b.to, b.from];\n bridges.push({\n source: \"ends\",\n from: [(a.from[0] + a.to[0]) / 2, (a.from[1] + a.to[1]) / 2],\n to: [(b.from[0] + b.to[0]) / 2, (b.from[1] + b.to[1]) / 2],\n thickness: (lineLength(a) + lineLength(b)) / 2,\n lines: [\n { from: a.from, to: b0, width, color },\n { from: a.to, to: b1, width, color },\n ],\n });\n }\n\n // The open ends: an end of a long line with no other line near it.\n const cell = Math.max(limits.touch * 3, 1e-9);\n const grid = new Map<string, number[]>();\n const keyOf = (x: number, y: number): string => `${Math.floor(x / cell)},${Math.floor(y / cell)}`;\n lines.forEach((line, index) => {\n const steps = Math.max(1, Math.ceil(lineLength(line) / cell));\n for (let k = 0; k <= steps; k++) {\n const key = keyOf(line.from[0] + ((line.to[0] - line.from[0]) * k) / steps, line.from[1] + ((line.to[1] - line.from[1]) * k) / steps);\n const list = grid.get(key) ?? [];\n if (list[list.length - 1] !== index) list.push(index);\n grid.set(key, list);\n }\n });\n const near = (x: number, y: number, self: number): boolean => {\n const cx = Math.floor(x / cell);\n const cy = Math.floor(y / cell);\n for (let dx = -1; dx <= 1; dx++) {\n for (let dy = -1; dy <= 1; dy++) {\n for (const index of grid.get(`${cx + dx},${cy + dy}`) ?? []) {\n if (index === self) continue;\n const line = lines[index]!;\n const vx = line.to[0] - line.from[0];\n const vy = line.to[1] - line.from[1];\n const square = vx * vx + vy * vy;\n const t = square > 0 ? Math.max(0, Math.min(1, ((x - line.from[0]) * vx + (y - line.from[1]) * vy) / square)) : 0;\n if (Math.hypot(x - line.from[0] - t * vx, y - line.from[1] - t * vy) < limits.touch) return true;\n }\n }\n }\n return false;\n };\n interface End {\n readonly x: number;\n readonly y: number;\n readonly dx: number;\n readonly dy: number;\n readonly line: number;\n }\n const open: End[] = [];\n lines.forEach((line, index) => {\n const length = lineLength(line);\n if (length < limits.longestEnd) return;\n const ux = (line.to[0] - line.from[0]) / length;\n const uy = (line.to[1] - line.from[1]) / length;\n if (!near(line.to[0], line.to[1], index)) open.push({ x: line.to[0], y: line.to[1], dx: ux, dy: uy, line: index });\n if (!near(line.from[0], line.from[1], index)) open.push({ x: line.from[0], y: line.from[1], dx: -ux, dy: -uy, line: index });\n });\n // The search of the partner of an open end looks only in the cells of the widest gap around it.\n const span = Math.max(limits.widest, 1e-9);\n const endGrid = new Map<string, number[]>();\n const spanKey = (x: number, y: number): string => `${Math.floor(x / span)},${Math.floor(y / span)}`;\n open.forEach((end, index) => {\n const key = spanKey(end.x, end.y);\n const list = endGrid.get(key) ?? [];\n list.push(index);\n endGrid.set(key, list);\n });\n const cosine = Math.cos((limits.angle * Math.PI) / 180);\n const best = open.map((end, a) => {\n let found = -1;\n let distance = Infinity;\n const cx = Math.floor(end.x / span);\n const cy = Math.floor(end.y / span);\n for (let dx = -1; dx <= 1; dx++) {\n for (let dy = -1; dy <= 1; dy++) {\n for (const b of endGrid.get(`${cx + dx},${cy + dy}`) ?? []) {\n const other = open[b]!;\n if (a === b || other.line === end.line) continue;\n const gx = other.x - end.x;\n const gy = other.y - end.y;\n const gap = Math.hypot(gx, gy);\n if (gap < limits.narrowest || gap > limits.widest) continue;\n if ((gx * end.dx + gy * end.dy) / gap < cosine) continue;\n if (-(other.dx * end.dx + other.dy * end.dy) < cosine) continue;\n // The sequence of the ends breaks a tie, so the result does not change with the sequence of the cells.\n if (gap < distance || (gap === distance && b < found)) {\n distance = gap;\n found = b;\n }\n }\n }\n }\n return found;\n });\n best.forEach((b, a) => {\n if (b < 0 || best[b] !== a || a > b) return;\n const end = open[a]!;\n const other = open[b]!;\n const line = lines[end.line]!;\n bridges.push({\n source: \"open\",\n from: [end.x, end.y],\n to: [other.x, other.y],\n thickness: undefined,\n lines: [{ from: [end.x, end.y], to: [other.x, other.y], width: line.width, color: line.color }],\n });\n });\n return bridges;\n}\n","import type { Ring } from \"@mark1russell7/layout-contract\";\nimport type { PlanPoint } from \"../room.ts\";\nimport type { SheetLine } from \"./sheet.ts\";\n\n/**\n * A grid of square cells over a sheet. The cell at column `x` and row `y` has the position `y * columns + x` in each array of the grid.\n * The plan import keeps its rasters here: each is specific to the method of the import.\n */\nexport interface Grid {\n readonly columns: number;\n readonly rows: number;\n /** The side of a cell, in the units of the sheet. */\n readonly cell: number;\n}\n\n/** This function gives a grid that covers a sheet. */\nexport function gridOf(width: number, height: number, cell: number): Grid {\n return { columns: Math.max(1, Math.ceil(width / cell)), rows: Math.max(1, Math.ceil(height / cell)), cell };\n}\n\n/** This function sets each cell under a line to 1. A line covers a square of cells around each point, with the half width of its pen, or half a cell or more. */\nexport function stampLines(grid: Grid, barrier: Uint8Array, lines: readonly SheetLine[]): void {\n const { columns, rows, cell } = grid;\n for (const line of lines) {\n const half = Math.max(0.5, line.width / 2 / cell);\n const reach = Math.ceil(half - 0.5);\n const length = Math.hypot(line.to[0] - line.from[0], line.to[1] - line.from[1]) / cell;\n const steps = Math.max(1, Math.ceil(length * 2));\n for (let k = 0; k <= steps; k++) {\n const x = Math.floor((line.from[0] + ((line.to[0] - line.from[0]) * k) / steps) / cell);\n const y = Math.floor((line.from[1] + ((line.to[1] - line.from[1]) * k) / steps) / cell);\n for (let dy = -reach; dy <= reach; dy++) {\n for (let dx = -reach; dx <= reach; dx++) {\n const xx = x + dx;\n const yy = y + dy;\n if (xx >= 0 && yy >= 0 && xx < columns && yy < rows) barrier[yy * columns + xx] = 1;\n }\n }\n }\n }\n}\n\n/** One region of a grid: a set of free cells with a path of side neighbors between each two cells. */\nexport interface GridRegion {\n /** The label of the region, from 1. */\n readonly label: number;\n /** The first cell of the region in the sequence of the grid. */\n readonly first: number;\n readonly cells: number;\n /** The mean column and the mean row of the cells. */\n readonly center: PlanPoint;\n /** This value is true when the region touches the border of the grid. */\n readonly border: boolean;\n /** The number of cell sides between the region and the barrier. */\n readonly perimeter: number;\n}\n\n/** The regions of a grid, and the label of each cell. A barrier cell has the label 0. */\nexport interface GridRegions {\n readonly labels: Int32Array;\n /** The regions in the sequence of their labels. The region with the label `n` is at the position `n - 1`. */\n readonly regions: readonly GridRegion[];\n}\n\n/** This function labels the free regions of a grid, with side neighbors only. The labels go in the sequence of the first cell of each region. */\nexport function labelRegions(grid: Grid, barrier: Uint8Array): GridRegions {\n const { columns, rows } = grid;\n const size = columns * rows;\n const labels = new Int32Array(size);\n const queue = new Int32Array(size);\n const regions: GridRegion[] = [];\n for (let start = 0; start < size; start++) {\n if (barrier[start] !== 0 || labels[start] !== 0) continue;\n const label = regions.length + 1;\n let head = 0;\n let tail = 0;\n queue[tail++] = start;\n labels[start] = label;\n let cells = 0;\n let sumX = 0;\n let sumY = 0;\n let border = false;\n let perimeter = 0;\n while (head < tail) {\n const index = queue[head++]!;\n const x = index % columns;\n const y = (index - x) / columns;\n cells++;\n sumX += x;\n sumY += y;\n if (x === 0 || y === 0 || x === columns - 1 || y === rows - 1) border = true;\n const near = [x > 0 ? index - 1 : -1, x < columns - 1 ? index + 1 : -1, y > 0 ? index - columns : -1, y < rows - 1 ? index + columns : -1];\n for (const next of near) {\n if (next < 0) continue;\n if (barrier[next] !== 0) {\n perimeter++;\n continue;\n }\n if (labels[next] === 0) {\n labels[next] = label;\n queue[tail++] = next;\n }\n }\n }\n regions.push({ label, first: start, cells, center: [sumX / cells, sumY / cells], border, perimeter });\n }\n return { labels, regions };\n}\n\n/**\n * This function gives each cell with its center inside a set of rings to `visit`, by the even-odd rule over all the rings.\n * It goes row by row.\n */\nexport function scanRings(grid: Grid, rings: readonly Ring[], visit: (row: number, first: number, last: number) => void): void {\n const { columns, rows, cell } = grid;\n let top = Infinity;\n let bottom = -Infinity;\n for (const ring of rings) {\n for (const [, y] of ring) {\n top = Math.min(top, y);\n bottom = Math.max(bottom, y);\n }\n }\n if (!(bottom >= top)) return;\n const firstRow = Math.max(0, Math.floor(top / cell));\n const lastRow = Math.min(rows - 1, Math.ceil(bottom / cell));\n for (let y = firstRow; y <= lastRow; y++) {\n const py = (y + 0.5) * cell;\n const xs: number[] = [];\n for (const ring of rings) {\n for (let i = 0; i < ring.length; i++) {\n const [ax, ay] = ring[i]!;\n const [bx, by] = ring[(i + 1) % ring.length]!;\n if (ay <= py !== by <= py) xs.push(ax + ((py - ay) * (bx - ax)) / (by - ay));\n }\n }\n xs.sort((p, q) => p - q);\n for (let k = 0; k + 1 < xs.length; k += 2) {\n const first = Math.max(0, Math.ceil(xs[k]! / cell - 0.5));\n const last = Math.min(columns - 1, Math.floor(xs[k + 1]! / cell - 0.5));\n if (last >= first) visit(y, first, last);\n }\n }\n}\n\n/** This function gives the number of cells of each label with the center inside one ring. */\nexport function ringCells(grid: Grid, labels: Int32Array, ring: Ring): Map<number, number> {\n const counts = new Map<number, number>();\n scanRings(grid, [ring], (row, first, last) => {\n for (let x = first; x <= last; x++) {\n const label = labels[row * grid.columns + x]!;\n if (label !== 0) counts.set(label, (counts.get(label) ?? 0) + 1);\n }\n });\n return counts;\n}\n\n/**\n * This function gives the outline of one region: the cell sides between the region and the other cells, as one ring.\n * The ring goes with the region on its right side in the coordinates of the grid. Thus in a plan with the y axis up, it goes counter-clockwise.\n * A hole of the region is not in the ring. The ring has a corner only where its direction changes.\n */\nexport function regionOutline(grid: Grid, labels: Int32Array, region: Pick<GridRegion, \"label\" | \"first\">): Ring {\n const { columns, rows, cell } = grid;\n const inside = (x: number, y: number): boolean => x >= 0 && y >= 0 && x < columns && y < rows && labels[y * columns + x] === region.label;\n const startX = region.first % columns;\n const startY = (region.first - startX) / columns;\n // The walk starts at the top left corner of the first cell, along its top side. The cells above it and to its left are not in the region.\n let x = startX;\n let y = startY;\n let dx = 1;\n let dy = 0;\n const corners: [number, number][] = [[x * cell, y * cell]];\n const limit = 4 * (columns + 1) * (rows + 1);\n for (let step = 0; step < limit; step++) {\n x += dx;\n y += dy;\n // The cells ahead of the corner, on the left side and on the right side of the direction.\n const left = inside(x + Math.floor((dx + dy) / 2), y + Math.floor((dy - dx) / 2));\n const right = inside(x + Math.floor((dx - dy) / 2), y + Math.floor((dy + dx) / 2));\n let nx = dx;\n let ny = dy;\n if (!right) {\n nx = -dy;\n ny = dx;\n } else if (left) {\n nx = dy;\n ny = -dx;\n }\n if (x === startX && y === startY && nx === 1 && ny === 0) break;\n if (nx !== dx || ny !== dy) corners.push([x * cell, y * cell]);\n dx = nx;\n dy = ny;\n }\n return corners;\n}\n","import { regionArea, type Ring } from \"@mark1russell7/layout-contract\";\nimport { median } from \"@mark1russell7/rigor-statistics\";\nimport { ROOM_SCHEMA, type Floor, type Opening, type OpeningKind, type PlanPoint, type Room, type Wall } from \"../room.ts\";\nimport { unitsPer } from \"../units.ts\";\nimport { findBridges, type Bridge, type BridgeLimits, type BridgeOptions } from \"./bridges.ts\";\nimport { gridOf, labelRegions, regionOutline, ringCells, scanRings, stampLines, type Grid, type GridRegion } from \"./raster.ts\";\nimport { lineLength, penOf, type Legend, type Sheet } from \"./sheet.ts\";\nimport { readPens, wallPairs, type PenRead, type WallLimits, type WallOptions } from \"./walls.ts\";\n\n/** The name of the side of an opening that is outside the building. */\nexport const OUTSIDE = \"outside\";\n\n/** The options of `importPlan`. Each length is in the `unit` of the sheet, and each area is in that unit squared. */\nexport interface ImportOptions {\n /** The legend of the sheet. Without it, the rooms have no use and the area gate has no rings. */\n readonly legend?: Legend | undefined;\n /** The wall pens. The default is each pen that `readPens` reads as a wall pen. */\n readonly wallPens?: readonly string[] | undefined;\n /** The pens of the doors, as barriers of the rooms. The default is the pen with the most curve lines: the pen of the door swings. */\n readonly doorPens?: readonly string[] | undefined;\n readonly walls?: WallOptions | undefined;\n readonly bridges?: BridgeOptions | undefined;\n /** The side of a cell of the grid. The default is 0.1 ft. */\n readonly cell?: number | undefined;\n /** The largest number of cells of the grid. A larger grid gets larger cells. The default is 40 000 000. */\n readonly largestGrid?: number | undefined;\n /** A free region with a smaller area is a speck, not a room. The default is 12 square ft. */\n readonly smallestRoom?: number | undefined;\n /** A free region with a smaller mean width is the space inside a wall, not a room. The mean width is two times the area over the perimeter. The default is 1.6 ft. */\n readonly thinnestRoom?: number | undefined;\n /** The height of each wall. The default is 8 ft. */\n readonly height?: number | undefined;\n /** The height of each opening. The default is 80 in. */\n readonly openingHeight?: number | undefined;\n /** A fill ring with a smaller area is not in the area gate. The default is 15 square ft. */\n readonly smallestRing?: number | undefined;\n /** The limits of the area gate, as parts of the area of a ring. The default is 0.05 and 0.1. */\n readonly gateLimits?: readonly number[] | undefined;\n}\n\n/** One room of a plan import: a free region of the grid inside the building. */\nexport interface ImportedRoom {\n /** The `id` of the room, and of its floor in the room record. */\n readonly id: string;\n /** The name of the fill color under most of the room, from the legend. */\n readonly use?: string | undefined;\n /** The fill color under most of the room. */\n readonly color?: string | undefined;\n /** The area of the cells of the room. */\n readonly area: number;\n /** The mean point of the cells of the room, in the plan. */\n readonly center: PlanPoint;\n}\n\n/** One opening of a plan import: a bridge across a gap in a wall. */\nexport interface ImportedOpening {\n /** The `id` of the opening in the room record. */\n readonly id: string;\n /** The `id` of the wall of the opening in the room record. */\n readonly wall: string;\n readonly kind: OpeningKind;\n readonly source: Bridge[\"source\"];\n /** The room on each side of the opening, or `OUTSIDE`. An opening with no room or a room on the two sides has no sides. */\n readonly sides?: readonly [string, string] | undefined;\n}\n\n/** The kinds of the free regions of the grid. */\nexport const REGION_KINDS: readonly [\"outside\", \"speck\", \"core\", \"room\"] = [\"outside\", \"speck\", \"core\", \"room\"];\n\n/** A kind of a free region of the grid. */\nexport type RegionKind = (typeof REGION_KINDS)[number];\n\n/** One fill ring of the area gate, and the rooms that it holds. */\nexport interface RingFit {\n /** The position of the fill in the fills of the sheet. */\n readonly fill: number;\n /** The position of the ring in the rings of the fill. */\n readonly ring: number;\n readonly use: string;\n /** The area of the ring. */\n readonly area: number;\n /** The rooms that have most of their cells in the ring, and half of their cells or more. */\n readonly rooms: readonly string[];\n /** The sum of the areas of the rooms over the area of the ring, minus 1. A ring with no room has no error. */\n readonly error?: number | undefined;\n}\n\n/** The area gate: each fill ring of a use of the legend against the rooms that it holds. */\nexport interface AreaGate {\n readonly rings: readonly RingFit[];\n /** The number of rings with an error of each limit or less, in the sequence of the limits. */\n readonly within: readonly { readonly limit: number; readonly rings: number }[];\n /** The median of the errors. A gate with no error has no median. */\n readonly median?: number | undefined;\n}\n\n/** The result of a plan import. */\nexport interface PlanImport {\n /**\n * The room record of the level: the walls, one opening for each bridge, and one floor for each room.\n * A wall from two faces has the `id` `wall-` and a number. The wall of a bridge has the `id` `bridge-` and the number of its opening.\n */\n readonly room: Room;\n readonly rooms: readonly ImportedRoom[];\n readonly openings: readonly ImportedOpening[];\n /** The number of free regions of each kind. */\n readonly regions: Readonly<Record<RegionKind, number>>;\n readonly pens: readonly PenRead[];\n readonly wallPens: readonly string[];\n readonly doorPens: readonly string[];\n /** The grid of the rooms. Its cell is in the `unit` of the sheet. */\n readonly grid: Grid;\n readonly gate: AreaGate;\n}\n\n/** The fill colors of a grid: a color number for each cell, or `NO_COLOR`. */\nconst NO_COLOR = 0xffff;\n\n/**\n * This function turns the vector paths of a floor plan into a room record with rooms, walls and openings.\n *\n * 1. A wall pen has long lines with a parallel partner at the distance of a wall thickness. Two such lines give a wall.\n * 2. A bridge closes each gap between two wall ends. The bridge is an opening of the room record.\n * 3. The walls, the door pens and the bridges go on a grid. Each free region of the grid that does not touch the border is a room, a speck or the space in a wall.\n * 4. A room gets the fill color under most of its cells, and its use from the legend.\n * 5. The area gate compares each fill ring of the legend with the rooms that have most of their cells in it.\n *\n * The coordinates of the sheet have the y axis down. The plan of the result has the y axis up, with the bottom left corner of the sheet at the origin.\n */\nexport function importPlan(sheet: Sheet, options: ImportOptions = {}): PlanImport {\n const scale = sheet.scale;\n const feet = unitsPer(\"ft\", sheet.unit);\n // A length in the unit of the sheet, from the option or from its default in feet, in the units of the sheet.\n const sheetLength = (value: number | undefined, defaultFeet: number): number => (value ?? defaultFeet * feet) * scale;\n const areaUnit = (cells: number, cell: number): number => (cells * cell * cell) / (scale * scale);\n const toPlan = (point: PlanPoint): PlanPoint => [tidy(point[0] / scale), tidy((sheet.height - point[1]) / scale)];\n const planRing = (ring: Ring): Ring => ring.map((point) => toPlan(point));\n\n const wallOptions = options.walls ?? {};\n const wallLimits: WallLimits = {\n thinnest: sheetLength(wallOptions.thinnest, 0.25),\n thickest: sheetLength(wallOptions.thickest, 1.5),\n longLine: sheetLength(wallOptions.longLine, 1.5),\n fewestLines: wallOptions.fewestLines ?? 8,\n leastLength: sheetLength(wallOptions.leastLength, 40),\n shortestWall: sheetLength(wallOptions.shortestWall, 1),\n };\n const bridgeOptions = options.bridges ?? {};\n const bridgeLimits: BridgeLimits = {\n narrowest: sheetLength(bridgeOptions.narrowest, 1.5),\n widest: sheetLength(bridgeOptions.widest, 4.5),\n shortestEnd: sheetLength(bridgeOptions.shortestEnd, 0.2),\n longestEnd: sheetLength(bridgeOptions.longestEnd, 1.6),\n touch: sheetLength(bridgeOptions.touch, 0.225),\n angle: bridgeOptions.angle ?? 25,\n };\n\n // 1. The pens and the walls.\n const pens = readPens(sheet.lines, wallLimits, scale);\n const wallPens = options.wallPens ?? pens.filter((read) => read.wall).map((read) => read.pen);\n const curves = new Map<string, number>();\n for (const line of sheet.lines) if (line.curve === true) curves.set(penOf(line), (curves.get(penOf(line)) ?? 0) + 1);\n const swing = [...curves].sort((a, b) => b[1] - a[1])[0];\n const doorPens = options.doorPens ?? (swing === undefined ? [] : [swing[0]]);\n const wallSet = new Set(wallPens);\n const doorSet = new Set(doorPens);\n const wallLines = sheet.lines.filter((line) => wallSet.has(penOf(line)));\n const straight = wallLines.filter((line) => line.curve !== true);\n const doorLines = sheet.lines.filter((line) => doorSet.has(penOf(line)));\n const pairs = wallPairs(straight, wallLimits);\n\n // 2. The bridges.\n const bridges = findBridges(straight, bridgeLimits);\n\n // 3. The grid and its regions.\n let cell = sheetLength(options.cell, 0.1);\n const largest = options.largestGrid ?? 40_000_000;\n const cellsOf = (side: number): number => Math.ceil(sheet.width / side) * Math.ceil(sheet.height / side);\n if (cellsOf(cell) > largest) cell *= Math.sqrt(cellsOf(cell) / largest) * 1.001;\n const grid = gridOf(sheet.width, sheet.height, cell);\n let barrier: Uint8Array | undefined = new Uint8Array(grid.columns * grid.rows);\n stampLines(grid, barrier, wallLines);\n stampLines(grid, barrier, doorLines);\n for (const bridge of bridges) stampLines(grid, barrier, bridge.lines);\n const { labels, regions } = labelRegions(grid, barrier);\n barrier = undefined;\n\n // 4. The fill color of each region.\n const fills = sheet.fills ?? [];\n const samples = new Set(options.legend?.samples ?? []);\n const names = options.legend?.names ?? {};\n const colors = [...new Set(fills.map((fill) => fill.color))];\n const colorIndex = new Map(colors.map((color, index) => [color, index]));\n const paint = new Uint16Array(grid.columns * grid.rows).fill(NO_COLOR);\n fills.forEach((fill, index) => {\n if (samples.has(index)) return;\n const value = colorIndex.get(fill.color)!;\n scanRings(grid, fill.rings, (row, first, last) => paint.fill(value, row * grid.columns + first, row * grid.columns + last + 1));\n });\n const counts = new Map<number, number>();\n for (let index = 0; index < labels.length; index++) {\n const label = labels[index]!;\n const color = paint[index]!;\n if (label === 0 || color === NO_COLOR) continue;\n const key = label * colors.length + color;\n counts.set(key, (counts.get(key) ?? 0) + 1);\n }\n\n const smallest = options.smallestRoom ?? 12 * feet * feet;\n const thinnest = options.thinnestRoom ?? 1.6 * feet;\n const kindOf = (region: GridRegion): RegionKind => {\n if (region.border) return \"outside\";\n const area = areaUnit(region.cells, cell);\n if (area < smallest) return \"speck\";\n const width = (2 * area) / ((region.perimeter * cell) / scale);\n return width < thinnest ? \"core\" : \"room\";\n };\n const kinds = regions.map((region) => kindOf(region));\n const tally: Record<RegionKind, number> = { outside: 0, speck: 0, core: 0, room: 0 };\n for (const kind of kinds) tally[kind]++;\n const idOf = new Map<number, string>();\n const rooms: ImportedRoom[] = [];\n const floors: Floor[] = [];\n regions.forEach((region, index) => {\n if (kinds[index] !== \"room\") return;\n const id = `room-${rooms.length + 1}`;\n idOf.set(region.label, id);\n let best = -1;\n let most = 0;\n for (let color = 0; color < colors.length; color++) {\n const count = counts.get(region.label * colors.length + color) ?? 0;\n if (count > most) {\n most = count;\n best = color;\n }\n }\n const color = best < 0 ? undefined : colors[best];\n const use = color === undefined ? undefined : names[color];\n const center = toPlan([(region.center[0] + 0.5) * cell, (region.center[1] + 0.5) * cell]);\n rooms.push({ id, ...(use === undefined ? {} : { use }), ...(color === undefined ? {} : { color }), area: tidy(areaUnit(region.cells, cell)), center });\n floors.push({ id, ...(use === undefined ? {} : { name: use }), ring: planRing(regionOutline(grid, labels, region)) });\n });\n\n // The walls, and the openings of the bridges with the rooms on their two sides.\n const walls: Wall[] = pairs.map((pair, index) => ({ id: `wall-${index + 1}`, from: toPlan(pair.from), to: toPlan(pair.to), thickness: tidy(pair.thickness / scale) }));\n const wallThickness = walls.length === 0 ? 0.5 * feet : tidy(median(walls.map((wall) => wall.thickness!)));\n const height = options.height ?? 8 * feet;\n const openingHeight = options.openingHeight ?? (80 / 12) * feet;\n const swings = doorLines.filter((line) => line.curve === true).map((line): PlanPoint => [(line.from[0] + line.to[0]) / 2, (line.from[1] + line.to[1]) / 2]);\n const sideOf = (label: number): string | undefined => {\n if (label === 0) return undefined;\n const kind = kinds[label - 1];\n return kind === \"outside\" ? OUTSIDE : kind === \"room\" ? idOf.get(label) : undefined;\n };\n const openings: Opening[] = [];\n const imported: ImportedOpening[] = [];\n bridges.forEach((bridge, index) => {\n const width = lineLength(bridge);\n if (!(width > 0)) return;\n const id = `opening-${index + 1}`;\n const wall = `bridge-${index + 1}`;\n const center: PlanPoint = [(bridge.from[0] + bridge.to[0]) / 2, (bridge.from[1] + bridge.to[1]) / 2];\n const along: PlanPoint = [(bridge.to[0] - bridge.from[0]) / width, (bridge.to[1] - bridge.from[1]) / width];\n const half = (bridge.thickness ?? 0) / 2;\n const reach = width * 1.2 + half;\n const kind: OpeningKind = swings.some((point) => Math.hypot(point[0] - center[0], point[1] - center[1]) <= reach) ? \"door\" : \"gap\";\n const sides = openingSides(grid, labels, center, along, width, half + 8 * feet * scale, sideOf);\n walls.push({ id: wall, from: toPlan(bridge.from), to: toPlan(bridge.to), ...(bridge.thickness === undefined ? {} : { thickness: tidy(bridge.thickness / scale) }) });\n openings.push({ id, wall, kind, offset: 0, width: tidy(width / scale), height: openingHeight });\n imported.push({ id, wall, kind, source: bridge.source, ...(sides === undefined ? {} : { sides }) });\n });\n\n // 5. The area gate.\n const fits: RingFit[] = [];\n const ringArea = options.smallestRing ?? 15 * feet * feet;\n const gateRings: { fill: number; ring: number; use: string; area: number; points: Ring }[] = [];\n fills.forEach((fill, index) => {\n const use = names[fill.color];\n if (use === undefined || samples.has(index)) return;\n fill.rings.forEach((points, ring) => {\n const area = regionArea({ kind: \"polygon\", points }) / (scale * scale);\n if (area >= ringArea) gateRings.push({ fill: index, ring, use, area, points });\n });\n });\n const overlaps = gateRings.map((ring) => ringCells(grid, labels, ring.points));\n const owners = new Map<number, string[]>();\n regions.forEach((region, index) => {\n if (kinds[index] !== \"room\") return;\n let best = -1;\n let most = 0;\n overlaps.forEach((overlap, ring) => {\n const count = overlap.get(region.label) ?? 0;\n if (count > most) {\n most = count;\n best = ring;\n }\n });\n if (best < 0 || most < 0.5 * region.cells) return;\n const list = owners.get(best) ?? [];\n list.push(idOf.get(region.label)!);\n owners.set(best, list);\n });\n const areaOf = new Map(rooms.map((room) => [room.id, room.area]));\n gateRings.forEach((ring, index) => {\n const held = owners.get(index) ?? [];\n const sum = held.reduce((total, id) => total + areaOf.get(id)!, 0);\n fits.push({ fill: ring.fill, ring: ring.ring, use: ring.use, area: tidy(ring.area), rooms: held, ...(held.length === 0 ? {} : { error: sum / ring.area - 1 }) });\n });\n const errors = fits.flatMap((fit) => (fit.error === undefined ? [] : [fit.error]));\n const limits = options.gateLimits ?? [0.05, 0.1];\n const gate: AreaGate = {\n rings: fits,\n within: limits.map((limit) => ({ limit, rings: errors.filter((error) => Math.abs(error) <= limit).length })),\n ...(errors.length === 0 ? {} : { median: median(errors) }),\n };\n\n const room: Room = {\n schema: ROOM_SCHEMA,\n unit: sheet.unit,\n height,\n wallThickness,\n walls,\n ...(openings.length === 0 ? {} : { openings }),\n ...(floors.length === 0 ? {} : { floors }),\n };\n return { room, rooms, openings: imported, regions: tally, pens, wallPens, doorPens, grid: { ...grid, cell: cell / scale }, gate };\n}\n\n/**\n * This function finds the rooms on the two sides of an opening. It goes from the center across the wall in the two directions.\n * It goes past the cells of a speck or of the space in a wall, to the first room or the outside.\n * It tries the center, then two points along the opening.\n */\nfunction openingSides(\n grid: Grid,\n labels: Int32Array,\n center: PlanPoint,\n along: PlanPoint,\n width: number,\n reach: number,\n sideOf: (label: number) => string | undefined,\n): readonly [string, string] | undefined {\n const { columns, rows, cell } = grid;\n const across: PlanPoint = [-along[1], along[0]];\n const side = (sign: number, shift: number): string | undefined => {\n const ox = center[0] + along[0] * shift;\n const oy = center[1] + along[1] * shift;\n for (let t = 0; t <= reach; t += cell / 2) {\n const x = Math.floor((ox + sign * across[0] * t) / cell);\n const y = Math.floor((oy + sign * across[1] * t) / cell);\n if (x < 0 || y < 0 || x >= columns || y >= rows) return undefined;\n const found = sideOf(labels[y * columns + x]!);\n if (found !== undefined) return found;\n }\n return undefined;\n };\n for (const shift of [0, -0.25, 0.25]) {\n const a = side(-1, shift * width);\n const b = side(1, shift * width);\n if (a !== undefined && b !== undefined) return a === b ? undefined : [a, b];\n }\n return undefined;\n}\n\n/** This function puts a calculated length on a grid of 1e-9, so the noise of float arithmetic does not go to a file. */\nfunction tidy(value: number): number {\n return Math.round(value * 1e9) / 1e9 + 0;\n}\n"],"mappings":";;;;;;AAmDA,SAAgB,MAAM,MAAkD;CACtE,OAAO,GAAG,KAAK,MAAM,GAAG,KAAK;AAC/B;;AAGA,SAAgB,WAAW,MAA8C;CACvE,OAAO,KAAK,MAAM,KAAK,GAAG,KAAK,KAAK,KAAK,IAAI,KAAK,GAAG,KAAK,KAAK,KAAK,EAAE;AACxE;;AAuBA,SAAgB,QAAQ,MAA4D;CAClF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uB;CACnC,OAAO,KAAK,MAAM,QAAQ,GAAG,IAAI,MAAM;AACzC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Ring } from "@mark1russell7/layout-contract";
|
|
2
|
+
/** These are the units of length that a room record can use. */
|
|
3
|
+
declare const LENGTH_UNITS: readonly ["m", "cm", "mm", "ft", "in"];
|
|
4
|
+
/** A unit of length of a room record. */
|
|
5
|
+
type LengthUnit = (typeof LENGTH_UNITS)[number];
|
|
6
|
+
/** This function gives the length of one unit in meters. The factor comes from `@mark1russell7/quantity`. */
|
|
7
|
+
declare function metersPer(unit: LengthUnit): number;
|
|
8
|
+
/** This function gives the length of one unit in a different unit. For example, one foot is 12 inches. */
|
|
9
|
+
declare function unitsPer(unit: LengthUnit, other: LengthUnit): number;
|
|
10
|
+
/**
|
|
11
|
+
* The largest length in meters that the model can use: 1 000 km. A larger number in a room record is a mistake.
|
|
12
|
+
* With this limit, each calculation of the model gives a finite number.
|
|
13
|
+
*/
|
|
14
|
+
declare const LARGEST_LENGTH = 1e6;
|
|
15
|
+
/** This function tells if the model can use each value as a length. Such a value is a finite number of meters, with a size of `LARGEST_LENGTH` or less. */
|
|
16
|
+
declare function lengthsInRange(...meters: readonly number[]): boolean;
|
|
17
|
+
/** A point of the plan: `[x, y]`. The plan is the view from above, and the z axis points up. */
|
|
18
|
+
type PlanPoint = readonly [number, number];
|
|
19
|
+
/** The name of the format of a room record. */
|
|
20
|
+
declare const ROOM_SCHEMA = "room/2";
|
|
21
|
+
/** The name of the format of a scene record. */
|
|
22
|
+
declare const SCENE_SCHEMA = "scene/2";
|
|
23
|
+
/**
|
|
24
|
+
* This function tells if a text is the name of a layer: a word, a slash and a version, for example `electrical/1`.
|
|
25
|
+
* The word has lowercase letters, digits and hyphens. Thus a layer name has no colon, and `recordName` gives each record one name.
|
|
26
|
+
*/
|
|
27
|
+
declare function isLayerName(text: string): boolean;
|
|
28
|
+
/** These are the sides of the line of a wall that can have the wall. */
|
|
29
|
+
declare const WALL_SIDES: readonly ["center", "left", "right"];
|
|
30
|
+
/**
|
|
31
|
+
* The side of the line of a wall that has the wall, for a person who looks from `from` to `to`.
|
|
32
|
+
* With `center`, the line is the middle of the wall. With `left` or `right`, the line is one face of the wall.
|
|
33
|
+
*/
|
|
34
|
+
type WallSide = (typeof WALL_SIDES)[number];
|
|
35
|
+
/** These are the faces of a wall, for a person who looks from `from` to `to`. */
|
|
36
|
+
declare const WALL_FACES: readonly ["left", "right"];
|
|
37
|
+
/** A face of a wall. */
|
|
38
|
+
type WallFace = (typeof WALL_FACES)[number];
|
|
39
|
+
/**
|
|
40
|
+
* A wall: a straight line in the plan, with a thickness and a height.
|
|
41
|
+
* A tape measure gives the faces of a wall, so `side` lets the line be a face. Two walls with a common end make a corner.
|
|
42
|
+
*/
|
|
43
|
+
interface Wall {
|
|
44
|
+
readonly id: string;
|
|
45
|
+
readonly from: PlanPoint;
|
|
46
|
+
readonly to: PlanPoint;
|
|
47
|
+
/** The thickness of the wall. The default is `wallThickness` of the room. */
|
|
48
|
+
readonly thickness?: number | undefined;
|
|
49
|
+
/** The height of the wall. The default is `height` of the room. */
|
|
50
|
+
readonly height?: number | undefined;
|
|
51
|
+
/** The side of the line that has the wall. The default is `center`. */
|
|
52
|
+
readonly side?: WallSide | undefined;
|
|
53
|
+
}
|
|
54
|
+
/** These are the kinds of an opening. A window has glass. A door and a gap are empty. */
|
|
55
|
+
declare const OPENING_KINDS: readonly ["door", "window", "gap"];
|
|
56
|
+
/** A kind of opening. */
|
|
57
|
+
type OpeningKind = (typeof OPENING_KINDS)[number];
|
|
58
|
+
/** An opening: a hole through a wall. */
|
|
59
|
+
interface Opening {
|
|
60
|
+
readonly id: string;
|
|
61
|
+
/** The `id` of the wall. */
|
|
62
|
+
readonly wall: string;
|
|
63
|
+
readonly kind: OpeningKind;
|
|
64
|
+
/** The distance along the line of the wall, from `from` to the near edge of the opening. */
|
|
65
|
+
readonly offset: number;
|
|
66
|
+
readonly width: number;
|
|
67
|
+
/** The height of the bottom of the opening above the floor. The default is 0. */
|
|
68
|
+
readonly sill?: number | undefined;
|
|
69
|
+
readonly height: number;
|
|
70
|
+
}
|
|
71
|
+
/** A floor: one area of the plan, for example one room of an apartment. The ring is the line where the floor touches the walls. */
|
|
72
|
+
interface Floor {
|
|
73
|
+
readonly id: string;
|
|
74
|
+
readonly name?: string | undefined;
|
|
75
|
+
readonly ring: Ring;
|
|
76
|
+
}
|
|
77
|
+
/** A room: the walls, the openings and the floors of one room or one apartment. */
|
|
78
|
+
interface Room {
|
|
79
|
+
readonly schema: typeof ROOM_SCHEMA;
|
|
80
|
+
readonly name?: string | undefined;
|
|
81
|
+
/** The unit of each length of the record. */
|
|
82
|
+
readonly unit: LengthUnit;
|
|
83
|
+
/** The height of each wall that has no height of its own. */
|
|
84
|
+
readonly height: number;
|
|
85
|
+
/** The thickness of each wall that has no thickness of its own. */
|
|
86
|
+
readonly wallThickness: number;
|
|
87
|
+
readonly walls: readonly Wall[];
|
|
88
|
+
readonly openings?: readonly Opening[] | undefined;
|
|
89
|
+
readonly floors?: readonly Floor[] | undefined;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A placed object: a box in the room, for example a desk, a rack or a computer.
|
|
93
|
+
* With a `parent`, the position and the turn are relative to that object, whose origin is the center of its bottom.
|
|
94
|
+
*/
|
|
95
|
+
interface PlacedObject {
|
|
96
|
+
readonly id: string;
|
|
97
|
+
/** The class of the object, for example `desk`, `rack` or `computer`. A viewer gives each class a color. */
|
|
98
|
+
readonly kind: string;
|
|
99
|
+
readonly name?: string | undefined;
|
|
100
|
+
/** The size before the turn: along x, along y, and the height. */
|
|
101
|
+
readonly size: readonly [number, number, number];
|
|
102
|
+
/** The point of the plan below the center of the object. */
|
|
103
|
+
readonly at: PlanPoint;
|
|
104
|
+
/** The height of the bottom of the object above the floor, or above the bottom of its parent. The default is 0. */
|
|
105
|
+
readonly lift?: number | undefined;
|
|
106
|
+
/** The turn about the vertical axis in degrees, counter-clockwise from above. The default is 0. */
|
|
107
|
+
readonly turn?: number | undefined;
|
|
108
|
+
/** The `id` of the object that holds this object. */
|
|
109
|
+
readonly parent?: string | undefined;
|
|
110
|
+
}
|
|
111
|
+
/** A scene: one room with its placed objects and the records of its add-ons. Two scenes of one room can be compared. */
|
|
112
|
+
interface Scene {
|
|
113
|
+
readonly schema: typeof SCENE_SCHEMA;
|
|
114
|
+
readonly name?: string | undefined;
|
|
115
|
+
readonly room: Room;
|
|
116
|
+
readonly objects?: readonly PlacedObject[] | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* The records of each add-on, by the name of its layer, for example `electrical/1`. `isLayerName` tells the form of a name.
|
|
119
|
+
* The core keeps each layer and does not read it. `checkLayers` examines the layers with a list of add-ons.
|
|
120
|
+
*/
|
|
121
|
+
readonly layers?: Readonly<Record<string, unknown>> | undefined;
|
|
122
|
+
}
|
|
123
|
+
export { unitsPer as S, LARGEST_LENGTH as _, PlacedObject as a, lengthsInRange as b, Room as c, WALL_FACES as d, WALL_SIDES as f, isLayerName as g, WallSide as h, OpeningKind as i, SCENE_SCHEMA as l, WallFace as m, OPENING_KINDS as n, PlanPoint as o, Wall as p, Opening as r, ROOM_SCHEMA as s, Floor as t, Scene as u, LENGTH_UNITS as v, metersPer as x, LengthUnit as y };
|
|
124
|
+
//# sourceMappingURL=room-BQua5eSs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room-BQua5eSs.d.ts","names":[],"sources":["../src/units.ts","../src/room.ts"],"mappings":";;cAGa;;KAGD,qBAAqB;;iBAGjB,UAAU,MAAM;;iBAKhB,SAAS,MAAM,YAAY,OAAO;;;;;cAQrC;;iBAGG,kBAAkB;;KCrBtB;;cAGC;;cAGA;;;;;iBAMG,YAAY;;cAKf;;;;;KAMD,mBAAmB;;cAGlB;;KAGD,mBAAmB;;;;;UAMd;WACN;WACA,MAAM;WACN,IAAI;;WAEJ;;WAEA;;WAEA,OAAO;;;cAIL;;KAGD,sBAAsB;;UAGjB;WACN;;WAEA;WACA,MAAM;;WAEN;WACA;;WAEA;WACA;;;UAIM;WACN;WACA;WACA,MAAM;;;UAIA;WACN,eAAe;WACf;;WAEA,MAAM;;WAEN;;WAEA;WACA,gBAAgB;WAChB,oBAAoB;WACpB,kBAAkB;;;;;;UAOZ;WACN;;WAEA;WACA;;WAEA;;WAEA,IAAI;;WAEJ;;WAEA;;WAEA;;;UAIM;WACN,eAAe;WACf;WACA,MAAM;WACN,mBAAmB;;;;;WAKnB,SAAS,SAAS"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/room.ts
|
|
2
|
+
/** The name of the format of a room record. */
|
|
3
|
+
const ROOM_SCHEMA = "room/2";
|
|
4
|
+
/** The name of the format of a scene record. */
|
|
5
|
+
const SCENE_SCHEMA = "scene/2";
|
|
6
|
+
/**
|
|
7
|
+
* This function tells if a text is the name of a layer: a word, a slash and a version, for example `electrical/1`.
|
|
8
|
+
* The word has lowercase letters, digits and hyphens. Thus a layer name has no colon, and `recordName` gives each record one name.
|
|
9
|
+
*/
|
|
10
|
+
function isLayerName(text) {
|
|
11
|
+
return /^[a-z][a-z0-9-]*\/[0-9]+$/.test(text);
|
|
12
|
+
}
|
|
13
|
+
/** These are the sides of the line of a wall that can have the wall. */
|
|
14
|
+
const WALL_SIDES = [
|
|
15
|
+
"center",
|
|
16
|
+
"left",
|
|
17
|
+
"right"
|
|
18
|
+
];
|
|
19
|
+
/** These are the faces of a wall, for a person who looks from `from` to `to`. */
|
|
20
|
+
const WALL_FACES = ["left", "right"];
|
|
21
|
+
/** These are the kinds of an opening. A window has glass. A door and a gap are empty. */
|
|
22
|
+
const OPENING_KINDS = [
|
|
23
|
+
"door",
|
|
24
|
+
"window",
|
|
25
|
+
"gap"
|
|
26
|
+
];
|
|
27
|
+
export { WALL_SIDES as a, WALL_FACES as i, ROOM_SCHEMA as n, isLayerName as o, SCENE_SCHEMA as r, OPENING_KINDS as t };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=room-CiVZ_07s.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room-CiVZ_07s.js","names":[],"sources":["../src/room.ts"],"sourcesContent":["import type { Ring } from \"@mark1russell7/layout-contract\";\nimport type { LengthUnit } from \"./units.ts\";\n\n/** A point of the plan: `[x, y]`. The plan is the view from above, and the z axis points up. */\nexport type PlanPoint = readonly [number, number];\n\n/** The name of the format of a room record. */\nexport const ROOM_SCHEMA = \"room/2\";\n\n/** The name of the format of a scene record. */\nexport const SCENE_SCHEMA = \"scene/2\";\n\n/**\n * This function tells if a text is the name of a layer: a word, a slash and a version, for example `electrical/1`.\n * The word has lowercase letters, digits and hyphens. Thus a layer name has no colon, and `recordName` gives each record one name.\n */\nexport function isLayerName(text: string): boolean {\n return /^[a-z][a-z0-9-]*\\/[0-9]+$/.test(text);\n}\n\n/** These are the sides of the line of a wall that can have the wall. */\nexport const WALL_SIDES: readonly [\"center\", \"left\", \"right\"] = [\"center\", \"left\", \"right\"];\n\n/**\n * The side of the line of a wall that has the wall, for a person who looks from `from` to `to`.\n * With `center`, the line is the middle of the wall. With `left` or `right`, the line is one face of the wall.\n */\nexport type WallSide = (typeof WALL_SIDES)[number];\n\n/** These are the faces of a wall, for a person who looks from `from` to `to`. */\nexport const WALL_FACES: readonly [\"left\", \"right\"] = [\"left\", \"right\"];\n\n/** A face of a wall. */\nexport type WallFace = (typeof WALL_FACES)[number];\n\n/**\n * A wall: a straight line in the plan, with a thickness and a height.\n * A tape measure gives the faces of a wall, so `side` lets the line be a face. Two walls with a common end make a corner.\n */\nexport interface Wall {\n readonly id: string;\n readonly from: PlanPoint;\n readonly to: PlanPoint;\n /** The thickness of the wall. The default is `wallThickness` of the room. */\n readonly thickness?: number | undefined;\n /** The height of the wall. The default is `height` of the room. */\n readonly height?: number | undefined;\n /** The side of the line that has the wall. The default is `center`. */\n readonly side?: WallSide | undefined;\n}\n\n/** These are the kinds of an opening. A window has glass. A door and a gap are empty. */\nexport const OPENING_KINDS: readonly [\"door\", \"window\", \"gap\"] = [\"door\", \"window\", \"gap\"];\n\n/** A kind of opening. */\nexport type OpeningKind = (typeof OPENING_KINDS)[number];\n\n/** An opening: a hole through a wall. */\nexport interface Opening {\n readonly id: string;\n /** The `id` of the wall. */\n readonly wall: string;\n readonly kind: OpeningKind;\n /** The distance along the line of the wall, from `from` to the near edge of the opening. */\n readonly offset: number;\n readonly width: number;\n /** The height of the bottom of the opening above the floor. The default is 0. */\n readonly sill?: number | undefined;\n readonly height: number;\n}\n\n/** A floor: one area of the plan, for example one room of an apartment. The ring is the line where the floor touches the walls. */\nexport interface Floor {\n readonly id: string;\n readonly name?: string | undefined;\n readonly ring: Ring;\n}\n\n/** A room: the walls, the openings and the floors of one room or one apartment. */\nexport interface Room {\n readonly schema: typeof ROOM_SCHEMA;\n readonly name?: string | undefined;\n /** The unit of each length of the record. */\n readonly unit: LengthUnit;\n /** The height of each wall that has no height of its own. */\n readonly height: number;\n /** The thickness of each wall that has no thickness of its own. */\n readonly wallThickness: number;\n readonly walls: readonly Wall[];\n readonly openings?: readonly Opening[] | undefined;\n readonly floors?: readonly Floor[] | undefined;\n}\n\n/**\n * A placed object: a box in the room, for example a desk, a rack or a computer.\n * With a `parent`, the position and the turn are relative to that object, whose origin is the center of its bottom.\n */\nexport interface PlacedObject {\n readonly id: string;\n /** The class of the object, for example `desk`, `rack` or `computer`. A viewer gives each class a color. */\n readonly kind: string;\n readonly name?: string | undefined;\n /** The size before the turn: along x, along y, and the height. */\n readonly size: readonly [number, number, number];\n /** The point of the plan below the center of the object. */\n readonly at: PlanPoint;\n /** The height of the bottom of the object above the floor, or above the bottom of its parent. The default is 0. */\n readonly lift?: number | undefined;\n /** The turn about the vertical axis in degrees, counter-clockwise from above. The default is 0. */\n readonly turn?: number | undefined;\n /** The `id` of the object that holds this object. */\n readonly parent?: string | undefined;\n}\n\n/** A scene: one room with its placed objects and the records of its add-ons. Two scenes of one room can be compared. */\nexport interface Scene {\n readonly schema: typeof SCENE_SCHEMA;\n readonly name?: string | undefined;\n readonly room: Room;\n readonly objects?: readonly PlacedObject[] | undefined;\n /**\n * The records of each add-on, by the name of its layer, for example `electrical/1`. `isLayerName` tells the form of a name.\n * The core keeps each layer and does not read it. `checkLayers` examines the layers with a list of add-ons.\n */\n readonly layers?: Readonly<Record<string, unknown>> | undefined;\n}\n"],"mappings":";;AAOA,MAAa,cAAc;;AAG3B,MAAa,eAAe;;;;;AAM5B,SAAgB,YAAY,MAAuB;CACjD,OAAO,4BAA4B,KAAK,IAAI;AAC9C;;AAGA,MAAa,aAAmD;CAAC;CAAU;CAAQ;AAAO;;AAS1F,MAAa,aAAyC,CAAC,QAAQ,OAAO;;AAsBtE,MAAa,gBAAoD;CAAC;CAAQ;CAAU;AAAK"}
|
package/build/sample.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Survey, c as Level } from "./level-
|
|
2
|
-
import {
|
|
1
|
+
import { S as Survey, c as Level } from "./level-DmEftWYn.js";
|
|
2
|
+
import { c as Room, u as Scene } from "./room-BQua5eSs.js";
|
|
3
3
|
/**
|
|
4
4
|
* A sample room in meters. It is not a real room. It has no records of an add-on: the add-ons give their own samples of this room.
|
|
5
5
|
*
|
package/build/schema.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { E as FindingLevel, I as Anchor, a as FileKind, t as AddOn } from "./layers-
|
|
2
|
-
import { S as Survey, c as Level } from "./level-
|
|
3
|
-
import {
|
|
1
|
+
import { E as FindingLevel, I as Anchor, a as FileKind, t as AddOn } from "./layers-BiiyFJwZ.js";
|
|
2
|
+
import { S as Survey, c as Level } from "./level-DmEftWYn.js";
|
|
3
|
+
import { c as Room, u as Scene } from "./room-BQua5eSs.js";
|
|
4
4
|
import * as z from "zod/mini";
|
|
5
5
|
/** The parse context of each read of this entry and of each add-on: the faults have the English messages of zod. */
|
|
6
6
|
export declare const READ_CONTEXT: z.core.ParseContext<z.core.$ZodIssue>;
|
package/build/schema.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as SQUARE_TURNS, i as LEVEL_SCHEMA, u as SURVEY_SCHEMA } from "./level-
|
|
3
|
-
import {
|
|
1
|
+
import { t as FILE_KINDS } from "./layers-DmTro5Ny.js";
|
|
2
|
+
import { c as SQUARE_TURNS, i as LEVEL_SCHEMA, u as SURVEY_SCHEMA } from "./level-CvbiwvhH.js";
|
|
3
|
+
import { a as WALL_SIDES, i as WALL_FACES, n as ROOM_SCHEMA, o as isLayerName, r as SCENE_SCHEMA, t as OPENING_KINDS } from "./room-CiVZ_07s.js";
|
|
4
|
+
import { n as LENGTH_UNITS } from "./units-BZmvVyu4.js";
|
|
4
5
|
import * as z from "zod/mini";
|
|
5
6
|
import en from "zod/v4/locales/en.js";
|
|
6
7
|
// src/schema.ts
|
package/build/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import * as z from \"zod/mini\";\nimport en from \"zod/v4/locales/en.js\";\nimport type { Anchor } from \"./anchors.ts\";\nimport type { FindingLevel } from \"./check.ts\";\nimport { FILE_KINDS, type AddOn, type FileKind } from \"./layers.ts\";\nimport { LEVEL_SCHEMA, type Level } from \"./level.ts\";\nimport { isLayerName, OPENING_KINDS, ROOM_SCHEMA, SCENE_SCHEMA, WALL_FACES, WALL_SIDES, type Room, type Scene } from \"./room.ts\";\nimport { SQUARE_TURNS, SURVEY_SCHEMA, type Survey } from \"./survey.ts\";\nimport { LENGTH_UNITS } from \"./units.ts\";\n\n// The schemas use `zod/mini`: a page gets only the parts of zod that the schemas use.\n// `zod/mini` has no messages, so each read gives the English messages of zod with `READ_CONTEXT`. It changes no setting of zod.\n\n/** The parse context of each read of this entry and of each add-on: the faults have the English messages of zod. */\nexport const READ_CONTEXT: z.core.ParseContext<z.core.$ZodIssue> = { error: en().localeError };\n\nconst id = z.string().check(z.minLength(1));\nconst planPoint = z.readonly(z.tuple([z.number(), z.number()]));\n\nconst point3 = z.readonly(z.tuple([z.number(), z.number(), z.number()]));\n\n/**\n * The schema of an anchor. It examines the form of the record, and it refuses a field that the surface of the anchor does not have.\n * The schema of an add-on uses it for the anchor of each record. `checkAnchor` examines the meaning of an anchor with a correct form.\n */\nexport const anchorSchema: z.ZodMiniType<Anchor> = z.discriminatedUnion(\"on\", [\n z.strictObject({ on: z.literal(\"wall\"), wall: id, face: z.enum(WALL_FACES), offset: z.number(), height: z.number() }),\n z.strictObject({ on: z.literal(\"floor\"), at: planPoint, floor: z.optional(id) }),\n z.strictObject({ on: z.literal(\"ceiling\"), at: planPoint, floor: z.optional(id) }),\n z.strictObject({ on: z.literal(\"object\"), object: id, at: z.optional(point3), out: z.optional(point3) }),\n]);\n\nconst wall = z.strictObject({\n id,\n from: planPoint,\n to: planPoint,\n thickness: z.optional(z.number()),\n height: z.optional(z.number()),\n side: z.optional(z.enum(WALL_SIDES)),\n});\n\nconst opening = z.strictObject({\n id,\n wall: id,\n kind: z.enum(OPENING_KINDS),\n offset: z.number(),\n width: z.number(),\n sill: z.optional(z.number()),\n height: z.number(),\n});\n\nconst floor = z.strictObject({\n id,\n name: z.optional(z.string()),\n ring: z.readonly(z.array(planPoint)),\n});\n\n/**\n * The schema of a room record. It examines the form of the record: the fields, their types and the finite numbers.\n * It refuses a field that the format does not have. `checkRoom` examines the meaning of a record with a correct form.\n */\nexport const roomSchema: z.ZodMiniType<Room> = z.strictObject({\n schema: z.literal(ROOM_SCHEMA),\n name: z.optional(z.string()),\n unit: z.enum(LENGTH_UNITS),\n height: z.number(),\n wallThickness: z.number(),\n walls: z.readonly(z.array(wall)),\n openings: z.optional(z.readonly(z.array(opening))),\n floors: z.optional(z.readonly(z.array(floor))),\n});\n\nconst placedObject = z.strictObject({\n id,\n kind: id,\n name: z.optional(z.string()),\n size: point3,\n at: planPoint,\n lift: z.optional(z.number()),\n turn: z.optional(z.number()),\n parent: z.optional(id),\n});\n\n// The layers of a scene, of a survey or of a level. The core does not read a layer, so it keeps each value. The add-on of a layer examines its form.\nconst layerName = z.string().check(z.refine(isLayerName, \"A layer name is a word, a slash and a version, for example electrical/1.\"));\nconst layers = z.optional(z.readonly(z.record(layerName, z.unknown())));\n\n/**\n * The schema of a scene record. It examines the form of the record, and it refuses a field that the format does not have.\n * `checkScene` examines the meaning of a record with a correct form.\n */\nexport const sceneSchema: z.ZodMiniType<Scene> = z.strictObject({\n schema: z.literal(SCENE_SCHEMA),\n name: z.optional(z.string()),\n room: roomSchema,\n objects: z.optional(z.readonly(z.array(placedObject))),\n layers,\n});\n\nconst surveySide = z.strictObject({\n id,\n length: z.number(),\n turn: z.union([z.enum(SQUARE_TURNS), z.number()]),\n thickness: z.optional(z.number()),\n height: z.optional(z.number()),\n});\n\nconst surveyCheck = z.strictObject({\n id,\n from: id,\n to: id,\n length: z.number(),\n});\n\nconst surveyObject = z.strictObject({\n id,\n kind: id,\n name: z.optional(z.string()),\n wall: z.optional(id),\n on: z.optional(id),\n offset: z.number(),\n width: z.number(),\n depth: z.number(),\n height: z.number(),\n gap: z.optional(z.number()),\n lift: z.optional(z.number()),\n});\n\n/**\n * The schema of a survey record. It examines the form of the record, and it refuses a field that the format does not have.\n * `expandSurvey` makes the room record of a survey with a correct form, and `checkRoom` examines that room record.\n */\nexport const surveySchema: z.ZodMiniType<Survey> = z.strictObject({\n schema: z.literal(SURVEY_SCHEMA),\n name: z.optional(z.string()),\n unit: z.enum(LENGTH_UNITS),\n height: z.number(),\n wallThickness: z.number(),\n sides: z.readonly(z.array(surveySide)),\n start: z.optional(planPoint),\n heading: z.optional(z.number()),\n checks: z.optional(z.readonly(z.array(surveyCheck))),\n openings: z.optional(z.readonly(z.array(opening))),\n objects: z.optional(z.readonly(z.array(surveyObject))),\n layers,\n});\n\nconst connectionEnd = z.strictObject({\n room: id,\n opening: id,\n});\n\n/**\n * The schema of a level record. It examines the form of the record and of each survey, and it refuses a field that the format does not have.\n * `expandLevel` makes the room record of a level with a correct form, and `checkRoom` examines that room record.\n */\nexport const levelSchema: z.ZodMiniType<Level> = z.strictObject({\n schema: z.literal(LEVEL_SCHEMA),\n name: z.optional(z.string()),\n unit: z.enum(LENGTH_UNITS),\n rooms: z.readonly(z.array(z.strictObject({ id, survey: surveySchema }))),\n connections: z.optional(z.readonly(z.array(z.strictObject({ id, from: connectionEnd, to: connectionEnd, thickness: z.optional(z.number()) })))),\n layers,\n});\n\n/** The record of each kind, in version 2. */\nexport interface KindRecords {\n readonly room: Room;\n readonly scene: Scene;\n readonly survey: Survey;\n readonly level: Level;\n}\n\n/** These are the codes of the findings of `readRecord`. */\nexport const READ_CODES: readonly [\"read-both\"] = [\"read-both\"];\n\n/** A finding of the read of a record of version 1. The read keeps the record, so a finding is not an error. */\nexport interface ReadFinding {\n readonly level: FindingLevel;\n /** A code of `READ_CODES`. */\n readonly code: string;\n /** The key of the layer in the record. */\n readonly layer: string;\n /** The `id` of the room of a level with the finding. A finding of the record has none. */\n readonly room?: string | undefined;\n /** The finding in plain words. */\n readonly message: string;\n}\n\n/** The result of `readRecord`: the record in version 2, its kind and its version in the file, or the faults of its form. */\nexport type RecordRead =\n | {\n readonly [Kind in FileKind]: {\n readonly ok: true;\n readonly kind: Kind;\n readonly record: KindRecords[Kind];\n /** The version of the format in the file. */\n readonly version: 1 | 2;\n readonly findings: readonly ReadFinding[];\n };\n }[FileKind]\n | { readonly ok: false; readonly errors: readonly string[] };\n\nconst KIND_NAMES: { readonly [Kind in FileKind]: string } = { room: ROOM_SCHEMA, scene: SCENE_SCHEMA, survey: SURVEY_SCHEMA, level: LEVEL_SCHEMA };\n\ntype Json = Readonly<Record<string, unknown>>;\n\n/** This function tells if a value is a JSON object. */\nfunction isJson(value: unknown): value is Json {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** This function gives the schema name of version 2 for a nested record of version 1. A different name stays, so the read tells its fault. */\nfunction newName(record: Json, kind: FileKind): unknown {\n return record[\"schema\"] === `${kind}/1` ? KIND_NAMES[kind] : record[\"schema\"];\n}\n\n/** This function gives the faults of a zod read. Each fault names its place in the record, for example `rooms.0.survey.sides`. */\nfunction faultsOf(error: z.core.$ZodError): readonly string[] {\n return error.issues.map((issue) => `${issue.path.length === 0 ? \"The record\" : `\"${issue.path.map(String).join(\".\")}\"`}: ${issue.message}`);\n}\n\n/**\n * This function reads the JSON of a record of the core in version 1 or in version 2. The record is a room, a scene, a survey or a level.\n * The result is the record in version 2. The schemas of this entry examine its form.\n *\n * A record of version 1 kept the records of some topics in fields of its own. For each add-on of the list with the read `v1`:\n *\n * - The read removes the fields of the add-on from the record, from each object and from each nested record.\n * - The function `read` of the add-on gives the layer of these fields. For a scene, this layer has the records of its room too.\n * For a level, the level record and the survey of each room get a layer.\n * - A record that has the layer and the old fields keeps the layer. The finding `read-both` tells it.\n *\n * A field of version 1 that no add-on of the list removes is a fault of the form. A room record has no layers.\n * Thus a `room/1` with old records gives a `scene/2` with the room and the layers, and a `room/1` with none gives a `room/2`.\n */\nexport function readRecord(value: unknown, addOns: readonly AddOn<unknown>[] = []): RecordRead {\n if (!isJson(value)) return { ok: false, errors: [\"The record is not a JSON object.\"] };\n const name = value[\"schema\"];\n const kind = FILE_KINDS.find((each) => KIND_NAMES[each] === name);\n if (kind !== undefined) return parsed(kind, value, 2, []);\n const old = FILE_KINDS.find((each) => `${each}/1` === name);\n if (old === undefined) return { ok: false, errors: [`The record has no known format: \"schema\" is ${JSON.stringify(name) ?? \"missing\"}.`] };\n const readers = addOns.filter((addOn) => addOn.v1 !== undefined);\n const findings: ReadFinding[] = [];\n const errors: string[] = [];\n const without = (record: Json, of: FileKind | \"object\"): Record<string, unknown> => {\n const gone = new Set(readers.flatMap((addOn) => addOn.v1?.fields[of] ?? []));\n return Object.fromEntries(Object.entries(record).filter(([key]) => !gone.has(key)));\n };\n const objectsOf = (record: Record<string, unknown>): void => {\n const objects = record[\"objects\"];\n if (Array.isArray(objects)) record[\"objects\"] = objects.map((object: unknown) => (isJson(object) ? without(object, \"object\") : object));\n };\n // The layers of the old fields of one record. A layer that the record has already stays.\n const withLayers = (record: Record<string, unknown>, raw: Json, of: FileKind, room?: string): void => {\n const given = isJson(raw[\"layers\"]) ? raw[\"layers\"] : {};\n const layers: Record<string, unknown> = { ...given };\n for (const addOn of readers) {\n const read = addOn.v1?.read(raw, of);\n if (read === undefined) continue;\n if (!read.ok) {\n errors.push(...read.errors);\n continue;\n }\n if (Object.hasOwn(given, addOn.schema)) {\n findings.push({\n level: \"warning\",\n code: \"read-both\",\n layer: addOn.schema,\n ...(room === undefined ? {} : { room }),\n message: `The record has the layer \"${addOn.schema}\" and its old fields. The layer stays, and the old fields go.`,\n });\n continue;\n }\n layers[addOn.schema] = read.layer;\n }\n if (Object.keys(layers).length > 0) record[\"layers\"] = layers;\n };\n const surveyOf = (raw: Json, room?: string): Record<string, unknown> => {\n const record = { ...without(raw, \"survey\"), schema: newName(raw, \"survey\") };\n objectsOf(record);\n withLayers(record, raw, \"survey\", room);\n return record;\n };\n const roomOf = (raw: unknown): unknown => (isJson(raw) ? { ...without(raw, \"room\"), schema: newName(raw, \"room\") } : raw);\n let next: unknown;\n let made: FileKind = old;\n if (old === \"survey\") next = surveyOf(value);\n else if (old === \"level\") {\n const level: Record<string, unknown> = { ...without(value, \"level\"), schema: LEVEL_SCHEMA };\n const rooms = value[\"rooms\"];\n if (Array.isArray(rooms)) {\n level[\"rooms\"] = rooms.map((room: unknown) => {\n if (!isJson(room) || !isJson(room[\"survey\"])) return room;\n return { ...room, survey: surveyOf(room[\"survey\"], typeof room[\"id\"] === \"string\" ? room[\"id\"] : undefined) };\n });\n }\n withLayers(level, value, \"level\");\n next = level;\n } else if (old === \"scene\") {\n const scene: Record<string, unknown> = { ...without(value, \"scene\"), schema: SCENE_SCHEMA, room: roomOf(value[\"room\"]) };\n objectsOf(scene);\n withLayers(scene, value, \"scene\");\n next = scene;\n } else {\n // A room record has no layers, so the layers of its old fields need a scene.\n const scene: Record<string, unknown> = { schema: SCENE_SCHEMA, room: roomOf(value) };\n withLayers(scene, value, \"room\");\n if (scene[\"layers\"] === undefined) next = scene[\"room\"];\n else {\n next = scene;\n made = \"scene\";\n }\n }\n if (errors.length > 0) return { ok: false, errors };\n return parsed(made, next, 1, findings);\n}\n\n/** This function reads a record of version 2 with the schema of its kind. */\nfunction parsed(kind: FileKind, value: unknown, version: 1 | 2, findings: readonly ReadFinding[]): RecordRead {\n if (kind === \"room\") {\n const read = roomSchema.safeParse(value, READ_CONTEXT);\n return read.success ? { ok: true, kind, record: read.data, version, findings } : { ok: false, errors: faultsOf(read.error) };\n }\n if (kind === \"scene\") {\n const read = sceneSchema.safeParse(value, READ_CONTEXT);\n return read.success ? { ok: true, kind, record: read.data, version, findings } : { ok: false, errors: faultsOf(read.error) };\n }\n if (kind === \"survey\") {\n const read = surveySchema.safeParse(value, READ_CONTEXT);\n return read.success ? { ok: true, kind, record: read.data, version, findings } : { ok: false, errors: faultsOf(read.error) };\n }\n const read = levelSchema.safeParse(value, READ_CONTEXT);\n return read.success ? { ok: true, kind, record: read.data, version, findings } : { ok: false, errors: faultsOf(read.error) };\n}\n"],"mappings":";;;;;;;AAcA,MAAa,eAAsD,EAAE,OAAO,GAAG,CAAC,CAAC,YAAY;AAE7F,MAAM,KAAK,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAC1C,MAAM,YAAY,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAE9D,MAAM,SAAS,EAAE,SAAS,EAAE,MAAM;CAAC,EAAE,OAAO;CAAG,EAAE,OAAO;CAAG,EAAE,OAAO;AAAC,CAAC,CAAC;;;;;AAMvE,MAAa,eAAsC,EAAE,mBAAmB,MAAM;CAC5E,EAAE,aAAa;EAAE,IAAI,EAAE,QAAQ,MAAM;EAAG,MAAM;EAAI,MAAM,EAAE,KAAK,UAAU;EA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EAAE;CAC7H;CACA,IAAI,SAAS,SAAS;EACpB,MAAM,OAAO,YAAY,UAAU,OAAO,YAAY;EACtD,OAAO,KAAK,UAAU;GAAE,IAAI;GAAM;GAAM,QAAQ,KAAK;GAAM;GAAS;EAAS,IAAI;GAAE,IAAI;GAAO,QAAQ,SAAS,KAAK,KAAK;EAAE;CAC7H;CACA,IAAI,SAAS,UAAU;EACrB,MAAM,OAAO,aAAa,UAAU,OAAO,YAAY;EACvD,OAAO,KAAK,UAAU;GAAE,IAAI;GAAM;GAAM,QAAQ,KAAK;GAAM;GAAS;EAAS,IAAI;GAAE,IAAI;GAAO,QAAQ,SAAS,KAAK,KAAK;EAAE;CAC7H;CACA,MAAM,OAAO,YAAY,UAAU,OAAO,YAAY;CACtD,OAAO,KAAK,UAAU;EAAE,IAAI;EAAM;EAAM,QAAQ,KAAK;EAAM;EAAS;CAAS,IAAI;EAAE,IAAI;EAAO,QAAQ,SAAS,KAAK,KAAK;CAAE;AAC7H"}
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import * as z from \"zod/mini\";\nimport en from \"zod/v4/locales/en.js\";\nimport type { Anchor } from \"./anchors.ts\";\nimport type { FindingLevel } from \"./check.ts\";\nimport { FILE_KINDS, type AddOn, type FileKind } from \"./layers.ts\";\nimport { LEVEL_SCHEMA, type Level } from \"./level.ts\";\nimport { isLayerName, OPENING_KINDS, ROOM_SCHEMA, SCENE_SCHEMA, WALL_FACES, WALL_SIDES, type Room, type Scene } from \"./room.ts\";\nimport { SQUARE_TURNS, SURVEY_SCHEMA, type Survey } from \"./survey.ts\";\nimport { LENGTH_UNITS } from \"./units.ts\";\n\n// The schemas use `zod/mini`: a page gets only the parts of zod that the schemas use.\n// `zod/mini` has no messages, so each read gives the English messages of zod with `READ_CONTEXT`. It changes no setting of zod.\n\n/** The parse context of each read of this entry and of each add-on: the faults have the English messages of zod. */\nexport const READ_CONTEXT: z.core.ParseContext<z.core.$ZodIssue> = { error: en().localeError };\n\nconst id = z.string().check(z.minLength(1));\nconst planPoint = z.readonly(z.tuple([z.number(), z.number()]));\n\nconst point3 = z.readonly(z.tuple([z.number(), z.number(), z.number()]));\n\n/**\n * The schema of an anchor. It examines the form of the record, and it refuses a field that the surface of the anchor does not have.\n * The schema of an add-on uses it for the anchor of each record. `checkAnchor` examines the meaning of an anchor with a correct form.\n */\nexport const anchorSchema: z.ZodMiniType<Anchor> = z.discriminatedUnion(\"on\", [\n z.strictObject({ on: z.literal(\"wall\"), wall: id, face: z.enum(WALL_FACES), offset: z.number(), height: z.number() }),\n z.strictObject({ on: z.literal(\"floor\"), at: planPoint, floor: z.optional(id) }),\n z.strictObject({ on: z.literal(\"ceiling\"), at: planPoint, floor: z.optional(id) }),\n z.strictObject({ on: z.literal(\"object\"), object: id, at: z.optional(point3), out: z.optional(point3) }),\n]);\n\nconst wall = z.strictObject({\n id,\n from: planPoint,\n to: planPoint,\n thickness: z.optional(z.number()),\n height: z.optional(z.number()),\n side: z.optional(z.enum(WALL_SIDES)),\n});\n\nconst opening = z.strictObject({\n id,\n wall: id,\n kind: z.enum(OPENING_KINDS),\n offset: z.number(),\n width: z.number(),\n sill: z.optional(z.number()),\n height: z.number(),\n});\n\nconst floor = z.strictObject({\n id,\n name: z.optional(z.string()),\n ring: z.readonly(z.array(planPoint)),\n});\n\n/**\n * The schema of a room record. It examines the form of the record: the fields, their types and the finite numbers.\n * It refuses a field that the format does not have. `checkRoom` examines the meaning of a record with a correct form.\n */\nexport const roomSchema: z.ZodMiniType<Room> = z.strictObject({\n schema: z.literal(ROOM_SCHEMA),\n name: z.optional(z.string()),\n unit: z.enum(LENGTH_UNITS),\n height: z.number(),\n wallThickness: z.number(),\n walls: z.readonly(z.array(wall)),\n openings: z.optional(z.readonly(z.array(opening))),\n floors: z.optional(z.readonly(z.array(floor))),\n});\n\nconst placedObject = z.strictObject({\n id,\n kind: id,\n name: z.optional(z.string()),\n size: point3,\n at: planPoint,\n lift: z.optional(z.number()),\n turn: z.optional(z.number()),\n parent: z.optional(id),\n});\n\n// The layers of a scene, of a survey or of a level. The core does not read a layer, so it keeps each value. The add-on of a layer examines its form.\nconst layerName = z.string().check(z.refine(isLayerName, \"A layer name is a word, a slash and a version, for example electrical/1.\"));\nconst layers = z.optional(z.readonly(z.record(layerName, z.unknown())));\n\n/**\n * The schema of a scene record. It examines the form of the record, and it refuses a field that the format does not have.\n * `checkScene` examines the meaning of a record with a correct form.\n */\nexport const sceneSchema: z.ZodMiniType<Scene> = z.strictObject({\n schema: z.literal(SCENE_SCHEMA),\n name: z.optional(z.string()),\n room: roomSchema,\n objects: z.optional(z.readonly(z.array(placedObject))),\n layers,\n});\n\nconst surveySide = z.strictObject({\n id,\n length: z.number(),\n turn: z.union([z.enum(SQUARE_TURNS), z.number()]),\n thickness: z.optional(z.number()),\n height: z.optional(z.number()),\n});\n\nconst surveyCheck = z.strictObject({\n id,\n from: id,\n to: id,\n length: z.number(),\n});\n\nconst surveyObject = z.strictObject({\n id,\n kind: id,\n name: z.optional(z.string()),\n wall: z.optional(id),\n on: z.optional(id),\n offset: z.number(),\n width: z.number(),\n depth: z.number(),\n height: z.number(),\n gap: z.optional(z.number()),\n lift: z.optional(z.number()),\n});\n\n/**\n * The schema of a survey record. It examines the form of the record, and it refuses a field that the format does not have.\n * `expandSurvey` makes the room record of a survey with a correct form, and `checkRoom` examines that room record.\n */\nexport const surveySchema: z.ZodMiniType<Survey> = z.strictObject({\n schema: z.literal(SURVEY_SCHEMA),\n name: z.optional(z.string()),\n unit: z.enum(LENGTH_UNITS),\n height: z.number(),\n wallThickness: z.number(),\n sides: z.readonly(z.array(surveySide)),\n start: z.optional(planPoint),\n heading: z.optional(z.number()),\n checks: z.optional(z.readonly(z.array(surveyCheck))),\n openings: z.optional(z.readonly(z.array(opening))),\n objects: z.optional(z.readonly(z.array(surveyObject))),\n layers,\n});\n\nconst connectionEnd = z.strictObject({\n room: id,\n opening: id,\n});\n\n/**\n * The schema of a level record. It examines the form of the record and of each survey, and it refuses a field that the format does not have.\n * `expandLevel` makes the room record of a level with a correct form, and `checkRoom` examines that room record.\n */\nexport const levelSchema: z.ZodMiniType<Level> = z.strictObject({\n schema: z.literal(LEVEL_SCHEMA),\n name: z.optional(z.string()),\n unit: z.enum(LENGTH_UNITS),\n rooms: z.readonly(z.array(z.strictObject({ id, survey: surveySchema }))),\n connections: z.optional(z.readonly(z.array(z.strictObject({ id, from: connectionEnd, to: connectionEnd, thickness: z.optional(z.number()) })))),\n layers,\n});\n\n/** The record of each kind, in version 2. */\nexport interface KindRecords {\n readonly room: Room;\n readonly scene: Scene;\n readonly survey: Survey;\n readonly level: Level;\n}\n\n/** These are the codes of the findings of `readRecord`. */\nexport const READ_CODES: readonly [\"read-both\"] = [\"read-both\"];\n\n/** A finding of the read of a record of version 1. The read keeps the record, so a finding is not an error. */\nexport interface ReadFinding {\n readonly level: FindingLevel;\n /** A code of `READ_CODES`. */\n readonly code: string;\n /** The key of the layer in the record. */\n readonly layer: string;\n /** The `id` of the room of a level with the finding. A finding of the record has none. */\n readonly room?: string | undefined;\n /** The finding in plain words. */\n readonly message: string;\n}\n\n/** The result of `readRecord`: the record in version 2, its kind and its version in the file, or the faults of its form. */\nexport type RecordRead =\n | {\n readonly [Kind in FileKind]: {\n readonly ok: true;\n readonly kind: Kind;\n readonly record: KindRecords[Kind];\n /** The version of the format in the file. */\n readonly version: 1 | 2;\n readonly findings: readonly ReadFinding[];\n };\n }[FileKind]\n | { readonly ok: false; readonly errors: readonly string[] };\n\nconst KIND_NAMES: { readonly [Kind in FileKind]: string } = { room: ROOM_SCHEMA, scene: SCENE_SCHEMA, survey: SURVEY_SCHEMA, level: LEVEL_SCHEMA };\n\ntype Json = Readonly<Record<string, unknown>>;\n\n/** This function tells if a value is a JSON object. */\nfunction isJson(value: unknown): value is Json {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** This function gives the schema name of version 2 for a nested record of version 1. A different name stays, so the read tells its fault. */\nfunction newName(record: Json, kind: FileKind): unknown {\n return record[\"schema\"] === `${kind}/1` ? KIND_NAMES[kind] : record[\"schema\"];\n}\n\n/** This function gives the faults of a zod read. Each fault names its place in the record, for example `rooms.0.survey.sides`. */\nfunction faultsOf(error: z.core.$ZodError): readonly string[] {\n return error.issues.map((issue) => `${issue.path.length === 0 ? \"The record\" : `\"${issue.path.map(String).join(\".\")}\"`}: ${issue.message}`);\n}\n\n/**\n * This function reads the JSON of a record of the core in version 1 or in version 2. The record is a room, a scene, a survey or a level.\n * The result is the record in version 2. The schemas of this entry examine its form.\n *\n * A record of version 1 kept the records of some topics in fields of its own. For each add-on of the list with the read `v1`:\n *\n * - The read removes the fields of the add-on from the record, from each object and from each nested record.\n * - The function `read` of the add-on gives the layer of these fields. For a scene, this layer has the records of its room too.\n * For a level, the level record and the survey of each room get a layer.\n * - A record that has the layer and the old fields keeps the layer. The finding `read-both` tells it.\n *\n * A field of version 1 that no add-on of the list removes is a fault of the form. A room record has no layers.\n * Thus a `room/1` with old records gives a `scene/2` with the room and the layers, and a `room/1` with none gives a `room/2`.\n */\nexport function readRecord(value: unknown, addOns: readonly AddOn<unknown>[] = []): RecordRead {\n if (!isJson(value)) return { ok: false, errors: [\"The record is not a JSON object.\"] };\n const name = value[\"schema\"];\n const kind = FILE_KINDS.find((each) => KIND_NAMES[each] === name);\n if (kind !== undefined) return parsed(kind, value, 2, []);\n const old = FILE_KINDS.find((each) => `${each}/1` === name);\n if (old === undefined) return { ok: false, errors: [`The record has no known format: \"schema\" is ${JSON.stringify(name) ?? \"missing\"}.`] };\n const readers = addOns.filter((addOn) => addOn.v1 !== undefined);\n const findings: ReadFinding[] = [];\n const errors: string[] = [];\n const without = (record: Json, of: FileKind | \"object\"): Record<string, unknown> => {\n const gone = new Set(readers.flatMap((addOn) => addOn.v1?.fields[of] ?? []));\n return Object.fromEntries(Object.entries(record).filter(([key]) => !gone.has(key)));\n };\n const objectsOf = (record: Record<string, unknown>): void => {\n const objects = record[\"objects\"];\n if (Array.isArray(objects)) record[\"objects\"] = objects.map((object: unknown) => (isJson(object) ? without(object, \"object\") : object));\n };\n // The layers of the old fields of one record. A layer that the record has already stays.\n const withLayers = (record: Record<string, unknown>, raw: Json, of: FileKind, room?: string): void => {\n const given = isJson(raw[\"layers\"]) ? raw[\"layers\"] : {};\n const layers: Record<string, unknown> = { ...given };\n for (const addOn of readers) {\n const read = addOn.v1?.read(raw, of);\n if (read === undefined) continue;\n if (!read.ok) {\n errors.push(...read.errors);\n continue;\n }\n if (Object.hasOwn(given, addOn.schema)) {\n findings.push({\n level: \"warning\",\n code: \"read-both\",\n layer: addOn.schema,\n ...(room === undefined ? {} : { room }),\n message: `The record has the layer \"${addOn.schema}\" and its old fields. The layer stays, and the old fields go.`,\n });\n continue;\n }\n layers[addOn.schema] = read.layer;\n }\n if (Object.keys(layers).length > 0) record[\"layers\"] = layers;\n };\n const surveyOf = (raw: Json, room?: string): Record<string, unknown> => {\n const record = { ...without(raw, \"survey\"), schema: newName(raw, \"survey\") };\n objectsOf(record);\n withLayers(record, raw, \"survey\", room);\n return record;\n };\n const roomOf = (raw: unknown): unknown => (isJson(raw) ? { ...without(raw, \"room\"), schema: newName(raw, \"room\") } : raw);\n let next: unknown;\n let made: FileKind = old;\n if (old === \"survey\") next = surveyOf(value);\n else if (old === \"level\") {\n const level: Record<string, unknown> = { ...without(value, \"level\"), schema: LEVEL_SCHEMA };\n const rooms = value[\"rooms\"];\n if (Array.isArray(rooms)) {\n level[\"rooms\"] = rooms.map((room: unknown) => {\n if (!isJson(room) || !isJson(room[\"survey\"])) return room;\n return { ...room, survey: surveyOf(room[\"survey\"], typeof room[\"id\"] === \"string\" ? room[\"id\"] : undefined) };\n });\n }\n withLayers(level, value, \"level\");\n next = level;\n } else if (old === \"scene\") {\n const scene: Record<string, unknown> = { ...without(value, \"scene\"), schema: SCENE_SCHEMA, room: roomOf(value[\"room\"]) };\n objectsOf(scene);\n withLayers(scene, value, \"scene\");\n next = scene;\n } else {\n // A room record has no layers, so the layers of its old fields need a scene.\n const scene: Record<string, unknown> = { schema: SCENE_SCHEMA, room: roomOf(value) };\n withLayers(scene, value, \"room\");\n if (scene[\"layers\"] === undefined) next = scene[\"room\"];\n else {\n next = scene;\n made = \"scene\";\n }\n }\n if (errors.length > 0) return { ok: false, errors };\n return parsed(made, next, 1, findings);\n}\n\n/** This function reads a record of version 2 with the schema of its kind. */\nfunction parsed(kind: FileKind, value: unknown, version: 1 | 2, findings: readonly ReadFinding[]): RecordRead {\n if (kind === \"room\") {\n const read = roomSchema.safeParse(value, READ_CONTEXT);\n return read.success ? { ok: true, kind, record: read.data, version, findings } : { ok: false, errors: faultsOf(read.error) };\n }\n if (kind === \"scene\") {\n const read = sceneSchema.safeParse(value, READ_CONTEXT);\n return read.success ? { ok: true, kind, record: read.data, version, findings } : { ok: false, errors: faultsOf(read.error) };\n }\n if (kind === \"survey\") {\n const read = surveySchema.safeParse(value, READ_CONTEXT);\n return read.success ? { ok: true, kind, record: read.data, version, findings } : { ok: false, errors: faultsOf(read.error) };\n }\n const read = levelSchema.safeParse(value, READ_CONTEXT);\n return read.success ? { ok: true, kind, record: read.data, version, findings } : { ok: false, errors: faultsOf(read.error) };\n}\n"],"mappings":";;;;;;;;AAcA,MAAa,eAAsD,EAAE,OAAO,GAAG,CAAC,CAAC,YAAY;AAE7F,MAAM,KAAK,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAC1C,MAAM,YAAY,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAE9D,MAAM,SAAS,EAAE,SAAS,EAAE,MAAM;CAAC,EAAE,OAAO;CAAG,EAAE,OAAO;CAAG,EAAE,OAAO;AAAC,CAAC,CAAC;;;;;AAMvE,MAAa,eAAsC,EAAE,mBAAmB,MAAM;CAC5E,EAAE,aAAa;EAAE,IAAI,EAAE,QAAQ,MAAM;EAAG,MAAM;EAAI,MAA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