@build-qube/takeoff-calculator 2.1.0 → 2.3.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.
Files changed (5) hide show
  1. package/README.md +4 -0
  2. package/browser.js +1 -1
  3. package/index.d.ts +351 -270
  4. package/index.js +754 -750
  5. package/package.json +14 -13
package/index.d.ts CHANGED
@@ -1,190 +1,238 @@
1
1
  /* auto-generated by NAPI-RS */
2
2
  /* eslint-disable */
3
3
  export declare class ContourWrapper {
4
- constructor(contour: ContourInput);
5
- /** Get the surface points for the contour. */
6
- getSurfacePoints(): Array<Point3D> | null;
7
- /**
8
- * Compute cut/fill volume against a reference surface.
9
- * Returns None if the surface mesh is not available (e.g. contour conversion failed).
10
- */
11
- volumeAgainst(
12
- reference: ReferenceSurfaceInput,
13
- cellSize?: number | undefined | null,
14
- ): VolumetricResult | null;
15
- /**
16
- * Get the z value at a given x, y coordinate.
17
- * Returns None if the surface mesh is not available (e.g. contour conversion failed).
18
- */
19
- getZAt(x: number, y: number): number | null;
20
- /**
21
- * Get scatter data for the contour.
22
- * Returns None if the surface mesh is not available (e.g. contour conversion failed).
23
- *
24
- * # Arguments
25
- *
26
- * * `step` - The step size for the scatter data.
27
- *
28
- * # Returns
29
- *
30
- * * `Vec<Point3D>` - The scatter data.
31
- * * `None` - If the surface mesh is not available (e.g. contour conversion failed).
32
- */
33
- getScatterData(step: number): Array<Point3D> | null;
4
+ /** Create a new contour wrapper from a contour input. */
5
+ constructor(contour: ContourInput);
6
+ /**
7
+ * Set the scale of the contour.
8
+ * This will rebuild the surface mesh.
9
+ */
10
+ setScale(scale: Scale): void;
11
+ /** Get the id of the contour. */
12
+ get id(): string;
13
+ /** Get the page id of the contour. */
14
+ get pageId(): string;
15
+ /** Get the scale of the contour. */
16
+ get scale(): Scale | null;
17
+ /** Get the surface points of the contour. */
18
+ getSurfacePoints(): Array<Point3D> | null;
19
+ /** Get the z value at the given x and y coordinates. */
20
+ getZAt(x: number, y: number): number | null;
21
+ /** Get the scatter data of the contour. */
22
+ getScatterData(step: number): Array<Point3D> | null;
23
+ /** Get scaled scatter data of the contour. */
24
+ getRealWorldScatterData(step: number): Array<Point3D> | null;
25
+ /** Compute raw cut/fill volume (pixel-space values) against a reference surface. */
26
+ rawVolumeAgainst(
27
+ reference: ReferenceSurfaceInput,
28
+ cellSize?: number | undefined | null,
29
+ ): VolumetricResult | null;
30
+ /**
31
+ * Compute unit-aware cut/fill volume against a reference surface.
32
+ * Returns None if surface mesh or scale is not available.
33
+ */
34
+ volumeAgainst(
35
+ reference: ReferenceSurfaceInput,
36
+ cellSize?: number | undefined | null,
37
+ ): VolumetricUnitResult | null;
34
38
  }
35
39
 
36
40
  export declare class GroupWrapper {
37
- /** Get the id of the group. */
38
- get id(): string;
39
- get area(): UnitValue | null;
40
- get length(): UnitValue | null;
41
- get points(): number | null;
42
- get count(): number | null;
43
- get group(): Group;
41
+ /** Get the id of the group. */
42
+ get id(): string;
43
+ /**
44
+ * Get the area for this group.
45
+ *
46
+ * Returns `None` if the area has not been computed or if the mutex is poisoned.
47
+ */
48
+ get area(): UnitValue | null;
49
+ /**
50
+ * Get the length for this group.
51
+ *
52
+ * Returns `None` if the length has not been computed or if the mutex is poisoned.
53
+ */
54
+ get length(): UnitValue | null;
55
+ /**
56
+ * Get the points count for this group.
57
+ *
58
+ * Returns `None` if the points count has not been computed or if the mutex is poisoned.
59
+ */
60
+ get points(): number | null;
61
+ /**
62
+ * Get the count for this group.
63
+ *
64
+ * Returns `None` if the count has not been computed or if the mutex is poisoned.
65
+ */
66
+ get count(): number | null;
67
+ get group(): Group;
44
68
  }
45
69
 
46
70
  export declare class MeasurementWrapper {
47
- get points(): number;
48
- get measurement(): Measurement;
49
- get area(): UnitValue | null;
50
- convertArea(unit: Unit): number | null;
51
- convertLength(unit: Unit): number | null;
52
- get length(): UnitValue | null;
53
- get scale(): Scale | null;
54
- get id(): string;
55
- get pageId(): string;
56
- get groupId(): string;
57
- get rawArea(): number;
58
- get rawPerimeter(): number;
71
+ get points(): number;
72
+ get count(): number;
73
+ get measurement(): Measurement;
74
+ get area(): UnitValue | null;
75
+ convertArea(unit: Unit): number | null;
76
+ convertLength(unit: Unit): number | null;
77
+ get length(): UnitValue | null;
78
+ get scale(): Scale | null;
79
+ get id(): string;
80
+ get pageId(): string;
81
+ get groupId(): string;
82
+ get rawArea(): number;
83
+ get rawPerimeter(): number;
59
84
  }
60
85
 
61
86
  export declare class TakeoffStateHandler {
62
- /**
63
- * Creates a new state.
64
- *
65
- * # Arguments
66
- *
67
- * * `options` - The options for the state.
68
- *
69
- * # Returns
70
- *
71
- * * `State` - The new state.
72
- */
73
- constructor(options?: StateOptions | undefined | null);
74
- getMeasurementsByGroupId(groupId: string): Array<MeasurementWrapper>;
75
- /**
76
- * Get the scale for a measurement.
77
- *
78
- * # Arguments
79
- *
80
- * * `measurement_id` - The id of the measurement.
81
- *
82
- * # Returns
83
- *
84
- * * `None` - If the measurement was not found.
85
- * * `Some(scale)` - If the scale was found.
86
- */
87
- getMeasurementScale(measurementId: string): Scale | null;
88
- /**
89
- * Inserts or updates a page in the state.
90
- *
91
- * # Arguments
92
- *
93
- * * `page` - The page to insert or update.
94
- *
95
- * # Returns
96
- *
97
- * * `None` - If the page was not found.
98
- * * `Some(page)` - If the page was found and updated.
99
- */
100
- upsertPage(page: Page): Page | null;
101
- removePage(pageId: string): Page | null;
102
- getGroup(groupId: string): GroupWrapper | null;
103
- /**
104
- * Inserts or updates a group in the state.
105
- *
106
- * # Arguments
107
- *
108
- * * `group` - The group to insert or update.
109
- *
110
- * # Returns
111
- *
112
- * * `None` - If the group was not found.
113
- * * `Some(group)` - If the group was found and updated.
114
- */
115
- upsertGroup(group: Group): Group | null;
116
- /**
117
- * Removes a group from the state.
118
- *
119
- * # Arguments
120
- *
121
- * * `group_id` - The id of the group to remove.
122
- *
123
- * # Returns
124
- * * `None` - If the group was not found.
125
- * * `Some(group)` - If the group was found and removed.
126
- */
127
- removeGroup(groupId: string): Group | null;
128
- /**
129
- * Inserts or updates a measurement in the state.
130
- *
131
- * # Arguments
132
- *
133
- * * `measurement` - The measurement to insert or update.
134
- *
135
- * # Returns
136
- *
137
- * * `None` - If the measurement was not found.
138
- * * `Some(measurement)` - If the measurement was found and updated.
139
- */
140
- upsertMeasurement(measurement: Measurement): Measurement | null;
141
- /**
142
- * Removes a measurement from the state.
143
- *
144
- * # Arguments
145
- *
146
- * * `measurement_id` - The id of the measurement to remove.
147
- *
148
- * # Returns
149
- *
150
- * * `None` - If the measurement was not found.
151
- * * `Some(measurement)` - If the measurement was found and removed.
152
- */
153
- removeMeasurement(measurementId: string): Measurement | null;
154
- getMeasurement(measurementId: string): MeasurementWrapper | null;
155
- /**
156
- * Inserts or updates a scale in the state.
157
- *
158
- * # Arguments
159
- *
160
- * * `scale` - The scale to insert or update.
161
- *
162
- * # Returns
163
- *
164
- * * `None` - If the scale was not found.
165
- * * `Some(scale)` - If the scale was found and updated.
166
- */
167
- upsertScale(scale: Scale): Scale | null;
168
- /**
169
- * Removes a scale from the state.
170
- *
171
- * # Arguments
172
- *
173
- * * `scale_id` - The id of the scale to remove.
174
- *
175
- * # Returns
176
- * * `None` - If the scale was not found.
177
- * * `Some(scale)` - If the scale was found and removed.
178
- */
179
- removeScale(scaleId: string): Scale | null;
180
- /**
181
- * Get the measurements that are missing a scale.
182
- *
183
- * # Returns
184
- *
185
- * * `Vec<MeasurementWrapper>` - The measurements that are missing a scale.
186
- */
187
- getMeasurementsMissingScale(): Array<MeasurementWrapper>;
87
+ /**
88
+ * Creates a new state.
89
+ *
90
+ * # Arguments
91
+ *
92
+ * * `options` - The options for the state.
93
+ *
94
+ * # Returns
95
+ *
96
+ * * `State` - The new state.
97
+ */
98
+ constructor(options?: StateOptions | undefined | null);
99
+ getMeasurementsByGroupId(groupId: string): Array<MeasurementWrapper>;
100
+ /**
101
+ * Get the measurements by page id.
102
+ *
103
+ * # Arguments
104
+ *
105
+ * * `page_id` - The id of the page.
106
+ *
107
+ * # Returns
108
+ *
109
+ * * `Vec<MeasurementWrapper>` - The measurements that are on the page.
110
+ */
111
+ getMeasurementsByPageId(pageId: string): Array<MeasurementWrapper>;
112
+ /**
113
+ * Get the scale for a measurement.
114
+ *
115
+ * # Arguments
116
+ *
117
+ * * `measurement_id` - The id of the measurement.
118
+ *
119
+ * # Returns
120
+ *
121
+ * * `None` - If the measurement was not found.
122
+ * * `Some(scale)` - If the scale was found.
123
+ */
124
+ getMeasurementScale(measurementId: string): Scale | null;
125
+ /**
126
+ * Inserts or updates a page in the state.
127
+ *
128
+ * # Arguments
129
+ *
130
+ * * `page` - The page to insert or update.
131
+ *
132
+ * # Returns
133
+ *
134
+ * * `None` - If the page was not found.
135
+ * * `Some(page)` - If the page was found and updated.
136
+ */
137
+ upsertPage(page: Page): Page | null;
138
+ removePage(pageId: string): Page | null;
139
+ getGroup(groupId: string): GroupWrapper | null;
140
+ /**
141
+ * Inserts or updates a group in the state.
142
+ *
143
+ * # Arguments
144
+ *
145
+ * * `group` - The group to insert or update.
146
+ *
147
+ * # Returns
148
+ *
149
+ * * `None` - If the group was not found.
150
+ * * `Some(group)` - If the group was found and updated.
151
+ */
152
+ upsertGroup(group: Group): Group | null;
153
+ /**
154
+ * Removes a group from the state.
155
+ *
156
+ * # Arguments
157
+ *
158
+ * * `group_id` - The id of the group to remove.
159
+ *
160
+ * # Returns
161
+ * * `None` - If the group was not found.
162
+ * * `Some(group)` - If the group was found and removed.
163
+ */
164
+ removeGroup(groupId: string): Group | null;
165
+ /**
166
+ * Inserts or updates a measurement in the state.
167
+ *
168
+ * # Arguments
169
+ *
170
+ * * `measurement` - The measurement to insert or update.
171
+ *
172
+ * # Returns
173
+ *
174
+ * * `None` - If the measurement was not found.
175
+ * * `Some(measurement)` - If the measurement was found and updated.
176
+ */
177
+ upsertMeasurement(measurement: Measurement): Measurement | null;
178
+ /**
179
+ * Removes a measurement from the state.
180
+ *
181
+ * # Arguments
182
+ *
183
+ * * `measurement_id` - The id of the measurement to remove.
184
+ *
185
+ * # Returns
186
+ *
187
+ * * `None` - If the measurement was not found.
188
+ * * `Some(measurement)` - If the measurement was found and removed.
189
+ */
190
+ removeMeasurement(measurementId: string): Measurement | null;
191
+ getMeasurement(measurementId: string): MeasurementWrapper | null;
192
+ /**
193
+ * Inserts or updates a scale in the state.
194
+ *
195
+ * # Arguments
196
+ *
197
+ * * `scale` - The scale to insert or update.
198
+ *
199
+ * # Returns
200
+ *
201
+ * * `None` - If the scale was not found.
202
+ * * `Some(scale)` - If the scale was found and updated.
203
+ */
204
+ upsertScale(scale: Scale): Scale | null;
205
+ /**
206
+ * Removes a scale from the state.
207
+ *
208
+ * # Arguments
209
+ *
210
+ * * `scale_id` - The id of the scale to remove.
211
+ *
212
+ * # Returns
213
+ * * `None` - If the scale was not found.
214
+ * * `Some(scale)` - If the scale was found and removed.
215
+ */
216
+ removeScale(scaleId: string): Scale | null;
217
+ /**
218
+ * Get the measurements that are missing a scale.
219
+ *
220
+ * # Returns
221
+ *
222
+ * * `Vec<MeasurementWrapper>` - The measurements that are missing a scale.
223
+ */
224
+ getMeasurementsMissingScale(): Array<MeasurementWrapper>;
225
+ upsertContour(input: ContourInput): void;
226
+ removeContour(contourId: string): boolean;
227
+ getContour(contourId: string): ContourWrapper | null;
228
+ getContoursByPageId(pageId: string): Array<ContourWrapper>;
229
+ getContoursMissingScale(): Array<ContourWrapper>;
230
+ }
231
+
232
+ export declare class VolumetricUnitResult {
233
+ get cut(): UnitValue;
234
+ get fill(): UnitValue;
235
+ get uncoveredArea(): UnitValue;
188
236
  }
189
237
 
190
238
  /** Add 100 to the input */
@@ -192,157 +240,190 @@ export declare function plus100(input: number): number;
192
240
 
193
241
  /** Add 200 to the input */
194
242
  export declare function plus200(input: number): number;
243
+
244
+ /** Input for creating a reference surface from JS/TS. */
245
+ export type ReferenceSurfaceInputJs =
246
+ | { type: 'Polygon'; points: Array<Point>; elevation: number; unit: Unit }
247
+ | {
248
+ type: 'Rectangle';
249
+ points: [Point, Point];
250
+ elevation: number;
251
+ unit: Unit;
252
+ };
195
253
  export declare class UnitValue {
196
- constructor(value: number, unit: Unit, magnitude: UnitValueItemType);
197
- display(unit: Unit): string;
198
- getConvertedValue(to: Unit): number;
254
+ constructor(value: number, unit: Unit, magnitude: UnitValueItemType);
255
+ display(unit: Unit): string;
256
+ getConvertedValue(to: Unit): number;
199
257
  }
200
258
 
201
259
  export interface ContourInput {
202
- id: string;
203
- name?: string;
204
- pageId: string;
205
- /** The lines that make up the contour map */
206
- lines: Array<ContourLineInput>;
207
- /** The points of interest that are used to create the contour map */
208
- pointsOfInterest: Array<ContourPointOfInterestInput>;
260
+ id: string;
261
+ name?: string;
262
+ pageId: string;
263
+ /** The lines that make up the contour map */
264
+ lines: Array<ContourLineInput>;
265
+ /** The points of interest that are used to create the contour map */
266
+ pointsOfInterest: Array<ContourPointOfInterestInput>;
209
267
  }
210
268
 
211
269
  export interface ContourLineInput {
212
- /** The elevation of the contour line (in pixels) */
213
- elevation: number;
214
- points: Array<Point>;
270
+ /** The elevation of the contour line (real-world value) */
271
+ elevation: number;
272
+ points: Array<Point>;
273
+ unit: Unit;
215
274
  }
216
275
 
217
276
  export interface ContourPointOfInterestInput {
218
- /** The elevation of the point of interest (in pixels) */
219
- elevation: number;
220
- point: Point;
277
+ /** The elevation of the point of interest (real-world value) */
278
+ elevation: number;
279
+ point: Point;
280
+ unit: Unit;
221
281
  }
222
282
 
223
283
  /** Calculate distance between two points */
224
284
  export declare function distance(
225
- points: [Point, Point] | [Point3D, Point3D],
285
+ points: [Point, Point] | [Point3D, Point3D],
226
286
  ): number;
227
287
 
228
- /** Get the centroid of a measurement */
288
+ /** Generate a random id */
289
+ export declare function generateRandomId(): string;
290
+
291
+ /**
292
+ * Get the centroid of a measurement
293
+ *
294
+ * Returns `None` if the measurement has invalid geometry.
295
+ * For more detailed error information, use `measurement.get_centroid()` directly.
296
+ */
229
297
  export declare function getCentroid(measurement: Measurement): Point | null;
230
298
 
231
299
  export interface Group {
232
- id: string;
233
- name?: string;
234
- measurementType: MeasurementType;
300
+ id: string;
301
+ name?: string;
302
+ measurementType: MeasurementType;
235
303
  }
236
304
 
237
305
  export type Measurement =
238
- | {
239
- type: "Count";
240
- id: string;
241
- pageId: string;
242
- groupId: string;
243
- points: [Point];
244
- }
245
- | {
246
- type: "Polygon";
247
- id: string;
248
- pageId: string;
249
- groupId: string;
250
- points: Array<Point>;
251
- }
252
- | {
253
- type: "Polyline";
254
- id: string;
255
- pageId: string;
256
- groupId: string;
257
- points: Array<Point>;
258
- }
259
- | {
260
- type: "Rectangle";
261
- id: string;
262
- pageId: string;
263
- groupId: string;
264
- points: [Point, Point];
265
- };
306
+ | {
307
+ type: 'Count';
308
+ id: string;
309
+ pageId: string;
310
+ groupId: string;
311
+ points: [Point];
312
+ }
313
+ | {
314
+ type: 'Polygon';
315
+ id: string;
316
+ pageId: string;
317
+ groupId: string;
318
+ points: Array<Point>;
319
+ }
320
+ | {
321
+ type: 'Polyline';
322
+ id: string;
323
+ pageId: string;
324
+ groupId: string;
325
+ points: Array<Point>;
326
+ }
327
+ | {
328
+ type: 'Rectangle';
329
+ id: string;
330
+ pageId: string;
331
+ groupId: string;
332
+ points: [Point, Point];
333
+ };
266
334
 
267
- export type MeasurementType = "Area" | "Linear" | "Count";
335
+ export type MeasurementType = 'Area' | 'Linear' | 'Count';
268
336
 
269
337
  export interface Page {
270
- id: string;
271
- name?: string;
272
- width?: number;
273
- height?: number;
274
- viewport?: PageViewport;
338
+ id: string;
339
+ name?: string;
340
+ width?: number;
341
+ height?: number;
342
+ viewport?: PageViewport;
275
343
  }
276
344
 
277
345
  export interface PageViewport {
278
- width: number;
279
- height: number;
346
+ width: number;
347
+ height: number;
280
348
  }
281
349
 
282
350
  /** Represents a 2D point with floating point coordinates */
283
351
  export interface Point {
284
- x: number;
285
- y: number;
352
+ x: number;
353
+ y: number;
286
354
  }
287
355
 
288
356
  export interface Point3D {
289
- x: number;
290
- y: number;
291
- z: number;
357
+ x: number;
358
+ y: number;
359
+ z: number;
292
360
  }
293
361
 
294
362
  /** Input for creating a reference surface from JS/TS. */
295
363
  export type ReferenceSurfaceInput =
296
- | { type: "Polygon"; points: Array<Point>; elevation: number }
297
- | { type: "Rectangle"; points: [Point, Point]; elevation: number };
364
+ | { type: 'Polygon'; points: Array<Point>; elevation: number }
365
+ | { type: 'Rectangle'; points: [Point, Point]; elevation: number };
366
+
367
+ /**
368
+ * Reposition a measurement so its centroid is at the given point.
369
+ * Returns a new measurement (same kind and metadata); area, length, and count are unchanged.
370
+ *
371
+ * # Errors
372
+ *
373
+ * Returns an error if the measurement has invalid or empty geometry (e.g. `EmptyGeometry`).
374
+ */
375
+ export declare function repositionMeasurementToCentroid(
376
+ measurement: Measurement,
377
+ newCentroid: Point,
378
+ ): Measurement;
298
379
 
299
380
  export type Scale =
300
- | {
301
- type: "Area";
302
- id: string;
303
- pageId: string;
304
- scale: ScaleDefinition;
305
- boundingBox: [Point, Point];
306
- }
307
- | { type: "Default"; id: string; pageId: string; scale: ScaleDefinition };
381
+ | {
382
+ type: 'Area';
383
+ id: string;
384
+ pageId: string;
385
+ scale: ScaleDefinition;
386
+ boundingBox: [Point, Point];
387
+ }
388
+ | { type: 'Default'; id: string; pageId: string; scale: ScaleDefinition };
308
389
 
309
390
  export interface ScaleDefinition {
310
- pixelDistance: number;
311
- realDistance: number;
312
- unit: Unit;
391
+ pixelDistance: number;
392
+ realDistance: number;
393
+ unit: Unit;
313
394
  }
314
395
 
315
396
  /** Simplify a polyline using the Ramer-Douglas-Peucker algorithm */
316
397
  export declare function simplifyPolyline(
317
- points: Array<Point>,
318
- tolerance: number,
398
+ points: Array<Point>,
399
+ tolerance: number,
319
400
  ): Array<Point>;
320
401
 
321
402
  export interface StateOptions {
322
- pages: Array<Page>;
323
- groups: Array<Group>;
324
- measurements: Array<Measurement>;
325
- scales: Array<Scale>;
403
+ pages: Array<Page>;
404
+ groups: Array<Group>;
405
+ measurements: Array<Measurement>;
406
+ scales: Array<Scale>;
326
407
  }
327
408
 
328
409
  /** Measurement units supported by the system */
329
410
  export type Unit =
330
- /** Imperial units */
331
- | "Yards"
332
- | "Feet"
333
- | "Inches"
334
- /** Metric units */
335
- | "Meters"
336
- | "Centimeters";
411
+ /** Imperial units */
412
+ | 'Yards'
413
+ | 'Feet'
414
+ | 'Inches'
415
+ /** Metric units */
416
+ | 'Meters'
417
+ | 'Centimeters';
337
418
 
338
- export type UnitValueItemType = "Area" | "Length";
419
+ export type UnitValueItemType = 'Area' | 'Length' | 'Volume';
339
420
 
340
421
  /** Result of a volumetric cut/fill calculation. */
341
422
  export interface VolumetricResult {
342
- /** Volume to remove (terrain above reference). */
343
- cut: number;
344
- /** Volume to add (terrain below reference). */
345
- fill: number;
346
- /** Area where terrain data was unavailable (z_at returned None). */
347
- uncoveredArea: number;
423
+ /** Volume to remove (terrain above reference). */
424
+ cut: number;
425
+ /** Volume to add (terrain below reference). */
426
+ fill: number;
427
+ /** Area where terrain data was unavailable (z_at returned None). */
428
+ uncoveredArea: number;
348
429
  }