bimdown-cli 0.3.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -3
- package/dist/chunk-4SKM4RHY.js +142 -0
- package/dist/chunk-4SKM4RHY.js.map +1 -0
- package/dist/chunk-4YHVOWS4.js +255 -0
- package/dist/chunk-4YHVOWS4.js.map +1 -0
- package/dist/chunk-AYAXRYGP.js +2129 -0
- package/dist/chunk-AYAXRYGP.js.map +1 -0
- package/dist/chunk-EC5MR5ZH.js +648 -0
- package/dist/chunk-EC5MR5ZH.js.map +1 -0
- package/dist/chunk-HS3PO2LB.js +487 -0
- package/dist/chunk-HS3PO2LB.js.map +1 -0
- package/dist/chunk-IQJA3EFO.js +179 -0
- package/dist/chunk-IQJA3EFO.js.map +1 -0
- package/dist/chunk-JY6KWRDB.js +80 -0
- package/dist/chunk-JY6KWRDB.js.map +1 -0
- package/dist/chunk-KWSGJUMZ.js +2501 -0
- package/dist/chunk-KWSGJUMZ.js.map +1 -0
- package/dist/chunk-LWYIPR64.js +35 -0
- package/dist/chunk-LWYIPR64.js.map +1 -0
- package/dist/chunk-OBY3UYCO.js +44 -0
- package/dist/chunk-OBY3UYCO.js.map +1 -0
- package/dist/chunk-XC6WHJRL.js +29 -0
- package/dist/chunk-XC6WHJRL.js.map +1 -0
- package/dist/chunk-XQU52JKB.js +187 -0
- package/dist/chunk-XQU52JKB.js.map +1 -0
- package/dist/clash-load-D3LNQR6G.js +941 -0
- package/dist/clash-load-D3LNQR6G.js.map +1 -0
- package/dist/cli.js +431 -0
- package/dist/cli.js.map +1 -0
- package/dist/dehydrate-ZHAGOI7Q.js +90 -0
- package/dist/dehydrate-ZHAGOI7Q.js.map +1 -0
- package/dist/diff-T2KOK2WR.js +89 -0
- package/dist/diff-T2KOK2WR.js.map +1 -0
- package/dist/engine-2TPWJVEQ.js +12 -0
- package/dist/engine-2TPWJVEQ.js.map +1 -0
- package/dist/hydrate-V24H7IF3.js +673 -0
- package/dist/hydrate-V24H7IF3.js.map +1 -0
- package/dist/import-ifc-RCZSXDA6.js +5324 -0
- package/dist/import-ifc-RCZSXDA6.js.map +1 -0
- package/dist/info-QC7YXWNX.js +92 -0
- package/dist/info-QC7YXWNX.js.map +1 -0
- package/dist/init-VWDML3UC.js +112 -0
- package/dist/init-VWDML3UC.js.map +1 -0
- package/dist/lib.d.ts +492 -0
- package/dist/lib.js +6528 -0
- package/dist/lib.js.map +1 -0
- package/dist/mep-W4HJI363.js +25 -0
- package/dist/mep-W4HJI363.js.map +1 -0
- package/dist/merge-ESOPDSA5.js +413 -0
- package/dist/merge-ESOPDSA5.js.map +1 -0
- package/dist/publish-3TAXQCUV.js +80 -0
- package/dist/publish-3TAXQCUV.js.map +1 -0
- package/dist/render-UEWYHPN6.js +1807 -0
- package/dist/render-UEWYHPN6.js.map +1 -0
- package/dist/resolve-topology-AQ2RO3W3.js +338 -0
- package/dist/resolve-topology-AQ2RO3W3.js.map +1 -0
- package/dist/spec/csv-schema/annotation/dimension.yaml +77 -0
- package/dist/spec/csv-schema/annotation/tag.yaml +44 -0
- package/dist/spec/csv-schema/annotation/text_note.yaml +52 -0
- package/dist/spec/csv-schema/architecture/ceiling.yaml +8 -1
- package/dist/spec/csv-schema/architecture/column.yaml +5 -1
- package/dist/spec/csv-schema/architecture/curtain_wall.yaml +45 -5
- package/dist/spec/csv-schema/architecture/door.yaml +5 -0
- package/dist/spec/csv-schema/architecture/furniture.yaml +28 -0
- package/dist/spec/csv-schema/architecture/opening.yaml +27 -6
- package/dist/spec/csv-schema/architecture/railing.yaml +35 -0
- package/dist/spec/csv-schema/architecture/roof.yaml +34 -1
- package/dist/spec/csv-schema/architecture/slab.yaml +19 -0
- package/dist/spec/csv-schema/architecture/space.yaml +11 -1
- package/dist/spec/csv-schema/architecture/stair.yaml +49 -0
- package/dist/spec/csv-schema/architecture/stair_landing.yaml +36 -0
- package/dist/spec/csv-schema/architecture/stair_run.yaml +31 -0
- package/dist/spec/csv-schema/architecture/wall.yaml +14 -1
- package/dist/spec/csv-schema/architecture/window.yaml +19 -0
- package/dist/spec/csv-schema/base/element.yaml +20 -11
- package/dist/spec/csv-schema/base/furniture_params.yaml +60 -0
- package/dist/spec/csv-schema/base/hosted_element.yaml +10 -2
- package/dist/spec/csv-schema/base/mep_connectable.yaml +23 -0
- package/dist/spec/csv-schema/base/mep_design.yaml +24 -0
- package/dist/spec/csv-schema/base/mep_insulated.yaml +9 -0
- package/dist/spec/csv-schema/base/mep_system_tag.yaml +12 -0
- package/dist/spec/csv-schema/base/point_element.yaml +1 -0
- package/dist/spec/csv-schema/base/section_profile.yaml +5 -0
- package/dist/spec/csv-schema/base/spatial_line_element.yaml +4 -2
- package/dist/spec/csv-schema/base/structural_section_profile.yaml +50 -0
- package/dist/spec/csv-schema/base/vertical_span.yaml +9 -3
- package/dist/spec/csv-schema/base/wall_bounded.yaml +21 -0
- package/dist/spec/csv-schema/grid.yaml +5 -0
- package/dist/spec/csv-schema/mep/cable_tray.yaml +10 -3
- package/dist/spec/csv-schema/mep/circuit.yaml +70 -0
- package/dist/spec/csv-schema/mep/conduit.yaml +2 -2
- package/dist/spec/csv-schema/mep/connector.yaml +112 -0
- package/dist/spec/csv-schema/mep/duct.yaml +10 -3
- package/dist/spec/csv-schema/mep/equipment.yaml +18 -1
- package/dist/spec/csv-schema/mep/mep_node.yaml +91 -2
- package/dist/spec/csv-schema/mep/mep_system.yaml +21 -0
- package/dist/spec/csv-schema/mep/pipe.yaml +27 -3
- package/dist/spec/csv-schema/mep/terminal.yaml +22 -1
- package/dist/spec/csv-schema/model_group.yaml +40 -0
- package/dist/spec/csv-schema/sheet/sheet.yaml +50 -0
- package/dist/spec/csv-schema/sheet/sheet_viewport.yaml +86 -0
- package/dist/spec/csv-schema/structure/beam.yaml +29 -1
- package/dist/spec/csv-schema/structure/beam_system.yaml +29 -0
- package/dist/spec/csv-schema/structure/brace.yaml +24 -1
- package/dist/spec/csv-schema/structure/foundation.yaml +40 -7
- package/dist/spec/csv-schema/structure/structure_column.yaml +19 -1
- package/dist/spec/csv-schema/structure/structure_slab.yaml +32 -0
- package/dist/spec/csv-schema/structure/structure_wall.yaml +22 -0
- package/dist/spec/csv-schema/types/beam_type.yaml +11 -0
- package/dist/spec/csv-schema/types/ceiling_type.yaml +6 -0
- package/dist/spec/csv-schema/types/column_type.yaml +12 -0
- package/dist/spec/csv-schema/types/curtain_wall_type.yaml +32 -0
- package/dist/spec/csv-schema/types/door_type.yaml +27 -0
- package/dist/spec/csv-schema/types/element_type.yaml +21 -0
- package/dist/spec/csv-schema/types/fenestration.yaml +16 -0
- package/dist/spec/csv-schema/types/foundation_type.yaml +36 -0
- package/dist/spec/csv-schema/types/furniture_type.yaml +11 -0
- package/dist/spec/csv-schema/types/layered_type.yaml +13 -0
- package/dist/spec/csv-schema/types/railing_type.yaml +40 -0
- package/dist/spec/csv-schema/types/roof_type.yaml +7 -0
- package/dist/spec/csv-schema/types/slab_type.yaml +9 -0
- package/dist/spec/csv-schema/types/type_layer.yaml +47 -0
- package/dist/spec/csv-schema/types/wall_type.yaml +6 -0
- package/dist/spec/csv-schema/types/window_type.yaml +31 -0
- package/dist/spec/csv-schema/underlay.yaml +73 -0
- package/dist/spec/csv-schema/view.yaml +36 -0
- package/dist/spec/duckdb-strategy.md +4 -3
- package/dist/spec/geojson-schema/readme.md +380 -0
- package/dist/spec/mep-port-conventions.md +190 -0
- package/dist/spec/migration-guide.md +1 -1
- package/dist/spec/project_metadata.schema.yaml +52 -4
- package/dist/spec/readme.md +356 -97
- package/dist/spec/starter-types/global/beam_type.csv +5 -0
- package/dist/spec/starter-types/global/ceiling_type.csv +3 -0
- package/dist/spec/starter-types/global/column_type.csv +5 -0
- package/dist/spec/starter-types/global/curtain_wall_type.csv +2 -0
- package/dist/spec/starter-types/global/door_type.csv +6 -0
- package/dist/spec/starter-types/global/foundation_type.csv +7 -0
- package/dist/spec/starter-types/global/furniture_type.csv +11 -0
- package/dist/spec/starter-types/global/railing_type.csv +5 -0
- package/dist/spec/starter-types/global/roof_type.csv +3 -0
- package/dist/spec/starter-types/global/slab_type.csv +4 -0
- package/dist/spec/starter-types/global/type_layer.csv +40 -0
- package/dist/spec/starter-types/global/wall_type.csv +8 -0
- package/dist/spec/starter-types/global/window_type.csv +6 -0
- package/dist/spec/svg-schema/readme.md +47 -1
- package/package.json +17 -5
- package/dist/index.js +0 -3366
- package/dist/index.js.map +0 -1
- package/dist/spec/csv-schema/base/mep_connected_segment.yaml +0 -17
- package/dist/spec/csv-schema/base/mep_system.yaml +0 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mep/check.ts","../src/mep/index.ts"],"sourcesContent":["/**\n * MEP connectivity check — pure core, no I/O.\n *\n * Two identical copies: bimdown-spec `cli/src/mep/check.ts` (bimdown build /\n * mep-check / resolve-topology) and bimdown-editor `editor/src/mep/mepCheck.ts`\n * (connectivity panel). Edit one, copy it over the other.\n *\n * Input is a flat, unit-agnostic model: curves (duct / pipe / conduit /\n * cable_tray) with 3D end points and `from` / `to` port refs, hosts\n * (equipment / terminal / mep_node) and their declared ports with world\n * positions. Output is a list of problems: open ends, references that don't\n * resolve, ends that don't sit on the port they reference, system and domain\n * mismatches, devices with no connection, orphan fittings, circuit problems,\n * cable tray fill. Also the electrical basics the editor and CLI share:\n * circuit phases and current (I = P / (U · cosφ), × √3 for three-phase).\n */\n\nexport type Vec3 = [number, number, number];\n\nexport interface MepCurveIn {\n id: string;\n /** Id scope (level directory). Ids are unique per level; refs resolve in\n * the curve's own scope first, then `global`, then anywhere. */\n scope?: string;\n table: string;\n a: Vec3;\n b: Vec3;\n from: string;\n to: string;\n system: string;\n /** Section (model units); omitted = unknown (no size checks). */\n shape?: string;\n w?: number;\n h?: number;\n /** cable_tray.max_fill, percent (omitted = the model's limit). */\n maxFill?: number;\n}\n\nexport interface MepHostIn {\n id: string;\n scope?: string;\n table: 'equipment' | 'terminal' | 'mep_node';\n pos: Vec3;\n /** mep_node.kind (empty = passive fitting). */\n kind: string;\n /** mep_node.fitting hint (cap / open keep a single-curve node). */\n fitting: string;\n system: string;\n /** equipment / terminal circuit_id. */\n circuitId: string;\n load: number;\n /** Design flow (L/s), equipment / terminals. */\n flow?: number;\n}\n\nexport interface MepPortIn {\n hostId: string;\n scope?: string;\n name: string;\n pos: Vec3;\n system: string;\n domain: string;\n shape?: string;\n w?: number;\n h?: number;\n /** in / out / bidirectional. */\n flowDir?: string;\n}\n\nexport interface MepCircuitIn {\n id: string;\n scope?: string;\n hostId: string;\n number: string;\n voltage: number;\n rating: number;\n /** circuit.phase (L1 / L2 / L3 / L1L2 / L2L3 / L3L1 / L1L2L3) and poles. */\n phase?: string;\n poles?: number;\n /** cosφ (omitted / 0 = DEFAULT_POWER_FACTOR). */\n powerFactor?: number;\n /** Cable outer diameter (model units) and the trays it runs in. */\n cableSize?: number;\n trays?: string[];\n}\n\nexport interface MepModelIn {\n curves: MepCurveIn[];\n hosts: MepHostIn[];\n ports: MepPortIn[];\n circuits?: MepCircuitIn[];\n /** When false, refs to hosts that aren't in the model are reported as\n * `info` (the editor only sees one level at a time). Default true. */\n complete?: boolean;\n /** Incomplete models: refs (`host` or `host:port`) made by curves outside\n * the model (other levels), so a riser's node or a port used from the\n * floor above counts as connected. */\n externalRefs?: string[];\n /** Incomplete models: host ids that exist outside the model; a ref to a\n * host found nowhere is a broken reference. */\n externalHosts?: string[];\n /** Cable tray fill limit, percent (default DEFAULT_TRAY_FILL); a tray's own maxFill wins. */\n trayFillLimit?: number;\n}\n\nexport type MepProblemCode =\n | 'open_end' | 'dangling_ref' | 'port_far' | 'node_far' | 'self_loop'\n | 'system_mismatch' | 'domain_mismatch' | 'disconnected_device'\n | 'unconnected_port' | 'unused_port' | 'orphan_fitting'\n | 'no_circuit' | 'circuit_overload' | 'external_ref'\n | 'duplicate_segment' | 'size_mismatch' | 'flow_balance' | 'tray_fill';\n\nexport interface MepProblem {\n severity: 'warning' | 'info';\n code: MepProblemCode;\n /** Element the problem is reported on. */\n id: string;\n scope?: string;\n table: string;\n message: string;\n /** Where to look (model units, same frame as the input). */\n at?: Vec3;\n system?: string;\n /** Message variant and values, for translated messages (`message` is English). */\n key?: string;\n vars?: Record<string, string | number>;\n /** The other element (duplicate segment). */\n other?: string;\n}\n\n/** A curve end must sit within this distance of the port it references. */\nexport const PORT_TOLERANCE = 0.05;\n/** Revit puts curve ends at fitting faces, an arm away from the node centre. */\nexport const NODE_TOLERANCE = 2.0;\n\n// ─── Electrical ───────────────────────────────────────────\n\nexport type Phase = 'L1' | 'L2' | 'L3';\nexport const PHASES: Phase[] = ['L1', 'L2', 'L3'];\nexport const PHASE_OPTIONS = ['L1', 'L2', 'L3', 'L1L2', 'L2L3', 'L3L1', 'L1L2L3'];\nexport const DEFAULT_POWER_FACTOR = 0.9;\n/** Cable tray fill limit, percent of the tray section. */\nexport const DEFAULT_TRAY_FILL = 40;\n\n/** Phases a circuit is on: its `phase`, else all three for a 3-pole breaker, else none (unassigned). */\nexport function circuitPhases(phase: string | undefined, poles?: number): Phase[] {\n const p = (phase ?? '').trim().toUpperCase();\n if (p) return PHASES.filter(x => p.includes(x));\n return poles === 3 ? [...PHASES] : [];\n}\n\n/** Line current, A: P / (U · cosφ); three-phase P / (√3 · U · cosφ) with U line-to-line. */\nexport function circuitCurrent(loadW: number, voltage: number, phases: number, powerFactor?: number): number {\n const pf = powerFactor! > 0 && powerFactor! <= 1 ? powerFactor! : DEFAULT_POWER_FACTOR;\n if (!(voltage > 0) || !(loadW > 0)) return 0;\n return loadW / ((phases === 3 ? Math.sqrt(3) : 1) * voltage * pf);\n}\n\nexport interface TrayFill {\n id: string;\n scope?: string;\n /** Percent of the tray section taken by cables and conduits. */\n fill: number;\n limit: number;\n cables: number;\n conduits: number;\n at: Vec3;\n}\n\n/**\n * Fill of every cable tray: the sections of the circuit cables routed\n * through it (`trays`, `cableSize`) plus conduits laid in it (parallel,\n * centre line inside the tray section over part of its length), as a\n * percentage of size_x × size_y.\n */\nexport function trayFills(model: MepModelIn): TrayFill[] {\n const limit = model.trayFillLimit! > 0 ? model.trayFillLimit! : DEFAULT_TRAY_FILL;\n const conduits = model.curves.filter(c => c.table === 'conduit' && c.w! > 0);\n const out: TrayFill[] = [];\n for (const t of model.curves) {\n if (t.table !== 'cable_tray' || !(t.w! > 0)) continue;\n const w = t.w!, h = t.h! > 0 ? t.h! : t.w!;\n let area = 0, cables = 0, inTray = 0;\n for (const c of model.circuits ?? []) {\n if (!(c.cableSize! > 0) || !(c.trays ?? []).includes(t.id)) continue;\n if (c.scope !== undefined && t.scope !== undefined && c.scope !== t.scope && c.scope !== 'global' && t.scope !== 'global') continue;\n area += Math.PI * (c.cableSize! / 2) ** 2;\n cables++;\n }\n const L = dist(t.a, t.b);\n if (L > 1e-9) {\n const u: Vec3 = [(t.b[0] - t.a[0]) / L, (t.b[1] - t.a[1]) / L, (t.b[2] - t.a[2]) / L];\n const hz = Math.hypot(u[0], u[1]);\n // Across the tray (horizontal) and up (perpendicular to it)\n const side: Vec3 = hz > 1e-6 ? [-u[1] / hz, u[0] / hz, 0] : [1, 0, 0];\n const up: Vec3 = [u[1] * side[2] - u[2] * side[1], u[2] * side[0] - u[0] * side[2], u[0] * side[1] - u[1] * side[0]];\n const local = (p: Vec3) => {\n const v: Vec3 = [p[0] - t.a[0], p[1] - t.a[1], p[2] - t.a[2]];\n return [v[0] * u[0] + v[1] * u[1] + v[2] * u[2], v[0] * side[0] + v[1] * side[1] + v[2] * side[2], v[0] * up[0] + v[1] * up[1] + v[2] * up[2]];\n };\n for (const c of conduits) {\n if ((c.scope ?? '') !== (t.scope ?? '')) continue;\n const la = local(c.a), lb = local(c.b);\n const cl = dist(c.a, c.b);\n if (!(cl > 1e-9) || Math.abs(lb[0] - la[0]) < 0.9 * cl) continue; // not parallel\n const s0 = Math.max(0, Math.min(la[0], lb[0])), s1 = Math.min(L, Math.max(la[0], lb[0]));\n if (s1 - s0 <= Math.min(0.1 * L, 0.5 * cl)) continue;\n const r = c.w! / 2;\n const inside = (q: number[]) => Math.abs(q[1]) <= w / 2 - r + 1e-6 && Math.abs(q[2]) <= h / 2 + 1e-6;\n if (!inside(la) || !inside(lb)) continue;\n area += Math.PI * r * r;\n inTray++;\n }\n }\n const fill = (100 * area) / (w * h);\n const mid: Vec3 = [(t.a[0] + t.b[0]) / 2, (t.a[1] + t.b[1]) / 2, (t.a[2] + t.b[2]) / 2];\n out.push({ id: t.id, scope: t.scope, fill, limit: t.maxFill! > 0 ? t.maxFill! : limit, cables, conduits: inTray, at: mid });\n }\n return out;\n}\n\nconst DOMAIN_TABLES: Record<string, string[]> = {\n hvac: ['duct'],\n piping: ['pipe'],\n electrical: ['conduit', 'cable_tray'],\n cable_tray_conduit: ['conduit', 'cable_tray'],\n};\n\nconst SINGLE_ENDED_FITTINGS = new Set(['cap', 'open']);\n\nfunction dist(a: Vec3, b: Vec3): number {\n return Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]);\n}\n\nexport function splitRef(ref: string): { hostId: string; port: string | null } | null {\n const s = (ref ?? '').trim();\n if (!s) return null;\n const i = s.indexOf(':');\n return i < 0 ? { hostId: s, port: null } : { hostId: s.slice(0, i), port: s.slice(i + 1) };\n}\n\nfunction fmtId(id: string): string { return id; }\n\nexport function checkMep(model: MepModelIn): MepProblem[] {\n const complete = model.complete ?? true;\n const extHosts = model.externalHosts ? new Set(model.externalHosts) : null;\n /** A ref to a host missing from the model: broken unless it may live elsewhere. */\n const missingIsBroken = (hostId: string) => complete || (extHosts !== null && !extHosts.has(hostId));\n const out: MepProblem[] = [];\n const key = (scope: string | undefined, id: string) => `${scope ?? ''}/${id}`;\n const hostByKey = new Map<string, MepHostIn>();\n const hostById = new Map<string, MepHostIn>();\n for (const h of model.hosts) {\n hostByKey.set(key(h.scope, h.id), h);\n if (!hostById.has(h.id)) hostById.set(h.id, h);\n }\n /** Resolve a host id the way refs do: own scope, then global, then any. */\n const findHost = (scope: string | undefined, id: string): MepHostIn | undefined =>\n hostByKey.get(key(scope, id)) ?? hostByKey.get(key('global', id)) ?? hostById.get(id);\n const hkey = (h: MepHostIn) => key(h.scope, h.id);\n const portsByHost = new Map<string, MepPortIn[]>();\n for (const p of model.ports) {\n const host = findHost(p.scope, p.hostId);\n if (!host) continue;\n const list = portsByHost.get(hkey(host)) ?? [];\n list.push(p);\n portsByHost.set(hkey(host), list);\n }\n const portsOf = (h: MepHostIn) => portsByHost.get(hkey(h)) ?? [];\n /** host key → set of referenced port names ('' = bare host ref). */\n const usedPorts = new Map<string, Set<string>>();\n /** passive node key → curves at it. */\n const nodeCurves = new Map<string, MepCurveIn[]>();\n /** Host ids / host:port refs used by curves outside the model. */\n const extUsed = new Set<string>();\n for (const r of model.externalRefs ?? []) {\n const p = splitRef(r);\n if (!p) continue;\n extUsed.add(p.hostId);\n if (p.port) extUsed.add(`${p.hostId}:${p.port}`);\n }\n\n for (const c of model.curves) {\n const refs = [{ side: 'from' as const, ref: c.from }, { side: 'to' as const, ref: c.to }];\n const parsed = refs.map(r => splitRef(r.ref));\n // Which end is `from`: the end nearer the from-host (Revit may reverse curves).\n let fromEnd = c.a, toEnd = c.b;\n const anchorOf = (r: { hostId: string; port: string | null } | null): Vec3 | null => {\n if (!r) return null;\n const host = findHost(c.scope, r.hostId);\n if (!host) return null;\n const port = r.port ? portsOf(host).find(p => p.name === r.port) : undefined;\n return port?.pos ?? host.pos;\n };\n const fromAnchor = anchorOf(parsed[0]);\n const toAnchor = anchorOf(parsed[1]);\n if (fromAnchor ? dist(fromAnchor, c.b) < dist(fromAnchor, c.a) : (toAnchor && dist(toAnchor, c.a) < dist(toAnchor, c.b))) {\n fromEnd = c.b; toEnd = c.a;\n }\n\n if (parsed[0] && parsed[1] && parsed[0].hostId === parsed[1].hostId && parsed[0].port === parsed[1].port) {\n out.push({ severity: 'warning', code: 'self_loop', id: c.id, scope: c.scope, table: c.table, system: c.system,\n message: `${c.table} ${fmtId(c.id)} starts and ends on the same ${parsed[0].port ? 'port' : 'fitting'} (${c.from})`, at: c.a,\n key: 'self_loop', vars: { table: c.table, id: c.id, ref: c.from } });\n continue;\n }\n\n for (let i = 0; i < 2; i++) {\n const side = refs[i].side;\n const end = i === 0 ? fromEnd : toEnd;\n const r = parsed[i];\n if (!r) {\n // A vent stack's open top (through the roof) is meant to be open\n const other = i === 0 ? toEnd : fromEnd;\n if (VENT.test((c.system ?? '').split(',')[0].trim()) && end[2] - other[2] > 2 * Math.hypot(end[0] - other[0], end[1] - other[1])) continue;\n out.push({ severity: 'warning', code: 'open_end', id: c.id, scope: c.scope, table: c.table, system: c.system,\n message: `${c.table} ${fmtId(c.id)} has an open end (${side} is empty)`, at: end,\n key: 'open_end', vars: { table: c.table, id: c.id, side } });\n continue;\n }\n const host = findHost(c.scope, r.hostId);\n if (!host) {\n const broken = missingIsBroken(r.hostId);\n out.push({ severity: broken ? 'warning' : 'info', code: broken ? 'dangling_ref' : 'external_ref', id: c.id, scope: c.scope, table: c.table, system: c.system,\n message: broken ? `${c.table} ${fmtId(c.id)}.${side} = \"${refs[i].ref}\" references a missing element`\n : `${c.table} ${fmtId(c.id)} connects to ${refs[i].ref} on another level`, at: end,\n key: broken ? 'dangling_ref' : 'external_ref', vars: { table: c.table, id: c.id, side, ref: refs[i].ref } });\n continue;\n }\n const used = usedPorts.get(hkey(host)) ?? new Set<string>();\n used.add(r.port ?? '');\n usedPorts.set(hkey(host), used);\n\n if (!r.port) {\n if (host.table === 'mep_node' && !host.kind) {\n const list = nodeCurves.get(hkey(host)) ?? [];\n list.push(c);\n nodeCurves.set(hkey(host), list);\n }\n if (dist(end, host.pos) > NODE_TOLERANCE) {\n out.push({ severity: 'warning', code: 'node_far', id: c.id, scope: c.scope, table: c.table, system: c.system,\n message: `${c.table} ${fmtId(c.id)}.${side} references ${host.id} but ends ${dist(end, host.pos).toFixed(2)} away from it`, at: end,\n key: 'node_far', vars: { table: c.table, id: c.id, side, host: host.id, d: dist(end, host.pos).toFixed(2) } });\n }\n continue;\n }\n const port = portsOf(host).find(p => p.name === r.port);\n if (!port) {\n out.push({ severity: 'warning', code: 'dangling_ref', id: c.id, scope: c.scope, table: c.table, system: c.system,\n message: `${c.table} ${fmtId(c.id)}.${side} = \"${refs[i].ref}\": ${host.id} has no port \"${r.port}\"`, at: end,\n key: 'dangling_port', vars: { table: c.table, id: c.id, side, ref: refs[i].ref, host: host.id, port: r.port } });\n continue;\n }\n const d = Math.min(dist(c.a, port.pos), dist(c.b, port.pos));\n if (d > PORT_TOLERANCE) {\n out.push({ severity: 'warning', code: 'port_far', id: c.id, scope: c.scope, table: c.table, system: c.system,\n message: `${c.table} ${fmtId(c.id)}.${side} references ${refs[i].ref} but its nearest end is ${d.toFixed(3)} from the port — move the end onto the port`, at: port.pos,\n key: 'port_far', vars: { table: c.table, id: c.id, side, ref: refs[i].ref, d: d.toFixed(3) } });\n }\n const allowed = DOMAIN_TABLES[port.domain];\n if (allowed && !allowed.includes(c.table)) {\n out.push({ severity: 'warning', code: 'domain_mismatch', id: c.id, scope: c.scope, table: c.table, system: c.system,\n message: `${c.table} ${fmtId(c.id)} connects to ${port.domain} port ${refs[i].ref}`, at: port.pos,\n key: 'domain_port', vars: { table: c.table, id: c.id, domain: port.domain, ref: refs[i].ref } });\n }\n if (port.system && c.system && port.system !== c.system) {\n out.push({ severity: 'warning', code: 'system_mismatch', id: c.id, scope: c.scope, table: c.table, system: c.system,\n message: `${c.table} ${fmtId(c.id)} is ${c.system} but port ${refs[i].ref} is ${port.system}`, at: port.pos,\n key: 'system_port', vars: { table: c.table, id: c.id, system: c.system, ref: refs[i].ref, portSystem: port.system } });\n }\n if (port.domain !== 'electrical' && !sameSection(c, port)) {\n // Terminals usually take a neck / flex connection: advisory there.\n out.push({ severity: host.table === 'terminal' ? 'info' : 'warning', code: 'size_mismatch', id: c.id, scope: c.scope, table: c.table, system: c.system,\n message: `${c.table} ${fmtId(c.id)} is ${sizeText(c)} but port ${refs[i].ref} is ${sizeText(port)} (add a transition)`, at: port.pos,\n key: 'size_mismatch', vars: { table: c.table, id: c.id, size: sizeText(c), ref: refs[i].ref, portSize: sizeText(port) } });\n }\n }\n }\n\n // Passive fittings: orphans, single-curve nodes, mixed systems / tables.\n for (const h of model.hosts) {\n if (h.table !== 'mep_node') continue;\n if (h.kind) {\n // Inline accessory: every declared port must be on the run.\n const used = usedPorts.get(hkey(h)) ?? new Set<string>();\n for (const p of portsOf(h)) {\n if (!used.has(p.name) && !extUsed.has(`${h.id}:${p.name}`)) {\n out.push({ severity: 'warning', code: 'unconnected_port', id: h.id, scope: h.scope, table: h.table, system: h.system || p.system,\n message: `${h.kind} ${h.id}: port \"${p.name}\" is not connected`, at: p.pos,\n key: 'unconnected_port', vars: { kind: h.kind, id: h.id, port: p.name } });\n }\n }\n continue;\n }\n const curves = nodeCurves.get(hkey(h)) ?? [];\n if (extUsed.has(h.id)) continue; // continues on another level\n if (curves.length === 0) {\n out.push({ severity: 'warning', code: 'orphan_fitting', id: h.id, scope: h.scope, table: h.table, system: h.system,\n message: `fitting ${h.id} has no connected curves`, at: h.pos,\n key: 'orphan_fitting', vars: { id: h.id } });\n continue;\n }\n if (curves.length === 1 && !SINGLE_ENDED_FITTINGS.has(h.fitting)) {\n out.push({ severity: 'warning', code: 'open_end', id: curves[0].id, scope: curves[0].scope, table: curves[0].table, system: curves[0].system,\n message: `${curves[0].table} ${curves[0].id} ends at ${h.id} with nothing else connected (cap it or connect it)`, at: h.pos,\n key: 'open_end_node', vars: { table: curves[0].table, id: curves[0].id, node: h.id } });\n }\n const systems = new Set(curves.map(c => c.system).filter(Boolean));\n if (systems.size > 1 && !ventOnStack(systems)) {\n out.push({ severity: 'warning', code: 'system_mismatch', id: h.id, scope: h.scope, table: h.table, system: [...systems].join(','),\n message: `fitting ${h.id} joins different systems: ${[...systems].join(', ')}`, at: h.pos,\n key: 'system_node', vars: { id: h.id, systems: [...systems].join(', ') } });\n }\n const tables = new Set(curves.map(c => c.table));\n if (tables.size > 1) {\n out.push({ severity: 'warning', code: 'domain_mismatch', id: h.id, scope: h.scope, table: h.table, system: h.system,\n message: `fitting ${h.id} joins ${[...tables].join(' and ')}`, at: h.pos,\n key: 'domain_node', vars: { id: h.id, tables: [...tables].join(' / ') } });\n }\n }\n\n // Devices: no connection at all, or unused ports. Electrical ports are fed by\n // circuits, not curves.\n const circuitIds = new Set((model.circuits ?? []).map(c => c.id));\n for (const h of model.hosts) {\n if (h.table === 'mep_node') continue;\n const ports = portsOf(h);\n const used = new Set(usedPorts.get(hkey(h)) ?? []);\n for (const p of ports) if (extUsed.has(`${h.id}:${p.name}`)) used.add(p.name);\n if (extUsed.has(h.id)) used.add('');\n const isElectric = (p: MepPortIn) => p.domain === 'electrical' && !used.has(p.name);\n const fluid = ports.filter(p => !isElectric(p));\n const electric = ports.filter(isElectric);\n if (electric.length > 0 && !h.circuitId && fluid.length === 0 && (model.circuits?.length ?? 0) > 0) {\n out.push({ severity: 'info', code: 'no_circuit', id: h.id, scope: h.scope, table: h.table, system: h.system,\n message: `${h.table} ${h.id} is not on a circuit`, at: h.pos,\n key: 'no_circuit', vars: { table: h.table, id: h.id } });\n }\n if (h.circuitId && complete && !circuitIds.has(h.circuitId)) {\n out.push({ severity: 'warning', code: 'dangling_ref', id: h.id, scope: h.scope, table: h.table, system: h.system,\n message: `${h.table} ${h.id}.circuit_id = \"${h.circuitId}\" references a missing circuit`, at: h.pos,\n key: 'dangling_circuit', vars: { table: h.table, id: h.id, ref: h.circuitId } });\n }\n if (fluid.length === 0) continue;\n const connected = fluid.filter(p => used.has(p.name));\n if (connected.length === 0 && !used.has('')) {\n out.push({ severity: 'warning', code: 'disconnected_device', id: h.id, scope: h.scope, table: h.table, system: h.system,\n message: `${h.table} ${h.id} has ${fluid.length} port(s) and none is connected`, at: h.pos,\n key: 'disconnected_device', vars: { table: h.table, id: h.id, n: fluid.length } });\n } else {\n for (const p of fluid) {\n if (used.has(p.name)) continue;\n out.push({ severity: 'info', code: 'unused_port', id: h.id, scope: h.scope, table: h.table, system: p.system,\n message: `${h.table} ${h.id}: port \"${p.name}\" (${p.system || p.domain}) is not connected`, at: p.pos,\n key: 'unused_port', vars: { table: h.table, id: h.id, port: p.name, system: p.system || p.domain } });\n }\n }\n }\n\n // Circuits: missing panel, connected load over 80 % of the breaker.\n for (const c of model.circuits ?? []) {\n if (!findHost(c.scope, c.hostId)) {\n const broken = missingIsBroken(c.hostId);\n out.push({ severity: broken ? 'warning' : 'info', code: broken ? 'dangling_ref' : 'external_ref', id: c.id, scope: c.scope, table: 'circuit',\n message: `circuit ${c.id} panel \"${c.hostId}\" is missing`,\n key: 'dangling_panel', vars: { id: c.id, ref: c.hostId } });\n }\n if (c.voltage > 0 && c.rating > 0) {\n const load = model.hosts.filter(h => h.circuitId === c.id).reduce((s, h) => s + (h.load || 0), 0);\n const current = circuitCurrent(load, c.voltage, circuitPhases(c.phase, c.poles).length, c.powerFactor);\n if (current > c.rating * 0.8) {\n const amps = Math.round(current * 10) / 10;\n out.push({ severity: 'warning', code: 'circuit_overload', id: c.id, scope: c.scope, table: 'circuit',\n message: `circuit ${c.number || c.id}: ${Math.round(load)} W draws ${amps} A, over 80 % of its ${c.rating} A breaker (${c.voltage} V)`,\n key: 'circuit_overload', vars: { id: c.number || c.id, load: Math.round(load), current: amps, rating: c.rating, voltage: c.voltage } });\n }\n }\n }\n\n // Cable trays over their fill limit.\n for (const f of trayFills(model)) {\n if (f.fill <= f.limit + 1e-9) continue;\n const pct = Math.round(f.fill * 10) / 10;\n out.push({ severity: 'warning', code: 'tray_fill', id: f.id, scope: f.scope, table: 'cable_tray', at: f.at,\n message: `cable_tray ${f.id} is ${pct} % full (${f.cables} cable(s), ${f.conduits} conduit(s)), over its ${f.limit} % limit`,\n key: 'tray_fill', vars: { id: f.id, fill: pct, limit: f.limit, cables: f.cables, conduits: f.conduits } });\n }\n\n out.push(...duplicateSegments(model.curves));\n out.push(...flowBalance(model, findHost, hkey, portsOf));\n return out;\n}\n\nconst VENT = /^(V|VENT|VTR|SV)$/i;\nconst DRAIN = /^(SAN|SS|SW|W|WASTE|SOIL|D|DR|DRAIN)$/i;\n/** A plumbing vent tying into the one drainage system it ventilates. */\nfunction ventOnStack(systems: Set<string>): boolean {\n const list = [...systems];\n return list.every(s => VENT.test(s) || DRAIN.test(s)) && list.filter(s => DRAIN.test(s)).length === 1;\n}\n\nconst roundSection = (table: string, shape: string | undefined) => table === 'pipe' || table === 'conduit' || shape === 'round';\nconst close = (a: number, b: number) => Math.abs(a - b) <= Math.max(1e-3, 0.02 * Math.max(Math.abs(a), Math.abs(b)));\n\n/** A curve section equals a port section (rect sides in either order). Unknown sizes match. */\nexport function sameSection(c: { table: string; shape?: string; w?: number; h?: number }, p: { shape?: string; w?: number; h?: number }): boolean {\n if (!(c.w! > 0) || !(p.w! > 0)) return true;\n const cr = roundSection(c.table, c.shape), pr = roundSection(c.table, p.shape) || !(p.h! > 0);\n if (cr !== pr) return false;\n if (cr) return close(c.w!, p.w!);\n const ch = c.h! > 0 ? c.h! : c.w!, ph = p.h!;\n return (close(c.w!, p.w!) && close(ch, ph)) || (close(c.w!, ph) && close(ch, p.w!));\n}\n\nfunction sizeText(x: { table?: string; shape?: string; w?: number; h?: number }): string {\n const f = (v: number) => String(Math.round(v * 1e4) / 1e4);\n if (!(x.w! > 0)) return '?';\n return roundSection(x.table ?? '', x.shape) || !(x.h! > 0) ? `Ø${f(x.w!)}` : `${f(x.w!)}×${f(x.h!)}`;\n}\n\n/** Tolerance (model units) for two segments to count as on top of each other. */\nconst OVERLAP_TOL = 0.01;\n\n/**\n * Duplicate / overlapping segments: two curves of the same table lying on\n * the same line and sharing more than OVERLAP_TOL of their length (a run\n * drawn twice, a back-and-forth riser).\n */\nexport function duplicateSegments(curves: MepCurveIn[]): MepProblem[] {\n const out: MepProblem[] = [];\n const items = curves.map(c => ({ c, lo: Math.min(c.a[0], c.b[0]), hi: Math.max(c.a[0], c.b[0]), len: dist(c.a, c.b) }))\n .filter(i => i.len > OVERLAP_TOL)\n .sort((p, q) => p.lo - q.lo);\n const flagged = new Set<string>();\n for (let i = 0; i < items.length; i++) {\n const A = items[i];\n for (let j = i + 1; j < items.length && items[j].lo <= A.hi + OVERLAP_TOL; j++) {\n const B = items[j];\n if (A.c.table !== B.c.table || (A.c.scope ?? '') !== (B.c.scope ?? '')) continue;\n const u: Vec3 = [(A.c.b[0] - A.c.a[0]) / A.len, (A.c.b[1] - A.c.a[1]) / A.len, (A.c.b[2] - A.c.a[2]) / A.len];\n // B's ends must lie on A's line.\n const off = (p: Vec3) => {\n const v: Vec3 = [p[0] - A.c.a[0], p[1] - A.c.a[1], p[2] - A.c.a[2]];\n const t = v[0] * u[0] + v[1] * u[1] + v[2] * u[2];\n return { t, d: Math.hypot(v[0] - u[0] * t, v[1] - u[1] * t, v[2] - u[2] * t) };\n };\n const p1 = off(B.c.a), p2 = off(B.c.b);\n if (p1.d > OVERLAP_TOL || p2.d > OVERLAP_TOL) continue;\n const overlap = Math.min(A.len, Math.max(p1.t, p2.t)) - Math.max(0, Math.min(p1.t, p2.t));\n if (overlap <= OVERLAP_TOL) continue;\n const key = `${B.c.scope ?? ''}/${B.c.id}`;\n if (flagged.has(key)) continue;\n flagged.add(key);\n const mid = Math.max(0, Math.min(p1.t, p2.t)) + overlap / 2;\n out.push({ severity: 'warning', code: 'duplicate_segment', id: B.c.id, scope: B.c.scope, table: B.c.table, system: B.c.system, other: A.c.id,\n message: `${B.c.table} ${B.c.id} lies on top of ${A.c.id} over ${overlap.toFixed(2)} (duplicate segment, delete one)`,\n at: [A.c.a[0] + u[0] * mid, A.c.a[1] + u[1] * mid, A.c.a[2] + u[2] * mid],\n key: 'duplicate_segment', vars: { table: B.c.table, id: B.c.id, other: A.c.id, length: overlap.toFixed(2) } });\n }\n }\n return out;\n}\n\n/**\n * Supply flow balance: equipment with a design flow vs the sum of the air\n * terminals its supply port reaches (through fittings, accessories and\n * pass-through devices such as VAV boxes). More than 10 % apart is flagged.\n */\nfunction flowBalance(\n model: MepModelIn,\n findHost: (scope: string | undefined, id: string) => MepHostIn | undefined,\n hkey: (h: MepHostIn) => string,\n portsOf: (h: MepHostIn) => MepPortIn[],\n): MepProblem[] {\n const out: MepProblem[] = [];\n const at = new Map<string, MepCurveIn[]>();\n const ends = new Map<MepCurveIn, MepHostIn[]>();\n for (const c of model.curves) {\n const hs: MepHostIn[] = [];\n for (const ref of [c.from, c.to]) {\n const r = splitRef(ref);\n const h = r ? findHost(c.scope, r.hostId) : undefined;\n if (!h) continue;\n hs.push(h);\n const list = at.get(hkey(h)) ?? [];\n list.push(c);\n at.set(hkey(h), list);\n }\n ends.set(c, hs);\n }\n const passThrough = (h: MepHostIn) => {\n const fl = portsOf(h).filter(p => p.domain === 'hvac');\n return fl.length === 2 && fl.map(p => p.flowDir ?? '').sort().join(',') === 'in,out';\n };\n for (const h of model.hosts) {\n if (h.table !== 'equipment' || !(h.flow! > 0)) continue;\n for (const p of portsOf(h)) {\n if (p.domain !== 'hvac' || p.flowDir !== 'out') continue;\n const start = (at.get(hkey(h)) ?? []).filter(c => [c.from, c.to].some(r => splitRef(r)?.port === p.name));\n if (start.length === 0) continue;\n const seenC = new Set<MepCurveIn>(), seenH = new Set<string>([hkey(h)]);\n const queue = [...start];\n let sum = 0, n = 0;\n while (queue.length) {\n const c = queue.pop()!;\n if (seenC.has(c)) continue;\n seenC.add(c);\n for (const o of ends.get(c) ?? []) {\n const k = hkey(o);\n if (seenH.has(k)) continue;\n seenH.add(k);\n if (o.table === 'terminal') { sum += o.flow ?? 0; n++; continue; }\n if (o.table === 'mep_node' || passThrough(o)) queue.push(...(at.get(k) ?? []));\n }\n }\n if (n === 0 || !(sum > 0) || Math.abs(sum - h.flow!) <= 0.1 * h.flow!) continue;\n const f = (v: number) => String(Math.round(v * 10) / 10);\n out.push({ severity: 'warning', code: 'flow_balance', id: h.id, scope: h.scope, table: h.table, system: p.system || h.system,\n message: `equipment ${h.id} supplies ${f(h.flow!)} L/s from port \"${p.name}\" but its ${n} terminal(s) take ${f(sum)} L/s`, at: p.pos,\n key: 'flow_balance', vars: { id: h.id, flow: f(h.flow!), port: p.name, n, sum: f(sum) } });\n }\n }\n return out;\n}\n","import { checkMep, type MepProblem } from './check.js';\nimport { loadMep, summarizeSystems, type SystemSummary } from './load.js';\n\nexport { checkMep, loadMep, summarizeSystems };\nexport type { MepProblem, SystemSummary };\n\nexport interface MepReport {\n systems: SystemSummary[];\n problems: (MepProblem & { dir: string })[];\n}\n\nexport function mepReport(dir: string): MepReport {\n const m = loadMep(dir);\n const problems = checkMep(m).map(p => ({ ...p, dir: p.scope ?? '' }));\n return { systems: summarizeSystems(m), problems };\n}\n\n/** One line per problem: `lv-1/duct.csv du-3: …`. */\nexport function formatProblem(p: MepProblem & { dir: string }): string {\n return `${p.dir ? `${p.dir}/` : ''}${p.table}.csv ${p.id}: [${p.code}] ${p.message}`;\n}\n\n/** Problems `bimdown build` reports as errors: a port / fitting / circuit reference to nothing. */\nconst ERROR_CODES = new Set(['dangling_ref']);\n\n/** Connectivity warnings for `bimdown build` (info-level findings and errors are left out). */\nexport function mepWarnings(dir: string): string[] {\n const r = mepReport(dir);\n return r.problems.filter(p => p.severity === 'warning' && !ERROR_CODES.has(p.code)).map(formatProblem);\n}\n\n/** Connectivity errors for `bimdown build`: references to elements or ports that don't exist. */\nexport function mepErrors(dir: string): string[] {\n const r = mepReport(dir);\n return r.problems.filter(p => p.severity === 'warning' && ERROR_CODES.has(p.code)).map(formatProblem);\n}\n"],"mappings":";;;;;;;AAmIO,IAAM,iBAAiB;AAEvB,IAAM,iBAAiB;AAKvB,IAAM,SAAkB,CAAC,MAAM,MAAM,IAAI;AAEzC,IAAM,uBAAuB;AAE7B,IAAM,oBAAoB;AAG1B,SAAS,cAAc,OAA2B,OAAyB;AAChF,QAAM,KAAK,SAAS,IAAI,KAAK,EAAE,YAAY;AAC3C,MAAI,EAAG,QAAO,OAAO,OAAO,OAAK,EAAE,SAAS,CAAC,CAAC;AAC9C,SAAO,UAAU,IAAI,CAAC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A,QAAgB,MAAM,EAAE,IAAI,EAAE,IAAI,MAAM,EAAE,EAAE,IAAK,GAAG,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,GAAG,EAAE;AAAA,MAAE,CAAC;AAAA,IAC7F;AAAA,EACF;AACA,SAAO;AACT;;;ACpmBO,SAAS,UAAU,KAAwB;AAChD,QAAM,IAAI,QAAQ,GAAG;AACrB,QAAM,WAAW,SAAS,CAAC,EAAE,IAAI,QAAM,EAAE,GAAG,GAAG,KAAK,EAAE,SAAS,GAAG,EAAE;AACpE,SAAO,EAAE,SAAS,iBAAiB,CAAC,GAAG,SAAS;AAClD;AAGO,SAAS,cAAc,GAAyC;AACrE,SAAO,GAAG,EAAE,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,KAAK,SAAS,EAAE,EAAE,MAAM,EAAE,IAAI,KAAK,EAAE,OAAO;AACrF;AAGA,IAAM,cAAc,oBAAI,IAAI,CAAC,cAAc,CAAC;AAGrC,SAAS,YAAY,KAAuB;AACjD,QAAM,IAAI,UAAU,GAAG;AACvB,SAAO,EAAE,SAAS,OAAO,OAAK,EAAE,aAAa,aAAa,CAAC,YAAY,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,aAAa;AACvG;AAGO,SAAS,UAAU,KAAuB;AAC/C,QAAM,IAAI,UAAU,GAAG;AACvB,SAAO,EAAE,SAAS,OAAO,OAAK,EAAE,aAAa,aAAa,YAAY,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,aAAa;AACtG;","names":[]}
|
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/geo/roof-solver.ts
|
|
4
|
+
var EPS = 1e-9;
|
|
5
|
+
var AREA_EPS = 1e-7;
|
|
6
|
+
function signedArea(poly) {
|
|
7
|
+
let a = 0;
|
|
8
|
+
for (let i = 0; i < poly.length; i++) {
|
|
9
|
+
const p = poly[i], q = poly[(i + 1) % poly.length];
|
|
10
|
+
a += p.x * q.y - q.x * p.y;
|
|
11
|
+
}
|
|
12
|
+
return a / 2;
|
|
13
|
+
}
|
|
14
|
+
function cleanRing(poly, eps = 1e-6) {
|
|
15
|
+
const out = [];
|
|
16
|
+
for (const p of poly) {
|
|
17
|
+
const last = out[out.length - 1];
|
|
18
|
+
if (!last || Math.hypot(p.x - last.x, p.y - last.y) > eps) out.push({ x: p.x, y: p.y });
|
|
19
|
+
}
|
|
20
|
+
while (out.length > 1 && Math.hypot(out[0].x - out[out.length - 1].x, out[0].y - out[out.length - 1].y) <= eps) out.pop();
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
var evalHp = (h, p) => h.a * p.x + h.b * p.y + h.c;
|
|
24
|
+
var riseOf = (pl, p) => pl.a * p.x + pl.b * p.y + pl.c;
|
|
25
|
+
function clipHalf(poly, h) {
|
|
26
|
+
const out = [];
|
|
27
|
+
const n = poly.length;
|
|
28
|
+
for (let i = 0; i < n; i++) {
|
|
29
|
+
const a = poly[i], b = poly[(i + 1) % n];
|
|
30
|
+
const fa = evalHp(h, a), fb = evalHp(h, b);
|
|
31
|
+
if (fa >= -EPS) out.push(a);
|
|
32
|
+
if (fa > EPS && fb < -EPS || fa < -EPS && fb > EPS) {
|
|
33
|
+
const t = fa / (fa - fb);
|
|
34
|
+
out.push({ x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return cleanRing(out, 1e-9);
|
|
38
|
+
}
|
|
39
|
+
function isPiece(poly) {
|
|
40
|
+
return poly.length >= 3 && Math.abs(signedArea(poly)) > AREA_EPS;
|
|
41
|
+
}
|
|
42
|
+
function triangulate(poly) {
|
|
43
|
+
const pts = cleanRing(poly);
|
|
44
|
+
if (pts.length < 3) return [];
|
|
45
|
+
const ccw = signedArea(pts) >= 0 ? pts : pts.slice().reverse();
|
|
46
|
+
const idx = ccw.map((_, i) => i);
|
|
47
|
+
const tris = [];
|
|
48
|
+
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
|
49
|
+
const inTri = (p, a, b, c) => cross(a, b, p) >= -EPS && cross(b, c, p) >= -EPS && cross(c, a, p) >= -EPS;
|
|
50
|
+
let guard = 0;
|
|
51
|
+
while (idx.length > 3 && guard++ < 1e4) {
|
|
52
|
+
let clipped = false;
|
|
53
|
+
for (let k = 0; k < idx.length; k++) {
|
|
54
|
+
const i0 = idx[(k + idx.length - 1) % idx.length], i1 = idx[k], i2 = idx[(k + 1) % idx.length];
|
|
55
|
+
const a = ccw[i0], b = ccw[i1], c = ccw[i2];
|
|
56
|
+
const cr = cross(a, b, c);
|
|
57
|
+
if (cr <= EPS) {
|
|
58
|
+
if (Math.abs(cr) <= EPS) {
|
|
59
|
+
idx.splice(k, 1);
|
|
60
|
+
clipped = true;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
let ear = true;
|
|
66
|
+
for (const j of idx) {
|
|
67
|
+
if (j === i0 || j === i1 || j === i2) continue;
|
|
68
|
+
const p = ccw[j];
|
|
69
|
+
if (p.x === a.x && p.y === a.y || p.x === b.x && p.y === b.y || p.x === c.x && p.y === c.y) continue;
|
|
70
|
+
if (inTri(p, a, b, c)) {
|
|
71
|
+
ear = false;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (!ear) continue;
|
|
76
|
+
tris.push([a, b, c]);
|
|
77
|
+
idx.splice(k, 1);
|
|
78
|
+
clipped = true;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
if (!clipped) break;
|
|
82
|
+
}
|
|
83
|
+
if (idx.length === 3) {
|
|
84
|
+
const t = idx.map((i) => ccw[i]);
|
|
85
|
+
if (Math.abs(signedArea(t)) > AREA_EPS) tris.push(signedArea(t) > 0 ? t : t.reverse());
|
|
86
|
+
}
|
|
87
|
+
return tris;
|
|
88
|
+
}
|
|
89
|
+
function bounds(poly) {
|
|
90
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
91
|
+
for (const p of poly) {
|
|
92
|
+
if (p.x < minX) minX = p.x;
|
|
93
|
+
if (p.x > maxX) maxX = p.x;
|
|
94
|
+
if (p.y < minY) minY = p.y;
|
|
95
|
+
if (p.y > maxY) maxY = p.y;
|
|
96
|
+
}
|
|
97
|
+
return { minX, minY, maxX, maxY };
|
|
98
|
+
}
|
|
99
|
+
function pointInPolygon(p, poly) {
|
|
100
|
+
let inside = false;
|
|
101
|
+
for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) {
|
|
102
|
+
const a = poly[i], b = poly[j];
|
|
103
|
+
if (a.y > p.y !== b.y > p.y && p.x < (b.x - a.x) * (p.y - a.y) / (b.y - a.y) + a.x) inside = !inside;
|
|
104
|
+
}
|
|
105
|
+
return inside;
|
|
106
|
+
}
|
|
107
|
+
function centroid(poly) {
|
|
108
|
+
let a = 0, cx = 0, cy = 0;
|
|
109
|
+
for (let i = 0; i < poly.length; i++) {
|
|
110
|
+
const p = poly[i], q = poly[(i + 1) % poly.length];
|
|
111
|
+
const c = p.x * q.y - q.x * p.y;
|
|
112
|
+
a += c;
|
|
113
|
+
cx += (p.x + q.x) * c;
|
|
114
|
+
cy += (p.y + q.y) * c;
|
|
115
|
+
}
|
|
116
|
+
if (Math.abs(a) < 1e-12) {
|
|
117
|
+
const n = poly.length || 1;
|
|
118
|
+
return { x: poly.reduce((s, v) => s + v.x, 0) / n, y: poly.reduce((s, v) => s + v.y, 0) / n };
|
|
119
|
+
}
|
|
120
|
+
return { x: cx / (3 * a), y: cy / (3 * a) };
|
|
121
|
+
}
|
|
122
|
+
var distFn = (e) => ({ a: e.n.x, b: e.n.y, c: -(e.a.x * e.n.x + e.a.y * e.n.y) });
|
|
123
|
+
var scale = (h, k) => ({ a: h.a * k, b: h.b * k, c: h.c * k });
|
|
124
|
+
var minus = (p, q) => ({ a: p.a - q.a, b: p.b - q.b, c: p.c - q.c });
|
|
125
|
+
function solveRoof(input) {
|
|
126
|
+
const outline = cleanRing(input.outline);
|
|
127
|
+
const n = outline.length;
|
|
128
|
+
const orient = signedArea(outline) >= 0 ? 1 : -1;
|
|
129
|
+
const planes = [];
|
|
130
|
+
const planeEdge = [];
|
|
131
|
+
const empty = {
|
|
132
|
+
planes: [{ a: 0, b: 0, c: 0 }],
|
|
133
|
+
planeEdge: [-1],
|
|
134
|
+
pieces: [],
|
|
135
|
+
rise: () => 0,
|
|
136
|
+
lines: [],
|
|
137
|
+
maxRise: 0,
|
|
138
|
+
maxSlopeDeg: 0
|
|
139
|
+
};
|
|
140
|
+
if (n < 3) return empty;
|
|
141
|
+
const edges = outline.map((a, i) => {
|
|
142
|
+
const b = outline[(i + 1) % n];
|
|
143
|
+
const len = Math.hypot(b.x - a.x, b.y - a.y) || 1;
|
|
144
|
+
const ux = (b.x - a.x) / len, uy = (b.y - a.y) / len;
|
|
145
|
+
const slope = input.edgeSlopes[i] ?? 0;
|
|
146
|
+
return {
|
|
147
|
+
a,
|
|
148
|
+
b,
|
|
149
|
+
n: { x: -uy * orient, y: ux * orient },
|
|
150
|
+
tan: slope > 0 ? Math.tan(Math.min(slope, 89) * Math.PI / 180) : 0,
|
|
151
|
+
mid: { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 }
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
const tris = triangulate(outline);
|
|
155
|
+
const zeroPlane = () => {
|
|
156
|
+
planes.push({ a: 0, b: 0, c: 0 });
|
|
157
|
+
planeEdge.push(-1);
|
|
158
|
+
return planes.length - 1;
|
|
159
|
+
};
|
|
160
|
+
if (input.profile && input.profile.pts.length >= 2) {
|
|
161
|
+
const { origin, across } = input.profile;
|
|
162
|
+
const pts = [...input.profile.pts].sort((p, q) => p.u - q.u);
|
|
163
|
+
const uFn = { a: across.x, b: across.y, c: -(origin.x * across.x + origin.y * across.y) };
|
|
164
|
+
const bands = [];
|
|
165
|
+
const addPlane = (k, z0) => {
|
|
166
|
+
planes.push({ a: k * uFn.a, b: k * uFn.b, c: z0 + k * uFn.c });
|
|
167
|
+
planeEdge.push(-1);
|
|
168
|
+
return planes.length - 1;
|
|
169
|
+
};
|
|
170
|
+
bands.push({ lo: -Infinity, hi: pts[0].u, plane: addPlane(0, pts[0].z) });
|
|
171
|
+
for (let i = 0; i + 1 < pts.length; i++) {
|
|
172
|
+
const du = pts[i + 1].u - pts[i].u;
|
|
173
|
+
if (du < 1e-9) continue;
|
|
174
|
+
const k = (pts[i + 1].z - pts[i].z) / du;
|
|
175
|
+
bands.push({ lo: pts[i].u, hi: pts[i + 1].u, plane: addPlane(k, pts[i].z - k * pts[i].u) });
|
|
176
|
+
}
|
|
177
|
+
bands.push({ lo: pts[pts.length - 1].u, hi: Infinity, plane: addPlane(0, pts[pts.length - 1].z) });
|
|
178
|
+
const pieces2 = [];
|
|
179
|
+
for (const tri of tris) {
|
|
180
|
+
for (const band of bands) {
|
|
181
|
+
let poly = tri;
|
|
182
|
+
if (band.lo > -Infinity) poly = clipHalf(poly, { ...uFn, c: uFn.c - band.lo });
|
|
183
|
+
if (band.hi < Infinity) poly = clipHalf(poly, scale({ ...uFn, c: uFn.c - band.hi }, -1));
|
|
184
|
+
if (isPiece(poly)) pieces2.push({ poly, plane: band.plane });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const rise2 = (p) => {
|
|
188
|
+
const u = evalHp(uFn, p);
|
|
189
|
+
for (const band of bands) if (u >= band.lo - 1e-9 && u <= band.hi + 1e-9) return riseOf(planes[band.plane], p);
|
|
190
|
+
return 0;
|
|
191
|
+
};
|
|
192
|
+
return finish(planes, planeEdge, pieces2, rise2, outline);
|
|
193
|
+
}
|
|
194
|
+
const sloped = edges.map((e) => e.tan > 0);
|
|
195
|
+
if (!sloped.some(Boolean)) {
|
|
196
|
+
const z = zeroPlane();
|
|
197
|
+
return finish(planes, planeEdge, tris.map((poly) => ({ poly, plane: z })), () => 0, outline);
|
|
198
|
+
}
|
|
199
|
+
const wedges = [];
|
|
200
|
+
edges.forEach((e, i) => {
|
|
201
|
+
if (!sloped[i]) return;
|
|
202
|
+
const d = distFn(e);
|
|
203
|
+
const pl = { a: d.a * e.tan, b: d.b * e.tan, c: d.c * e.tan };
|
|
204
|
+
let pi = planes.findIndex((q, k) => planeEdge[k] >= 0 && Math.abs(q.a - pl.a) < 1e-9 && Math.abs(q.b - pl.b) < 1e-9 && Math.abs(q.c - pl.c) < 1e-7);
|
|
205
|
+
if (pi < 0) {
|
|
206
|
+
planes.push(pl);
|
|
207
|
+
planeEdge.push(i);
|
|
208
|
+
pi = planes.length - 1;
|
|
209
|
+
}
|
|
210
|
+
const hps = [d];
|
|
211
|
+
for (const j of [(i + n - 1) % n, (i + 1) % n]) {
|
|
212
|
+
const o = edges[j];
|
|
213
|
+
const g = sloped[j] ? minus(scale(d, e.tan), scale(distFn(o), o.tan)) : distFn(o);
|
|
214
|
+
const s = evalHp(g, e.mid);
|
|
215
|
+
if (Math.abs(s) < 1e-9) continue;
|
|
216
|
+
hps.push(scale(g, s > 0 ? 1 : -1));
|
|
217
|
+
}
|
|
218
|
+
wedges.push({ plane: pi, hps });
|
|
219
|
+
});
|
|
220
|
+
let capPlane = -1;
|
|
221
|
+
if (input.cap !== void 0 && input.cap > 0) {
|
|
222
|
+
planes.push({ a: 0, b: 0, c: input.cap });
|
|
223
|
+
planeEdge.push(-1);
|
|
224
|
+
capPlane = planes.length - 1;
|
|
225
|
+
}
|
|
226
|
+
let zero = -1;
|
|
227
|
+
const inWedge = (w, p, tol = 1e-7) => w.hps.every((h) => evalHp(h, p) >= -tol);
|
|
228
|
+
const activeAt = (p, tol) => {
|
|
229
|
+
const act = [];
|
|
230
|
+
for (const w of wedges) if (!act.includes(w.plane) && inWedge(w, p, tol)) act.push(w.plane);
|
|
231
|
+
if (capPlane >= 0) act.push(capPlane);
|
|
232
|
+
return act;
|
|
233
|
+
};
|
|
234
|
+
const rise = (p) => {
|
|
235
|
+
let z = Infinity;
|
|
236
|
+
for (const pl of activeAt(p, 1e-6)) z = Math.min(z, riseOf(planes[pl], p));
|
|
237
|
+
return z === Infinity ? 0 : Math.max(0, z);
|
|
238
|
+
};
|
|
239
|
+
const lines = uniqueLines(wedges.flatMap((w) => w.hps));
|
|
240
|
+
const pieces = [];
|
|
241
|
+
for (const tri of tris) {
|
|
242
|
+
let cells = [tri];
|
|
243
|
+
for (const ln of lines) {
|
|
244
|
+
const next = [];
|
|
245
|
+
for (const cell of cells) {
|
|
246
|
+
let pos = false, neg = false;
|
|
247
|
+
for (const p of cell) {
|
|
248
|
+
const v = evalHp(ln, p);
|
|
249
|
+
if (v > 1e-9) pos = true;
|
|
250
|
+
else if (v < -1e-9) neg = true;
|
|
251
|
+
}
|
|
252
|
+
if (!(pos && neg)) {
|
|
253
|
+
next.push(cell);
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
const a = clipHalf(cell, ln), b = clipHalf(cell, scale(ln, -1));
|
|
257
|
+
if (isPiece(a)) next.push(a);
|
|
258
|
+
if (isPiece(b)) next.push(b);
|
|
259
|
+
}
|
|
260
|
+
cells = next;
|
|
261
|
+
}
|
|
262
|
+
for (const cell of cells) {
|
|
263
|
+
const act = activeAt(centroid(cell));
|
|
264
|
+
if (act.length === 0) {
|
|
265
|
+
if (zero < 0) zero = zeroPlane();
|
|
266
|
+
pieces.push({ poly: cell, plane: zero });
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
for (const i of act) {
|
|
270
|
+
let poly = cell;
|
|
271
|
+
for (const j of act) {
|
|
272
|
+
if (j === i || poly.length < 3) continue;
|
|
273
|
+
const pi = planes[i], pj = planes[j];
|
|
274
|
+
poly = clipHalf(poly, { a: pj.a - pi.a, b: pj.b - pi.b, c: pj.c - pi.c });
|
|
275
|
+
}
|
|
276
|
+
if (isPiece(poly)) pieces.push({ poly, plane: i });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return finish(planes, planeEdge, pieces, rise, outline);
|
|
281
|
+
}
|
|
282
|
+
function uniqueLines(hps) {
|
|
283
|
+
const out = [];
|
|
284
|
+
for (const h of hps) {
|
|
285
|
+
const len = Math.hypot(h.a, h.b);
|
|
286
|
+
if (len < 1e-12) continue;
|
|
287
|
+
const k = { a: h.a / len, b: h.b / len, c: h.c / len };
|
|
288
|
+
if (out.some((o) => Math.abs(o.a - k.a) < 1e-7 && Math.abs(o.b - k.b) < 1e-7 && Math.abs(o.c - k.c) < 1e-6 || Math.abs(o.a + k.a) < 1e-7 && Math.abs(o.b + k.b) < 1e-7 && Math.abs(o.c + k.c) < 1e-6)) continue;
|
|
289
|
+
out.push(k);
|
|
290
|
+
}
|
|
291
|
+
return out;
|
|
292
|
+
}
|
|
293
|
+
function finish(planes, planeEdge, pieces, rise, outline) {
|
|
294
|
+
const ccwPieces = pieces.map((pc) => ({ ...pc, poly: signedArea(pc.poly) >= 0 ? pc.poly : pc.poly.slice().reverse() }));
|
|
295
|
+
let maxRise = 0;
|
|
296
|
+
for (const pc of ccwPieces) for (const p of pc.poly) maxRise = Math.max(maxRise, riseOf(planes[pc.plane], p));
|
|
297
|
+
let maxSlopeDeg = 0;
|
|
298
|
+
const used = new Set(ccwPieces.map((p) => p.plane));
|
|
299
|
+
for (const i of used) {
|
|
300
|
+
const g = Math.hypot(planes[i].a, planes[i].b);
|
|
301
|
+
maxSlopeDeg = Math.max(maxSlopeDeg, Math.atan(g) * 180 / Math.PI);
|
|
302
|
+
}
|
|
303
|
+
return {
|
|
304
|
+
planes,
|
|
305
|
+
planeEdge,
|
|
306
|
+
pieces: ccwPieces,
|
|
307
|
+
rise,
|
|
308
|
+
lines: foldLines(planes, ccwPieces, rise, outline),
|
|
309
|
+
maxRise,
|
|
310
|
+
maxSlopeDeg
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function foldLines(planes, pieces, rise, outline) {
|
|
314
|
+
const DELTA = 1e-3;
|
|
315
|
+
const planeAt = (p) => {
|
|
316
|
+
for (const pc of pieces) {
|
|
317
|
+
let inside = true;
|
|
318
|
+
const poly = pc.poly;
|
|
319
|
+
for (let i = 0; i < poly.length; i++) {
|
|
320
|
+
const a = poly[i], b = poly[(i + 1) % poly.length];
|
|
321
|
+
if ((b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x) < -1e-9) {
|
|
322
|
+
inside = false;
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (inside) return pc.plane;
|
|
327
|
+
}
|
|
328
|
+
return -1;
|
|
329
|
+
};
|
|
330
|
+
const samePlane = (i, j) => {
|
|
331
|
+
const p = planes[i], q = planes[j];
|
|
332
|
+
return Math.abs(p.a - q.a) < 1e-9 && Math.abs(p.b - q.b) < 1e-9 && Math.abs(p.c - q.c) < 1e-7;
|
|
333
|
+
};
|
|
334
|
+
const groups = /* @__PURE__ */ new Map();
|
|
335
|
+
for (const pc of pieces) {
|
|
336
|
+
const poly = pc.poly;
|
|
337
|
+
for (let i = 0; i < poly.length; i++) {
|
|
338
|
+
const a = poly[i], b = poly[(i + 1) % poly.length];
|
|
339
|
+
const len = Math.hypot(b.x - a.x, b.y - a.y);
|
|
340
|
+
if (len < 1e-6) continue;
|
|
341
|
+
const ux = (b.x - a.x) / len, uy = (b.y - a.y) / len;
|
|
342
|
+
const m = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
343
|
+
const probe = { x: m.x + uy * DELTA, y: m.y - ux * DELTA };
|
|
344
|
+
if (!pointInPolygon(probe, outline)) continue;
|
|
345
|
+
const other = planeAt(probe);
|
|
346
|
+
if (other < 0 || other === pc.plane || samePlane(other, pc.plane)) continue;
|
|
347
|
+
const key = pc.plane < other ? `${pc.plane}|${other}` : `${other}|${pc.plane}`;
|
|
348
|
+
let g = groups.get(key);
|
|
349
|
+
if (!g) groups.set(key, g = { dir: { x: ux, y: uy }, origin: a, spans: [] });
|
|
350
|
+
const t = (p) => (p.x - g.origin.x) * g.dir.x + (p.y - g.origin.y) * g.dir.y;
|
|
351
|
+
const ta = t(a), tb = t(b);
|
|
352
|
+
g.spans.push([Math.min(ta, tb), Math.max(ta, tb)]);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const out = [];
|
|
356
|
+
for (const g of groups.values()) {
|
|
357
|
+
g.spans.sort((p, q) => p[0] - q[0]);
|
|
358
|
+
const merged = [];
|
|
359
|
+
for (const s of g.spans) {
|
|
360
|
+
const last = merged[merged.length - 1];
|
|
361
|
+
if (last && s[0] <= last[1] + 1e-5) last[1] = Math.max(last[1], s[1]);
|
|
362
|
+
else merged.push([s[0], s[1]]);
|
|
363
|
+
}
|
|
364
|
+
for (const [t0, t1] of merged) {
|
|
365
|
+
if (t1 - t0 < 1e-4) continue;
|
|
366
|
+
const a = { x: g.origin.x + g.dir.x * t0, y: g.origin.y + g.dir.y * t0 };
|
|
367
|
+
const b = { x: g.origin.x + g.dir.x * t1, y: g.origin.y + g.dir.y * t1 };
|
|
368
|
+
const m = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
369
|
+
const nx = -g.dir.y, ny = g.dir.x;
|
|
370
|
+
const h = rise(m);
|
|
371
|
+
const h1 = rise({ x: m.x + nx * DELTA * 5, y: m.y + ny * DELTA * 5 });
|
|
372
|
+
const h2 = rise({ x: m.x - nx * DELTA * 5, y: m.y - ny * DELTA * 5 });
|
|
373
|
+
const convex = h - (h1 + h2) / 2 > 0;
|
|
374
|
+
const level = Math.abs(rise(a) - rise(b)) < 1e-6;
|
|
375
|
+
out.push({ a, b, kind: !convex ? "valley" : level ? "ridge" : "hip" });
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return out;
|
|
379
|
+
}
|
|
380
|
+
function parseNumberList(s) {
|
|
381
|
+
if (!s || !s.trim()) return [];
|
|
382
|
+
return s.split(";").map((v) => v.trim() === "" ? NaN : Number(v));
|
|
383
|
+
}
|
|
384
|
+
function legacyEdgeSlopes(outline, roofType, slopeDeg) {
|
|
385
|
+
const n = outline.length;
|
|
386
|
+
if (roofType === "flat" || !(slopeDeg > 0) || n < 3) return new Array(n).fill(0);
|
|
387
|
+
if (roofType === "hip" || roofType === "mansard") return new Array(n).fill(slopeDeg);
|
|
388
|
+
const len = (i) => {
|
|
389
|
+
const a = outline[i], b = outline[(i + 1) % n];
|
|
390
|
+
return Math.hypot(b.x - a.x, b.y - a.y);
|
|
391
|
+
};
|
|
392
|
+
const { minX, minY, maxX, maxY } = bounds(outline);
|
|
393
|
+
const alongX = maxX - minX >= maxY - minY;
|
|
394
|
+
const dirOf = (i) => {
|
|
395
|
+
const a = outline[i], b = outline[(i + 1) % n];
|
|
396
|
+
const l = len(i) || 1;
|
|
397
|
+
return { x: (b.x - a.x) / l, y: (b.y - a.y) / l };
|
|
398
|
+
};
|
|
399
|
+
if (roofType === "shed") {
|
|
400
|
+
let best = -1, bestKey = Infinity;
|
|
401
|
+
for (let i = 0; i < n; i++) {
|
|
402
|
+
const d = dirOf(i);
|
|
403
|
+
if (Math.abs(alongX ? d.x : d.y) < 0.99) continue;
|
|
404
|
+
const a = outline[i], b = outline[(i + 1) % n];
|
|
405
|
+
const key = alongX ? (a.y + b.y) / 2 : (a.x + b.x) / 2;
|
|
406
|
+
if (key < bestKey - 1e-9) {
|
|
407
|
+
bestKey = key;
|
|
408
|
+
best = i;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (best < 0) {
|
|
412
|
+
for (let i = 0; i < n; i++) if (best < 0 || len(i) > len(best)) best = i;
|
|
413
|
+
}
|
|
414
|
+
return outline.map((_, i) => i === best ? slopeDeg : 0);
|
|
415
|
+
}
|
|
416
|
+
const orient = signedArea(outline) >= 0 ? 1 : -1;
|
|
417
|
+
const convex = (v) => {
|
|
418
|
+
const p = outline[(v + n - 1) % n], c = outline[v], q = outline[(v + 1) % n];
|
|
419
|
+
return ((c.x - p.x) * (q.y - c.y) - (c.y - p.y) * (q.x - c.x)) * orient > 1e-9;
|
|
420
|
+
};
|
|
421
|
+
const ends = outline.map((_, i) => convex(i) && convex((i + 1) % n) && len(i) < len((i + n - 1) % n) - 1e-6 && len(i) < len((i + 1) % n) - 1e-6);
|
|
422
|
+
if (!ends.some(Boolean)) {
|
|
423
|
+
for (let i = 0; i < n; i++) {
|
|
424
|
+
const d = dirOf(i);
|
|
425
|
+
if (Math.abs(alongX ? d.y : d.x) > 0.99) ends[i] = true;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return outline.map((_, i) => ends[i] ? 0 : slopeDeg);
|
|
429
|
+
}
|
|
430
|
+
function mansardCap(outline, steepDeg) {
|
|
431
|
+
const { minX, minY, maxX, maxY } = bounds(outline);
|
|
432
|
+
const halfSpan = Math.min(maxX - minX, maxY - minY) / 2;
|
|
433
|
+
return halfSpan * 0.3 * Math.tan(steepDeg * Math.PI / 180);
|
|
434
|
+
}
|
|
435
|
+
var mansardSlope = (slopeDeg) => Math.min(slopeDeg + 20, 70);
|
|
436
|
+
function roofInputFor(outline, attrs) {
|
|
437
|
+
const ring = cleanRing(outline);
|
|
438
|
+
const roofType = attrs.roof_type || "flat";
|
|
439
|
+
const slope = parseFloat(attrs.slope || "0") || 0;
|
|
440
|
+
if (roofType === "extrusion") {
|
|
441
|
+
const profile = parseProfile(attrs.profile);
|
|
442
|
+
if (ring.length >= 3 && profile.length >= 2) {
|
|
443
|
+
const a = ring[0], b = ring[1];
|
|
444
|
+
const len = Math.hypot(b.x - a.x, b.y - a.y) || 1;
|
|
445
|
+
const orient = signedArea(ring) >= 0 ? 1 : -1;
|
|
446
|
+
return {
|
|
447
|
+
outline: ring,
|
|
448
|
+
edgeSlopes: [],
|
|
449
|
+
profile: { origin: a, across: { x: -(b.y - a.y) / len * orient, y: (b.x - a.x) / len * orient }, pts: profile }
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
return { outline: ring, edgeSlopes: new Array(ring.length).fill(0) };
|
|
453
|
+
}
|
|
454
|
+
const explicit = parseNumberList(attrs.edge_slopes);
|
|
455
|
+
if (explicit.length === ring.length && explicit.some((v) => v > 0)) {
|
|
456
|
+
const edgeSlopes = explicit.map((v) => Number.isFinite(v) && v > 0 ? v : 0);
|
|
457
|
+
const cap = roofType === "mansard" ? mansardCap(ring, Math.max(...edgeSlopes)) : void 0;
|
|
458
|
+
return { outline: ring, edgeSlopes, cap };
|
|
459
|
+
}
|
|
460
|
+
if (roofType === "mansard" && slope > 0) {
|
|
461
|
+
const steep = mansardSlope(slope);
|
|
462
|
+
return { outline: ring, edgeSlopes: new Array(ring.length).fill(steep), cap: mansardCap(ring, steep) };
|
|
463
|
+
}
|
|
464
|
+
return { outline: ring, edgeSlopes: legacyEdgeSlopes(ring, roofType, slope) };
|
|
465
|
+
}
|
|
466
|
+
function parseProfile(s) {
|
|
467
|
+
if (!s) return [];
|
|
468
|
+
const out = [];
|
|
469
|
+
for (const pair of s.split(";")) {
|
|
470
|
+
const [u, z] = pair.split(",").map((v) => Number(v.trim()));
|
|
471
|
+
if (Number.isFinite(u) && Number.isFinite(z)) out.push({ u, z });
|
|
472
|
+
}
|
|
473
|
+
return out;
|
|
474
|
+
}
|
|
475
|
+
function verticalThickness(t, slopeDeg) {
|
|
476
|
+
const c = Math.cos(Math.min(slopeDeg, 80) * Math.PI / 180);
|
|
477
|
+
return c > 1e-6 ? t / c : t;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
export {
|
|
481
|
+
signedArea,
|
|
482
|
+
centroid,
|
|
483
|
+
solveRoof,
|
|
484
|
+
roofInputFor,
|
|
485
|
+
verticalThickness
|
|
486
|
+
};
|
|
487
|
+
//# sourceMappingURL=chunk-HS3PO2LB.js.map
|