alpha2-geometry 0.4.3

Deterministic vector geometry and coverage rasterization for alpha2 shapes.
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
//! A content tree evaluated at one time, and the scene it draws.
//!
//! The rules are After Effects' and Lottie's. A group is read front to back.
//! Geometry accumulates in its group; a fill or stroke paints the geometry
//! listed before it there, nested groups' included, and a trim cuts that
//! geometry and replaces it. Paints listed earlier are drawn on top, so a
//! group's drawing is emitted from its last item back to its first.
//!
//! Positions are normalized and lengths fractions of the shorter side, as
//! the model has them; [`build_scene`] takes them to device pixels. A
//! group's transform acts in pixel space, and the paths, strokes, and paint
//! coordinates under it go through it: a stroke is expanded in the space of
//! the group its stroke item is in, then transformed, so a non-uniform scale
//! makes its pen an ellipse.

use crate::scene::{IRect, PaintKind, ScenePaint, SceneStop, VectorOp, VectorScene};
use crate::trim::{Measured, TrimSpan};
use crate::{CanvasSize, StrokeStyle, affine, project_far, shapes, stroke_outline, trim};
use alpha2_model::{FillRule, LineCap, LineJoin, Paint, PolystarKind, TrimMode};
use kurbo::{Affine, BezPath, Point, Vec2};
use std::sync::Arc;

/// A path vertex evaluated at one time, normalized.
#[derive(Copy, Clone, Debug, Default, PartialEq)]
pub struct EvaluatedVertex {
    /// Where it lies.
    pub point: Point,
    /// The control point of the segment ending here, relative to `point`.
    pub in_tangent: Vec2,
    /// The control point of the segment starting here, relative to `point`.
    pub out_tangent: Vec2,
}

/// A subpath evaluated at one time.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct EvaluatedSubpath {
    /// Whether a segment joins the last vertex back to the first.
    pub closed: bool,
    /// The vertices.
    pub vertices: Vec<EvaluatedVertex>,
}

/// A path evaluated at one time.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct EvaluatedPath {
    /// The subpaths.
    pub subpaths: Vec<EvaluatedSubpath>,
}

impl From<&alpha2_model::Path> for EvaluatedPath {
    fn from(path: &alpha2_model::Path) -> Self {
        let point = |value: alpha2_model::Vec2| Point::new(f64::from(value.x), f64::from(value.y));
        let vector = |value: alpha2_model::Vec2| Vec2::new(f64::from(value.x), f64::from(value.y));
        Self {
            subpaths: path
                .subpaths
                .iter()
                .map(|subpath| EvaluatedSubpath {
                    closed: subpath.closed,
                    vertices: subpath
                        .vertices
                        .iter()
                        .map(|vertex| EvaluatedVertex {
                            point: point(vertex.point),
                            in_tangent: vector(vertex.in_tangent),
                            out_tangent: vector(vertex.out_tangent),
                        })
                        .collect(),
                })
                .collect(),
        }
    }
}

/// A geometry item evaluated at one time.
#[derive(Clone, Debug, PartialEq)]
pub enum EvaluatedGeometry {
    /// A rectangle.
    Rectangle {
        /// Centre.
        center: Point,
        /// Full size.
        size: Vec2,
        /// Corner radius, a fraction of the shorter side.
        corner_radius: f64,
        /// Clockwise rotation in degrees.
        rotation_degrees: f64,
    },
    /// An ellipse.
    Ellipse {
        /// Centre.
        center: Point,
        /// Full size.
        size: Vec2,
        /// Clockwise rotation in degrees.
        rotation_degrees: f64,
    },
    /// A star or polygon.
    Polystar {
        /// Star or polygon.
        kind: PolystarKind,
        /// Centre.
        center: Point,
        /// Number of points; a fraction is dropped.
        points: f64,
        /// Points' radius, a fraction of the shorter side.
        outer_radius: f64,
        /// A star's inner radius, a fraction of the shorter side.
        inner_radius: f64,
        /// Roundness of the points.
        outer_roundness: f64,
        /// Roundness of a star's inner corners.
        inner_roundness: f64,
        /// Clockwise rotation in degrees.
        rotation_degrees: f64,
    },
    /// A Bezier path.
    Path(Arc<EvaluatedPath>),
}

impl EvaluatedGeometry {
    /// The geometry in the pixels of a picture of `size`.
    #[must_use]
    pub fn to_path(&self, size: CanvasSize) -> BezPath {
        let scale = size.scale();
        let pixel = |point: Point| Point::new(point.x * scale.x, point.y * scale.y);
        let extent = |vector: Vec2| Vec2::new(vector.x * scale.x, vector.y * scale.y);
        let unit = size.unit();
        match self {
            Self::Rectangle {
                center,
                size: extent_value,
                corner_radius,
                rotation_degrees,
            } => shapes::rectangle(
                pixel(*center),
                extent(*extent_value),
                corner_radius * unit,
                *rotation_degrees,
            ),
            Self::Ellipse {
                center,
                size: extent_value,
                rotation_degrees,
            } => shapes::ellipse(pixel(*center), extent(*extent_value), *rotation_degrees),
            Self::Polystar {
                kind,
                center,
                points,
                outer_radius,
                inner_radius,
                outer_roundness,
                inner_roundness,
                rotation_degrees,
            } => shapes::polystar(&shapes::Polystar {
                star: *kind == PolystarKind::Star,
                center: pixel(*center),
                points: *points,
                outer_radius: outer_radius * unit,
                inner_radius: inner_radius * unit,
                outer_roundness: *outer_roundness,
                inner_roundness: *inner_roundness,
                degrees: *rotation_degrees,
            }),
            Self::Path(path) => {
                let mut bez = BezPath::new();
                let mut vertices = Vec::new();
                for subpath in &path.subpaths {
                    vertices.clear();
                    vertices.extend(subpath.vertices.iter().map(|vertex| shapes::Vertex {
                        point: pixel(vertex.point),
                        in_tangent: extent(vertex.in_tangent),
                        out_tangent: extent(vertex.out_tangent),
                    }));
                    shapes::append_subpath(&mut bez, &vertices, subpath.closed);
                }
                bez
            }
        }
    }
}

/// A group's transform evaluated at one time, normalized.
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct EvaluatedTransform {
    /// The point of the items placed at `position`.
    pub anchor: Point,
    /// Where `anchor` is placed.
    pub position: Point,
    /// Per-axis scale.
    pub scale: Vec2,
    /// Clockwise rotation in degrees.
    pub rotation_degrees: f64,
    /// Group opacity, in `0..=1`.
    pub opacity: f64,
}

impl Default for EvaluatedTransform {
    fn default() -> Self {
        Self {
            anchor: Point::ZERO,
            position: Point::ZERO,
            scale: Vec2::new(1.0, 1.0),
            rotation_degrees: 0.0,
            opacity: 1.0,
        }
    }
}

impl EvaluatedTransform {
    /// The transform in the pixels of a picture of `size`.
    #[must_use]
    pub fn affine(&self, size: CanvasSize) -> Affine {
        affine::placement(
            size.point(self.position.x, self.position.y),
            size.point(self.anchor.x, self.anchor.y),
            self.scale,
            self.rotation_degrees,
        )
    }
}

/// One content-tree item evaluated at one time.
#[derive(Clone, Debug, PartialEq)]
pub enum EvaluatedItem {
    /// Items drawn through one transform and opacity.
    Group {
        /// The items, front first. Shared, so a subtree that does not change
        /// over time is evaluated once.
        items: Arc<[EvaluatedItem]>,
        /// The group's transform.
        transform: EvaluatedTransform,
    },
    /// Geometry.
    Geometry(EvaluatedGeometry),
    /// A fill of the geometry before it.
    Fill {
        /// What covers it.
        paint: Paint,
        /// Opacity in `0..=1`.
        opacity: f64,
        /// Which regions are inside.
        rule: FillRule,
    },
    /// A stroke of the geometry before it.
    Stroke {
        /// What covers it.
        paint: Paint,
        /// Full width, a fraction of the shorter side.
        width: f64,
        /// Opacity in `0..=1`.
        opacity: f64,
        /// How segments meet.
        join: LineJoin,
        /// Miter limit.
        miter_limit: f64,
        /// How ends look.
        cap: LineCap,
        /// Dash and gap lengths, fractions of the shorter side; solid when
        /// empty.
        dash: Vec<f64>,
        /// Dash offset, a fraction of the shorter side.
        dash_offset: f64,
    },
    /// A trim of the geometry before it.
    Trim {
        /// Start fraction.
        start: f64,
        /// End fraction.
        end: f64,
        /// Offset in turns.
        offset: f64,
        /// Together or individually.
        mode: TrimMode,
    },
}

/// Geometry accumulated in a group: a path in the space of the item that
/// made it, and the transform from there to the group's space.
#[derive(Clone)]
struct Entry {
    path: BezPath,
    relative: Affine,
}

/// What [`item_paths`] reports of one item.
#[derive(Clone, Debug, PartialEq)]
pub struct ItemPath {
    /// The item's place in the tree, like `items[0].items[2]`.
    pub at: String,
    /// What it covers in device pixels: geometry's outline, a fill's area,
    /// a stroke's outline; empty for a group. Trims are not recorded.
    pub path: BezPath,
    /// How `path` is filled.
    pub rule: FillRule,
    /// Whether it is paint (a fill or a stroke) rather than geometry.
    pub paint: bool,
    /// The device pixels it reaches; a group's is its items'.
    pub bounds: kurbo::Rect,
}

struct Builder {
    size: CanvasSize,
    canvas: IRect,
    /// Whether items are named by their place in the tree: only queries
    /// read the names, so a scene drawn for a frame formats none.
    named: bool,
    /// Every item's outline or area, when queries need them.
    records: Option<Vec<ItemPath>>,
}

/// A group's drawing, in item order: the scene emits it back to front.
type Chunks = Vec<Vec<(VectorOp, String)>>;

/// The scene `items` draw on a picture of `size`.
#[must_use]
pub fn build_scene(items: &[EvaluatedItem], size: CanvasSize) -> VectorScene {
    let ops = build_scene_in(items, size, kurbo::Vec2::ZERO, size);
    VectorScene::new(ops, size.width, size.height)
}

/// The operations `items` draw on a picture of `space` whose top-left
/// corner lies at `origin` on a canvas of `canvas`, as an SVG viewBox
/// places its picture: positions are normalized to `space`, lengths are
/// fractions of its shorter side, and paints are in it. What they cover is
/// clipped to `canvas`. [`build_scene`] is the case `space == canvas` at the
/// origin.
#[must_use]
pub fn build_scene_in(
    items: &[EvaluatedItem],
    space: CanvasSize,
    origin: kurbo::Vec2,
    canvas: CanvasSize,
) -> Vec<VectorOp> {
    let mut builder = Builder::new(space, false, false);
    builder.canvas = canvas_rect(canvas);
    let (_, chunks) = builder.group(items, Affine::translate(origin), "");
    back_to_front(chunks)
        .into_iter()
        .map(|(op, _)| op)
        .collect()
}

fn canvas_rect(size: CanvasSize) -> IRect {
    IRect::new(
        0,
        0,
        i32::try_from(size.width).unwrap_or(i32::MAX),
        i32::try_from(size.height).unwrap_or(i32::MAX),
    )
}

/// The scene `items` draw, with the item each of its operations was drawn
/// for (empty for a layer's push and pop).
#[must_use]
pub fn build_scene_with_items(
    items: &[EvaluatedItem],
    size: CanvasSize,
) -> (VectorScene, Vec<String>) {
    let mut builder = Builder::new(size, true, false);
    let (_, chunks) = builder.group(items, Affine::IDENTITY, "items");
    let (ops, owners): (Vec<_>, Vec<_>) = back_to_front(chunks).into_iter().unzip();
    (VectorScene::new(ops, size.width, size.height), owners)
}

/// Every item's outline or painted area, in document order, for the
/// editor's queries.
#[must_use]
pub fn item_paths(items: &[EvaluatedItem], size: CanvasSize) -> Vec<ItemPath> {
    let mut builder = Builder::new(size, true, true);
    builder.group(items, Affine::IDENTITY, "items");
    builder.records.unwrap_or_default()
}

fn back_to_front(chunks: Chunks) -> Vec<(VectorOp, String)> {
    chunks.into_iter().rev().flatten().collect()
}

impl Builder {
    fn new(size: CanvasSize, named: bool, records: bool) -> Self {
        Self {
            size,
            canvas: canvas_rect(size),
            named,
            records: records.then(Vec::new),
        }
    }

    /// The pixel size of the space positions are normalized in.
    #[allow(clippy::cast_precision_loss)]
    fn space(&self) -> [f32; 2] {
        [self.size.width as f32, self.size.height as f32]
    }

    fn record(&mut self, at: &str, path: BezPath, rule: FillRule, paint: bool) {
        if let Some(records) = &mut self.records {
            let bounds = if path.elements().is_empty() {
                kurbo::Rect::ZERO
            } else {
                kurbo::Shape::bounding_box(&path)
            };
            records.push(ItemPath {
                at: at.to_owned(),
                path,
                rule,
                paint,
                bounds,
            });
        }
    }

    /// Reads a group's items: the geometry it leaves for the enclosing group
    /// (in this group's space) and its drawing.
    #[allow(clippy::too_many_lines)]
    fn group(
        &mut self,
        items: &[EvaluatedItem],
        to_device: Affine,
        at: &str,
    ) -> (Vec<Entry>, Chunks) {
        let mut entries: Vec<Entry> = Vec::new();
        let mut chunks: Chunks = Vec::new();
        for (index, item) in items.iter().enumerate() {
            let at = if self.named {
                format!("{at}[{index}]")
            } else {
                String::new()
            };
            match item {
                EvaluatedItem::Group { items, transform } => {
                    let local = transform.affine(self.size);
                    let record_index = self.records.as_ref().map(Vec::len);
                    let inner_at = if self.named {
                        format!("{at}.items")
                    } else {
                        String::new()
                    };
                    let (inner, drawing) = self.group(items, to_device * local, &inner_at);
                    if let (Some(records), Some(first)) = (&mut self.records, record_index) {
                        let bounds = records[first..]
                            .iter()
                            .map(|record| record.bounds)
                            .filter(|bounds| {
                                bounds.area() > 0.0 || bounds.width() > 0.0 || bounds.height() > 0.0
                            })
                            .reduce(|a, b| a.union(b))
                            .unwrap_or(kurbo::Rect::ZERO);
                        records.insert(
                            first,
                            ItemPath {
                                at: at.clone(),
                                path: BezPath::new(),
                                rule: FillRule::Nonzero,
                                paint: false,
                                bounds,
                            },
                        );
                    }
                    entries.extend(inner.into_iter().map(|entry| Entry {
                        path: entry.path,
                        relative: local * entry.relative,
                    }));
                    let ops = back_to_front(drawing);
                    #[allow(clippy::cast_possible_truncation)]
                    let opacity = transform.opacity.clamp(0.0, 1.0) as f32;
                    if ops.is_empty() || opacity <= 0.0 {
                        continue;
                    }
                    if opacity < 1.0 {
                        let bounds = ops
                            .iter()
                            .filter_map(|(op, _)| match op {
                                VectorOp::Fill { bounds, .. } => Some(*bounds),
                                _ => None,
                            })
                            .fold(IRect::default(), IRect::union);
                        let mut layer = Vec::with_capacity(ops.len() + 2);
                        layer.push((VectorOp::PushLayer { opacity, bounds }, String::new()));
                        layer.extend(ops);
                        layer.push((VectorOp::PopLayer, String::new()));
                        chunks.push(layer);
                    } else {
                        chunks.push(ops);
                    }
                }
                EvaluatedItem::Geometry(geometry) => {
                    let path = geometry.to_path(self.size);
                    if self.records.is_some() {
                        let device = to_device * path.clone();
                        self.record(&at, device, FillRule::Nonzero, false);
                    }
                    entries.push(Entry {
                        path,
                        relative: Affine::IDENTITY,
                    });
                }
                EvaluatedItem::Fill {
                    paint,
                    opacity,
                    rule,
                } => {
                    let mut device = BezPath::new();
                    for entry in &entries {
                        device.extend(
                            (to_device * entry.relative * entry.path.clone())
                                .elements()
                                .iter()
                                .copied(),
                        );
                    }
                    let device = project_far(&device, self.size.width, self.size.height);
                    self.record(&at, device.clone(), *rule, true);
                    if let Some(op) = self.fill_op(device, *rule, paint, *opacity, to_device) {
                        chunks.push(vec![(op, at)]);
                    }
                }
                EvaluatedItem::Stroke {
                    paint,
                    width,
                    opacity,
                    join,
                    miter_limit,
                    cap,
                    dash,
                    dash_offset,
                } => {
                    let unit = self.size.unit();
                    let style = StrokeStyle {
                        width: width * unit,
                        join: *join,
                        miter_limit: *miter_limit,
                        cap: *cap,
                        dash: dash.iter().map(|length| length.max(0.0) * unit).collect(),
                        dash_offset: dash_offset * unit,
                    };
                    let mut local = BezPath::new();
                    for entry in &entries {
                        local.extend(
                            (entry.relative * entry.path.clone())
                                .elements()
                                .iter()
                                .copied(),
                        );
                    }
                    let outline = stroke_outline(&local, &style, to_device);
                    let outline = project_far(&outline, self.size.width, self.size.height);
                    self.record(&at, outline.clone(), FillRule::Nonzero, true);
                    if let Some(op) =
                        self.fill_op(outline, FillRule::Nonzero, paint, *opacity, to_device)
                    {
                        chunks.push(vec![(op, at)]);
                    }
                }
                EvaluatedItem::Trim {
                    start,
                    end,
                    offset,
                    mode,
                } => {
                    entries = trim_entries(&entries, to_device, *start, *end, *offset, *mode);
                }
            }
        }
        (entries, chunks)
    }

    fn fill_op(
        &self,
        path: BezPath,
        rule: FillRule,
        paint: &Paint,
        opacity: f64,
        to_device: Affine,
    ) -> Option<VectorOp> {
        #[allow(clippy::cast_possible_truncation)]
        let opacity = opacity.clamp(0.0, 1.0) as f32;
        if opacity <= 0.0 || path.elements().is_empty() || !affine::is_invertible(to_device) {
            return None;
        }
        let bounds = IRect::covering(&path, self.canvas);
        if bounds.is_empty() {
            return None;
        }
        Some(VectorOp::Fill {
            path: Arc::new(path),
            rule,
            paint: scene_paint(paint, to_device.inverse(), self.space()),
            opacity,
            bounds,
        })
    }
}

/// Trims `entries`, measured in device pixels, keeping each entry's
/// transform for what remains of it.
fn trim_entries(
    entries: &[Entry],
    to_device: Affine,
    start: f64,
    end: f64,
    offset: f64,
    mode: TrimMode,
) -> Vec<Entry> {
    let span = TrimSpan { start, end, offset };
    // Every subpath, with the entry it came from.
    let mut owners = Vec::new();
    let mut parts = Vec::new();
    for (index, entry) in entries.iter().enumerate() {
        for subpath in trim::subpaths(&entry.path) {
            owners.push(index);
            parts.push(Measured {
                subpath,
                measure: to_device * entry.relative,
            });
        }
    }
    let kept = match mode {
        TrimMode::Together => trim::trim_together(&parts, span),
        TrimMode::Individually => trim::trim_individually(&parts, span),
    };
    let mut result: Vec<Entry> = Vec::new();
    for (part, subpath) in kept {
        let relative = entries[owners[part]].relative;
        match result.last_mut() {
            Some(last) if last.relative == relative => trim::append(&mut last.path, &subpath),
            _ => {
                let mut path = BezPath::new();
                trim::append(&mut path, &subpath);
                result.push(Entry { path, relative });
            }
        }
    }
    result
}

/// `paint` as the scene paints it, through `inverse` from device pixels into
/// a paint space of `space` pixels.
#[must_use]
pub fn scene_paint(paint: &Paint, inverse: Affine, space: [f32; 2]) -> ScenePaint {
    let color = |value: alpha2_model::Rgba| [value.red, value.green, value.blue, value.alpha];
    let stops = |list: &[alpha2_model::GradientStop]| {
        list.iter()
            .map(|stop| SceneStop {
                offset: stop.offset,
                color: color(stop.color),
            })
            .collect::<Vec<_>>()
    };
    let spread = |value: alpha2_model::Spread| match value {
        alpha2_model::Spread::Pad => 0,
        alpha2_model::Spread::Repeat => 1,
        alpha2_model::Spread::Reflect => 2,
    };
    match paint {
        Paint::Solid { color: value } => ScenePaint {
            kind: PaintKind::Solid,
            a: [0.0; 2],
            b: [0.0; 2],
            spread: 0,
            stops: vec![SceneStop {
                offset: 0.0,
                color: color(*value),
            }],
            inverse,
            space,
        },
        Paint::LinearGradient {
            start,
            end,
            stops: list,
            spread: mode,
        } => ScenePaint {
            kind: PaintKind::Linear,
            a: [start.x, start.y],
            b: [end.x, end.y],
            spread: spread(*mode),
            stops: stops(list),
            inverse,
            space,
        },
        Paint::RadialGradient {
            center,
            radius,
            stops: list,
            spread: mode,
        } => ScenePaint {
            kind: PaintKind::Radial,
            a: [center.x, center.y],
            b: [*radius, 0.0],
            spread: spread(*mode),
            stops: stops(list),
            inverse,
            space,
        },
        Paint::ConicGradient {
            center,
            angle_degrees,
            stops: list,
        } => ScenePaint {
            kind: PaintKind::Conic,
            a: [center.x, center.y],
            b: [angle_degrees.to_radians(), 0.0],
            spread: 0,
            stops: stops(list),
            inverse,
            space,
        },
    }
}