@nubisco/bim 0.0.0-stage → 0.0.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.
- package/LICENSE +21 -0
- package/README.md +80 -2
- package/dist/cells-G6pIWvCF.d.ts +110 -0
- package/dist/cells.d.ts +2 -0
- package/dist/cells.js +25 -0
- package/dist/chunk-6Q4JIXFQ.js +54 -0
- package/dist/chunk-7YR7CGBI.js +1115 -0
- package/dist/chunk-EHYUT42U.js +126 -0
- package/dist/chunk-I47MDCHW.js +457 -0
- package/dist/chunk-L3Z5LJAA.js +58 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-OCAFB7M7.js +286 -0
- package/dist/chunk-SFKOZPPS.js +308 -0
- package/dist/chunk-TE5NK6DO.js +686 -0
- package/dist/chunk-TVNU2NAO.js +47 -0
- package/dist/convert.d.ts +39 -0
- package/dist/convert.js +17 -0
- package/dist/edges-CnXyFuCX.d.ts +67 -0
- package/dist/edges.d.ts +2 -0
- package/dist/edges.js +18 -0
- package/dist/history.d.ts +33 -0
- package/dist/history.js +7 -0
- package/dist/ifc-read.d.ts +61 -0
- package/dist/ifc-read.js +17 -0
- package/dist/ifc.d.ts +60 -0
- package/dist/ifc.js +20 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +81 -0
- package/dist/v1-CnwNIVI8.d.ts +260 -0
- package/dist/v1.d.ts +2 -0
- package/dist/v1.js +21 -0
- package/dist/v2.d.ts +198 -0
- package/dist/v2.js +27 -0
- package/dist/validate.d.ts +13 -0
- package/dist/validate.js +10 -0
- package/package.json +110 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nubisco Lda
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,81 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nubisco/bim
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A building as a model, in pure TypeScript: storeys, walls, spaces, doors and windows,
|
|
4
|
+
measured in whole millimetres, with validation, plan geometry, an edit history, and an
|
|
5
|
+
IFC4 writer and reader. No WebAssembly, no Node and no DOM, so the same code runs in a
|
|
6
|
+
browser and on a server.
|
|
7
|
+
|
|
8
|
+
It began as the House plan of [OpenBridge](https://github.com/nubisco/openbridge), and is
|
|
9
|
+
the building model of Keystone, Nubisco's renovation project manager.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
pnpm add @nubisco/bim
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## What is in it
|
|
16
|
+
|
|
17
|
+
| Module | What it does |
|
|
18
|
+
| ----------------------- | ------------------------------------------------------------------------------------------------------ |
|
|
19
|
+
| `@nubisco/bim/v2` | The plan: `Plan`, `Storey`, `Wall`, `Space`, `Opening` (door, window, gap), `Radiator`, `Furniture` |
|
|
20
|
+
| `@nubisco/bim/validate` | `validatePlan`: checks a plan from the outside world and returns a clean copy, or throws `PlanError` |
|
|
21
|
+
| `@nubisco/bim/ifc` | `toIfc`: the plan as an IFC4 STEP file, with stable GlobalIds |
|
|
22
|
+
| `@nubisco/bim/ifc-read` | `fromIfc`: an IFC file read into a plan, with notes on what was left out, and `adoptIds` |
|
|
23
|
+
| `@nubisco/bim/v1` | Version 1: the plan as a grid of half metre cells and rectangles, which a simple editor draws |
|
|
24
|
+
| `@nubisco/bim/convert` | `fromV1` and `toV1`, carrying what version 1 cannot say (wall thickness, angled walls, any room shape) |
|
|
25
|
+
| `@nubisco/bim/cells` | Plane geometry on any measurements: point in polygon, areas, outlines of rectangles |
|
|
26
|
+
| `@nubisco/bim/edges` | Straight edges at any angle in whole millimetres: which lie on one line, and the walls rooms make |
|
|
27
|
+
| `@nubisco/bim/history` | `History`: undo and redo over whole snapshots |
|
|
28
|
+
|
|
29
|
+
`@nubisco/bim` re-exports the plan, validation, IFC and history by name, and version 1,
|
|
30
|
+
`cells` and `edges` as namespaces.
|
|
31
|
+
|
|
32
|
+
## The plan
|
|
33
|
+
|
|
34
|
+
Every length is a whole number of millimetres. x grows to the right and y grows down the
|
|
35
|
+
plan as drawn, with (0, 0) at the plot's top left corner. Walls are elements of their own,
|
|
36
|
+
a straight centre line with a thickness. Spaces are polygons. Doors and windows are hosted
|
|
37
|
+
by a wall, at a distance along it.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { validatePlan, type Plan } from '@nubisco/bim'
|
|
41
|
+
import { toIfc } from '@nubisco/bim/ifc'
|
|
42
|
+
import { fromIfc } from '@nubisco/bim/ifc-read'
|
|
43
|
+
|
|
44
|
+
const plan: Plan = validatePlan(JSON.parse(json))
|
|
45
|
+
const ifc = toIfc(plan, { name: 'Home' })
|
|
46
|
+
|
|
47
|
+
const { plan: read, notes } = fromIfc(ifcText)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
A placement is a device on the plan. Its `ref` is opaque here: the application that uses
|
|
51
|
+
the model decides what it names. `toIfc` exports only the devices its caller describes.
|
|
52
|
+
|
|
53
|
+
## IFC
|
|
54
|
+
|
|
55
|
+
The export maps storeys, spaces, walls (with a material layer for their thickness), slabs,
|
|
56
|
+
doors and windows (filling openings that void their wall), shading devices, radiators and
|
|
57
|
+
furniture. Detail IFC has no place for goes in the property sets `House_Site`,
|
|
58
|
+
`House_Opening`, `House_Covering` and `House_Device`, so an export read back is the same
|
|
59
|
+
building. Every export in the tests is validated with IfcOpenShell.
|
|
60
|
+
|
|
61
|
+
The import reads what the common tools write: walls by their Axis or body, spaces by their
|
|
62
|
+
footprint (moved from the inside faces of the walls onto their centre lines), doors and
|
|
63
|
+
windows through their openings, in millimetres, metres or feet. What it cannot read it
|
|
64
|
+
leaves out and says so in `notes`.
|
|
65
|
+
|
|
66
|
+
The full mapping, and the decisions behind it, are in [docs/design.md](docs/design.md).
|
|
67
|
+
|
|
68
|
+
## Development
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
pnpm install
|
|
72
|
+
pnpm run quality:check
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The IfcOpenShell check runs when `IFC_PYTHON` points at a Python with `ifcopenshell` and
|
|
76
|
+
`pytest` (CI installs them). `test/fixtures/make-foreign-ifc.py` regenerates the file the
|
|
77
|
+
import is tested against. See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Point } from './v2.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shapes made of grid cells, and the polygons around them. Version 1 rooms
|
|
5
|
+
* are rectangles, version 2 spaces are polygons, and these turn one into the
|
|
6
|
+
* other exactly.
|
|
7
|
+
*
|
|
8
|
+
* The cells are not a fixed size. A `Grid` cuts the plane at every x and y a
|
|
9
|
+
* shape has a corner at, so a rectangle of any size is a block of whole
|
|
10
|
+
* cells, and the algorithms here walk a few dozen cells however finely the
|
|
11
|
+
* shape is measured. Cells are named by their index in the grid, and the
|
|
12
|
+
* grid turns indices back into coordinates.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
interface Rect {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
w: number;
|
|
19
|
+
h: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The coordinates a grid is cut at along one axis. Values that differ by
|
|
23
|
+
* less than a thousandth of a millimetre at the scale they are given in are
|
|
24
|
+
* the same cut, so sums like x + w land on the cut they mean.
|
|
25
|
+
*/
|
|
26
|
+
declare class Axis {
|
|
27
|
+
private readonly scale;
|
|
28
|
+
readonly at: number[];
|
|
29
|
+
private readonly index;
|
|
30
|
+
constructor(values: number[], scale?: number);
|
|
31
|
+
private key;
|
|
32
|
+
/** The index of a cut. Throws for a value the grid was not cut at, which is a bug. */
|
|
33
|
+
i(v: number): number;
|
|
34
|
+
get length(): number;
|
|
35
|
+
}
|
|
36
|
+
/** A plane cut at every corner of some shapes. */
|
|
37
|
+
declare class Grid {
|
|
38
|
+
readonly xs: Axis;
|
|
39
|
+
readonly ys: Axis;
|
|
40
|
+
constructor(xs: Axis, ys: Axis);
|
|
41
|
+
/**
|
|
42
|
+
* Cut at every edge of these rectangles and corner of these loops.
|
|
43
|
+
* `scale` is how many millimetres one unit is, so cuts closer than a
|
|
44
|
+
* micrometre merge (1 for millimetres, 500 for version 1 cells).
|
|
45
|
+
*/
|
|
46
|
+
static of(rects: Rect[], loops?: Point[][], scale?: number): Grid;
|
|
47
|
+
/** The cells these rectangles cover. Each must sit on the grid's cuts. */
|
|
48
|
+
cells(rects: Rect[]): Cells;
|
|
49
|
+
point([i, j]: Point): Point;
|
|
50
|
+
rect(r: Rect): Rect;
|
|
51
|
+
/** How large a block of cells is, in real units. */
|
|
52
|
+
area(r: Rect): number;
|
|
53
|
+
/** The cells whose centres are inside an outline and outside its holes. */
|
|
54
|
+
inside(outline: Point[], holes: Point[][]): Cells;
|
|
55
|
+
}
|
|
56
|
+
/** The outline of some rectangles and its holes, in their own units: `cellLoops` on a grid cut to fit. */
|
|
57
|
+
declare function rectLoops(rects: Rect[], scale?: number): Point[][];
|
|
58
|
+
/** A set of cells, each named by its top left corner. */
|
|
59
|
+
declare class Cells {
|
|
60
|
+
private readonly set;
|
|
61
|
+
add(x: number, y: number): void;
|
|
62
|
+
delete(x: number, y: number): void;
|
|
63
|
+
has(x: number, y: number): boolean;
|
|
64
|
+
get size(): number;
|
|
65
|
+
[Symbol.iterator](): IterableIterator<[number, number]>;
|
|
66
|
+
static of(rects: Rect[]): Cells;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The boundary of a set of cells as closed loops of corner points, with
|
|
70
|
+
* straight runs merged into one edge. The outer loop of a piece runs
|
|
71
|
+
* clockwise on screen (y down), and a hole anticlockwise. Loops are listed
|
|
72
|
+
* largest first, so a connected shape's outline is the first.
|
|
73
|
+
*/
|
|
74
|
+
declare function cellLoops(cells: Cells): Point[][];
|
|
75
|
+
/** Drop corners in the middle of a straight run. */
|
|
76
|
+
declare function simplify(loop: Point[]): Point[];
|
|
77
|
+
/** Signed area by the shoelace formula, positive for clockwise on screen (y down). */
|
|
78
|
+
declare function area(loop: Point[]): number;
|
|
79
|
+
/** Whether a point lies on a polygon's edge, within `eps`. */
|
|
80
|
+
declare function onEdge(p: Point, loop: Point[], eps?: number): boolean;
|
|
81
|
+
/** Whether a point is inside a polygon (even-odd rule), not counting its edge. */
|
|
82
|
+
declare function inside(p: Point, loop: Point[]): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Split a connected set of cells into as few rectangles as this greedy finds:
|
|
85
|
+
* the largest first (by real area, given the grid the cells are on), then each time the largest that shares an edge with
|
|
86
|
+
* what is taken. Ties go to the top, then the left, so the answer is stable.
|
|
87
|
+
*/
|
|
88
|
+
declare function rectangles(cells: Cells, grid?: Grid): Rect[];
|
|
89
|
+
|
|
90
|
+
type cells_Axis = Axis;
|
|
91
|
+
declare const cells_Axis: typeof Axis;
|
|
92
|
+
type cells_Cells = Cells;
|
|
93
|
+
declare const cells_Cells: typeof Cells;
|
|
94
|
+
type cells_Grid = Grid;
|
|
95
|
+
declare const cells_Grid: typeof Grid;
|
|
96
|
+
type cells_Rect = Rect;
|
|
97
|
+
declare const cells_area: typeof area;
|
|
98
|
+
declare const cells_cellLoops: typeof cellLoops;
|
|
99
|
+
declare const cells_inside: typeof inside;
|
|
100
|
+
declare const cells_onEdge: typeof onEdge;
|
|
101
|
+
declare const cells_rectLoops: typeof rectLoops;
|
|
102
|
+
declare const cells_rectangles: typeof rectangles;
|
|
103
|
+
declare const cells_simplify: typeof simplify;
|
|
104
|
+
declare namespace cells {
|
|
105
|
+
export { cells_Axis as Axis, cells_Cells as Cells, cells_Grid as Grid, cells_area as area, cells_cellLoops as cellLoops, cells_inside as inside, cells_onEdge as onEdge, cells_rectLoops as rectLoops, cells_rectangles as rectangles, cells_simplify as simplify };
|
|
106
|
+
export type { cells_Rect as Rect };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { Axis as A, Cells as C, Grid as G, area as a, cellLoops as b, cells as c, rectangles as d, inside as i, onEdge as o, rectLoops as r, simplify as s };
|
|
110
|
+
export type { Rect as R };
|
package/dist/cells.d.ts
ADDED
package/dist/cells.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Axis,
|
|
3
|
+
Cells,
|
|
4
|
+
Grid,
|
|
5
|
+
area,
|
|
6
|
+
cellLoops,
|
|
7
|
+
inside,
|
|
8
|
+
onEdge,
|
|
9
|
+
rectLoops,
|
|
10
|
+
rectangles,
|
|
11
|
+
simplify
|
|
12
|
+
} from "./chunk-OCAFB7M7.js";
|
|
13
|
+
import "./chunk-MLKGABMK.js";
|
|
14
|
+
export {
|
|
15
|
+
Axis,
|
|
16
|
+
Cells,
|
|
17
|
+
Grid,
|
|
18
|
+
area,
|
|
19
|
+
cellLoops,
|
|
20
|
+
inside,
|
|
21
|
+
onEdge,
|
|
22
|
+
rectLoops,
|
|
23
|
+
rectangles,
|
|
24
|
+
simplify
|
|
25
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/v2.ts
|
|
2
|
+
var PLAN_VERSION = 2;
|
|
3
|
+
var DOOR_OPERATIONS = ["swing", "double-swing", "sliding", "lift-slide", "folding", "pocket"];
|
|
4
|
+
var WINDOW_OPERATIONS = ["fixed", "casement", "tilt-turn", "sliding", "awning", "hung"];
|
|
5
|
+
var LEAVES = ["solid", "glazed", "part-glazed"];
|
|
6
|
+
var FRAME_MATERIALS = ["aluminium", "pvc", "wood", "steel"];
|
|
7
|
+
var COVERING_KINDS = ["shutter", "external-blind", "awning", "curtain", "blind"];
|
|
8
|
+
function isGlazed(o) {
|
|
9
|
+
return o.kind === "window" || o.kind === "door" && o.leaf !== "solid";
|
|
10
|
+
}
|
|
11
|
+
var FURNITURE_KINDS = [
|
|
12
|
+
"table",
|
|
13
|
+
"cabinet",
|
|
14
|
+
"island",
|
|
15
|
+
"bed",
|
|
16
|
+
"sofa",
|
|
17
|
+
"shelves",
|
|
18
|
+
"rug",
|
|
19
|
+
"bath",
|
|
20
|
+
"shower",
|
|
21
|
+
"toilet",
|
|
22
|
+
"basin",
|
|
23
|
+
"lounger",
|
|
24
|
+
"parasol",
|
|
25
|
+
"planter",
|
|
26
|
+
"pergola"
|
|
27
|
+
];
|
|
28
|
+
var LIGHT_MOUNTS = ["ceiling", "wall", "floor", "table", "pool"];
|
|
29
|
+
var DEVICE_LOOKS = ["outlet", "tv", "fridge", "washer", "dehumidifier", "vacuum", "mower", "tap"];
|
|
30
|
+
var DEFAULTS = {
|
|
31
|
+
storeyHeight: 2800,
|
|
32
|
+
wallHeight: 2500,
|
|
33
|
+
/** A wall with a room on one side only. */
|
|
34
|
+
outerWall: 300,
|
|
35
|
+
/** A wall between two rooms. */
|
|
36
|
+
innerWall: 100,
|
|
37
|
+
doorHead: 2100,
|
|
38
|
+
windowSill: 900,
|
|
39
|
+
windowHead: 2100
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
PLAN_VERSION,
|
|
44
|
+
DOOR_OPERATIONS,
|
|
45
|
+
WINDOW_OPERATIONS,
|
|
46
|
+
LEAVES,
|
|
47
|
+
FRAME_MATERIALS,
|
|
48
|
+
COVERING_KINDS,
|
|
49
|
+
isGlazed,
|
|
50
|
+
FURNITURE_KINDS,
|
|
51
|
+
LIGHT_MOUNTS,
|
|
52
|
+
DEVICE_LOOKS,
|
|
53
|
+
DEFAULTS
|
|
54
|
+
};
|