@mark1russell7/room-view 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -294,6 +294,11 @@ export interface ImportOptions {
294
294
  readonly smallestRing?: number | undefined;
295
295
  /** The limits of the area gate, as parts of the area of a ring. The default is 0.05 and 0.1. */
296
296
  readonly gateLimits?: readonly number[] | undefined;
297
+ /**
298
+ * A fill ring is in the area gate only when this part of its edge or more is near a line of the sheet.
299
+ * A ring with no line on its edge is a letter or a symbol, not a room. The value 0 keeps each ring. The default is 0.25.
300
+ */
301
+ readonly gateEdge?: number | undefined;
297
302
  }
298
303
  /** One room of a plan import: a free region of the grid inside the building. */
299
304
  export interface ImportedRoom {
@@ -1 +1 @@
1
- {"version":3,"file":"plan-import.d.ts","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"],"mappings":";;;;;;iBAQiB;WACN,MAAM;WACN,IAAI;;WAEJ;;WAEA;;WAEA;;;iBAIM;WACN;WACA,gBAAgB;;;iBAIV;WACN;WACA,IAAI;;WAEJ;;;;;;iBAOM;;WAEN;;WAEA;WACA;;WAEA,MAAM;WACN,gBAAgB;WAChB,iBAAiB;WACjB,iBAAiB;;;wBAIZ,MAAM,MAAM,KAAK;;wBAKjB,WAAW,MAAM,KAAK;;iBAKrB;;WAEN,OAAO,SAAS;;WAEhB;;;iBAIM;;WAEN;;WAEA;;WAEA;;WAEA;;;wBAIK,QAAQ,MAAM;;;;;wBAoBd,WAAW,OAAO,KAAK,2BAA2B,UAAS,gBAAqB;;iBCjG/E;;WAEN;;WAEA;;WAEA;;WAEA;;;iBAIM;WACN,gBAAgB;;WAEhB,OAAO;;;;;;wBA8BF,cAAc,gBAAgB,aAAa,iBAAiB,kBAAkB,iBAAiB,qBAAqB;;iBAyDnH;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;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KN,MAAM;WACN,gBAAgB;WAChB,mBAAmB;;WAEnB,SAAS,SAAS,OAAO;WACzB,eAAe;WACf;WACA;;WAEA,MAAM;WACN,MAAM;;WAEN,UAAU;;;;;;;;;;;;;;wBAkBL,WAAW,OAAO,OAAO,UAAS,gBAAqB"}
1
+ {"version":3,"file":"plan-import.d.ts","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"],"mappings":";;;;;;iBAQiB;WACN,MAAM;WACN,IAAI;;WAEJ;;WAEA;;WAEA;;;iBAIM;WACN;WACA,gBAAgB;;;iBAIV;WACN;WACA,IAAI;;WAEJ;;;;;;iBAOM;;WAEN;;WAEA;WACA;;WAEA,MAAM;WACN,gBAAgB;WAChB,iBAAiB;WACjB,iBAAiB;;;wBAIZ,MAAM,MAAM,KAAK;;wBAKjB,WAAW,MAAM,KAAK;;iBAKrB;;WAEN,OAAO,SAAS;;WAEhB;;;iBAIM;;WAEN;;WAEA;;WAEA;;WAEA;;;wBAIK,QAAQ,MAAM;;;;;wBAoBd,WAAW,OAAO,KAAK,2BAA2B,UAAS,gBAAqB;;iBCjG/E;;WAEN;;WAEA;;WAEA;;WAEA;;;iBAIM;WACN,gBAAgB;;WAEhB,OAAO;;;;;;wBA8BF,cAAc,gBAAgB,aAAa,iBAAiB,kBAAkB,iBAAiB,qBAAqB;;iBAyDnH;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA,OAAO;;WAEP;;WAEA;;WAEA;;WAEA;;;qBAIE;;YAGD,mBAAmB;;iBAGd;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;iBAIM;WACN;WACA;WACA;WACA;WACA;WACA;;WAEA,OAAO;;WAEP;;WAEA;;WAEA;;WAEA;;;;;;;;;;wBAWK,SAAS,gBAAgB,aAAa,QAAQ,YAAY,yBAAyB;;iBAwClF;WACN;WACA;WACA,MAAM;W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- import { regionArea } from "@mark1russell7/layout-contract";
3
+ import { pointSegmentDistance, regionArea } from "@mark1russell7/layout-contract";
4
4
  import { median } from "@mark1russell7/rigor-statistics";
5
5
  // src/plan-import/sheet.ts
6
6
  /** This function gives the name of the pen of a line: its width, a bar, then its color. */
@@ -971,6 +971,8 @@ function importPlan(sheet, options = {}) {
971
971
  const fits = [];
972
972
  const ringArea = options.smallestRing ?? 15 * feet * feet;
973
973
  const gateRings = [];
974
+ const edgeShare = options.gateEdge ?? .25;
975
+ const edgeOf = edgeShare > 0 ? lineEdge(sheet.lines, sheetLength(void 0, .4)) : void 0;
974
976
  fills.forEach((fill, index) => {
975
977
  const use = names[fill.color];
976
978
  if (use === void 0 || samples.has(index)) return;
@@ -979,7 +981,9 @@ function importPlan(sheet, options = {}) {
979
981
  kind: "polygon",
980
982
  points
981
983
  }) / (scale * scale);
982
- if (area >= ringArea) gateRings.push({
984
+ if (area < ringArea) return;
985
+ if (edgeOf !== void 0 && edgeOf(points, sheetLength(void 0, .5)) < edgeShare) return;
986
+ gateRings.push({
983
987
  fill: index,
984
988
  ring,
985
989
  use,
@@ -1081,6 +1085,52 @@ function openingSides(grid, labels, center, along, width, reach, sideOf) {
1081
1085
  if (a !== void 0 && b !== void 0) return a === b ? void 0 : [a, b];
1082
1086
  }
1083
1087
  }
1088
+ /**
1089
+ * This function measures the edge of a ring. The measure is the part of its points with a line of the sheet at `reach` or less.
1090
+ * The points are at the distance `step` or less along the edge. A hash of cells finds the lines near each point.
1091
+ */
1092
+ function lineEdge(lines, reach) {
1093
+ const cell = Math.max(reach * 4, 1e-9);
1094
+ const keyOf = (x, y) => `${Math.floor(x / cell)},${Math.floor(y / cell)}`;
1095
+ const hash = /* @__PURE__ */ new Map();
1096
+ lines.forEach((line, index) => {
1097
+ const steps = Math.max(1, Math.ceil(lineLength(line) / cell));
1098
+ const keys = /* @__PURE__ */ new Set();
1099
+ for (let k = 0; k <= steps; k++) keys.add(keyOf(line.from[0] + (line.to[0] - line.from[0]) * k / steps, line.from[1] + (line.to[1] - line.from[1]) * k / steps));
1100
+ for (const key of keys) hash.set(key, [...hash.get(key) ?? [], index]);
1101
+ });
1102
+ const near = (x, y) => {
1103
+ const cx = Math.floor(x / cell);
1104
+ const cy = Math.floor(y / cell);
1105
+ for (let dx = -1; dx <= 1; dx++) for (let dy = -1; dy <= 1; dy++) for (const index of hash.get(`${cx + dx},${cy + dy}`) ?? []) {
1106
+ const line = lines[index];
1107
+ if (pointSegmentDistance({
1108
+ x,
1109
+ y
1110
+ }, {
1111
+ x: line.from[0],
1112
+ y: line.from[1]
1113
+ }, {
1114
+ x: line.to[0],
1115
+ y: line.to[1]
1116
+ }) <= reach) return true;
1117
+ }
1118
+ return false;
1119
+ };
1120
+ return (ring, step) => {
1121
+ let points = 0;
1122
+ let lined = 0;
1123
+ ring.forEach(([x0, y0], index) => {
1124
+ const [x1, y1] = ring[(index + 1) % ring.length];
1125
+ const count = Math.max(1, Math.ceil(Math.hypot(x1 - x0, y1 - y0) / step));
1126
+ for (let k = 0; k < count; k++) {
1127
+ points++;
1128
+ if (near(x0 + (x1 - x0) * (k + .5) / count, y0 + (y1 - y0) * (k + .5) / count)) lined++;
1129
+ }
1130
+ });
1131
+ return points === 0 ? 0 : lined / points;
1132
+ };
1133
+ }
1084
1134
  /** This function puts a calculated length on a grid of 1e-9, so the noise of float arithmetic does not go to a file. */
1085
1135
  function tidy(value) {
1086
1136
  return Math.round(value * 1e9) / 1e9 + 0;
@@ -1 +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 /** The read of the wall lines. `pens` takes only the lines of the wall pens. `lines` also takes the wall faces of the other pens. The default is `lines`. */\n readonly read?: WallRead | undefined;\n /** A pen with a smaller part of one-side lines is a pattern pen, for example a hatch or glazing. Its lines are not wall faces. The default is 0.4. */\n readonly patternSide?: number | undefined;\n /** This value is true when a wall face can have its partner in a different pen. The default is true. */\n readonly crossPens?: boolean | undefined;\n /** This value is true when the glazing lines of the pattern pens close the rooms. The default is true. */\n readonly glazing?: boolean | undefined;\n /** The largest gap at an open end of a wall line that the import closes. The value 0 closes no gap. The default is 1 ft. */\n readonly snap?: number | undefined;\n}\n\n/** These are the reads of the wall lines. `pens` takes the wall pens only. `lines` also takes the wall faces of the other pens. */\nexport const WALL_READS: readonly [\"pens\", \"lines\"] = [\"pens\", \"lines\"];\n\n/** A read of the wall lines. */\nexport type WallRead = (typeof WALL_READS)[number];\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 /** The read of the wall lines. The default is `lines`. */\n readonly read?: WallRead | undefined;\n /** The largest part of one-side lines of a pattern pen. The default is 0.4. */\n readonly patternSide?: number | undefined;\n /** This value is true when a wall face can have its partner in a different pen. The default is true. */\n readonly crossPens?: boolean | undefined;\n /** This value is true when the glazing lines close the rooms. The default is true. */\n readonly glazing?: boolean | undefined;\n /** Two ends touch when the distance between them is this value or less. The default is `thinnest`. */\n readonly touch?: number | undefined;\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\n/** The wall lines of a sheet, from `readWallLines`. */\nexport interface WallLineRead {\n /** The lines of the wall pens, the wall faces of the other pens and the end lines of these faces. */\n readonly walls: readonly SheetLine[];\n /** The glazing lines of the pattern pens. They close the rooms, but they are not walls. */\n readonly glazing: readonly SheetLine[];\n /** The number of faces and end lines from each pen that is not a wall pen. */\n readonly faces: Readonly<Record<string, number>>;\n /** The number of glazing lines from each pattern pen. */\n readonly glazingPens: Readonly<Record<string, number>>;\n}\n\n/** A point of a sheet. */\ntype Point = readonly [number, number];\n\n/** This function puts each point in the square cell of a grid with the side `cell`. */\nfunction pointHash(points: readonly Point[], cell: number): Map<string, Point[]> {\n const hash = new Map<string, Point[]>();\n for (const point of points) {\n const key = `${Math.floor(point[0] / cell)},${Math.floor(point[1] / cell)}`;\n const list = hash.get(key) ?? [];\n list.push(point);\n hash.set(key, list);\n }\n return hash;\n}\n\n/** This function is true when a point of the hash is at the distance `reach` or less from the point (`x`, `y`). The value `reach` is not more than the cell. */\nfunction nearPoint(hash: Map<string, Point[]>, cell: number, x: number, y: number, reach: 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 point of hash.get(`${cx + dx},${cy + dy}`) ?? []) if (Math.hypot(point[0] - x, point[1] - y) <= reach) return true;\n }\n }\n return false;\n}\n\n/** This function gives the ends of the straight lines. */\nfunction endsOf(lines: readonly SheetLine[]): Point[] {\n const ends: Point[] = [];\n for (const line of lines) if (line.curve !== true) ends.push(line.from, line.to);\n return ends;\n}\n\n/**\n * This function reads the wall lines one line at a time, not one pen at a time.\n *\n * - A wall pen gives all its lines.\n * - A pattern pen has most of its long lines in pairs, and few lines with partners on one side only. A hatch and glazing are pattern pens.\n * - Each other pen gives its wall faces. A face is a long line with a parallel partner at a wall thickness on one side only.\n * - Such a pen also gives its end lines. An end line is a short line that joins two face ends.\n * - A long line of a pattern pen with 1 to 3 partners is a glazing line when its two ends are near wall ends. A glazing line closes the rooms, but it is not a wall.\n *\n * The option `read: \"pens\"` gives only the lines of the wall pens. The limits are in the units of the sheet.\n */\nexport function readWallLines(lines: readonly SheetLine[], reads: readonly PenRead[], limits: WallLimits, wallPens: readonly string[]): WallLineRead {\n const wallSet = new Set(wallPens);\n const walls: SheetLine[] = lines.filter((line) => wallSet.has(penOf(line)));\n if (limits.read === \"pens\") return { walls, glazing: [], faces: {}, glazingPens: {} };\n const patternSide = limits.patternSide ?? 0.4;\n const touch = limits.touch ?? limits.thinnest;\n const readOf = new Map(reads.map((read) => [read.pen, read]));\n const kindOf = (pen: string): \"wall\" | \"mixed\" | \"pattern\" | \"none\" => {\n const read = readOf.get(pen);\n if (read === undefined || read.lines < limits.fewestLines) return \"none\";\n if (wallSet.has(pen)) return \"wall\";\n if (read.oneSide >= patternSide) return \"mixed\";\n // A pen with few pairs and few faces, for example a pen of doors, gives no line.\n return read.paired >= 0.5 ? \"pattern\" : \"none\";\n };\n\n // The faces: the long lines of the mixed pens with partners on one side only.\n const groups = new Map<string, SheetLine[]>();\n for (const line of lines) {\n if (line.curve === true || lineLength(line) < limits.longLine) continue;\n const pen = penOf(line);\n if (kindOf(pen) !== \"mixed\") continue;\n const key = (limits.crossPens ?? true) ? \"\" : pen;\n const list = groups.get(key) ?? [];\n list.push(line);\n groups.set(key, list);\n }\n const faces: Record<string, number> = {};\n const faceLines: SheetLine[] = [];\n const count = (line: SheetLine): void => {\n faceLines.push(line);\n faces[penOf(line)] = (faces[penOf(line)] ?? 0) + 1;\n };\n for (const group of groups.values()) {\n const { sides } = parallelPairs(group, limits.thinnest, limits.thickest, limits.longLine);\n group.forEach((line, index) => {\n if (sides[2 * index]! > 0 !== sides[2 * index + 1]! > 0) count(line);\n });\n }\n\n // The end lines: the short lines of the mixed pens with their two ends at the ends of faces or walls.\n const cell = Math.max(touch, 1e-9);\n const hash = pointHash(endsOf([...faceLines, ...walls]), cell);\n for (const line of lines) {\n if (line.curve === true) continue;\n const length = lineLength(line);\n if (length >= limits.longLine || length < touch || kindOf(penOf(line)) !== \"mixed\") continue;\n if (nearPoint(hash, cell, line.from[0], line.from[1], touch) && nearPoint(hash, cell, line.to[0], line.to[1], touch)) count(line);\n }\n walls.push(...faceLines);\n\n // The glazing: the long lines of the pattern pens with few partners, between two wall ends.\n const glazing: SheetLine[] = [];\n const glazingPens: Record<string, number> = {};\n if (limits.glazing ?? true) {\n const reach = Math.max(limits.thickest, 1e-9);\n const endHash = pointHash(endsOf(walls), reach);\n const byPen = new Map<string, SheetLine[]>();\n for (const line of lines) {\n if (line.curve === true || lineLength(line) < limits.longLine) continue;\n const pen = penOf(line);\n if (kindOf(pen) !== \"pattern\") continue;\n const list = byPen.get(pen) ?? [];\n list.push(line);\n byPen.set(pen, list);\n }\n for (const [pen, group] of byPen) {\n const { sides } = parallelPairs(group, 0.02 * reach, reach, limits.longLine);\n group.forEach((line, index) => {\n const partners = sides[2 * index]! + sides[2 * index + 1]!;\n if (partners < 1 || partners > 3) return;\n if (!nearPoint(endHash, reach, line.from[0], line.from[1], reach) || !nearPoint(endHash, reach, line.to[0], line.to[1], reach)) return;\n glazing.push(line);\n glazingPens[pen] = (glazingPens[pen] ?? 0) + 1;\n });\n }\n }\n return { walls, glazing, faces, glazingPens };\n}\n\n/**\n * This function closes the small gaps at the open ends of the wall lines. An open end has no other line at a distance less than `touch`.\n * The end goes on along its line to the first line within `reach`, or to the nearest line end within `reach` and `angle` degrees.\n * A gap that is narrower than a door is not a passage. Thus each closure is a barrier of the rooms.\n */\nexport function snapEnds(lines: readonly SheetLine[], reach: number, touch: number, angle = 25): readonly SheetLine[] {\n if (!(reach > 0)) return [];\n const cell = Math.max(reach, touch, 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 around = (x: number, y: number): Set<number> => {\n const found = new Set<number>();\n const cx = Math.floor(x / cell);\n const cy = Math.floor(y / cell);\n for (let dx = -1; dx <= 1; dx++) for (let dy = -1; dy <= 1; dy++) for (const index of grid.get(`${cx + dx},${cy + dy}`) ?? []) found.add(index);\n return found;\n };\n const distanceTo = (x: number, y: number, line: SheetLine): number => {\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 return Math.hypot(x - line.from[0] - t * vx, y - line.from[1] - t * vy);\n };\n const cosine = Math.cos((angle * Math.PI) / 180);\n const snaps: SheetLine[] = [];\n lines.forEach((line, index) => {\n const length = lineLength(line);\n if (length < 2 * touch) return;\n const ux = (line.to[0] - line.from[0]) / length;\n const uy = (line.to[1] - line.from[1]) / length;\n const ends: readonly (readonly [number, number, number, number])[] = [\n [line.to[0], line.to[1], ux, uy],\n [line.from[0], line.from[1], -ux, -uy],\n ];\n for (const [x, y, dx, dy] of ends) {\n const near = around(x, y);\n let open = true;\n for (const other of near) {\n if (other !== index && distanceTo(x, y, lines[other]!) < touch) {\n open = false;\n break;\n }\n }\n if (!open) continue;\n let best = Infinity;\n let point: Point | undefined;\n for (const other of near) {\n if (other === index) continue;\n const o = lines[other]!;\n // The ray from the end along its line, against the other line.\n const ex = o.to[0] - o.from[0];\n const ey = o.to[1] - o.from[1];\n const denominator = dx * ey - dy * ex;\n if (Math.abs(denominator) > 1e-9) {\n const t = ((o.from[0] - x) * ey - (o.from[1] - y) * ex) / denominator;\n const s = ((o.from[0] - x) * dy - (o.from[1] - y) * dx) / denominator;\n if (t > 0 && t <= reach && s >= 0 && s <= 1 && t < best) {\n best = t;\n point = [x + dx * t, y + dy * t];\n }\n }\n // The ends of the other line in front of the end.\n for (const [px, py] of [o.from, o.to]) {\n const gx = px - x;\n const gy = py - y;\n const gap = Math.hypot(gx, gy);\n if (gap <= 0 || gap > reach || (gx * dx + gy * dy) / gap < cosine) continue;\n if (gap < best) {\n best = gap;\n point = [px, py];\n }\n }\n }\n if (point !== undefined) snaps.push({ from: [x, y], to: point, width: line.width, color: line.color });\n }\n });\n return snaps;\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, readWallLines, snapEnds, wallPairs, type PenRead, type WallLimits, type WallLineRead, 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 /** The wall lines, the glazing lines and the faces of each pen, from `readWallLines`. */\n readonly lineRead: WallLineRead;\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 * `readWallLines` also takes the wall faces and the glazing of the other pens. `snapEnds` closes the small gaps at the open wall ends.\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 // Two wall ends touch at this distance or less.\n const touch = sheetLength(undefined, 0.225);\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 read: wallOptions.read ?? \"lines\",\n patternSide: wallOptions.patternSide ?? 0.4,\n crossPens: wallOptions.crossPens ?? true,\n glazing: wallOptions.glazing ?? true,\n touch,\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 doorSet = new Set(doorPens);\n const lineRead = readWallLines(sheet.lines, pens, wallLimits, wallPens);\n const wallLines = lineRead.walls;\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 const snaps = snapEnds(straight, sheetLength(wallOptions.snap, 1), touch);\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 stampLines(grid, barrier, lineRead.glazing);\n stampLines(grid, barrier, snaps);\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, lineRead };\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,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,KAAK,MAAM,QAAQ,KAAK,OACtB,KAAK,MAAM,CAAC,GAAG,MAAM,MAAM;EACzB,KAAK,KAAK,IAAI,IAAI,CAAC;EACnB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AAO,WAAW,IAAI,CAAC,IAAI,EAAE,OAAO;EAE9B;EAAG;EAAO,UAAU;EAAU,SAAS;EAAO;EAAM;EAAU;EAAU,MAAM;GAAE,GAAG;GAAM,MAAM,OAAO;EAAM;EAAG;EAAM;CAAS;AAC5I;;;;;;AAOA,SAAS,aACP,MACA,QACA,QACA,OACA,OACA,OACA,QACuC;CACvC,MAAM,EAAE,SAAS,MAAM,SAAS;CAChC,MAAM,SAAoB,CAAC,CAAC,MAAM,IAAI,MAAM,EAAE;CAC9C,MAAM,QAAQ,MAAc,UAAsC;EAChE,MAAM,KAAK,OAAO,KAAK,MAAM,KAAK;EAClC,MAAM,KAAK,OAAO,KAAK,MAAM,KAAK;EAClC,KAAK,IAAI,IAAI,GAAG,KAAK,OAAO,KAAK,OAAO,GAAG;GACzC,MAAM,IAAI,KAAK,OAAO,KAAK,OAAO,OAAO,KAAK,KAAK,IAAI;GACvD,MAAM,IAAI,KAAK,OAAO,KAAK,OAAO,OAAO,KAAK,KAAK,IAAI;GACvD,IAAI,IAAI,KAAK,IAAI,KAAK,KAAK,WAAW,KAAK,MAAM,OAAO,KAAA;GACxD,MAAM,QAAQ,OAAO,OAAO,IAAI,UAAU,EAAG;GAC7C,IAAI,UAAU,KAAA,GAAW,OAAO;EAClC;CAEF;CACA,KAAK,MAAM,SAAS;EAAC;EAAG;EAAO;CAAI,GAAG;EACpC,MAAM,IAAI,KAAK,IAAI,QAAQ,KAAK;EAChC,MAAM,IAAI,KAAK,GAAG,QAAQ,KAAK;EAC/B,IAAI,MAAM,KAAA,KAAa,MAAM,KAAA,GAAW,OAAO,MAAM,IAAI,KAAA,IAAY,CAAC,GAAG,CAAC;CAC5E;AAEF;;AAGA,SAAS,KAAK,OAAuB;CACnC,OAAO,KAAK,MAAM,QAAQ,GAAG,IAAI,MAAM;AACzC"}
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 /** The read of the wall lines. `pens` takes only the lines of the wall pens. `lines` also takes the wall faces of the other pens. The default is `lines`. */\n readonly read?: WallRead | undefined;\n /** A pen with a smaller part of one-side lines is a pattern pen, for example a hatch or glazing. Its lines are not wall faces. The default is 0.4. */\n readonly patternSide?: number | undefined;\n /** This value is true when a wall face can have its partner in a different pen. The default is true. */\n readonly crossPens?: boolean | undefined;\n /** This value is true when the glazing lines of the pattern pens close the rooms. The default is true. */\n readonly glazing?: boolean | undefined;\n /** The largest gap at an open end of a wall line that the import closes. The value 0 closes no gap. The default is 1 ft. */\n readonly snap?: number | undefined;\n}\n\n/** These are the reads of the wall lines. `pens` takes the wall pens only. `lines` also takes the wall faces of the other pens. */\nexport const WALL_READS: readonly [\"pens\", \"lines\"] = [\"pens\", \"lines\"];\n\n/** A read of the wall lines. */\nexport type WallRead = (typeof WALL_READS)[number];\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 /** The read of the wall lines. The default is `lines`. */\n readonly read?: WallRead | undefined;\n /** The largest part of one-side lines of a pattern pen. The default is 0.4. */\n readonly patternSide?: number | undefined;\n /** This value is true when a wall face can have its partner in a different pen. The default is true. */\n readonly crossPens?: boolean | undefined;\n /** This value is true when the glazing lines close the rooms. The default is true. */\n readonly glazing?: boolean | undefined;\n /** Two ends touch when the distance between them is this value or less. The default is `thinnest`. */\n readonly touch?: number | undefined;\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\n/** The wall lines of a sheet, from `readWallLines`. */\nexport interface WallLineRead {\n /** The lines of the wall pens, the wall faces of the other pens and the end lines of these faces. */\n readonly walls: readonly SheetLine[];\n /** The glazing lines of the pattern pens. They close the rooms, but they are not walls. */\n readonly glazing: readonly SheetLine[];\n /** The number of faces and end lines from each pen that is not a wall pen. */\n readonly faces: Readonly<Record<string, number>>;\n /** The number of glazing lines from each pattern pen. */\n readonly glazingPens: Readonly<Record<string, number>>;\n}\n\n/** A point of a sheet. */\ntype Point = readonly [number, number];\n\n/** This function puts each point in the square cell of a grid with the side `cell`. */\nfunction pointHash(points: readonly Point[], cell: number): Map<string, Point[]> {\n const hash = new Map<string, Point[]>();\n for (const point of points) {\n const key = `${Math.floor(point[0] / cell)},${Math.floor(point[1] / cell)}`;\n const list = hash.get(key) ?? [];\n list.push(point);\n hash.set(key, list);\n }\n return hash;\n}\n\n/** This function is true when a point of the hash is at the distance `reach` or less from the point (`x`, `y`). The value `reach` is not more than the cell. */\nfunction nearPoint(hash: Map<string, Point[]>, cell: number, x: number, y: number, reach: 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 point of hash.get(`${cx + dx},${cy + dy}`) ?? []) if (Math.hypot(point[0] - x, point[1] - y) <= reach) return true;\n }\n }\n return false;\n}\n\n/** This function gives the ends of the straight lines. */\nfunction endsOf(lines: readonly SheetLine[]): Point[] {\n const ends: Point[] = [];\n for (const line of lines) if (line.curve !== true) ends.push(line.from, line.to);\n return ends;\n}\n\n/**\n * This function reads the wall lines one line at a time, not one pen at a time.\n *\n * - A wall pen gives all its lines.\n * - A pattern pen has most of its long lines in pairs, and few lines with partners on one side only. A hatch and glazing are pattern pens.\n * - Each other pen gives its wall faces. A face is a long line with a parallel partner at a wall thickness on one side only.\n * - Such a pen also gives its end lines. An end line is a short line that joins two face ends.\n * - A long line of a pattern pen with 1 to 3 partners is a glazing line when its two ends are near wall ends. A glazing line closes the rooms, but it is not a wall.\n *\n * The option `read: \"pens\"` gives only the lines of the wall pens. The limits are in the units of the sheet.\n */\nexport function readWallLines(lines: readonly SheetLine[], reads: readonly PenRead[], limits: WallLimits, wallPens: readonly string[]): WallLineRead {\n const wallSet = new Set(wallPens);\n const walls: SheetLine[] = lines.filter((line) => wallSet.has(penOf(line)));\n if (limits.read === \"pens\") return { walls, glazing: [], faces: {}, glazingPens: {} };\n const patternSide = limits.patternSide ?? 0.4;\n const touch = limits.touch ?? limits.thinnest;\n const readOf = new Map(reads.map((read) => [read.pen, read]));\n const kindOf = (pen: string): \"wall\" | \"mixed\" | \"pattern\" | \"none\" => {\n const read = readOf.get(pen);\n if (read === undefined || read.lines < limits.fewestLines) return \"none\";\n if (wallSet.has(pen)) return \"wall\";\n if (read.oneSide >= patternSide) return \"mixed\";\n // A pen with few pairs and few faces, for example a pen of doors, gives no line.\n return read.paired >= 0.5 ? \"pattern\" : \"none\";\n };\n\n // The faces: the long lines of the mixed pens with partners on one side only.\n const groups = new Map<string, SheetLine[]>();\n for (const line of lines) {\n if (line.curve === true || lineLength(line) < limits.longLine) continue;\n const pen = penOf(line);\n if (kindOf(pen) !== \"mixed\") continue;\n const key = (limits.crossPens ?? true) ? \"\" : pen;\n const list = groups.get(key) ?? [];\n list.push(line);\n groups.set(key, list);\n }\n const faces: Record<string, number> = {};\n const faceLines: SheetLine[] = [];\n const count = (line: SheetLine): void => {\n faceLines.push(line);\n faces[penOf(line)] = (faces[penOf(line)] ?? 0) + 1;\n };\n for (const group of groups.values()) {\n const { sides } = parallelPairs(group, limits.thinnest, limits.thickest, limits.longLine);\n group.forEach((line, index) => {\n if (sides[2 * index]! > 0 !== sides[2 * index + 1]! > 0) count(line);\n });\n }\n\n // The end lines: the short lines of the mixed pens with their two ends at the ends of faces or walls.\n const cell = Math.max(touch, 1e-9);\n const hash = pointHash(endsOf([...faceLines, ...walls]), cell);\n for (const line of lines) {\n if (line.curve === true) continue;\n const length = lineLength(line);\n if (length >= limits.longLine || length < touch || kindOf(penOf(line)) !== \"mixed\") continue;\n if (nearPoint(hash, cell, line.from[0], line.from[1], touch) && nearPoint(hash, cell, line.to[0], line.to[1], touch)) count(line);\n }\n walls.push(...faceLines);\n\n // The glazing: the long lines of the pattern pens with few partners, between two wall ends.\n const glazing: SheetLine[] = [];\n const glazingPens: Record<string, number> = {};\n if (limits.glazing ?? true) {\n const reach = Math.max(limits.thickest, 1e-9);\n const endHash = pointHash(endsOf(walls), reach);\n const byPen = new Map<string, SheetLine[]>();\n for (const line of lines) {\n if (line.curve === true || lineLength(line) < limits.longLine) continue;\n const pen = penOf(line);\n if (kindOf(pen) !== \"pattern\") continue;\n const list = byPen.get(pen) ?? [];\n list.push(line);\n byPen.set(pen, list);\n }\n for (const [pen, group] of byPen) {\n const { sides } = parallelPairs(group, 0.02 * reach, reach, limits.longLine);\n group.forEach((line, index) => {\n const partners = sides[2 * index]! + sides[2 * index + 1]!;\n if (partners < 1 || partners > 3) return;\n if (!nearPoint(endHash, reach, line.from[0], line.from[1], reach) || !nearPoint(endHash, reach, line.to[0], line.to[1], reach)) return;\n glazing.push(line);\n glazingPens[pen] = (glazingPens[pen] ?? 0) + 1;\n });\n }\n }\n return { walls, glazing, faces, glazingPens };\n}\n\n/**\n * This function closes the small gaps at the open ends of the wall lines. An open end has no other line at a distance less than `touch`.\n * The end goes on along its line to the first line within `reach`, or to the nearest line end within `reach` and `angle` degrees.\n * A gap that is narrower than a door is not a passage. Thus each closure is a barrier of the rooms.\n */\nexport function snapEnds(lines: readonly SheetLine[], reach: number, touch: number, angle = 25): readonly SheetLine[] {\n if (!(reach > 0)) return [];\n const cell = Math.max(reach, touch, 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 around = (x: number, y: number): Set<number> => {\n const found = new Set<number>();\n const cx = Math.floor(x / cell);\n const cy = Math.floor(y / cell);\n for (let dx = -1; dx <= 1; dx++) for (let dy = -1; dy <= 1; dy++) for (const index of grid.get(`${cx + dx},${cy + dy}`) ?? []) found.add(index);\n return found;\n };\n const distanceTo = (x: number, y: number, line: SheetLine): number => {\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 return Math.hypot(x - line.from[0] - t * vx, y - line.from[1] - t * vy);\n };\n const cosine = Math.cos((angle * Math.PI) / 180);\n const snaps: SheetLine[] = [];\n lines.forEach((line, index) => {\n const length = lineLength(line);\n if (length < 2 * touch) return;\n const ux = (line.to[0] - line.from[0]) / length;\n const uy = (line.to[1] - line.from[1]) / length;\n const ends: readonly (readonly [number, number, number, number])[] = [\n [line.to[0], line.to[1], ux, uy],\n [line.from[0], line.from[1], -ux, -uy],\n ];\n for (const [x, y, dx, dy] of ends) {\n const near = around(x, y);\n let open = true;\n for (const other of near) {\n if (other !== index && distanceTo(x, y, lines[other]!) < touch) {\n open = false;\n break;\n }\n }\n if (!open) continue;\n let best = Infinity;\n let point: Point | undefined;\n for (const other of near) {\n if (other === index) continue;\n const o = lines[other]!;\n // The ray from the end along its line, against the other line.\n const ex = o.to[0] - o.from[0];\n const ey = o.to[1] - o.from[1];\n const denominator = dx * ey - dy * ex;\n if (Math.abs(denominator) > 1e-9) {\n const t = ((o.from[0] - x) * ey - (o.from[1] - y) * ex) / denominator;\n const s = ((o.from[0] - x) * dy - (o.from[1] - y) * dx) / denominator;\n if (t > 0 && t <= reach && s >= 0 && s <= 1 && t < best) {\n best = t;\n point = [x + dx * t, y + dy * t];\n }\n }\n // The ends of the other line in front of the end.\n for (const [px, py] of [o.from, o.to]) {\n const gx = px - x;\n const gy = py - y;\n const gap = Math.hypot(gx, gy);\n if (gap <= 0 || gap > reach || (gx * dx + gy * dy) / gap < cosine) continue;\n if (gap < best) {\n best = gap;\n point = [px, py];\n }\n }\n }\n if (point !== undefined) snaps.push({ from: [x, y], to: point, width: line.width, color: line.color });\n }\n });\n return snaps;\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 { pointSegmentDistance, 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, type SheetLine } from \"./sheet.ts\";\nimport { readPens, readWallLines, snapEnds, wallPairs, type PenRead, type WallLimits, type WallLineRead, 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 * A fill ring is in the area gate only when this part of its edge or more is near a line of the sheet.\n * A ring with no line on its edge is a letter or a symbol, not a room. The value 0 keeps each ring. The default is 0.25.\n */\n readonly gateEdge?: 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 /** The wall lines, the glazing lines and the faces of each pen, from `readWallLines`. */\n readonly lineRead: WallLineRead;\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 * `readWallLines` also takes the wall faces and the glazing of the other pens. `snapEnds` closes the small gaps at the open wall ends.\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 // Two wall ends touch at this distance or less.\n const touch = sheetLength(undefined, 0.225);\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 read: wallOptions.read ?? \"lines\",\n patternSide: wallOptions.patternSide ?? 0.4,\n crossPens: wallOptions.crossPens ?? true,\n glazing: wallOptions.glazing ?? true,\n touch,\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 doorSet = new Set(doorPens);\n const lineRead = readWallLines(sheet.lines, pens, wallLimits, wallPens);\n const wallLines = lineRead.walls;\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 const snaps = snapEnds(straight, sheetLength(wallOptions.snap, 1), touch);\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 stampLines(grid, barrier, lineRead.glazing);\n stampLines(grid, barrier, snaps);\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 const edgeShare = options.gateEdge ?? 0.25;\n // A point of the edge of a ring is near a line at 0.4 ft or less. The points of the edge are 0.5 ft apart.\n const edgeOf = edgeShare > 0 ? lineEdge(sheet.lines, sheetLength(undefined, 0.4)) : undefined;\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) return;\n if (edgeOf !== undefined && edgeOf(points, sheetLength(undefined, 0.5)) < edgeShare) return;\n 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, lineRead };\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/**\n * This function measures the edge of a ring. The measure is the part of its points with a line of the sheet at `reach` or less.\n * The points are at the distance `step` or less along the edge. A hash of cells finds the lines near each point.\n */\nfunction lineEdge(lines: readonly SheetLine[], reach: number): (ring: Ring, step: number) => number {\n const cell = Math.max(reach * 4, 1e-9);\n const keyOf = (x: number, y: number): string => `${Math.floor(x / cell)},${Math.floor(y / cell)}`;\n const hash = new Map<string, number[]>();\n lines.forEach((line, index) => {\n // The points of the line are one cell or less apart, so each cell that the line crosses gets the line.\n const steps = Math.max(1, Math.ceil(lineLength(line) / cell));\n const keys = new Set<string>();\n for (let k = 0; k <= steps; k++) keys.add(keyOf(line.from[0] + ((line.to[0] - line.from[0]) * k) / steps, line.from[1] + ((line.to[1] - line.from[1]) * k) / steps));\n for (const key of keys) hash.set(key, [...(hash.get(key) ?? []), index]);\n });\n const near = (x: number, y: 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 hash.get(`${cx + dx},${cy + dy}`) ?? []) {\n const line = lines[index]!;\n if (pointSegmentDistance({ x, y }, { x: line.from[0], y: line.from[1] }, { x: line.to[0], y: line.to[1] }) <= reach) return true;\n }\n }\n }\n return false;\n };\n return (ring, step) => {\n let points = 0;\n let lined = 0;\n ring.forEach(([x0, y0], index) => {\n const [x1, y1] = ring[(index + 1) % ring.length]!;\n const count = Math.max(1, Math.ceil(Math.hypot(x1 - x0, y1 - y0) / step));\n for (let k = 0; k < count; k++) {\n points++;\n if (near(x0 + ((x1 - x0) * (k + 0.5)) / count, y0 + ((y1 - y0) * (k + 0.5)) / count)) lined++;\n }\n });\n return points === 0 ? 0 : lined / points;\n };\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":";;;;;;AAmD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AAM,IAAI,IAAI;EAC9B,KAAK,IAAI,KAAK,IAAI,MAAM,GAAG,MACzB,KAAK,IAAI,KAAK,IAAI,MAAM,GAAG,MACzB,KAAK,MAAM,SAAS,KAAK,IAAI,GAAG,KAAK,GAAG,GAAG,KAAK,IAAI,KAAK,CAAC,GAAG;GAC3D,MAAM,OAAO,MAAM;GACnB,IAAI,qBAAqB;IAAE;IAAG;GAAE,GAAG;IAAE,GAAG,KAAK,KAAK;IAAI,GAAG,KAAK,KAAK;GAAG,GAAG;IAAE,GAAG,KAAK,GAAG;IAAI,GAAG,KAAK,GAAG;GAAG,CAAC,KAAK,OAAO,OAAO;EAC9H;EAGJ,OAAO;CACT;CACA,QAAQ,MAAM,SAAS;EACrB,IAAI,SAAS;EACb,IAAI,QAAQ;EACZ,KAAK,SAAS,CAAC,IAAI,KAAK,UAAU;GAChC,MAAM,CAAC,IAAI,MAAM,MAAM,QAAQ,KAAK,KAAK;GACzC,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,KAAK,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,IAAI,IAAI,CAAC;GACxE,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;IAC9B;IACA,IAAI,KAAK,MAAO,KAAK,OAAO,IAAI,MAAQ,OAAO,MAAO,KAAK,OAAO,IAAI,MAAQ,KAAK,GAAG;GACxF;EACF,CAAC;EACD,OAAO,WAAW,IAAI,IAAI,QAAQ;CACpC;AACF;;AAGA,SAAS,KAAK,OAAuB;CACnC,OAAO,KAAK,MAAM,QAAQ,GAAG,IAAI,MAAM;AACzC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/room-view",
4
- "version": "0.4.0",
4
+ "version": "0.5.0",
5
5
  "description": "A room as data, and its 3D model from that data: walls with openings, floors, outlets, circuits and placed objects.",
6
6
  "license": "MIT",
7
7
  "repository": {