alice-lol 0.4.2

ALICE-LOL: Law-Oriented Language — proc_macro + runtime DSL compiling to SdfNode (GLSL/WGSL/HLSL transpile), print export (STL/3MF/OBJ/FBX), law checker, laser pattern generator, and optional LLM Guided Generation bridge.
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
//! # reinforcement — 補強要素 primitive (Phase A.3)
//!
//! 部品の強度・剛性を高める 6 primitive を提供する
//!
//! | primitive | 用途 | 実装 |
//! |-----------|------|------|
//! | [`rib`] | 板裏の補強リブ | Box3d 単体 |
//! | [`boss`] | ネジ穴周りボス | Cylinder outer + tap hole subtraction (pipeline `screw_boss_od = screw_dia × 2.2`) |
//! | [`fillet`] | 内角 R (2 `SdfNode` ブレンド) | `SdfNode::SmoothUnion` wrapper |
//! | [`chamfer`] | edge 面取り (2 `SdfNode`) | `SdfNode::ChamferUnion` wrapper |
//! | [`honeycomb_infill`] | 6 角形 infill 壁パターン | `RepeatFinite` + `HexPrism` を container から `Subtraction` |
//! | [`gyroid_infill`] | Gyroid TPMS infill | 既存 `SdfNode::Gyroid` + container との `Intersection` |
//!
//! ## alice-physics 連携 (`physics` feature、opt-in、AGPL-3.0 汚染注意)
//!
//! `--features physics` で有効化すると以下 API が使える
//!
//! - `fillet_kt_shaft_shoulder` — `alice_physics::fillet_stress::kt_shaft_shoulder_bending`
//! - `material_elastic_modulus_gpa` — `alice_physics::filament_db::MaterialProperties::pla/petg/abs`
//! - `recommended_fillet_radius_mm` — `alice_physics::fillet_stress::recommended_fillet_radius_mm`
//!
//! pipeline `safety module` の canonical material spec と SSOT を共有できる

use alice_sdf::SdfNode;
use glam::Vec3;
use std::sync::Arc;

// ────────────────────────────────────────────────────────
// 定数 (pipeline formulas 準拠、実プリント検証は Phase B.2 予定)
// ────────────────────────────────────────────────────────

/// ネジ穴周りボスの外径係数 (pipeline `formulas::PrintParams::screw_boss_od`)
///
/// boss 外径 = `screw_dia` × [`SCREW_BOSS_OD_RATIO`]、周囲肉厚を確保する経験式
pub const SCREW_BOSS_OD_RATIO: f32 = 2.2;

/// タップ下穴公式のノズル精度余白 A のデフォルト値 (Phase A.1 [`crate::stdlib::hardsurface::fastener::DEFAULT_ACCURACY`] と同値、boss 内穴計算に流用)
pub const BOSS_TAP_ACCURACY: f32 = 0.1;

// ────────────────────────────────────────────────────────
// 1. rib
// ────────────────────────────────────────────────────────

/// 補強リブ (Box3d 単体、板裏の強度確保用)
///
/// 座標系: 長辺 = X、高さ = Y (板から立ち上がる方向)、厚 = Z
///
/// # 引数
///
/// - `length`: リブ長 (mm、X 軸)
/// - `height`: リブ高 (mm、Y 軸、板表面からの立上り)
/// - `thickness`: リブ厚 (mm、Z 軸、通常 板厚 × 0.6-0.8 推奨)
///
/// # 使用例
///
/// ```
/// use alice_lol::stdlib::hardsurface::reinforcement::rib;
/// let r = rib(30.0, 5.0, 1.6);
/// // 30mm 長 × 5mm 高 × 1.6mm 厚 (板厚 2mm 相当の 80%)
/// ```
#[must_use]
pub fn rib(length: f32, height: f32, thickness: f32) -> SdfNode {
    SdfNode::Box3d {
        half_extents: Vec3::new(length * 0.5, height * 0.5, thickness * 0.5),
    }
}

// ────────────────────────────────────────────────────────
// 2. boss
// ────────────────────────────────────────────────────────

/// ネジ穴周りボス (外径 [`SCREW_BOSS_OD_RATIO`] × `screw_dia`、内側 tap 穴 subtraction)
///
/// 構造: 外筒 Cylinder (外径 = `screw_dia` × 2.2) - 内側 tap 穴 (`screw_dia` × 0.85 + 2A)
/// 軸 = Y (Cylinder native)
///
/// # 引数
///
/// - `screw_dia`: ネジ呼び径 (mm)
/// - `height`: ボス全長 (mm、Y 軸)
///
/// # 使用例
///
/// ```
/// use alice_lol::stdlib::hardsurface::reinforcement::boss;
/// let b = boss(3.0, 8.0);
/// // M3 ボス: 外径 6.6mm × 内穴径 2.75mm × 長 8mm
/// ```
#[must_use]
pub fn boss(screw_dia: f32, height: f32) -> SdfNode {
    let outer_r = screw_dia * SCREW_BOSS_OD_RATIO * 0.5;
    let tap_r = screw_dia.mul_add(0.85, 2.0 * BOSS_TAP_ACCURACY) * 0.5;
    let barrel = SdfNode::Cylinder {
        radius: outer_r,
        half_height: height * 0.5,
    };
    let hole = SdfNode::Cylinder {
        radius: tap_r,
        // +5.0 = 5mm each side、preview MC (cell ~1mm) で確実 punch through
        // (cavity margin rule)
        half_height: height.mul_add(0.5, 5.0),
    };
    SdfNode::Subtraction {
        a: Arc::new(barrel),
        b: Arc::new(hole),
    }
}

// ────────────────────────────────────────────────────────
// 3. fillet (SmoothUnion wrapper)
// ────────────────────────────────────────────────────────

/// 内角 R (2 `SdfNode` を smooth-union で滑らかに blend)
///
/// 応力集中を緩和する canonical 手段
/// R が大きいほど内角の応力集中係数 Kt が下がる (`physics` feature で計算可)
///
/// # 引数
///
/// - `a`, `b`: blend 対象の 2 `SdfNode`
/// - `radius`: フィレット半径 (mm、smooth-union の blend radius k)
///
/// # 使用例
///
/// ```
/// use alice_lol::stdlib::hardsurface::reinforcement::fillet;
/// use alice_sdf::SdfNode;
/// use glam::Vec3;
/// let base = SdfNode::Box3d { half_extents: Vec3::new(10.0, 2.0, 20.0) };
/// let vertical = SdfNode::Box3d { half_extents: Vec3::new(2.0, 15.0, 20.0) };
/// let filleted = fillet(base, vertical, 1.5);
/// // L 字部品の内角に R1.5mm フィレット
/// ```
#[must_use]
pub fn fillet(a: SdfNode, b: SdfNode, radius: f32) -> SdfNode {
    SdfNode::SmoothUnion {
        a: Arc::new(a),
        b: Arc::new(b),
        k: radius,
    }
}

// ────────────────────────────────────────────────────────
// 4. chamfer (ChamferUnion wrapper)
// ────────────────────────────────────────────────────────

/// 面取り (2 `SdfNode` を 45° chamfer union で結合)
///
/// fillet より加工しやすい直線的 edge、CNC / レーザー切断で標準
///
/// # 引数
///
/// - `a`, `b`: 結合対象の 2 `SdfNode`
/// - `size`: 面取り寸法 (mm、chamfer 幅)
///
/// # 使用例
///
/// ```
/// use alice_lol::stdlib::hardsurface::reinforcement::chamfer;
/// use alice_sdf::SdfNode;
/// use glam::Vec3;
/// let base = SdfNode::Box3d { half_extents: Vec3::new(10.0, 2.0, 20.0) };
/// let vertical = SdfNode::Box3d { half_extents: Vec3::new(2.0, 15.0, 20.0) };
/// let chamfered = chamfer(base, vertical, 1.0);
/// // L 字部品の内角に C1.0 面取り
/// ```
#[must_use]
pub fn chamfer(a: SdfNode, b: SdfNode, size: f32) -> SdfNode {
    SdfNode::ChamferUnion {
        a: Arc::new(a),
        b: Arc::new(b),
        r: size,
    }
}

// ────────────────────────────────────────────────────────
// 5. honeycomb infill
// ────────────────────────────────────────────────────────

/// ハニカム infill (container を 6 角形 cell の repeat から Subtraction、壁だけ残す)
///
/// 内部を 6 角形 pattern で刳り抜いて軽量化しつつ剛性を確保する
///
/// # 引数
///
/// - `container`: 中身を刳り抜く対象 `SdfNode` (bbox 内で cell を repeat)
/// - `cell_size`: 6 角形 cell の対辺距離 (mm、hexagon flat-to-flat)
/// - `wall_thickness`: 残す壁厚 (mm、cell 間の材料肉厚)
/// - `count`: 各軸方向の repeat 半径 (`2 * count + 1` 個生成、X-Z 平面)
///
/// # 使用例
///
/// ```
/// use alice_lol::stdlib::hardsurface::reinforcement::honeycomb_infill;
/// use alice_sdf::SdfNode;
/// use glam::Vec3;
/// let plate = SdfNode::Box3d { half_extents: Vec3::new(50.0, 5.0, 50.0) };
/// let lightweight = honeycomb_infill(plate, 8.0, 1.2, 6);
/// ```
#[must_use]
pub fn honeycomb_infill(
    container: SdfNode,
    cell_size: f32,
    wall_thickness: f32,
    count: u32,
) -> SdfNode {
    // 6 角形 hex_radius (中心から頂点までの距離) = cell_size / √3 (flat-to-flat / √3)
    // hex_prism は Y 軸押出、板は Y = 板厚方向想定 (rib と揃える)
    let hex_r = cell_size / 3.0_f32.sqrt();
    // wall_thickness 分だけ hex を縮小して壁を残す (cell 間ギャップ = wall)
    let cell_effective_r = crate::det_math::max(wall_thickness.mul_add(-0.5, hex_r), 0.0);
    let hex = SdfNode::HexPrism {
        hex_radius: cell_effective_r,
        half_height: 1000.0, // container で切るので大きめに取る
    };
    // 6 角形千鳥は複雑なので Phase A.3 では rect grid で単純化 (Phase A.4 で hex 千鳥化検討)
    // X 方向 pitch = cell_size × √3 (行間)、Z 方向 pitch = cell_size × 1.5 (列間)
    let repeated = SdfNode::RepeatFinite {
        child: Arc::new(hex),
        count: [count, 0, count],
        spacing: Vec3::new(cell_size * 3.0_f32.sqrt(), 1.0, cell_size * 1.5),
    };
    SdfNode::Subtraction {
        a: Arc::new(container),
        b: Arc::new(repeated),
    }
}

// ────────────────────────────────────────────────────────
// 6. gyroid infill (TPMS)
// ────────────────────────────────────────────────────────

/// Gyroid TPMS infill (container ∩ Gyroid 曲面壁)
///
/// Gyroid = 極小曲面、等方性・高剛性の TPMS ラティス
/// Bambu Studio infill 「Gyroid」相当を LOL レベルで直接生成する
///
/// # 引数
///
/// - `container`: 中身を Gyroid で埋める対象 `SdfNode`
/// - `cell_scale`: Gyroid 空間周波数 (小さいほど cell 大)
/// - `wall_thickness`: Gyroid 曲面の壁半厚 (mm)
///
/// # 使用例
///
/// ```
/// use alice_lol::stdlib::hardsurface::reinforcement::gyroid_infill;
/// use alice_sdf::SdfNode;
/// use glam::Vec3;
/// let cube = SdfNode::Box3d { half_extents: Vec3::new(20.0, 20.0, 20.0) };
/// let g = gyroid_infill(cube, 3.0, 0.4);
/// ```
///
/// # Panics
///
/// `cell_scale` が有限かつ `0.0` より大きくない、または `wall_thickness` が
/// 有限でない時 ([`crate::limits::checked_tpms_fields`] の契約、この crate の
/// 他の infallible builder と同じ `try_*` が無い生の builder の panic 規約)
#[must_use]
pub fn gyroid_infill(container: SdfNode, cell_scale: f32, wall_thickness: f32) -> SdfNode {
    let (scale, thickness) = crate::limits::checked_tpms_fields(cell_scale, wall_thickness * 0.5)
        .unwrap_or_else(|e| panic!("gyroid_infill: {e}"));
    let gyroid = SdfNode::Gyroid { scale, thickness };
    SdfNode::Intersection {
        a: Arc::new(container),
        b: Arc::new(gyroid),
    }
}

// ────────────────────────────────────────────────────────
// alice-physics 連携 (opt-in、`physics` feature 必須)
// ────────────────────────────────────────────────────────

/// 材料名から弾性率 (`GPa`) を取得 (`alice_physics::filament_db::MaterialProperties`)
///
/// SSOT: pipeline `safety module` と同じ `FilamentDb` を参照 hardcode 定数を置換
/// 対応材料: `"pla"` / `"petg"` / `"abs"` (大文字小文字不問)
///
/// # 使用例
///
/// ```ignore
/// // cargo test --features physics
/// use alice_lol::stdlib::hardsurface::reinforcement::material_elastic_modulus_gpa;
/// let e = material_elastic_modulus_gpa("pla");
/// assert!(e.is_some());
/// ```
#[cfg(feature = "physics")]
#[must_use]
pub fn material_elastic_modulus_gpa(name: &str) -> Option<f32> {
    use alice_physics::filament_db::MaterialProperties;
    let props = match name.to_ascii_lowercase().as_str() {
        "pla" => MaterialProperties::pla(),
        "petg" => MaterialProperties::petg(),
        "abs" => MaterialProperties::abs(),
        _ => return None,
    };
    Some(props.youngs_modulus_gpa.to_f32())
}

/// 段付き軸曲げの応力集中係数 Kt (`alice_physics::fillet_stress::kt_shaft_shoulder_bending`)
///
/// フィレット半径が大きいほど Kt が下がる (応力集中緩和)
///
/// # 引数
///
/// - `fillet_radius_mm`: フィレット半径 R (mm)
/// - `small_dia_mm`: 小径 d (mm)
/// - `large_dia_mm`: 大径 D (mm)
///
/// # 使用例
///
/// ```ignore
/// // cargo test --features physics
/// use alice_lol::stdlib::hardsurface::reinforcement::fillet_kt_shaft_shoulder;
/// let kt = fillet_kt_shaft_shoulder(0.5, 10.0, 20.0);
/// assert!(kt > 1.0);
/// ```
#[cfg(feature = "physics")]
#[must_use]
pub fn fillet_kt_shaft_shoulder(
    fillet_radius_mm: f32,
    small_dia_mm: f32,
    large_dia_mm: f32,
) -> f32 {
    use alice_physics::fillet_stress::kt_shaft_shoulder_bending;
    use alice_physics::math::Fix128;
    let kt = kt_shaft_shoulder_bending(
        Fix128::from_f32(fillet_radius_mm),
        Fix128::from_f32(small_dia_mm),
        Fix128::from_f32(large_dia_mm),
    );
    kt.to_f32()
}

/// 目標 Kt に対する推奨フィレット半径 (mm) を逆算 (`alice_physics::fillet_stress::recommended_fillet_radius_mm`)
///
/// # 引数
///
/// - `small_dia_mm`: 小径 d (mm)
/// - `large_dia_mm`: 大径 D (mm)
/// - `kt_target`: 目標応力集中係数
///
/// # 使用例
///
/// ```ignore
/// // cargo test --features physics
/// use alice_lol::stdlib::hardsurface::reinforcement::recommended_fillet_radius_mm;
/// let r = recommended_fillet_radius_mm(10.0, 20.0, 1.5);
/// assert!(r > 0.0);
/// ```
#[cfg(feature = "physics")]
#[must_use]
pub fn recommended_fillet_radius_mm(small_dia_mm: f32, large_dia_mm: f32, kt_target: f32) -> f32 {
    use alice_physics::fillet_stress::recommended_fillet_radius_mm as inner;
    use alice_physics::math::Fix128;
    inner(
        Fix128::from_f32(small_dia_mm),
        Fix128::from_f32(large_dia_mm),
        Fix128::from_f32(kt_target),
    )
    .to_f32()
}

// ────────────────────────────────────────────────────────
// テスト
// ────────────────────────────────────────────────────────

#[cfg(test)]
mod tests {
    use super::*;
    use alice_sdf::eval;

    fn approx_eq(a: f32, b: f32) -> bool {
        (a - b).abs() < 1e-4
    }

    #[test]
    fn rib_is_box3d_with_expected_dimensions() {
        let node = rib(30.0, 5.0, 1.6);
        match node {
            SdfNode::Box3d { half_extents } => {
                assert!(approx_eq(half_extents.x, 15.0));
                assert!(approx_eq(half_extents.y, 2.5));
                assert!(approx_eq(half_extents.z, 0.8));
            }
            _ => panic!("expected Box3d"),
        }
    }

    #[test]
    fn boss_outer_diameter_uses_pipeline_screw_boss_od_ratio() {
        // M3 → 外径 = 3 * 2.2 = 6.6mm、外半径 3.3mm
        let node = boss(3.0, 8.0);
        match &node {
            SdfNode::Subtraction { a, b: _ } => match &**a {
                SdfNode::Cylinder { radius, .. } => assert!(approx_eq(*radius, 3.3)),
                _ => panic!("expected outer Cylinder"),
            },
            _ => panic!("expected Subtraction"),
        }
    }

    #[test]
    fn boss_inner_hole_uses_tap_formula() {
        // M3 tap: 3 * 0.85 + 0.2 = 2.75mm 直径、半径 1.375mm
        let node = boss(3.0, 8.0);
        match &node {
            SdfNode::Subtraction { a: _, b } => match &**b {
                SdfNode::Cylinder { radius, .. } => assert!(approx_eq(*radius, 1.375)),
                _ => panic!("expected inner Cylinder"),
            },
            _ => panic!("expected Subtraction"),
        }
    }

    #[test]
    fn fillet_returns_smooth_union() {
        let a = SdfNode::Sphere { radius: 1.0 };
        let b = SdfNode::Sphere { radius: 1.0 };
        let f = fillet(a, b, 0.3);
        match f {
            SdfNode::SmoothUnion { k, .. } => assert!(approx_eq(k, 0.3)),
            _ => panic!("expected SmoothUnion"),
        }
    }

    #[test]
    fn chamfer_returns_chamfer_union() {
        let a = SdfNode::Sphere { radius: 1.0 };
        let b = SdfNode::Sphere { radius: 1.0 };
        let c = chamfer(a, b, 0.5);
        match c {
            SdfNode::ChamferUnion { r, .. } => assert!(approx_eq(r, 0.5)),
            _ => panic!("expected ChamferUnion"),
        }
    }

    #[test]
    fn honeycomb_infill_returns_subtraction() {
        let container = SdfNode::Box3d {
            half_extents: Vec3::new(50.0, 5.0, 50.0),
        };
        let node = honeycomb_infill(container, 8.0, 1.2, 6);
        assert!(matches!(node, SdfNode::Subtraction { .. }));
    }

    #[test]
    fn gyroid_infill_returns_intersection_with_gyroid() {
        let container = SdfNode::Box3d {
            half_extents: Vec3::new(20.0, 20.0, 20.0),
        };
        let node = gyroid_infill(container, 3.0, 0.4);
        match &node {
            SdfNode::Intersection { a: _, b } => {
                assert!(matches!(&**b, SdfNode::Gyroid { .. }));
            }
            _ => panic!("expected Intersection with Gyroid"),
        }
    }

    #[test]
    #[should_panic(expected = "gyroid_infill")]
    fn gyroid_infill_panics_on_a_degenerate_cell_scale() {
        let container = SdfNode::Box3d {
            half_extents: Vec3::new(20.0, 20.0, 20.0),
        };
        let _ = gyroid_infill(container, -0.0, 0.4);
    }

    #[test]
    #[should_panic(expected = "gyroid_infill")]
    fn gyroid_infill_panics_on_a_non_finite_wall_thickness() {
        let container = SdfNode::Box3d {
            half_extents: Vec3::new(20.0, 20.0, 20.0),
        };
        let _ = gyroid_infill(container, 3.0, f32::NAN);
    }

    /// Any finite positive `cell_scale` is accepted, down to a subnormal
    /// `f32` -- `1e-45`/`5e-7` were rejected by an earlier `>= 1e-6` floor.
    #[test]
    fn gyroid_infill_accepts_any_finite_positive_cell_scale() {
        for cell_scale in [1e-45_f32, 5e-7] {
            let container = SdfNode::Box3d {
                half_extents: Vec3::new(20.0, 20.0, 20.0),
            };
            let node = gyroid_infill(container, cell_scale, 0.4);
            assert!(
                matches!(node, SdfNode::Intersection { .. }),
                "cell_scale={cell_scale} should build an Intersection node"
            );
        }
    }

    #[test]
    fn boss_evaluation_at_origin_is_inside_tap_hole() {
        // 原点 (0, 0, 0) は tap 穴内部 = 物質「外」(穴は空間)
        let node = boss(3.0, 8.0);
        assert!(eval(&node, Vec3::ZERO) > 0.0);
    }

    #[test]
    fn boss_evaluation_between_tap_and_outer_is_inside_material() {
        // 半径 2.0mm 位置 (tap 1.375 外、外 3.3 内) は材料内部
        let node = boss(3.0, 8.0);
        assert!(eval(&node, Vec3::new(2.0, 0.0, 0.0)) < 0.0);
    }

    #[test]
    fn rib_evaluation_at_center_is_inside() {
        let node = rib(30.0, 5.0, 1.6);
        assert!(eval(&node, Vec3::ZERO) < 0.0);
    }

    #[test]
    fn all_reinforcement_primitives_produce_finite_sdf() {
        let container = SdfNode::Box3d {
            half_extents: Vec3::new(20.0, 20.0, 20.0),
        };
        let nodes = [
            rib(30.0, 5.0, 1.6),
            boss(3.0, 8.0),
            fillet(
                SdfNode::Sphere { radius: 1.0 },
                SdfNode::Sphere { radius: 1.0 },
                0.3,
            ),
            chamfer(
                SdfNode::Sphere { radius: 1.0 },
                SdfNode::Sphere { radius: 1.0 },
                0.5,
            ),
            honeycomb_infill(container.clone(), 8.0, 1.2, 6),
            gyroid_infill(container, 3.0, 0.4),
        ];
        for (i, node) in nodes.iter().enumerate() {
            let d = eval(node, Vec3::new(0.1, 0.1, 0.1));
            assert!(d.is_finite(), "primitive {i} produced non-finite SDF: {d}");
        }
    }

    #[cfg(feature = "physics")]
    #[test]
    fn physics_material_elastic_modulus_pla_matches_hardcode() {
        // Phase A.2 hardcode (3.5 GPa) と physics feature の FilamentDb 値が一致するか
        let e = material_elastic_modulus_gpa("pla").expect("PLA registered");
        // pipeline FilamentDb の PLA elastic_modulus は 3.5 GPa (実装値)
        assert!((3.0..=4.0).contains(&e), "PLA elastic modulus = {e} GPa");
    }

    #[cfg(feature = "physics")]
    #[test]
    fn physics_fillet_kt_decreases_with_larger_radius() {
        // R を大きくすると Kt が下がる (応力集中緩和)
        let kt_small = fillet_kt_shaft_shoulder(0.2, 10.0, 20.0);
        let kt_large = fillet_kt_shaft_shoulder(2.0, 10.0, 20.0);
        assert!(
            kt_large < kt_small,
            "kt_large ({kt_large}) should be < kt_small ({kt_small})"
        );
    }

    #[cfg(feature = "physics")]
    #[test]
    fn physics_recommended_fillet_radius_positive() {
        let r = recommended_fillet_radius_mm(10.0, 20.0, 1.5);
        assert!(r > 0.0, "recommended R = {r}");
    }

    #[cfg(feature = "physics")]
    #[test]
    fn physics_unknown_material_returns_none() {
        assert!(material_elastic_modulus_gpa("unknown_polymer").is_none());
    }
}