hephaestus 0.2.0

Backend-agnostic 2D scene renderer for data visualization.
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
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
//! `PointGeom` — vectorised point glyphs drawn at scaled `(x, y)` positions.
//!
//! Channels consumed (any can be set as Constant or Data; key column is
//! synthesised if no `.keys(…)` supplied):
//!
//! - `"x"` — position along x axis (required; numeric data).
//! - `"y"` — position along y axis (required; numeric data).
//! - `"x_offset"` — absolute **pt** offset added to the resolved x
//!   position (optional). Positive → right.
//! - `"y_offset"` — absolute **pt** offset added to the resolved y
//!   position (optional). Positive → up (math convention).
//! - `"x_band"` — offset in **band fractions** of the x scale's band
//!   width (optional). Positive → right. No effect on continuous scales
//!   (their `band_width` is 0). Use for jitter / dodge on discrete x
//!   axes.
//! - `"y_band"` — same as `"x_band"` for y. Positive → up.
//! - `"fill"` — interior color for fill subpaths (optional).
//! - `"stroke"` — outline color for stroke subpaths (optional).
//! - `"fill_opacity"` — overrides the alpha component of the resolved
//!   fill color (optional; expects a 0..=1 number).
//! - `"stroke_opacity"` — overrides the alpha component of the resolved
//!   stroke color (optional; expects a 0..=1 number).
//! - `"size"` — glyph diameter in pt (optional; defaults to 5pt).
//! - `"size_band"` — additional glyph-diameter contribution, expressed
//!   as a fraction of the discrete-band width at the row's `(x, y)`
//!   position. Composes additively with `"size"`:
//!
//!   ```text
//!   diameter_px = pt_to_px(size_pt) + size_band * band_px
//!   ```
//!
//!   `band_px` is the smallest non-zero band width across x and y at the
//!   row's centre, in panel pixels — single-discrete → that axis's
//!   band, both-discrete → smaller of the two (so the glyph fits the
//!   cell on both axes), both-continuous → 0 (no contribution).
//!   Mirrors `WedgeGeom::radius_band`. Defaults to 0; the existing
//!   5pt `"size"` default is unchanged, so callers wanting pure band
//!   sizing also pass `size = 0`.
//! - `"linewidth"` — stroke width in **pt** (optional; defaults to
//!   `theme.geom.point.stroke_width_pt`, conventionally 1pt). Sets the
//!   width of the marker's outline stroke when `"stroke"` is bound;
//!   the rendered stroke is constant in output pixels regardless of
//!   the marker's `"size"`.
//! - `"shape"` — registered shape name (optional; defaults to "circle").
//!   Glyph-backed shapes (constructed via [`crate::shape::Shape::glyph`]
//!   or the [`crate::text::glyph_marker`] convenience) are valid here and
//!   render via `scene.draw_glyphs`. For glyph shapes, `"stroke"` has no
//!   effect — the glyph is filled with the resolved `"fill"` colour.
//!   Glyph height is normalised to the same bounding-box convention as
//!   the built-in vector shapes (`~1.6` units across), so a vector
//!   `"circle"` and a glyph `"letter-a"` at the same `"size"` render at
//!   comparable extent. Visible glyph ink still occupies only ~70% of
//!   its em-box (cap-height), so letters look slightly smaller than a
//!   solid disc of the same `"size"` — bump `"size"` if you need exact
//!   visual parity.
//! - `"angle"` — rotation in **radians** around the placement point,
//!   mathematical CCW (positive rotates the glyph counter-clockwise in
//!   the rendered image). Default `0.0` (no rotation). Applies after
//!   scale + pivot resolution and before the pt-space offsets — the
//!   offsets translate the rotated glyph by absolute pt, they aren't
//!   rotated themselves.
//!
//! Channels are stored in a `HashMap<String, Channel>` keyed by channel
//! name. There is a single binding method,
//! [`GeomBuilder::set`](super::GeomBuilder::set) on the builder +
//! [`PointGeom::set`] at runtime; the data-vs-constant
//! distinction is inferred from the value's type via `Into<Channel>`. The
//! same call site works for first-binding and update.
//!
//! Fill and stroke are independent: a shape's fill subpaths are filled
//! with the resolved fill color (or skipped if `"fill"` is unset); its
//! stroke subpaths are stroked with the resolved stroke color (or
//! skipped if `"stroke"` is unset). Both can be set, only one, or
//! neither.

use crate::brush::Brush;
use crate::geometry::Affine;
use crate::path::FillRule;
#[cfg(test)]
use crate::plot::value::Value;
use crate::scene::{Glyph, GlyphRun, SceneBuilder};
use crate::shape::{Shape, ShapeKind, ShapeStyle};
use crate::stroke::Stroke;
#[cfg(test)]
use std::sync::Arc;

use super::resolve::{
    band_width_at, override_alpha, pt_to_px, resolve_angle_channel, resolve_color_channel_or_theme,
    resolve_number_channel, resolve_number_channel_or, resolve_pick_id, resolve_position,
    resolve_str_channel_or, smallest_nonzero,
};
use super::state::{finalize_state, require_x_and_siblings, GeomState, KeysStrategy};
use super::{BuildableGeom, Channel, ExpectedOutput, Geom, GeomBuilder, GeomContext};

// ─── Defaults ────────────────────────────────────────────────────────────────

// Style defaults — size, shape, stroke width — come from
// `theme.geom.point` at draw time. The geom no longer injects
// `Channel::Constant(...)` for missing channels in `build_from`; the
// draw loop calls the `resolve_*_or` helpers with the theme value as
// the fallback.

/// Reference local-bbox height for built-in vector shapes (circle:
/// r=0.8 → bbox 1.6×1.6). The glyph branch scales font-size by
/// `GLYPH_BBOX_REFERENCE / em_bbox.height()` so a glyph shape at a given
/// `"size"` renders with a bounding-box height comparable to a vector
/// shape at the same `"size"`. (Visible glyph ink remains ~70% of its
/// em-box due to font cap-height; that residual mismatch is documented
/// but not corrected — would require per-font metric reads.)
pub(crate) const GLYPH_BBOX_REFERENCE: f64 = 1.6;

/// Catalog of channels this geom recognises, with their expected scale
/// output type. New channels: add an entry here + handle the resolved
/// value in `draw`. The `filter_declared` helper turns this into the
/// per-instance `ChannelDecl` list reported to `view.validate()`.
const CHANNELS: &[(&str, ExpectedOutput)] = &[
    ("x", ExpectedOutput::Numbers),
    ("y", ExpectedOutput::Numbers),
    ("x_offset", ExpectedOutput::Numbers),
    ("y_offset", ExpectedOutput::Numbers),
    ("x_band", ExpectedOutput::Numbers),
    ("y_band", ExpectedOutput::Numbers),
    ("fill", ExpectedOutput::Colors),
    ("stroke", ExpectedOutput::Colors),
    ("fill_opacity", ExpectedOutput::Numbers),
    ("stroke_opacity", ExpectedOutput::Numbers),
    ("size", ExpectedOutput::Numbers),
    ("size_band", ExpectedOutput::Numbers),
    ("linewidth", ExpectedOutput::Numbers),
    ("shape", ExpectedOutput::Strings),
    ("angle", ExpectedOutput::Numbers),
    ("pick_id", ExpectedOutput::Numbers),
];

// ─── PointGeom ───────────────────────────────────────────────────────────────

/// A vectorised point geom. Non-generic — all channel data flows through
/// the `DataColumn` enum.
pub struct PointGeom {
    pub(crate) state: GeomState,
}

crate::impl_geom_inherents!(PointGeom);

// ─── BuildableGeom impl ──────────────────────────────────────────────────────

impl BuildableGeom for PointGeom {
    fn build_from(builder: GeomBuilder<Self>) -> Self {
        let (keys_opt, channels) = builder.into_parts();
        let n = require_x_and_siblings(&channels, &["y"], "PointGeom");
        let state = finalize_state(
            keys_opt,
            channels,
            n,
            KeysStrategy::PerRow,
            CHANNELS,
            "PointGeom",
        );
        PointGeom { state }
    }
}

// ─── Geom impl ───────────────────────────────────────────────────────────────

impl Geom for PointGeom {
    fn state(&self) -> &GeomState {
        &self.state
    }

    fn state_mut(&mut self) -> &mut GeomState {
        &mut self.state
    }

    fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
        self
    }

    fn kind(&self) -> Option<&'static str> {
        Some("point")
    }

    fn draw(&self, scene: &mut dyn SceneBuilder, ctx: &GeomContext<'_>) {
        let panel = ctx.panel_rect;
        let panel_w = panel.x1 - panel.x0;
        let panel_h = panel.y1 - panel.y0;
        if panel_w <= 0.0 || panel_h <= 0.0 {
            return;
        }

        let n = self.len();
        if n == 0 {
            return;
        }

        // Resolve scales by channel name (None == identity / position-frac).
        // `Channel::RawData` columns bypass the scale; we shadow the bound
        // scale to None after the column pattern-match below so position
        // resolution + band_width_at uniformly skip it.
        let x_scale_bound = ctx.scale_for("x");
        let y_scale_bound = ctx.scale_for("y");
        let fill_scale = ctx.scale_for("fill");
        let stroke_scale = ctx.scale_for("stroke");
        let fill_opacity_scale = ctx.scale_for("fill_opacity");
        let stroke_opacity_scale = ctx.scale_for("stroke_opacity");
        let x_offset_scale = ctx.scale_for("x_offset");
        let y_offset_scale = ctx.scale_for("y_offset");
        let x_band_scale = ctx.scale_for("x_band");
        let y_band_scale = ctx.scale_for("y_band");
        let size_scale = ctx.scale_for("size");
        let size_band_scale = ctx.scale_for("size_band");
        let shape_scale = ctx.scale_for("shape");
        let linewidth_scale = ctx.scale_for("linewidth");
        let angle_scale = ctx.scale_for("angle");
        let pick_id_scale = ctx.scale_for("pick_id");

        // x/y are always data columns (build_from guaranteed). RawData
        // columns supply pre-computed panel fractions and disable the
        // bound scale for that axis.
        let channels = &self.state.channels;
        let (x_col, x_scale) = match channels.get("x") {
            Some(Channel::Data(c)) => (c, x_scale_bound),
            Some(Channel::RawData(c)) => (c, None),
            _ => return,
        };
        let (y_col, y_scale) = match channels.get("y") {
            Some(Channel::Data(c)) => (c, y_scale_bound),
            Some(Channel::RawData(c)) => (c, None),
            _ => return,
        };

        let fill_ch = channels.get("fill");
        let stroke_ch = channels.get("stroke");
        let fill_opacity_ch = channels.get("fill_opacity");
        let stroke_opacity_ch = channels.get("stroke_opacity");
        let x_offset_ch = channels.get("x_offset");
        let y_offset_ch = channels.get("y_offset");
        let x_band_ch = channels.get("x_band");
        let y_band_ch = channels.get("y_band");
        let size_ch = channels.get("size");
        let size_band_ch = channels.get("size_band");
        let linewidth_ch = channels.get("linewidth");
        let shape_ch = channels.get("shape");
        let angle_ch = channels.get("angle");
        let pick_id_ch = channels.get("pick_id");

        for i in 0..n {
            // ── Position (per row) ──
            let x_raw = x_col.get(i);
            let y_raw = y_col.get(i);
            let x_band = resolve_number_channel_or(x_band_ch, x_band_scale, i, 0.0);
            let y_band = resolve_number_channel_or(y_band_ch, y_band_scale, i, 0.0);
            let px_frac = resolve_position(x_raw.clone(), x_scale, x_band);
            let py_frac = resolve_position(y_raw.clone(), y_scale, y_band);
            if !px_frac.is_finite() || !py_frac.is_finite() {
                continue;
            }
            let (px0, py0) = ctx
                .projection
                .project_to_panel_px(panel, &[px_frac, py_frac]);
            let mut px = px0;
            let mut py = py0;

            if let Some(off) = resolve_number_channel(x_offset_ch, x_offset_scale, i) {
                px += pt_to_px(off, ctx.dpi);
            }
            if let Some(off) = resolve_number_channel(y_offset_ch, y_offset_scale, i) {
                py -= pt_to_px(off, ctx.dpi);
            }

            // ── Channel resolves ──
            let fill_color = override_alpha(
                resolve_color_channel_or_theme(
                    fill_ch,
                    fill_scale,
                    i,
                    ctx.theme.geom.point.fill.as_ref(),
                    &ctx.theme.palette,
                ),
                resolve_number_channel(fill_opacity_ch, fill_opacity_scale, i),
            );
            let stroke_color = override_alpha(
                resolve_color_channel_or_theme(
                    stroke_ch,
                    stroke_scale,
                    i,
                    ctx.theme.geom.point.stroke.as_ref(),
                    &ctx.theme.palette,
                ),
                resolve_number_channel(stroke_opacity_ch, stroke_opacity_scale, i),
            );
            let size_pt =
                resolve_number_channel_or(size_ch, size_scale, i, ctx.theme.geom.point.size_pt);
            let shape_name =
                resolve_str_channel_or(shape_ch, shape_scale, i, &ctx.theme.geom.point.shape);

            // Glyph diameter: pt contribution + band contribution. band_px
            // is the smallest non-zero band width across x and y at the
            // row's centre (matches WedgeGeom's radius_band semantics).
            let size_band = resolve_number_channel_or(size_band_ch, size_band_scale, i, 0.0);
            let x_band_px = band_width_at(x_scale, &x_raw) * panel_w;
            let y_band_px = band_width_at(y_scale, &y_raw) * panel_h;
            let band_px = smallest_nonzero(x_band_px, y_band_px);
            let size_px = pt_to_px(size_pt, ctx.dpi) + size_band * band_px;
            if !size_px.is_finite() || size_px <= 0.0 {
                continue;
            }

            // ── Shape lookup ──
            let shape: &Shape = match ctx.shapes.get(&shape_name) {
                Some(s) => s,
                None => continue,
            };

            // Rotation: math CCW from the user (positive = visible
            // counter-clockwise). Kurbo's `Affine::rotate` uses
            // mathematical convention where positive theta rotates +x
            // toward +y — in screen space (y-down) this looks clockwise.
            // Negate to get user-visible CCW. Rotation is around the
            // glyph's own centre, which is the path origin pre-translate.
            let angle = resolve_angle_channel(angle_ch, angle_scale, i);
            let xform = if angle == 0.0 {
                Affine::translate((px, py)) * Affine::scale(size_px)
            } else {
                Affine::translate((px, py)) * Affine::rotate(-angle) * Affine::scale(size_px)
            };

            let pick = resolve_pick_id(pick_id_ch, pick_id_scale, i);
            // Stroke width: per-row `"linewidth"` channel takes
            // precedence, otherwise theme default. Divided by
            // `size_px` to invert the `Affine::scale(size_px)` on
            // the path — the rendered stroke is then a constant
            // width in output pixels regardless of marker size.
            let stroke_width_pt = resolve_number_channel_or(
                linewidth_ch,
                linewidth_scale,
                i,
                ctx.theme.geom.point.stroke_width_pt,
            );
            let stroke_width_local = pt_to_px(stroke_width_pt, ctx.dpi) / size_px;
            match shape.kind() {
                ShapeKind::Paths { paths, style } => {
                    for sub in paths {
                        match style {
                            ShapeStyle::Fill => {
                                if let Some(fc) = fill_color {
                                    scene.fill(
                                        FillRule::NonZero,
                                        xform,
                                        &Brush::Solid(fc),
                                        None,
                                        sub,
                                        pick,
                                    );
                                }
                                if let Some(sc) = stroke_color {
                                    let st = Stroke::new(stroke_width_local);
                                    scene.stroke(&st, xform, &Brush::Solid(sc), None, sub, pick);
                                }
                            }
                            ShapeStyle::Stroke => {
                                if let Some(sc) = stroke_color {
                                    let st = Stroke::new(stroke_width_local);
                                    scene.stroke(&st, xform, &Brush::Solid(sc), None, sub, pick);
                                }
                            }
                        }
                    }
                }
                ShapeKind::Glyph {
                    font,
                    glyph_id,
                    em_bbox,
                    em_origin,
                } => {
                    let Some(fc) = fill_color else { continue };
                    // Normalise glyph height to the vector-shape bbox
                    // convention so vector and glyph markers at the same
                    // "size" render at comparable visual extent. The
                    // effective em-to-pixel scale is baked into
                    // `font_size` rather than the transform so vello
                    // picks the matching bitmap strike for colour
                    // emoji fonts; a `font_size: 1.0` with a transform
                    // scale would pick the smallest strike and upscale
                    // it, producing fuzzy rendering at chart sizes.
                    let h = em_bbox.height();
                    if h <= 0.0 || !h.is_finite() {
                        continue;
                    }
                    let bbox_norm = GLYPH_BBOX_REFERENCE / h;
                    let effective_font_size_px = size_px * bbox_norm;
                    let centring_px =
                        (em_origin.to_vec2() - em_bbox.center().to_vec2()) * effective_font_size_px;
                    let glyphs = [Glyph {
                        id: glyph_id,
                        x: 0.0,
                        y: 0.0,
                    }];
                    let brush = Brush::Solid(fc);
                    let run = GlyphRun {
                        font,
                        font_size: effective_font_size_px as f32,
                        transform: Affine::translate((px + centring_px.x, py + centring_px.y)),
                        glyph_transform: None,
                        brush: &brush,
                        brush_alpha: 1.0,
                        hint: false,
                        glyphs: &glyphs,
                        style: None,
                    };
                    scene.draw_glyphs(&run, pick);
                }
            }
        }
    }
}

// ─── Tests ───────────────────────────────────────────────────────────────────

#[cfg(test)]
mod tests {
    use super::*;
    use crate::color::Color;
    use crate::geometry::Rect;
    use crate::plot::geom::{DirectScaleResolver, Keys, Raw};
    use crate::plot::value::Date;
    use crate::scene::recording::{Op, RecordingScene};

    fn registry() -> crate::shape::ShapeRegistry {
        crate::shape::ShapeRegistry::with_builtins()
    }

    fn ctx<'a>(
        panel: Rect,
        shapes: &'a crate::shape::ShapeRegistry,
        scales: &'a DirectScaleResolver<'a>,
    ) -> GeomContext<'a> {
        GeomContext::new(panel, 96.0, shapes, scales)
    }

    // ── build() validation ──

    #[test]
    fn builder_synthesises_positional_keys() {
        let g = PointGeom::builder()
            .set("x", vec![0.0_f64, 1.0, 2.0])
            .set("y", vec![0.0_f64, 1.0, 4.0])
            .build();
        assert_eq!(g.len(), 3);
        assert!(!g.has_explicit_keys());
        match &g.state.keys {
            Keys::Positional(n) => assert_eq!(*n, 3),
            Keys::Explicit(_) => panic!("expected positional keys"),
        }
    }

    #[test]
    fn builder_uses_explicit_keys() {
        let g = PointGeom::builder()
            .keys(vec!["a", "b", "c"])
            .set("x", vec![0.0_f64, 1.0, 2.0])
            .set("y", vec![0.0_f64, 1.0, 2.0])
            .build();
        assert!(g.has_explicit_keys());
        assert_eq!(g.len(), 3);
    }

    #[test]
    #[should_panic(expected = "missing required channel")]
    fn builder_missing_x_panics() {
        PointGeom::builder()
            .set("y", vec![1.0_f64, 2.0, 3.0])
            .build();
    }

    #[test]
    #[should_panic(expected = "missing required channel")]
    fn builder_missing_y_panics() {
        PointGeom::builder()
            .set("x", vec![1.0_f64, 2.0, 3.0])
            .build();
    }

    #[test]
    #[should_panic(expected = "unknown channel \"colour\"")]
    fn builder_unknown_channel_panics() {
        PointGeom::builder()
            .set("x", vec![1.0_f64, 2.0])
            .set("y", vec![1.0_f64, 2.0])
            .set("colour", vec!["a", "b"])
            .build();
    }

    #[test]
    #[should_panic(expected = "unknown channels \"alpha\", \"width\"")]
    fn builder_lists_every_unknown_channel_sorted() {
        PointGeom::builder()
            .set("x", vec![1.0_f64, 2.0])
            .set("y", vec![1.0_f64, 2.0])
            .set("width", 2.0)
            .set("alpha", 0.5)
            .build();
    }

    #[test]
    #[should_panic(expected = "must be data, not constant")]
    fn builder_x_constant_panics() {
        PointGeom::builder()
            .set("x", 5.0)
            .set("y", vec![1.0_f64])
            .build();
    }

    #[test]
    fn builder_x_string_column_ok() {
        // String x columns are accepted at build time; their resolution
        // happens through the bound (typically Discrete/Ordinal) scale at
        // draw time. Without a scale they'd render as NaN positions and
        // skip — but build() itself doesn't reject them.
        let g = PointGeom::builder()
            .set("x", vec!["a", "b", "c"])
            .set("y", vec![1.0_f64, 2.0, 3.0])
            .build();
        assert_eq!(g.len(), 3);
    }

    #[test]
    fn builder_temporal_x_ok() {
        let g = PointGeom::builder()
            .set(
                "x",
                vec![Date::from_ymd(2024, 1, 1), Date::from_ymd(2024, 1, 2)],
            )
            .set("y", vec![0.0_f64, 1.0])
            .build();
        assert_eq!(g.len(), 2);
    }

    #[test]
    #[should_panic(expected = "does not match")]
    fn builder_mismatched_lengths_panic() {
        PointGeom::builder()
            .set("x", vec![0.0_f64, 1.0, 2.0])
            .set("y", vec![0.0_f64, 1.0])
            .build();
    }

    #[test]
    fn builder_leaves_size_and_shape_unset_for_theme_fallback() {
        // Defaults for size + shape now come from `theme.geom.point`
        // at draw time. `build_from` no longer injects
        // `Channel::Constant(...)` for missing channels — they stay
        // absent, and the resolve helpers fall back to the theme.
        let g = PointGeom::builder()
            .set("x", vec![0.0_f64])
            .set("y", vec![0.0_f64])
            .build();
        assert!(
            !g.state.channels.contains_key("size"),
            "expected no size channel (theme provides default at draw)"
        );
        assert!(
            !g.state.channels.contains_key("shape"),
            "expected no shape channel (theme provides default at draw)"
        );
    }

    // ── Draw output ──

    fn no_scales<'a>() -> DirectScaleResolver<'a> {
        DirectScaleResolver::new()
    }

    fn red_solid() -> Color {
        Color::new([1.0, 0.0, 0.0, 1.0])
    }

    #[test]
    fn draw_emits_one_op_per_row() {
        let mut g = PointGeom::builder()
            .set("x", vec![0.0_f64, 0.5, 1.0])
            .set("y", vec![0.0_f64, 1.0, 0.0])
            .set("fill", red_solid())
            .build();
        g.rebuild_diff_against_previous();
        let shapes = registry();
        let scales = no_scales();
        let c = ctx(Rect::new(0.0, 0.0, 100.0, 100.0), &shapes, &scales);
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &c);
        let fills = scene
            .ops
            .iter()
            .filter(|op| matches!(op, Op::Fill { .. }))
            .count();
        assert_eq!(fills, 3);
    }

    #[test]
    fn shape_channel_maps_through_its_scale() {
        // Domain values reach the registry only after the bound
        // `"shape"` scale maps them to registered names.
        let shape_scale = crate::plot::scale::ordinal(["a", "b"])
            .range_strings([Arc::from("circle"), Arc::from("square")]);
        let mut g = PointGeom::builder()
            .set("x", vec![0.0_f64, 1.0])
            .set("y", vec![0.0_f64, 1.0])
            .set("fill", red_solid())
            .set("shape", vec!["a", "b"])
            .build();
        g.rebuild_diff_against_previous();
        let shapes = registry();
        let scales = DirectScaleResolver::new().with("shape", &shape_scale);
        let c = ctx(Rect::new(0.0, 0.0, 100.0, 100.0), &shapes, &scales);
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &c);
        let fills = scene
            .ops
            .iter()
            .filter(|op| matches!(op, Op::Fill { .. }))
            .count();
        assert_eq!(fills, 2, "unmapped shape names drop the row entirely");
    }

    fn synthetic_glyph_shape() -> crate::shape::Shape {
        let blob = crate::brush::Blob::new(std::sync::Arc::new(Vec::<u8>::new()));
        let font = crate::scene::Font::new(blob, 0);
        let em_bbox = crate::geometry::Rect::new(0.0, 0.0, 0.6, 1.0);
        let em_origin = crate::geometry::Point::new(0.05, 0.8);
        let anchor = crate::geometry::Point::new(-0.5, 0.0);
        crate::shape::Shape::glyph(font, 1, em_bbox, em_origin, anchor)
    }

    #[test]
    fn glyph_shape_emits_draw_glyphs() {
        let mut shapes = registry();
        shapes.insert("synthetic-glyph", synthetic_glyph_shape());
        let mut g = PointGeom::builder()
            .set("x", vec![0.0_f64, 0.5, 1.0])
            .set("y", vec![0.0_f64, 1.0, 0.0])
            .set("fill", red_solid())
            .set("shape", "synthetic-glyph")
            .set("size", 14.0_f64)
            .build();
        g.rebuild_diff_against_previous();
        let scales = no_scales();
        let c = ctx(Rect::new(0.0, 0.0, 100.0, 100.0), &shapes, &scales);
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &c);

        let glyph_ops: Vec<_> = scene
            .ops
            .iter()
            .filter(|op| matches!(op, Op::DrawGlyphs(_)))
            .collect();
        assert_eq!(glyph_ops.len(), 3, "one DrawGlyphs op per row");

        // Fills/strokes from glyph rows: none.
        let fills = scene
            .ops
            .iter()
            .filter(|op| matches!(op, Op::Fill { .. }))
            .count();
        let strokes = scene
            .ops
            .iter()
            .filter(|op| matches!(op, Op::Stroke { .. }))
            .count();
        assert_eq!(fills, 0);
        assert_eq!(strokes, 0);
    }

    #[test]
    fn glyph_shape_with_no_fill_emits_nothing() {
        // Stroke channel is ignored for glyph shapes; without a fill,
        // nothing should be emitted.
        let mut shapes = registry();
        shapes.insert("synthetic-glyph", synthetic_glyph_shape());
        let mut g = PointGeom::builder()
            .set("x", vec![0.0_f64])
            .set("y", vec![0.0_f64])
            .set("stroke", red_solid())
            .set("shape", "synthetic-glyph")
            .build();
        g.rebuild_diff_against_previous();
        let scales = no_scales();
        let c = ctx(Rect::new(0.0, 0.0, 100.0, 100.0), &shapes, &scales);
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &c);
        assert!(
            scene.ops.is_empty(),
            "glyph shape with stroke-only should emit nothing, got {:?}",
            scene.ops
        );
    }

    #[test]
    fn mixed_path_and_glyph_shapes_both_render() {
        // Per-row mix: half the rows use the vector "circle", half use a
        // glyph shape. Recording should contain both Fill and DrawGlyphs.
        let mut shapes = registry();
        shapes.insert("synthetic-glyph", synthetic_glyph_shape());
        let mut g = PointGeom::builder()
            .set("x", vec![0.0_f64, 0.25, 0.5, 0.75])
            .set("y", vec![0.5_f64, 0.5, 0.5, 0.5])
            .set("fill", red_solid())
            .set(
                "shape",
                vec!["circle", "circle", "synthetic-glyph", "synthetic-glyph"],
            )
            .build();
        g.rebuild_diff_against_previous();
        let scales = no_scales();
        let c = ctx(Rect::new(0.0, 0.0, 100.0, 100.0), &shapes, &scales);
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &c);

        let fills = scene
            .ops
            .iter()
            .filter(|op| matches!(op, Op::Fill { .. }))
            .count();
        let glyphs = scene
            .ops
            .iter()
            .filter(|op| matches!(op, Op::DrawGlyphs(_)))
            .count();
        assert_eq!(fills, 2, "two vector-shape fills");
        assert_eq!(glyphs, 2, "two glyph draws");
    }

    #[test]
    fn draw_skips_non_finite_rows() {
        let mut g = PointGeom::builder()
            .set("x", vec![0.0_f64, f64::NAN, 1.0])
            .set("y", vec![0.0_f64, 1.0, 0.0])
            .set("fill", red_solid())
            .build();
        g.rebuild_diff_against_previous();
        let shapes = registry();
        let scales = no_scales();
        let c = ctx(Rect::new(0.0, 0.0, 100.0, 100.0), &shapes, &scales);
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &c);
        let fills = scene
            .ops
            .iter()
            .filter(|op| matches!(op, Op::Fill { .. }))
            .count();
        assert_eq!(fills, 2);
    }

    #[test]
    fn declared_channels_alphabetical() {
        let g = PointGeom::builder()
            .set("x", vec![0.0_f64])
            .set("y", vec![0.0_f64])
            .set("fill", red_solid())
            .build();
        let names: Vec<&str> = g.declared_channels().iter().map(|d| d.name).collect();
        let mut sorted = names.clone();
        sorted.sort();
        assert_eq!(names, sorted);
    }

    // ── More build() validation ──

    #[test]
    #[should_panic(expected = "does not match")]
    fn builder_y_length_mismatch_panics() {
        PointGeom::builder()
            .set("x", vec![1.0_f64, 2.0, 3.0])
            .set("y", vec![1.0_f64, 2.0])
            .build();
    }

    #[test]
    #[should_panic(expected = "does not match row count")]
    fn builder_color_length_mismatch_panics() {
        PointGeom::builder()
            .set("x", vec![1.0_f64, 2.0, 3.0])
            .set("y", vec![1.0_f64, 2.0, 3.0])
            .set("fill", vec!["a", "b"])
            .build();
    }

    #[test]
    #[should_panic(expected = "does not match row count")]
    fn builder_keys_length_mismatch_panics() {
        PointGeom::builder()
            .keys(vec!["a", "b"])
            .set("x", vec![1.0_f64, 2.0, 3.0])
            .set("y", vec![1.0_f64, 2.0, 3.0])
            .build();
    }

    // ── declared_channels ──

    #[test]
    fn declared_channels_sorted_and_classified() {
        use std::collections::HashMap;
        // `declared_channels` now reflects user-bound channels only —
        // theme-defaulted channels (size, shape when unbound) are
        // absent because no `Channel::Constant` is injected at build.
        let g = PointGeom::builder()
            .set("x", vec![0.0_f64, 1.0])
            .set("y", vec![0.0_f64, 1.0])
            .set("fill", Color::new([1.0, 0.0, 0.0, 1.0]))
            .set("shape", "circle")
            .set("size", 5.0)
            .build();
        let decls = g.declared_channels();
        let names: Vec<_> = decls.iter().map(|d| d.name).collect();
        assert_eq!(names, vec!["fill", "shape", "size", "x", "y"]);

        let by_name: HashMap<_, _> = decls.iter().map(|d| (d.name, d)).collect();
        assert!(by_name["x"].data_bound);
        assert!(by_name["y"].data_bound);
        assert!(!by_name["fill"].data_bound);
        assert_eq!(by_name["x"].expected_output, ExpectedOutput::Numbers);
        assert_eq!(by_name["fill"].expected_output, ExpectedOutput::Colors);
        assert_eq!(by_name["shape"].expected_output, ExpectedOutput::Strings);
    }

    #[test]
    fn declared_opacity_channels_are_numeric() {
        use std::collections::HashMap;
        let g = PointGeom::builder()
            .set("x", vec![0.0_f64, 1.0])
            .set("y", vec![0.0_f64, 1.0])
            .set("fill_opacity", 0.3)
            .set("stroke_opacity", vec![0.2_f64, 0.8])
            .build();
        let decls = g.declared_channels();
        let by_name: HashMap<_, _> = decls.iter().map(|d| (d.name, d)).collect();
        assert_eq!(
            by_name["fill_opacity"].expected_output,
            ExpectedOutput::Numbers
        );
        assert_eq!(
            by_name["stroke_opacity"].expected_output,
            ExpectedOutput::Numbers
        );
        assert!(!by_name["fill_opacity"].data_bound);
        assert!(by_name["stroke_opacity"].data_bound);
    }

    // ── diff plumbing ──

    #[test]
    fn diff_positional_path_after_mutation() {
        let mut g = PointGeom::builder()
            .set("x", vec![0.0_f64, 1.0, 2.0])
            .set("y", vec![0.0_f64, 1.0, 2.0])
            .build();
        g.rebuild_diff_against_previous();
        assert_eq!(g.state.enter, vec![0, 1, 2]);
        assert!(g.state.update.is_empty());
        assert!(g.state.exit.is_empty());
        g.set("y", vec![10.0_f64, 20.0, 30.0]);
        g.rebuild_diff_against_previous();
        assert!(g.state.enter.is_empty());
        assert_eq!(g.state.update, vec![(0, 0), (1, 1), (2, 2)]);
        assert!(g.state.exit.is_empty());
    }

    #[test]
    fn update_closure_atomic_multi_channel() {
        let mut g = PointGeom::builder()
            .set("x", vec![0.0_f64, 1.0, 2.0])
            .set("y", vec![10.0_f64, 20.0, 30.0])
            .build();
        g.update(|b| {
            b.set("x", vec![100.0_f64, 200.0, 300.0, 400.0]);
            b.set("y", vec![1.0_f64, 2.0, 3.0, 4.0]);
        });
        assert_eq!(g.len(), 4);
        g.rebuild_diff_against_previous();
        assert_eq!(g.state.update, vec![(0, 0), (1, 1), (2, 2)]);
        assert_eq!(g.state.enter, vec![3]);
        assert!(g.state.exit.is_empty());
    }

    #[test]
    fn update_closure_can_change_keys() {
        let mut g = PointGeom::builder()
            .keys(vec!["a", "b", "c"])
            .set("x", vec![0.0_f64, 1.0, 2.0])
            .set("y", vec![0.0_f64, 1.0, 2.0])
            .build();
        g.rebuild_diff_against_previous();

        g.update(|b| {
            b.keys(vec!["c", "a", "d"]);
            b.set("x", vec![20.0_f64, 0.0, 99.0]);
            b.set("y", vec![20.0_f64, 0.0, 99.0]);
        });
        g.rebuild_diff_against_previous();
        assert_eq!(g.state.update, vec![(2, 0), (0, 1)]);
        assert_eq!(g.state.enter, vec![2]);
        assert_eq!(g.state.exit.len(), 1);
        assert_eq!(g.state.exit[0].as_str(), Some("b"));
    }

    #[test]
    #[should_panic(expected = "must be data, not constant")]
    fn update_closure_validation_panics_on_invalid_state() {
        let mut g = PointGeom::builder()
            .set("x", vec![0.0_f64, 1.0])
            .set("y", vec![0.0_f64, 1.0])
            .build();
        g.update(|b| {
            b.set("x", 5.0);
        });
    }

    #[test]
    fn diff_columns_path_with_reordered_keys() {
        let mut g = PointGeom::builder()
            .keys(vec!["a", "b", "c"])
            .set("x", vec![0.0_f64, 1.0, 2.0])
            .set("y", vec![0.0_f64, 1.0, 2.0])
            .build();
        g.rebuild_diff_against_previous();
        assert_eq!(g.state.enter, vec![0, 1, 2]);

        g.state.keys = Keys::Explicit(vec!["c", "a", "b"].into());
        g.state.dirty = true;
        g.rebuild_diff_against_previous();
        assert!(g.state.enter.is_empty());
        assert!(g.state.exit.is_empty());
        assert_eq!(g.state.update, vec![(2, 0), (0, 1), (1, 2)]);
    }

    // ── draw() ──

    fn count_ops(ops: &[Op]) -> (usize, usize) {
        let mut fills = 0;
        let mut strokes = 0;
        for op in ops {
            match op {
                Op::Fill { .. } => fills += 1,
                Op::Stroke { .. } => strokes += 1,
                _ => {}
            }
        }
        (fills, strokes)
    }

    #[test]
    fn draw_fills_circle_when_fill_bound() {
        let g = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let (fills, strokes) = count_ops(&scene.ops);
        assert!(fills >= 1);
        assert_eq!(strokes, 0);
    }

    #[test]
    fn draw_strokes_circle_when_stroke_bound() {
        let g = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("stroke", Color::new([0.0, 0.0, 0.0, 1.0]))
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let (fills, strokes) = count_ops(&scene.ops);
        assert_eq!(fills, 0);
        assert!(strokes >= 1);
    }

    #[test]
    fn draw_both_fill_and_stroke() {
        let g = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .set("stroke", Color::new([0.0, 0.0, 0.0, 1.0]))
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let (fills, strokes) = count_ops(&scene.ops);
        assert!(fills >= 1);
        assert!(strokes >= 1);
    }

    #[test]
    fn draw_fill_opacity_overrides_alpha() {
        let g = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .set("fill_opacity", 0.25)
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let alphas: Vec<f32> = scene
            .ops
            .iter()
            .filter_map(|op| match op {
                Op::Fill {
                    brush: crate::brush::Brush::Solid(c),
                    ..
                } => Some(c.components[3]),
                _ => None,
            })
            .collect();
        assert!(!alphas.is_empty());
        for a in &alphas {
            assert!((*a as f64 - 0.25).abs() < 1e-6);
        }
    }

    #[test]
    fn draw_stroke_opacity_overrides_alpha() {
        let g = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("stroke", Color::new([0.0, 0.0, 0.0, 1.0]))
            .set("stroke_opacity", 0.5)
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let alphas: Vec<f32> = scene
            .ops
            .iter()
            .filter_map(|op| match op {
                Op::Stroke {
                    brush: crate::brush::Brush::Solid(c),
                    ..
                } => Some(c.components[3]),
                _ => None,
            })
            .collect();
        assert!(!alphas.is_empty());
        for a in &alphas {
            assert!((*a as f64 - 0.5).abs() < 1e-6);
        }
    }

    #[test]
    fn draw_opacity_unset_preserves_color_alpha() {
        let g = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("fill", Color::new([1.0, 0.0, 0.0, 0.7]))
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        for op in &scene.ops {
            if let Op::Fill {
                brush: crate::brush::Brush::Solid(c),
                ..
            } = op
            {
                assert!((c.components[3] as f64 - 0.7).abs() < 1e-6);
            }
        }
    }

    #[test]
    fn draw_per_row_opacity_data_column() {
        let g = PointGeom::builder()
            .set("x", vec![0.25_f64, 0.75])
            .set("y", vec![0.5_f64, 0.5])
            .set("fill", Color::new([0.0, 0.0, 1.0, 1.0]))
            .set("fill_opacity", vec![0.2_f64, 0.8])
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let alphas: Vec<f32> = scene
            .ops
            .iter()
            .filter_map(|op| match op {
                Op::Fill {
                    brush: crate::brush::Brush::Solid(c),
                    ..
                } => Some(c.components[3]),
                _ => None,
            })
            .collect();
        assert_eq!(alphas.len(), 2);
        assert!((alphas[0] as f64 - 0.2).abs() < 1e-6);
        assert!((alphas[1] as f64 - 0.8).abs() < 1e-6);
    }

    fn first_fill_translation(scene: &RecordingScene) -> Option<(f64, f64)> {
        for op in &scene.ops {
            if let Op::Fill { transform, .. } = op {
                let v = transform.translation();
                return Some((v.x, v.y));
            }
        }
        None
    }

    #[test]
    fn draw_x_offset_shifts_right() {
        let g = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .set("x_offset", 9.0)
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let (px, py) = first_fill_translation(&scene).expect("fill op");
        assert!((px - 62.0).abs() < 1e-6, "px = {px}");
        assert!((py - 50.0).abs() < 1e-6, "py = {py}");
    }

    #[test]
    fn draw_y_offset_positive_is_up() {
        let g = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .set("y_offset", 9.0)
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let (px, py) = first_fill_translation(&scene).expect("fill op");
        assert!((px - 50.0).abs() < 1e-6);
        assert!((py - 38.0).abs() < 1e-6, "py = {py}");
    }

    #[test]
    fn draw_x_band_offset_on_discrete_scale() {
        use crate::plot::scale;
        let x_scale = scale::discrete(
            ["a", "b", "c", "d"]
                .into_iter()
                .map(|s| crate::plot::value::Value::String(Arc::from(s))),
        );
        let resolver = DirectScaleResolver::new().with("x", &x_scale);
        let g = PointGeom::builder()
            .set("x", vec!["b"])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .set("x_band", 0.5)
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let (px, _py) = first_fill_translation(&scene).expect("fill op");
        assert!((px - 50.0).abs() < 1e-6, "px = {px}");
    }

    #[test]
    fn draw_on_reversed_binned_scale_mirrors_the_mark() {
        use crate::plot::scale;
        use crate::scales::Direction;
        let x_scale = scale::binned(0.0..=30.0, vec![0.0, 10.0, 20.0, 30.0])
            .with_direction(Direction::Reversed);
        let resolver = DirectScaleResolver::new().with("x", &x_scale);
        let g = PointGeom::builder()
            .set("x", vec![5.0_f64])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        // The first bin's centre sits a sixth of the way in, measured
        // from the far end.
        let (px, _py) = first_fill_translation(&scene).expect("fill op");
        assert!((px - 100.0 / 6.0 * 5.0).abs() < 1e-6, "px = {px}");
    }

    #[test]
    fn draw_x_band_no_op_on_continuous_scale() {
        use crate::plot::scale;
        let x_scale = scale::continuous(0.0..=10.0);
        let resolver = DirectScaleResolver::new().with("x", &x_scale);
        let g = PointGeom::builder()
            .set("x", vec![5.0_f64])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .set("x_band", 0.5)
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let (px, _py) = first_fill_translation(&scene).expect("fill op");
        assert!((px - 50.0).abs() < 1e-6);
    }

    #[test]
    fn draw_per_row_offset_jitter() {
        let g = PointGeom::builder()
            .set("x", vec![0.5_f64, 0.5, 0.5])
            .set("y", vec![0.5_f64, 0.5, 0.5])
            .set("fill", red_solid())
            .set("x_offset", vec![-9.0_f64, 0.0, 9.0])
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let xs: Vec<f64> = scene
            .ops
            .iter()
            .filter_map(|op| match op {
                Op::Fill { transform, .. } => Some(transform.translation().x),
                _ => None,
            })
            .collect();
        assert_eq!(xs.len(), 3);
        assert!((xs[0] - 38.0).abs() < 1e-6);
        assert!((xs[1] - 50.0).abs() < 1e-6);
        assert!((xs[2] - 62.0).abs() < 1e-6);
    }

    // ── Raw (scale-bypass) channels ──

    #[test]
    fn raw_position_bypasses_scale() {
        // x_scale maps domain [0..100] → [0,1] fraction. A Raw column
        // should bypass that mapping entirely — supplied values are
        // treated as panel fractions directly.
        use crate::plot::scale;
        let x_scale = scale::continuous(0.0..=100.0);
        let resolver = DirectScaleResolver::new().with("x", &x_scale);
        let g = PointGeom::builder()
            .set("x", Raw(vec![0.25_f64, 0.5, 0.75]))
            .set("y", vec![0.5_f64, 0.5, 0.5])
            .set("fill", red_solid())
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let xs: Vec<f64> = scene
            .ops
            .iter()
            .filter_map(|op| match op {
                Op::Fill { transform, .. } => Some(transform.translation().x),
                _ => None,
            })
            .collect();
        // Without bypass these would be domain values run through the
        // scale → 0.25, 0.5, 0.75 → 0.0025, 0.005, 0.0075 of the panel.
        // With bypass they're already fractions → 25, 50, 75 px.
        assert!((xs[0] - 25.0).abs() < 1e-6, "xs[0] = {}", xs[0]);
        assert!((xs[1] - 50.0).abs() < 1e-6, "xs[1] = {}", xs[1]);
        assert!((xs[2] - 75.0).abs() < 1e-6, "xs[2] = {}", xs[2]);
    }

    #[test]
    fn raw_color_bypasses_scale() {
        // Even when a colour scale is bound to "fill", a Raw colour
        // ignores it and uses the literal value.
        use crate::plot::scale;
        use crate::plot::value::Value;
        let fill_scale = scale::ordinal(["a", "b"].iter().map(|s| Value::String(Arc::from(*s))))
            .range_colors([
                Color::new([0.0, 0.0, 1.0, 1.0]),
                Color::new([0.0, 1.0, 0.0, 1.0]),
            ]);
        let resolver = DirectScaleResolver::new().with("fill", &fill_scale);
        let literal = Color::new([1.0, 0.0, 0.0, 1.0]);
        let g = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("fill", Raw(literal))
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let fill_color = scene.ops.iter().find_map(|op| match op {
            Op::Fill {
                brush: crate::brush::Brush::Solid(c),
                ..
            } => Some(*c),
            _ => None,
        });
        let c = fill_color.expect("fill op");
        assert!((c.components[0] - 1.0).abs() < 1e-6);
        assert!((c.components[1] - 0.0).abs() < 1e-6);
        assert!((c.components[2] - 0.0).abs() < 1e-6);
    }

    #[test]
    fn raw_position_outside_panel_clips() {
        // Raw fractions outside [0, 1] are drawn at the corresponding
        // off-panel pixel; the panel clip in draw_panel_into handles
        // the visual cutoff. Here we just verify the geom emits the
        // op with the off-panel translation (no skip / no panic).
        let g = PointGeom::builder()
            .set("x", Raw(vec![-0.5_f64, 1.5]))
            .set("y", vec![0.5_f64, 0.5])
            .set("fill", red_solid())
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let xs: Vec<f64> = scene
            .ops
            .iter()
            .filter_map(|op| match op {
                Op::Fill { transform, .. } => Some(transform.translation().x),
                _ => None,
            })
            .collect();
        assert_eq!(xs.len(), 2);
        assert!((xs[0] - -50.0).abs() < 1e-6);
        assert!((xs[1] - 150.0).abs() < 1e-6);
    }

    #[test]
    fn raw_constant_size_bypasses_size_scale() {
        // size_scale maps domain values to pt; Raw("size", 20.0) skips
        // it and uses 20pt directly. 20pt at 96dpi = ~26.67 px.
        use crate::plot::scale;
        let size_scale = scale::continuous(0.0..=10.0).range_numbers([2.0, 10.0]);
        let resolver = DirectScaleResolver::new().with("size", &size_scale);
        let g = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .set("size", Raw(20.0_f64))
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let scale_factor = scene.ops.iter().find_map(|op| match op {
            Op::Fill { transform, .. } => Some(transform.as_coeffs()[0]),
            _ => None,
        });
        let s = scale_factor.expect("fill");
        // 20pt → 20 * 96/72 = 26.6667 px.
        assert!((s - 20.0 * 96.0 / 72.0).abs() < 1e-6, "size = {s}");
    }

    #[test]
    fn raw_length_validated_at_build() {
        // RawData length mismatch panics just like Data length mismatch.
        let r = std::panic::catch_unwind(|| {
            PointGeom::builder()
                .set("x", vec![0.0_f64, 1.0])
                .set("y", Raw(vec![0.5_f64, 0.5, 0.5])) // wrong length
                .build()
        });
        assert!(r.is_err());
    }

    #[test]
    fn raw_data_x_is_required_position_data() {
        // require_data_column accepts RawData for required position
        // channels — building succeeds.
        let g = PointGeom::builder()
            .set("x", Raw(vec![0.25_f64, 0.75]))
            .set("y", Raw(vec![0.5_f64, 0.5]))
            .build();
        assert_eq!(g.len(), 2);
    }

    #[test]
    #[should_panic(expected = "must be a non-negative integer")]
    fn raw_pick_id_validated_at_build() {
        // RawConstant pick_id is build-validated the same as Constant.
        PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("pick_id", Raw(0x100_0000_i64))
            .build();
    }

    #[test]
    fn raw_pick_id_passes_through_per_row() {
        let g = PointGeom::builder()
            .set("x", vec![0.2_f64, 0.5, 0.8])
            .set("y", vec![0.5_f64, 0.5, 0.5])
            .set("fill", red_solid())
            .set("pick_id", Raw(vec![5_i64, 6, 7]))
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let picks: Vec<u32> = scene
            .ops
            .iter()
            .filter_map(|op| match op {
                Op::Fill {
                    pick_id: crate::pick::PickId::Id(n),
                    ..
                } => Some(*n),
                _ => None,
            })
            .collect();
        assert_eq!(picks, vec![5, 6, 7]);
    }

    #[test]
    fn draw_neither_fill_nor_stroke_emits_nothing() {
        let g = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let (fills, strokes) = count_ops(&scene.ops);
        assert_eq!(fills, 0);
        assert_eq!(strokes, 0);
    }

    #[test]
    fn draw_vectorised_n_rows() {
        let g = PointGeom::builder()
            .set("x", vec![0.1_f64, 0.3, 0.5, 0.7, 0.9])
            .set("y", vec![0.5_f64; 5])
            .set("fill", Color::new([0.0, 0.0, 1.0, 1.0]))
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let (fills, _) = count_ops(&scene.ops);
        assert!(fills >= 5);
    }

    #[test]
    fn draw_routes_x_through_scale() {
        use crate::plot::scale;
        let x_scale = scale::continuous(0.0..=100.0);
        let resolver = DirectScaleResolver::new().with("x", &x_scale);
        let g = PointGeom::builder()
            .set("x", vec![50.0_f64])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let (fills, _) = count_ops(&scene.ops);
        assert!(fills >= 1);
    }

    #[test]
    fn draw_skips_unknown_shape() {
        let g = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .set("shape", "definitely-not-a-shape")
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let (fills, strokes) = count_ops(&scene.ops);
        assert_eq!(fills, 0);
        assert_eq!(strokes, 0);
    }

    fn first_fill_scale(scene: &RecordingScene) -> Option<f64> {
        for op in &scene.ops {
            if let Op::Fill { transform, .. } = op {
                let m = transform.as_coeffs();
                // For Affine::translate(...) * Affine::scale(s), the
                // first coefficient is the x scale factor — equal to s.
                return Some(m[0]);
            }
        }
        None
    }

    #[test]
    fn draw_size_band_on_discrete_x_sizes_to_band() {
        use crate::plot::scale;
        let x_scale = scale::discrete(
            ["a", "b", "c", "d"]
                .into_iter()
                .map(|s| Value::String(Arc::from(s))),
        );
        let resolver = DirectScaleResolver::new().with("x", &x_scale);
        // Panel 100 wide, 4 bands → band = 25 px. size_band = 1.0,
        // size = 0 → diameter = 25 px.
        let g = PointGeom::builder()
            .set("x", vec!["b"])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .set("size", 0.0_f64)
            .set("size_band", 1.0_f64)
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let s = first_fill_scale(&scene).expect("fill");
        assert!((s - 25.0).abs() < 1e-6, "diameter = {s}");
    }

    #[test]
    fn draw_size_band_no_op_on_continuous_axes() {
        // Both axes continuous → band contribution drops out; only the
        // pt size remains.
        let g = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .set("size", 6.0_f64)
            .set("size_band", 1.0_f64)
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let s = first_fill_scale(&scene).expect("fill");
        // 6 pt at 96 dpi = 8 px.
        assert!((s - 8.0).abs() < 1e-6, "diameter = {s}");
    }

    #[test]
    fn draw_size_band_picks_smallest_when_both_axes_discrete() {
        use crate::plot::scale;
        // x: 4 bands over 100 px → 25 px; y: 2 bands over 100 px → 50 px.
        // smallest_nonzero picks 25 → diameter = 25 px at size_band = 1.0.
        let x_scale = scale::discrete(
            ["a", "b", "c", "d"]
                .into_iter()
                .map(|s| Value::String(Arc::from(s))),
        );
        let y_scale = scale::discrete(["p", "q"].into_iter().map(|s| Value::String(Arc::from(s))));
        let resolver = DirectScaleResolver::new()
            .with("x", &x_scale)
            .with("y", &y_scale);
        let g = PointGeom::builder()
            .set("x", vec!["b"])
            .set("y", vec!["q"])
            .set("fill", red_solid())
            .set("size", 0.0_f64)
            .set("size_band", 1.0_f64)
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let s = first_fill_scale(&scene).expect("fill");
        assert!((s - 25.0).abs() < 1e-6, "diameter = {s}");
    }

    #[test]
    fn draw_size_band_additive_with_size_pt() {
        use crate::plot::scale;
        // size = 6pt (= 8px at 96dpi), size_band = 0.5 over 25px band
        // → diameter = 8 + 12.5 = 20.5 px.
        let x_scale = scale::discrete(
            ["a", "b", "c", "d"]
                .into_iter()
                .map(|s| Value::String(Arc::from(s))),
        );
        let resolver = DirectScaleResolver::new().with("x", &x_scale);
        let g = PointGeom::builder()
            .set("x", vec!["b"])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .set("size", 6.0_f64)
            .set("size_band", 0.5_f64)
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let s = first_fill_scale(&scene).expect("fill");
        assert!((s - 20.5).abs() < 1e-6, "diameter = {s}");
    }

    #[test]
    fn angle_zero_produces_unrotated_recording() {
        // Regression guard: angle=0 must produce the same Affine as a
        // build with no `angle` channel at all.
        let g_no_angle = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .set("size", 10.0_f64)
            .build();
        let g_zero = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .set("size", 10.0_f64)
            .set("angle", 0.0_f64)
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut s1 = RecordingScene::default();
        let mut s2 = RecordingScene::default();
        g_no_angle.draw(&mut s1, &ctx(panel, &shapes, &resolver));
        g_zero.draw(&mut s2, &ctx(panel, &shapes, &resolver));
        let t1 = first_fill_translation(&s1).unwrap();
        let t2 = first_fill_translation(&s2).unwrap();
        assert!((t1.0 - t2.0).abs() < 1e-9 && (t1.1 - t2.1).abs() < 1e-9);
    }

    #[test]
    fn angle_rotates_glyph_about_centre_math_ccw() {
        // triangle-up apex is at path-local (0, -0.92). After a math-CCW
        // rotation of π/2 about the placement point, the apex should
        // land to the LEFT of the placement point (because math CCW in
        // a y-up frame moves +y → -x; on the screen y-down frame, the
        // geom internally negates angle so the visible motion is +up →
        // -x = left).
        use std::f64::consts::FRAC_PI_2;
        let g = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .set("size", 10.0_f64)
            .set("shape", "triangle-up")
            .set("angle", FRAC_PI_2)
            .build();
        let panel = Rect::new(0.0, 0.0, 100.0, 100.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        let xform = scene.ops.iter().find_map(|op| match op {
            Op::Fill { transform, .. } => Some(*transform),
            _ => None,
        });
        let xform = xform.expect("fill op");
        // Apex world position. size_px = pt_to_px(10) = 10*96/72 ≈ 13.33.
        // Apex path (0, -0.92). Math CCW by π/2 should put the apex at
        // (x_centre - 0.92*size_px, y_centre).
        let apex_path = crate::geometry::Point::new(0.0, -0.92);
        let apex_world = xform * apex_path;
        let size_px = 10.0 * 96.0 / 72.0;
        let expected_x = 50.0 - 0.92 * size_px;
        let expected_y = 50.0;
        assert!(
            (apex_world.x - expected_x).abs() < 0.5,
            "apex.x = {}, expected {}",
            apex_world.x,
            expected_x
        );
        assert!(
            (apex_world.y - expected_y).abs() < 0.5,
            "apex.y = {}, expected {}",
            apex_world.y,
            expected_y
        );
    }

    #[test]
    fn draw_silent_on_degenerate_panel() {
        let g = PointGeom::builder()
            .set("x", vec![0.5_f64])
            .set("y", vec![0.5_f64])
            .set("fill", red_solid())
            .build();
        let panel = Rect::new(0.0, 0.0, 0.0, 0.0);
        let shapes = registry();
        let resolver = no_scales();
        let mut scene = RecordingScene::default();
        g.draw(&mut scene, &ctx(panel, &shapes, &resolver));
        assert!(scene.ops.is_empty());
    }
}