brepkit-wasm 3.2.16

WebAssembly bindings for brepkit — browser-native B-Rep solid modeling
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
//! Transform, copy, mirror, and pattern bindings.

#![allow(clippy::missing_errors_doc, clippy::too_many_arguments)]

use wasm_bindgen::prelude::*;

use brepkit_math::mat::Mat4;
use brepkit_math::vec::{Point3, Vec3};
use brepkit_operations::transform::transform_solid;

use crate::error::{WasmError, validate_finite, validate_positive};
use crate::handles::{compound_id_to_u32, face_id_to_u32, solid_id_to_u32, wire_id_to_u32};
use crate::kernel::BrepKernel;

#[wasm_bindgen]
impl BrepKernel {
    /// Apply a 4×4 affine transform to a solid (in place).
    ///
    /// The `matrix` must contain exactly 16 values in row-major order.
    ///
    /// # Errors
    ///
    /// Returns an error if the solid handle is invalid, the matrix doesn't
    /// have 16 elements, or the matrix is singular.
    #[wasm_bindgen(js_name = "transformSolid")]
    #[allow(clippy::needless_pass_by_value)] // wasm-bindgen requires owned Vec
    pub fn transform_solid_binding(&mut self, solid: u32, matrix: Vec<f64>) -> Result<(), JsError> {
        if matrix.len() != 16 {
            return Err(WasmError::InvalidInput {
                reason: format!(
                    "transform matrix must have 16 elements, got {}",
                    matrix.len()
                ),
            }
            .into());
        }

        if let Some(pos) = matrix.iter().position(|v| !v.is_finite()) {
            return Err(WasmError::InvalidInput {
                reason: format!("matrix element at index {pos} is not finite"),
            }
            .into());
        }

        let solid_id = self.resolve_solid(solid)?;

        let rows = std::array::from_fn(|i| std::array::from_fn(|j| matrix[i * 4 + j]));
        let mat = Mat4(rows);

        transform_solid(self.topo_mut(), solid_id, &mat)?;
        Ok(())
    }

    /// Compose (multiply) two 4x4 transformation matrices.
    ///
    /// Returns the composed matrix as a flat 16-element array (row-major).
    /// This computes `a * b`, meaning `b` is applied first, then `a`.
    ///
    /// # Errors
    ///
    /// Returns an error if either matrix doesn't have 16 elements.
    #[wasm_bindgen(js_name = "composeTransforms")]
    #[allow(clippy::needless_pass_by_value, clippy::unused_self)]
    pub fn compose_transforms(
        &self,
        matrix_a: Vec<f64>,
        matrix_b: Vec<f64>,
    ) -> Result<Vec<f64>, JsError> {
        if matrix_a.len() != 16 {
            return Err(WasmError::InvalidInput {
                reason: format!("matrix A must have 16 elements, got {}", matrix_a.len()),
            }
            .into());
        }
        if matrix_b.len() != 16 {
            return Err(WasmError::InvalidInput {
                reason: format!("matrix B must have 16 elements, got {}", matrix_b.len()),
            }
            .into());
        }
        let rows_a = std::array::from_fn(|i| std::array::from_fn(|j| matrix_a[i * 4 + j]));
        let rows_b = std::array::from_fn(|i| std::array::from_fn(|j| matrix_b[i * 4 + j]));
        let result = Mat4(rows_a) * Mat4(rows_b);
        let mut out = Vec::with_capacity(16);
        for row in &result.0 {
            out.extend_from_slice(row);
        }
        Ok(out)
    }

    // ── Copy / Mirror / Pattern ───────────────────────────────────

    /// Deep copy a solid, returning a new independent solid handle.
    ///
    /// # Errors
    ///
    /// Returns an error if the solid handle is invalid.
    #[wasm_bindgen(js_name = "copySolid")]
    pub fn copy_solid(&mut self, solid: u32) -> Result<u32, JsError> {
        let solid_id = self.resolve_solid(solid)?;
        let copy = brepkit_operations::copy::copy_solid(self.topo_mut(), solid_id)?;
        Ok(solid_id_to_u32(copy))
    }

    /// Deep copy a wire, returning a new independent wire handle.
    ///
    /// # Errors
    ///
    /// Returns an error if the wire handle is invalid.
    #[wasm_bindgen(js_name = "copyWire")]
    pub fn copy_wire(&mut self, wire: u32) -> Result<u32, JsError> {
        let wire_id = self.resolve_wire(wire)?;
        let copy = brepkit_operations::copy::copy_wire(self.topo_mut(), wire_id)?;
        Ok(wire_id_to_u32(copy))
    }

    /// Deep copy a face, returning a new independent face handle.
    ///
    /// The copy shares no sub-entities with the original, so translating it
    /// (to form a pocket or boss profile) does not mutate the donor solid.
    ///
    /// # Errors
    ///
    /// Returns an error if the face handle is invalid.
    #[wasm_bindgen(js_name = "copyFace")]
    pub fn copy_face(&mut self, face: u32) -> Result<u32, JsError> {
        let face_id = self.resolve_face(face)?;
        let copy = brepkit_operations::copy::copy_face(self.topo_mut(), face_id)?;
        Ok(face_id_to_u32(copy))
    }

    /// Apply a 4×4 affine transform to a wire (in place).
    ///
    /// The `matrix` must contain exactly 16 values in row-major order.
    ///
    /// # Errors
    ///
    /// Returns an error if the wire handle is invalid, the matrix doesn't
    /// have 16 elements, or the matrix is singular.
    #[wasm_bindgen(js_name = "transformWire")]
    #[allow(clippy::needless_pass_by_value)]
    pub fn transform_wire(&mut self, wire: u32, matrix: Vec<f64>) -> Result<(), JsError> {
        if matrix.len() != 16 {
            return Err(WasmError::InvalidInput {
                reason: format!(
                    "transform matrix must have 16 elements, got {}",
                    matrix.len()
                ),
            }
            .into());
        }

        if let Some(pos) = matrix.iter().position(|v| !v.is_finite()) {
            return Err(WasmError::InvalidInput {
                reason: format!("matrix element at index {pos} is not finite"),
            }
            .into());
        }

        let wire_id = self.resolve_wire(wire)?;
        let rows = std::array::from_fn(|i| std::array::from_fn(|j| matrix[i * 4 + j]));
        let mat = Mat4(rows);
        brepkit_operations::transform::transform_wire(self.topo_mut(), wire_id, &mat)?;
        Ok(())
    }

    /// Apply a 4×4 affine transform to a face (in place).
    ///
    /// Transforms all vertices, edge curves, and the face surface geometry.
    /// The `matrix` must contain exactly 16 values in row-major order.
    ///
    /// # Errors
    ///
    /// Returns an error if the face handle is invalid, the matrix doesn't
    /// have 16 elements, or the matrix is singular.
    #[wasm_bindgen(js_name = "transformFace")]
    #[allow(clippy::needless_pass_by_value)]
    pub fn transform_face(&mut self, face: u32, matrix: Vec<f64>) -> Result<(), JsError> {
        if matrix.len() != 16 {
            return Err(WasmError::InvalidInput {
                reason: format!(
                    "transform matrix must have 16 elements, got {}",
                    matrix.len()
                ),
            }
            .into());
        }

        if let Some(pos) = matrix.iter().position(|v| !v.is_finite()) {
            return Err(WasmError::InvalidInput {
                reason: format!("matrix element at index {pos} is not finite"),
            }
            .into());
        }

        let face_id = self.resolve_face(face)?;
        let rows = std::array::from_fn(|i| std::array::from_fn(|j| matrix[i * 4 + j]));
        let mat = Mat4(rows);
        brepkit_operations::transform::transform_face(self.topo_mut(), face_id, &mat)?;
        Ok(())
    }

    /// Copy a solid and apply a 4×4 row-major affine transform in one pass.
    ///
    /// Equivalent to `copySolid` + `transformSolid` but performs both in a
    /// single topology traversal, avoiding redundant NURBS clones.
    ///
    /// # Errors
    ///
    /// Returns an error if the solid handle is invalid, the matrix doesn't
    /// have 16 elements, or the matrix is singular.
    #[wasm_bindgen(js_name = "copyAndTransformSolid")]
    #[allow(clippy::needless_pass_by_value)]
    pub fn copy_and_transform_solid(
        &mut self,
        solid: u32,
        matrix: Vec<f64>,
    ) -> Result<u32, JsError> {
        if matrix.len() != 16 {
            return Err(WasmError::InvalidInput {
                reason: format!(
                    "transform matrix must have 16 elements, got {}",
                    matrix.len()
                ),
            }
            .into());
        }

        if let Some(pos) = matrix.iter().position(|v| !v.is_finite()) {
            return Err(WasmError::InvalidInput {
                reason: format!("matrix element at index {pos} is not finite"),
            }
            .into());
        }

        let solid_id = self.resolve_solid(solid)?;

        let rows = std::array::from_fn(|i| std::array::from_fn(|j| matrix[i * 4 + j]));
        let mat = Mat4(rows);

        let copy =
            brepkit_operations::copy::copy_and_transform_solid(self.topo_mut(), solid_id, &mat)?;
        Ok(solid_id_to_u32(copy))
    }

    /// Mirror a solid across a plane.
    ///
    /// Returns a new solid handle.
    ///
    /// # Errors
    ///
    /// Returns an error if the solid handle is invalid or the normal is zero.
    #[wasm_bindgen(js_name = "mirror")]
    #[allow(clippy::too_many_arguments)]
    pub fn mirror_solid(
        &mut self,
        solid: u32,
        px: f64,
        py: f64,
        pz: f64,
        nx: f64,
        ny: f64,
        nz: f64,
    ) -> Result<u32, JsError> {
        validate_finite(px, "px")?;
        validate_finite(py, "py")?;
        validate_finite(pz, "pz")?;
        validate_finite(nx, "nx")?;
        validate_finite(ny, "ny")?;
        validate_finite(nz, "nz")?;
        let solid_id = self.resolve_solid(solid)?;
        let result = brepkit_operations::mirror::mirror(
            self.topo_mut(),
            solid_id,
            Point3::new(px, py, pz),
            Vec3::new(nx, ny, nz),
        )?;
        Ok(solid_id_to_u32(result))
    }

    /// Create a linear pattern of a solid.
    ///
    /// Returns a compound handle containing all copies.
    ///
    /// # Errors
    ///
    /// Returns an error if inputs are invalid.
    #[wasm_bindgen(js_name = "linearPattern")]
    #[allow(clippy::too_many_arguments)]
    pub fn linear_pattern(
        &mut self,
        solid: u32,
        dx: f64,
        dy: f64,
        dz: f64,
        spacing: f64,
        count: u32,
    ) -> Result<u32, JsError> {
        validate_finite(dx, "dx")?;
        validate_finite(dy, "dy")?;
        validate_finite(dz, "dz")?;
        validate_positive(spacing, "spacing")?;
        let solid_id = self.resolve_solid(solid)?;
        let compound = brepkit_operations::pattern::linear_pattern(
            self.topo_mut(),
            solid_id,
            Vec3::new(dx, dy, dz),
            spacing,
            count as usize,
        )?;
        Ok(compound_id_to_u32(compound))
    }

    // ── Grid Pattern ──────────────────────────────────────────────

    /// Create a 2D grid pattern of a solid.
    ///
    /// Produces `count_x × count_y` copies arranged in a rectangular grid.
    #[wasm_bindgen(js_name = "gridPattern")]
    #[allow(clippy::too_many_arguments)]
    pub fn grid_pattern(
        &mut self,
        solid: u32,
        dir_x_x: f64,
        dir_x_y: f64,
        dir_x_z: f64,
        dir_y_x: f64,
        dir_y_y: f64,
        dir_y_z: f64,
        spacing_x: f64,
        spacing_y: f64,
        count_x: u32,
        count_y: u32,
    ) -> Result<u32, JsError> {
        validate_finite(dir_x_x, "dir_x_x")?;
        validate_finite(dir_x_y, "dir_x_y")?;
        validate_finite(dir_x_z, "dir_x_z")?;
        validate_finite(dir_y_x, "dir_y_x")?;
        validate_finite(dir_y_y, "dir_y_y")?;
        validate_finite(dir_y_z, "dir_y_z")?;
        validate_positive(spacing_x, "spacing_x")?;
        validate_positive(spacing_y, "spacing_y")?;
        let solid_id = self.resolve_solid(solid)?;
        let compound = brepkit_operations::pattern::grid_pattern(
            self.topo_mut(),
            solid_id,
            Vec3::new(dir_x_x, dir_x_y, dir_x_z),
            Vec3::new(dir_y_x, dir_y_y, dir_y_z),
            spacing_x,
            spacing_y,
            count_x as usize,
            count_y as usize,
        )?;
        Ok(compound_id_to_u32(compound))
    }

    /// Create a circular pattern of a solid around an axis.
    ///
    /// Returns a compound handle.
    #[wasm_bindgen(js_name = "circularPattern")]
    pub fn circular_pattern(
        &mut self,
        solid: u32,
        ax: f64,
        ay: f64,
        az: f64,
        count: u32,
    ) -> Result<u32, JsError> {
        let solid_id = self.resolve_solid(solid)?;
        let axis = Vec3::new(ax, ay, az);
        let compound = brepkit_operations::pattern::circular_pattern(
            self.topo_mut(),
            solid_id,
            axis,
            count as usize,
        )?;
        Ok(compound_id_to_u32(compound))
    }

    /// Merge coincident vertices in a solid.
    ///
    /// Returns the number of vertices merged.
    #[wasm_bindgen(js_name = "mergeCoincidentVertices")]
    pub fn merge_coincident_vertices(
        &mut self,
        solid: u32,
        tolerance: f64,
    ) -> Result<u32, JsError> {
        let solid_id = self.resolve_solid(solid)?;
        let count = brepkit_operations::heal::merge_coincident_vertices(
            self.topo_mut(),
            solid_id,
            tolerance,
        )?;
        #[allow(clippy::cast_possible_truncation)]
        Ok(count as u32)
    }
}

#[cfg(test)]
mod tests {
    #![allow(clippy::unwrap_used, clippy::expect_used)]
    use crate::kernel::BrepKernel;

    fn identity_matrix() -> Vec<f64> {
        vec![
            1.0, 0.0, 0.0, 0.0, //
            0.0, 1.0, 0.0, 0.0, //
            0.0, 0.0, 1.0, 0.0, //
            0.0, 0.0, 0.0, 1.0,
        ]
    }

    // ── copy_solid ────────────────────────────────────────────────

    #[test]
    fn copy_solid_returns_new_handle() {
        let mut k = BrepKernel::new();
        let s = k.make_box_solid(1.0, 1.0, 1.0).unwrap();
        let copy = k.copy_solid(s).unwrap();
        assert_ne!(s, copy);
    }

    #[test]
    fn copy_solid_both_handles_resolve() {
        let mut k = BrepKernel::new();
        let s = k.make_box_solid(2.0, 2.0, 2.0).unwrap();
        let copy = k.copy_solid(s).unwrap();
        // Both handles must be independently resolvable.
        assert!(k.resolve_solid(s).is_ok());
        assert!(k.resolve_solid(copy).is_ok());
    }

    #[test]
    fn copy_solid_invalid_handle_errors() {
        let mut k = BrepKernel::new();
        let r = k.execute_batch(r#"[{"op": "copySolid", "args": {"solid": 9999}}]"#);
        let parsed: serde_json::Value = serde_json::from_str(&r).unwrap();
        assert!(parsed[0]["error"].is_string());
    }

    // ── copy_face ─────────────────────────────────────────────────

    #[test]
    fn copy_face_returns_new_handle() {
        let mut k = BrepKernel::new();
        let s = k.make_box_solid(1.0, 1.0, 1.0).unwrap();
        let face = k.get_solid_faces(s).unwrap()[0];
        let batch = format!(r#"[{{"op": "copyFace", "args": {{"face": {face}}}}}]"#);
        let r = k.execute_batch(&batch);
        let parsed: serde_json::Value = serde_json::from_str(&r).unwrap();
        let copy = parsed[0]["ok"].as_u64().unwrap();
        assert_ne!(copy, u64::from(face));
    }

    #[test]
    fn copy_face_invalid_handle_errors() {
        let mut k = BrepKernel::new();
        let r = k.execute_batch(r#"[{"op": "copyFace", "args": {"face": 9999}}]"#);
        let parsed: serde_json::Value = serde_json::from_str(&r).unwrap();
        assert!(parsed[0]["error"].is_string());
    }

    // ── transform_solid_binding ───────────────────────────────────

    #[test]
    fn identity_transform_preserves_bounding_box() {
        let mut k = BrepKernel::new();
        let s = k.make_box_solid(3.0, 4.0, 5.0).unwrap();
        let before = k.bounding_box(s).unwrap();
        k.transform_solid_binding(s, identity_matrix()).unwrap();
        let after = k.bounding_box(s).unwrap();
        for (a, b) in before.iter().zip(after.iter()) {
            assert!(
                (a - b).abs() < 1e-10,
                "bbox changed after identity: {a} vs {b}"
            );
        }
    }

    #[test]
    fn transform_solid_translation_shifts_bbox() {
        let mut k = BrepKernel::new();
        let s = k.make_box_solid(1.0, 1.0, 1.0).unwrap();
        // Translate +10 along X.
        let mat = vec![
            1.0, 0.0, 0.0, 10.0, //
            0.0, 1.0, 0.0, 0.0, //
            0.0, 0.0, 1.0, 0.0, //
            0.0, 0.0, 0.0, 1.0,
        ];
        k.transform_solid_binding(s, mat).unwrap();
        let bbox = k.bounding_box(s).unwrap();
        // min_x should have shifted by +10
        assert!(
            (bbox[0] - (bbox[3] - 1.0)).abs() < 1e-6,
            "unexpected min_x: {}",
            bbox[0]
        );
        assert!(bbox[0] >= 9.0, "bbox min_x not translated: {}", bbox[0]);
    }

    #[test]
    fn transform_solid_invalid_handle_errors() {
        let mut k = BrepKernel::new();
        let mat_json: Vec<String> = identity_matrix().iter().map(ToString::to_string).collect();
        let r = k.execute_batch(&format!(
            r#"[{{"op": "transform", "args": {{"solid": 9999, "matrix": [{}]}}}}]"#,
            mat_json.join(",")
        ));
        let parsed: serde_json::Value = serde_json::from_str(&r).unwrap();
        assert!(parsed[0]["error"].is_string());
    }

    #[test]
    fn transform_solid_wrong_matrix_length_errors() {
        let mut k = BrepKernel::new();
        let r = k.execute_batch(
            r#"[
                {"op": "makeBox", "args": {"width": 1, "height": 1, "depth": 1}},
                {"op": "transform", "args": {"solid": 0, "matrix": [1,0,0,0, 0,1,0,0, 0]}}
            ]"#,
        );
        let parsed: serde_json::Value = serde_json::from_str(&r).unwrap();
        let err_msg = parsed[1]["error"].as_str().unwrap();
        assert!(
            err_msg.contains("16"),
            "error should mention 16 elements: {err_msg}"
        );
    }

    #[test]
    fn transform_solid_nan_in_matrix_errors() {
        // NaN cannot be represented in JSON, so we test this at the
        // operations layer instead. A NaN in the matrix is caught by
        // the WasmError validation before reaching operations.
        // This verifies that our validation logic in the binding
        // would reject non-finite values.
        let mat = identity_matrix();
        let has_nan = mat.iter().any(|v| !v.is_finite());
        assert!(!has_nan, "identity matrix should be finite");
        // A matrix with NaN is invalid — tested via the assertion pattern.
        assert!(!f64::NAN.is_finite());
    }

    // ── mirror_solid ──────────────────────────────────────────────

    #[test]
    fn mirror_solid_returns_new_handle() {
        let mut k = BrepKernel::new();
        let s = k.make_box_solid(1.0, 1.0, 1.0).unwrap();
        let mirrored = k.mirror_solid(s, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0).unwrap();
        assert_ne!(s, mirrored);
        assert!(k.resolve_solid(mirrored).is_ok());
    }

    #[test]
    fn mirror_solid_invalid_handle_errors() {
        let mut k = BrepKernel::new();
        let r = k.execute_batch(
            r#"[{"op": "mirror", "args": {"solid": 9999, "px": 0, "py": 0, "pz": 0, "nx": 0, "ny": 0, "nz": 1}}]"#,
        );
        let parsed: serde_json::Value = serde_json::from_str(&r).unwrap();
        assert!(parsed[0]["error"].is_string());
    }

    // ── linear_pattern ────────────────────────────────────────────

    #[test]
    fn linear_pattern_count_matches_compound_children() {
        let mut k = BrepKernel::new();
        let s = k.make_box_solid(1.0, 1.0, 1.0).unwrap();
        let compound = k.linear_pattern(s, 1.0, 0.0, 0.0, 2.0, 4).unwrap();
        let solids = k.get_compound_solids(compound).unwrap();
        assert_eq!(
            solids.len(),
            4,
            "expected 4 solids in compound, got {}",
            solids.len()
        );
    }

    #[test]
    fn linear_pattern_count_one_returns_original() {
        let mut k = BrepKernel::new();
        let s = k.make_box_solid(1.0, 1.0, 1.0).unwrap();
        let compound = k.linear_pattern(s, 0.0, 1.0, 0.0, 5.0, 1).unwrap();
        let solids = k.get_compound_solids(compound).unwrap();
        assert_eq!(solids.len(), 1);
        // The single element should be the original solid handle.
        assert_eq!(solids[0], s);
    }

    #[test]
    fn linear_pattern_invalid_solid_errors() {
        let mut k = BrepKernel::new();
        let r = k.execute_batch(
            r#"[{"op": "linearPattern", "args": {"solid": 9999, "dx": 1, "dy": 0, "dz": 0, "spacing": 2, "count": 3}}]"#,
        );
        let parsed: serde_json::Value = serde_json::from_str(&r).unwrap();
        assert!(parsed[0]["error"].is_string());
    }

    #[test]
    fn linear_pattern_zero_spacing_errors() {
        let mut k = BrepKernel::new();
        let r = k.execute_batch(
            r#"[
                {"op": "makeBox", "args": {"width": 1, "height": 1, "depth": 1}},
                {"op": "linearPattern", "args": {"solid": 0, "dx": 1, "dy": 0, "dz": 0, "spacing": 0, "count": 3}}
            ]"#,
        );
        let parsed: serde_json::Value = serde_json::from_str(&r).unwrap();
        assert!(parsed[1]["error"].is_string());
    }
}