BREP_render 0.1.0

BREP Rust rendering engine: kernel-fed scene store + wgpu renderer (headless artifact, desktop window, and wasm canvas shells).
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
//! Picking in Rust (R23/R24), replacing the retired raycaster +
//! `selectionMethods._pickAtEvent`: returns KERNEL NAMES with the candidate
//! priority order VERTEX > EDGE > FACE > … > SOLID, CSS-pixel thresholds for
//! lines/points (the earlier picker's `worldPerPixel * 6` is exactly 6 CSS px), a
//! double-sided face toggle, and a ranked candidate list feeding the host's
//! multi-candidate popup. Selection-filter *filtering* stays in the UI layer where the
//! filter state lives — the engine reports everything under the cursor.
//!
//! CPU ray/screen-space testing over the scene's display buffers: exact,
//! deterministic, identical on native and wasm, and cheap at CAD face counts
//! (per-face triangle ranges give a bbox reject before any triangle test).

use crate::scene::{RenderScene, SolidDisplay};
use crate::view::{add3, cross3, dot3, scale3, sub3, Projection, Ray, ViewCamera};

/// Pick thresholds in CSS pixels (ported from `selectionMethods`).
pub const EDGE_PICK_PX: f64 = 6.0;
pub const VERTEX_PICK_PX: f64 = 6.0;
const MAX_CANDIDATES: usize = 16;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum PickKind {
    Vertex = 0,
    Edge = 1,
    Face = 2,
    Solid = 3,
}

impl PickKind {
    pub fn as_str(&self) -> &'static str {
        match self {
            PickKind::Vertex => "VERTEX",
            PickKind::Edge => "EDGE",
            PickKind::Face => "FACE",
            PickKind::Solid => "SOLID",
        }
    }
}

#[derive(Debug, Clone)]
pub struct PickCandidate {
    pub kind: PickKind,
    /// Kernel name (faces/edges; empty for unnamed). For vertices this is
    /// empty — vertices resolve by `position` within `solid`.
    pub name: String,
    /// Owning solid's scene name.
    pub solid: String,
    /// View-space depth of the hit (for ranking within a kind).
    pub depth: f64,
    /// Cursor→hit distance in CSS px (0 for face hits).
    pub screen_dist: f64,
    /// World-space hit position (face hit point / edge closest point / vertex).
    pub position: [f64; 3],
}

#[derive(Debug, Clone, Copy)]
pub struct PickOptions {
    pub double_sided: bool,
    pub edge_px: f64,
    pub vertex_px: f64,
}

impl Default for PickOptions {
    fn default() -> Self {
        Self {
            // The retired picker force-flipped FrontSide materials to DoubleSide
            // for every pick, so double-sided is the parity default.
            double_sided: true,
            edge_px: EDGE_PICK_PX,
            vertex_px: VERTEX_PICK_PX,
        }
    }
}

/// Rank candidates under CSS-pixel `(x, y)`. Ordered by the priority chain
/// then depth; a SOLID entry per hit solid is appended at the end (the earlier
/// "extras" behavior).
pub fn pick(
    scene: &RenderScene,
    camera: &ViewCamera,
    x: f64,
    y: f64,
    options: &PickOptions,
) -> Vec<PickCandidate> {
    let ray = camera.pick_ray(x, y);
    let (_, _, forward) = camera.basis();
    let persp = matches!(camera.projection, Projection::Perspective { .. });

    let mut hits: Vec<PickCandidate> = Vec::new();
    for solid in scene.solids() {
        if !solid.visible {
            continue;
        }
        pick_faces(solid, camera, &ray, forward, options, &mut hits);
        pick_edges(solid, camera, x, y, forward, persp, options, &mut hits);
        pick_vertices(solid, camera, x, y, forward, persp, options, &mut hits);
    }

    hits.sort_by(|a, b| {
        (a.kind as u8)
            .cmp(&(b.kind as u8))
            .then(a.depth.total_cmp(&b.depth))
            .then(a.screen_dist.total_cmp(&b.screen_dist))
    });
    hits.truncate(MAX_CANDIDATES);

    // Append one SOLID candidate per hit solid, ordered by first (best) hit.
    let mut solids_seen: Vec<String> = Vec::new();
    let mut solid_entries: Vec<PickCandidate> = Vec::new();
    for hit in &hits {
        if solids_seen.iter().any(|name| name == &hit.solid) {
            continue;
        }
        solids_seen.push(hit.solid.clone());
        solid_entries.push(PickCandidate {
            kind: PickKind::Solid,
            name: hit.solid.clone(),
            solid: hit.solid.clone(),
            depth: hit.depth,
            screen_dist: hit.screen_dist,
            position: hit.position,
        });
    }
    hits.extend(solid_entries);
    hits
}

/// The nearest hit of an ALLOWED KIND under CSS-pixel `(x, y)`, using the same
/// ranking as [`pick`]. `filter` is a set of kind strings (`"SOLID"`, `"FACE"`,
/// `"EDGE"`, `"VERTEX"`, case-insensitive); an empty filter means any kind. This
/// is the type-constrained pick the reference-selection widget uses so a
/// `targetSolid` field resolves the SOLID under the cursor (candidates rank
/// faces first, then the trailing SOLID entry — `find` walks that order and
/// returns the first candidate whose kind is allowed). Returns the full
/// candidate (name + owning solid + position) or `None` on a miss.
pub fn pick_filtered(
    scene: &RenderScene,
    camera: &ViewCamera,
    x: f64,
    y: f64,
    options: &PickOptions,
    filter: &[String],
) -> Option<PickCandidate> {
    pick(scene, camera, x, y, options).into_iter().find(|c| {
        filter.is_empty() || filter.iter().any(|f| f.eq_ignore_ascii_case(c.kind.as_str()))
    })
}

fn view_depth(camera: &ViewCamera, forward: [f64; 3], point: [f64; 3]) -> f64 {
    dot3(sub3(point, camera.eye), forward)
}

fn pick_faces(
    solid: &SolidDisplay,
    camera: &ViewCamera,
    ray: &Ray,
    forward: [f64; 3],
    options: &PickOptions,
    out: &mut Vec<PickCandidate>,
) {
    if solid.mesh.indices.is_empty() {
        return;
    }
    if !ray_hits_aabb(ray, &solid.bbox) {
        return;
    }
    let positions = &solid.mesh.positions;
    let indices = &solid.mesh.indices;
    for (index, face) in solid.faces.iter().enumerate() {
        // Per-entity visibility (the scene tree's face checkboxes): a hidden
        // face isn't rendered, so it must not be hoverable/pickable either.
        if !solid.visibility.is_face_visible(index) {
            continue;
        }
        if face.tri_count == 0 {
            continue;
        }
        let mut best: Option<(f64, [f64; 3])> = None;
        let start = face.tri_start as usize;
        let end = start + face.tri_count as usize;
        for tri in start..end.min(indices.len() / 3) {
            let i0 = indices[tri * 3] as usize;
            let i1 = indices[tri * 3 + 1] as usize;
            let i2 = indices[tri * 3 + 2] as usize;
            let a = to_f64(positions[i0]);
            let b = to_f64(positions[i1]);
            let c = to_f64(positions[i2]);
            if let Some(t) = ray_triangle(ray, a, b, c, options.double_sided) {
                let point = add3(ray.origin, scale3(ray.dir, t));
                if best.map(|(bt, _)| t < bt).unwrap_or(true) {
                    best = Some((t, point));
                }
            }
        }
        if let Some((_, point)) = best {
            out.push(PickCandidate {
                kind: PickKind::Face,
                name: face.name.clone(),
                solid: solid.name.clone(),
                depth: view_depth(camera, forward, point),
                screen_dist: 0.0,
                position: point,
            });
        }
    }
}

#[allow(clippy::too_many_arguments)]
fn pick_edges(
    solid: &SolidDisplay,
    camera: &ViewCamera,
    x: f64,
    y: f64,
    forward: [f64; 3],
    persp: bool,
    options: &PickOptions,
    out: &mut Vec<PickCandidate>,
) {
    for (index, edge) in solid.edges.iter().enumerate() {
        // Hidden edges (scene-tree checkboxes) are not rendered → not pickable.
        if !solid.visibility.is_edge_visible(index) {
            continue;
        }
        let mut best: Option<(f64, f64, [f64; 3])> = None; // (screen_dist, depth, world)
        for pair in edge.polyline.windows(2) {
            let mut a = to_f64(pair[0]);
            let mut b = to_f64(pair[1]);
            if persp {
                let da = view_depth(camera, forward, a);
                let db = view_depth(camera, forward, b);
                const EPS: f64 = 1e-6;
                if da <= EPS && db <= EPS {
                    continue;
                }
                if da <= EPS || db <= EPS {
                    // Clip the behind-eye endpoint to just in front.
                    let t = (EPS - da) / (db - da);
                    let clip = add3(a, scale3(sub3(b, a), t));
                    if da <= EPS {
                        a = clip;
                    } else {
                        b = clip;
                    }
                }
            }
            let (ax, ay, _) = camera.project(a);
            let (bx, by, _) = camera.project(b);
            let (dist, t) = point_segment_distance_2d(x, y, ax, ay, bx, by);
            if dist <= options.edge_px {
                let world = add3(a, scale3(sub3(b, a), t));
                let depth = view_depth(camera, forward, world);
                if best
                    .map(|(bd, bdepth, _)| dist < bd || (dist == bd && depth < bdepth))
                    .unwrap_or(true)
                {
                    best = Some((dist, depth, world));
                }
            }
        }
        if let Some((screen_dist, depth, position)) = best {
            out.push(PickCandidate {
                kind: PickKind::Edge,
                name: edge.name.clone(),
                solid: solid.name.clone(),
                depth,
                screen_dist,
                position,
            });
        }
    }
}

#[allow(clippy::too_many_arguments)]
fn pick_vertices(
    solid: &SolidDisplay,
    camera: &ViewCamera,
    x: f64,
    y: f64,
    forward: [f64; 3],
    persp: bool,
    options: &PickOptions,
    out: &mut Vec<PickCandidate>,
) {
    for (index, vertex) in solid.vertices.iter().enumerate() {
        // Hidden vertices (scene-tree checkboxes) are not rendered → not pickable.
        if !solid.visibility.is_vertex_visible(index) {
            continue;
        }
        let depth = view_depth(camera, forward, vertex.position);
        if persp && depth <= 1e-6 {
            continue;
        }
        let (sx, sy, _) = camera.project(vertex.position);
        let dist = ((sx - x).powi(2) + (sy - y).powi(2)).sqrt();
        if dist <= options.vertex_px {
            out.push(PickCandidate {
                kind: PickKind::Vertex,
                name: String::new(),
                solid: solid.name.clone(),
                depth,
                screen_dist: dist,
                position: vertex.position,
            });
        }
    }
}

fn to_f64(p: [f32; 3]) -> [f64; 3] {
    [p[0] as f64, p[1] as f64, p[2] as f64]
}

/// Distance from point to segment in 2D + the segment parameter of the
/// closest point.
fn point_segment_distance_2d(px: f64, py: f64, ax: f64, ay: f64, bx: f64, by: f64) -> (f64, f64) {
    let abx = bx - ax;
    let aby = by - ay;
    let len2 = abx * abx + aby * aby;
    let t = if len2 <= 1e-18 {
        0.0
    } else {
        (((px - ax) * abx + (py - ay) * aby) / len2).clamp(0.0, 1.0)
    };
    let cx = ax + abx * t;
    let cy = ay + aby * t;
    (((px - cx).powi(2) + (py - cy).powi(2)).sqrt(), t)
}

/// Möller–Trumbore; returns the ray parameter t of the hit.
fn ray_triangle(ray: &Ray, a: [f64; 3], b: [f64; 3], c: [f64; 3], double_sided: bool) -> Option<f64> {
    let e1 = sub3(b, a);
    let e2 = sub3(c, a);
    let pvec = cross3(ray.dir, e2);
    let det = dot3(e1, pvec);
    const EPS: f64 = 1e-14;
    if double_sided {
        if det.abs() < EPS {
            return None;
        }
    } else if det < EPS {
        return None;
    }
    let inv_det = 1.0 / det;
    let tvec = sub3(ray.origin, a);
    let u = dot3(tvec, pvec) * inv_det;
    if !(-1e-9..=1.0 + 1e-9).contains(&u) {
        return None;
    }
    let qvec = cross3(tvec, e1);
    let v = dot3(ray.dir, qvec) * inv_det;
    if v < -1e-9 || u + v > 1.0 + 1e-9 {
        return None;
    }
    let t = dot3(e2, qvec) * inv_det;
    if t <= 0.0 {
        return None;
    }
    Some(t)
}

fn ray_hits_aabb(ray: &Ray, bbox: &crate::camera::Aabb) -> bool {
    if bbox.is_empty() {
        return false;
    }
    let mut t_min = f64::NEG_INFINITY;
    let mut t_max = f64::INFINITY;
    for axis in 0..3 {
        let dir = ray.dir[axis];
        let origin = ray.origin[axis];
        if dir.abs() < 1e-15 {
            if origin < bbox.min[axis] - 1e-9 || origin > bbox.max[axis] + 1e-9 {
                return false;
            }
            continue;
        }
        let inv = 1.0 / dir;
        let t0 = (bbox.min[axis] - origin) * inv;
        let t1 = (bbox.max[axis] - origin) * inv;
        let (lo, hi) = if t0 <= t1 { (t0, t1) } else { (t1, t0) };
        t_min = t_min.max(lo);
        t_max = t_max.min(hi);
        if t_min > t_max {
            return false;
        }
    }
    t_max > 0.0
}

/// Serialize candidates for the R3 JSON boundary.
pub fn candidates_to_json(candidates: &[PickCandidate]) -> String {
    let list: Vec<serde_json::Value> = candidates
        .iter()
        .map(|c| {
            serde_json::json!({
                "kind": c.kind.as_str(),
                "name": c.name,
                "solid": c.solid,
                "depth": c.depth,
                "screenDist": c.screen_dist,
                "position": c.position,
            })
        })
        .collect();
    serde_json::Value::Array(list).to_string()
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::pipeline::scene_from_history_json;

    fn cube_scene() -> RenderScene {
        let request = serde_json::json!({
            "expressions": "",
            "configurator": {},
            "features": [{
                "type": "P.CU",
                "inputParams": {
                    "id": "PickCube",
                    "sizeX": 10.0, "sizeY": 10.0, "sizeZ": 10.0,
                    "transform": {
                        "position": [0.0, 0.0, 0.0],
                        "rotationEuler": [0.0, 0.0, 0.0],
                        "scale": [1.0, 1.0, 1.0]
                    },
                    "boolean": { "targets": [], "operation": "NONE" }
                },
                "persistentData": {}
            }]
        })
        .to_string();
        let (scene, report) = scene_from_history_json(&request).unwrap();
        assert!(report.feature_errors.is_empty(), "{:?}", report.feature_errors);
        scene
    }

    fn front_camera() -> ViewCamera {
        // Straight down -Z at the cube (cube spans 0..10 in x,y,z).
        ViewCamera {
            eye: [5.0, 5.0, 50.0],
            target: [5.0, 5.0, 5.0],
            up: [0.0, 1.0, 0.0],
            projection: Projection::Orthographic { half_height: 10.0 },
            width: 800.0,
            height: 600.0,
            near: -1000.0,
            far: 1000.0,
        }
    }

    #[test]
    fn face_pick_at_center_is_deterministic() {
        let scene = cube_scene();
        let camera = front_camera();
        let first = pick(&scene, &camera, 400.0, 300.0, &PickOptions::default());
        let second = pick(&scene, &camera, 400.0, 300.0, &PickOptions::default());
        assert!(!first.is_empty());
        assert_eq!(first.len(), second.len());
        for (a, b) in first.iter().zip(second.iter()) {
            assert_eq!(a.kind, b.kind);
            assert_eq!(a.name, b.name);
            assert_eq!(a.depth.to_bits(), b.depth.to_bits(), "deterministic depth");
        }
        // Center of the face: nothing but faces (both sides of the cube) and
        // the trailing SOLID entry.
        assert_eq!(first[0].kind, PickKind::Face);
        assert!(!first[0].name.is_empty(), "face has a kernel name");
        assert_eq!(first.last().unwrap().kind, PickKind::Solid);
        assert_eq!(first.last().unwrap().name, "PickCube");
        // Nearest face first: the +Z face (z = 10) is closer than z = 0.
        assert!(first[0].depth < first[1].depth);
        assert!((first[0].position[2] - 10.0).abs() < 1e-9);
    }

    #[test]
    fn edge_and_vertex_priority_ranking() {
        let scene = cube_scene();
        let camera = front_camera();
        // The cube's top-right-front corner (10, 10, 10) in screen space.
        let (cx, cy, _) = camera.project([10.0, 10.0, 10.0]);
        let hits = pick(&scene, &camera, cx, cy, &PickOptions::default());
        assert!(!hits.is_empty());
        // Priority: VERTEX first even though faces/edges are hit too.
        assert_eq!(hits[0].kind, PickKind::Vertex);
        assert!(crate::view::len3(crate::view::sub3(hits[0].position, [10.0, 10.0, 10.0])) < 1e-9);
        assert!(hits.iter().any(|h| h.kind == PickKind::Edge));
        assert!(hits.iter().any(|h| h.kind == PickKind::Face));
        assert_eq!(hits.last().unwrap().kind, PickKind::Solid);

        // A point on the top edge midway (5, 10, 10): edge above face.
        let (ex, ey, _) = camera.project([5.0, 10.0, 10.0]);
        let hits = pick(&scene, &camera, ex, ey, &PickOptions::default());
        assert_eq!(hits[0].kind, PickKind::Edge);
        assert!(!hits[0].name.is_empty(), "edge has a kernel name");
    }

    #[test]
    fn filtered_pick_constrains_to_kind() {
        let scene = cube_scene();
        let camera = front_camera();
        // Center of a face: unconstrained best is a FACE; a SOLID filter walks
        // past the faces to the trailing SOLID entry.
        let face = pick_filtered(&scene, &camera, 400.0, 300.0, &PickOptions::default(), &["FACE".into()]);
        assert_eq!(face.as_ref().unwrap().kind, PickKind::Face);
        let solid = pick_filtered(&scene, &camera, 400.0, 300.0, &PickOptions::default(), &["SOLID".into()]);
        assert_eq!(solid.as_ref().unwrap().kind, PickKind::Solid);
        assert_eq!(solid.unwrap().name, "PickCube");
        // Case-insensitive filter + empty filter = any (the top-ranked candidate).
        let any = pick_filtered(&scene, &camera, 400.0, 300.0, &PickOptions::default(), &[]);
        assert_eq!(any.unwrap().kind, PickKind::Face);
        let lower = pick_filtered(&scene, &camera, 400.0, 300.0, &PickOptions::default(), &["solid".into()]);
        assert_eq!(lower.unwrap().kind, PickKind::Solid);
        // A miss yields nothing under any filter.
        assert!(pick_filtered(&scene, &camera, 10.0, 10.0, &PickOptions::default(), &["SOLID".into()]).is_none());
    }

    #[test]
    fn miss_returns_empty() {
        let scene = cube_scene();
        let camera = front_camera();
        let hits = pick(&scene, &camera, 10.0, 10.0, &PickOptions::default());
        assert!(hits.is_empty(), "{hits:?}");
    }

    /// Per-ENTITY visibility (the scene tree's face/edge/vertex checkboxes)
    /// must gate picking exactly like rendering: a hidden face isn't drawn, so
    /// hovering/clicking must fall through to what IS visible behind it.
    #[test]
    fn hidden_entities_are_not_pickable() {
        use crate::visibility::EntityKind;
        let mut scene = cube_scene();
        let camera = front_camera();

        // Hide the front (+Z) face: the top-ranked face pick must become the
        // BACK face (z = 0), and the front face must vanish from candidates.
        let before = pick(&scene, &camera, 400.0, 300.0, &PickOptions::default());
        assert_eq!(before[0].kind, PickKind::Face);
        let front_name = before[0].name.clone();
        let front_index = scene
            .solids()
            .iter()
            .find(|s| s.name == "PickCube")
            .unwrap()
            .faces
            .iter()
            .position(|f| f.name == front_name)
            .unwrap();
        scene
            .solid_mut("PickCube")
            .unwrap()
            .visibility
            .set_visible(EntityKind::Face, front_index, false);
        let after = pick(&scene, &camera, 400.0, 300.0, &PickOptions::default());
        assert!(
            after
                .iter()
                .all(|c| !(c.kind == PickKind::Face && c.name == front_name)),
            "hidden face still picked: {after:?}"
        );
        assert_eq!(after[0].kind, PickKind::Face, "the back face is still pickable");
        assert!((after[0].position[2] - 0.0).abs() < 1e-9, "back face at z=0");

        // Hide every vertex: a corner pick no longer yields VERTEX candidates
        // (the corner's edges take priority instead).
        let vertex_count = scene.solids()[0].vertices.len();
        scene
            .solid_mut("PickCube")
            .unwrap()
            .visibility
            .set_group_visible(EntityKind::Vertex, vertex_count, false);
        let (cx, cy, _) = camera.project([10.0, 10.0, 10.0]);
        let corner = pick(&scene, &camera, cx, cy, &PickOptions::default());
        assert!(
            corner.iter().all(|c| c.kind != PickKind::Vertex),
            "hidden vertices still picked: {corner:?}"
        );
        assert_eq!(corner[0].kind, PickKind::Edge, "edges now outrank the hidden vertex");

        // Hide every edge too: only faces (and the trailing solid) remain.
        let edge_count = scene.solids()[0].edges.len();
        scene
            .solid_mut("PickCube")
            .unwrap()
            .visibility
            .set_group_visible(EntityKind::Edge, edge_count, false);
        let corner = pick(&scene, &camera, cx, cy, &PickOptions::default());
        assert!(corner.iter().all(|c| c.kind != PickKind::Edge));
        assert!(corner.iter().any(|c| c.kind == PickKind::Face));
    }

    #[test]
    fn hidden_solid_is_not_pickable() {
        let mut scene = cube_scene();
        scene.solid_mut("PickCube").unwrap().visible = false;
        let camera = front_camera();
        let hits = pick(&scene, &camera, 400.0, 300.0, &PickOptions::default());
        assert!(hits.is_empty());
    }
}