printobserver-core 0.20.1

Supervision logic for printobserver.
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
//! The planned geometry of a print, read from its G-code by the one read the
//! [`GcodeIndex`](crate::GcodeIndex) makes: each object's footprint outline,
//! and one layer's toolpath read back from the print's spool.
//!
//! The index's single streamed read of a print's file also copies its bytes
//! to a per-print spool file and records each layer's byte range, so a
//! toolpath is read from that range of the spool and never from a second read
//! of the printer's file. The core alone reads G-code; what leaves it is
//! segments in bed millimetres, each with the [`ExtrusionKind`] its
//! `;TYPE:` maps to.

use std::path::{Path, PathBuf};

use printobserver_types::PrintId;

/// How many directions an outline is bounded in: its most vertices.
pub const OUTLINE_DIRECTIONS: usize = 64;

/// What a toolpath segment lays, from `PrusaSlicer`'s `;TYPE:` label.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ExtrusionKind {
    /// `External perimeter` and `Perimeter`.
    Wall,
    /// `Internal infill`: the sparse pattern inside the part.
    SparseInfill,
    /// `Solid infill` and `Gap fill`: solid layers inside the part, and the
    /// gaps between its walls.
    SolidInfill,
    /// `Top solid infill`: the part's top surface at this layer.
    TopSolidInfill,
    /// `Support material` and `Support material interface`.
    Support,
    /// `Bridge infill`.
    Bridge,
    /// `Overhang perimeter`.
    Overhang,
    /// Anything else: the skirt or brim, the slicer's own start and end
    /// G-code, or an unlabelled move.
    Other,
}

impl ExtrusionKind {
    /// The kind a `;TYPE:` label names.
    #[must_use]
    pub fn of_type(name: &str) -> Self {
        match name {
            "External perimeter" | "Perimeter" => Self::Wall,
            "Internal infill" => Self::SparseInfill,
            "Solid infill" | "Gap fill" => Self::SolidInfill,
            "Top solid infill" => Self::TopSolidInfill,
            "Support material" | "Support material interface" => Self::Support,
            "Bridge infill" => Self::Bridge,
            "Overhang perimeter" => Self::Overhang,
            _ => Self::Other,
        }
    }

    /// Whether this kind holds the part up rather than making it.
    #[must_use]
    pub const fn is_support(self) -> bool {
        matches!(self, Self::Support)
    }

    /// Whether this kind fills the part's inside: sparse, solid or top solid
    /// infill.
    #[must_use]
    pub const fn is_infill(self) -> bool {
        matches!(
            self,
            Self::SparseInfill | Self::SolidInfill | Self::TopSolidInfill
        )
    }

    /// What a person calls it, as the check image's text and a turn's line
    /// name it.
    #[must_use]
    pub const fn name(self) -> &'static str {
        match self {
            Self::Wall => "wall",
            Self::SparseInfill => "sparse infill",
            Self::SolidInfill => "solid infill",
            Self::TopSolidInfill => "top solid infill",
            Self::Support => "support",
            Self::Bridge => "bridge",
            Self::Overhang => "overhang",
            Self::Other => "skirt, brim or other",
        }
    }

    /// The kind as the check image's colour key names it.
    #[must_use]
    pub const fn short_name(self) -> &'static str {
        match self {
            Self::Wall => "wall",
            Self::SparseInfill => "sparse",
            Self::SolidInfill => "solid",
            Self::TopSolidInfill => "top solid",
            Self::Support => "support",
            Self::Bridge => "bridge",
            Self::Overhang => "overhang",
            Self::Other => "other",
        }
    }
}

/// One object's footprint: an outward bound of the convex hull of every
/// extrusion move laying it, in bed millimetres, counter-clockwise, with at
/// most [`OUTLINE_DIRECTIONS`] vertices.
#[derive(Debug, Clone, PartialEq)]
pub struct ObjectOutline {
    /// The vertices, counter-clockwise.
    pub hull_mm: Vec<[f32; 2]>,
}

/// One layer of an index, as the index that answered it numbers it.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct LayerRef(pub(crate) usize);

impl LayerRef {
    /// The layer at one place among a file's layers, the first being 0; an
    /// index answers [`SpoolError::UnknownLayer`] for one it does not have.
    #[must_use]
    pub const fn of_index(index: usize) -> Self {
        Self(index)
    }

    /// Its place among the file's layers, the first being 0.
    #[must_use]
    pub const fn index(self) -> usize {
        self.0
    }
}

/// One extrusion move, or one chord of an arc, of a layer.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ToolpathSegment {
    /// Where it starts, in bed millimetres.
    pub from_mm: [f32; 2],
    /// Where it ends.
    pub to_mm: [f32; 2],
    /// What it lays.
    pub kind: ExtrusionKind,
    /// The extrusion width the slicer laid it at, from the last `;WIDTH:`
    /// before it, in millimetres; 0 when the file states none.
    pub width_mm: f32,
    /// The file offset just past the line laying it: a job whose file
    /// position has reached this has sent it to the printer.
    pub ends_at: u64,
}

impl ToolpathSegment {
    /// Its length on the bed, in millimetres.
    #[must_use]
    pub fn length_mm(&self) -> f64 {
        let dx = f64::from(self.to_mm[0]) - f64::from(self.from_mm[0]);
        let dy = f64::from(self.to_mm[1]) - f64::from(self.from_mm[1]);
        dx.hypot(dy)
    }

    /// Whether a job standing at `file_position_bytes` has sent it.
    #[must_use]
    pub const fn sent_by(&self, file_position_bytes: u64) -> bool {
        self.ends_at <= file_position_bytes
    }
}

/// Every extrusion move of one layer, in file order.
#[derive(Debug, Clone, PartialEq)]
pub struct LayerToolpath {
    /// The layer's height, from its `;Z:`; 0 when the file states none.
    pub z_mm: f32,
    /// Its segments.
    pub segments: Vec<ToolpathSegment>,
}

impl LayerToolpath {
    /// Whether any segment is object extrusion: anything but supports, as
    /// `GcodeIndex::object_layer_at_or_below` reads it, so an `Other` segment
    /// (skirt, brim or custom G-code) counts.
    #[must_use]
    pub fn carries_object_extrusion(&self) -> bool {
        self.segments
            .iter()
            .any(|segment| !segment.kind.is_support())
    }

    /// How far a job standing at `file_position_bytes` is through this layer:
    /// what it has sent and what it has still to send, by path length and by
    /// kind.
    #[must_use]
    pub fn progress(&self, file_position_bytes: u64) -> LayerProgress {
        let mut progress = LayerProgress::default();
        for segment in &self.segments {
            let length = segment.length_mm();
            progress.total_mm += length;
            let (kinds, sent) = if segment.sent_by(file_position_bytes) {
                (&mut progress.kinds_sent, length)
            } else {
                (&mut progress.kinds_left, 0.0)
            };
            progress.sent_mm += sent;
            if !kinds.contains(&segment.kind) {
                kinds.push(segment.kind);
            }
        }
        progress
    }
}

/// How far a job is through one layer's toolpath.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct LayerProgress {
    /// The path length of the segments sent, in millimetres.
    pub sent_mm: f64,
    /// The path length of every segment of the layer.
    pub total_mm: f64,
    /// The kinds any sent segment lays, in the order the layer first lays
    /// them.
    pub kinds_sent: Vec<ExtrusionKind>,
    /// The kinds any segment still to send lays, in the same order: a kind
    /// part-way through is in both.
    pub kinds_left: Vec<ExtrusionKind>,
}

impl LayerProgress {
    /// The share of the layer's path length sent, in whole percent; 0 for a
    /// layer that lays nothing.
    #[must_use]
    pub fn percent_sent(&self) -> u32 {
        if self.total_mm <= 0.0 {
            return 0;
        }
        #[expect(
            clippy::cast_possible_truncation,
            clippy::cast_sign_loss,
            reason = "a share of 0 to 100 percent, rounded"
        )]
        let percent = (100.0 * self.sent_mm / self.total_mm)
            .round()
            .clamp(0.0, 100.0) as u32;
        percent
    }
}

/// What a check is told of the layer a job stands in: where it is among the
/// file's layers, the colour it should be laying, the planned change nearest
/// it, and how far through the layer the job has sent.
#[derive(Debug, Clone, PartialEq)]
pub struct LayerFacts {
    /// The layer's number, counting the file's first as 1.
    pub number: usize,
    /// How many layers the file plans.
    pub count: usize,
    /// The layer's height, in millimetres.
    pub z_mm: f64,
    /// The colour the job should be laying, as `#RRGGBB`, when the file plans
    /// a colour change and names the colour of the stretch the job is in;
    /// none for a file planning no change, whose sliced colour says nothing
    /// of the spool loaded.
    pub expected_colour: Option<String>,
    /// The planned change just made before this layer, else the next one.
    pub change: Option<ChangeFact>,
    /// How far through the layer the job has sent.
    pub progress: LayerProgress,
}

/// A planned change as a check is told of it.
#[derive(Debug, Clone, PartialEq)]
pub struct ChangeFact {
    /// Whether it was made just before this layer, rather than still ahead.
    pub just_made: bool,
    /// Its number among the file's changes, counting from 1 in file order.
    pub number: u32,
    /// Whether it is a colour change rather than a planned pause.
    pub colour_change: bool,
    /// The first layer printed after it, counting the first as 1.
    pub layer: u32,
    /// That layer's height, in millimetres.
    pub z_mm: f64,
    /// The colour loaded at it, as `#RRGGBB`, when the file names one.
    pub colour: Option<String>,
}

impl LayerFacts {
    /// The facts as three short lines of text, as a check's turn is told
    /// them of panel 1: the layer, its colour and the planned change; how
    /// far through the layer the job has sent and the kinds sent; and the
    /// kinds still to print.
    #[must_use]
    pub fn lines(&self) -> Vec<String> {
        let colour = self.expected_colour.as_deref().map_or_else(
            || "no colour expected".to_owned(),
            |c| format!("expect {c}"),
        );
        let change = self
            .change
            .as_ref()
            .map_or_else(|| "no change ahead".to_owned(), ChangeFact::line);
        let named = |kinds: &[ExtrusionKind]| {
            if kinds.is_empty() {
                "nothing".to_owned()
            } else {
                kinds
                    .iter()
                    .map(|kind| kind.short_name())
                    .collect::<Vec<_>>()
                    .join(", ")
            }
        };
        vec![
            format!(
                "layer {}/{}, Z {:.2} mm, {colour}; {change}",
                self.number, self.count, self.z_mm
            ),
            format!(
                "{}% sent by length, bold: {}",
                self.progress.percent_sent(),
                named(&self.progress.kinds_sent)
            ),
            format!("to print, grey: {}", named(&self.progress.kinds_left)),
        ]
    }
}

impl ChangeFact {
    /// The change as one clause.
    #[must_use]
    pub fn line(&self) -> String {
        let what = if self.colour_change {
            "colour change"
        } else {
            "pause"
        };
        let to = self
            .colour
            .as_deref()
            .map_or_else(String::new, |colour| format!(", to {colour}"));
        if self.just_made {
            format!("{what} {} just made{to}", self.number)
        } else {
            format!(
                "{what} {} next: layer {}, Z {:.2} mm{to}",
                self.number, self.layer, self.z_mm
            )
        }
    }
}

/// Why a layer's toolpath could not be read back.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SpoolError {
    /// The index was built with no spool beside it.
    NoSpool,
    /// The layer is not one of this index's.
    UnknownLayer,
    /// The spool could not be read, or is shorter than the index recorded.
    Io {
        /// What the filesystem said.
        detail: String,
    },
}

impl core::fmt::Display for SpoolError {
    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::NoSpool => formatter.write_str("the print's G-code was indexed with no spool"),
            Self::UnknownLayer => formatter.write_str("no such layer in the print's index"),
            Self::Io { detail } => write!(formatter, "the print's G-code spool: {detail}"),
        }
    }
}

impl std::error::Error for SpoolError {}

/// The spool file of one print under a spool directory.
#[must_use]
pub fn spool_path(directory: &Path, print_id: PrintId) -> PathBuf {
    directory.join(format!("{print_id}{SPOOL_SUFFIX}"))
}

/// What every spool file's name ends in.
pub(crate) const SPOOL_SUFFIX: &str = ".gcode";

/// The unit vectors an outline is bounded along, counter-clockwise from +X.
fn direction(k: usize) -> [f64; 2] {
    let angle = core::f64::consts::TAU * f64::from(u32::try_from(k).unwrap_or(0))
        / f64::from(u32::try_from(OUTLINE_DIRECTIONS).unwrap_or(1));
    [angle.cos(), angle.sin()]
}

/// How far an outline reaches along each of its directions: the support
/// function of every point it was given. Its polygon is the intersection of
/// one half-plane per direction, so it holds every point and only grows
/// outward from the hull.
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct Reach {
    /// The furthest point's projection on each direction.
    extent: [f64; OUTLINE_DIRECTIONS],
    /// Whether any point was given.
    any: bool,
    /// A circle inside the polygon so far: its centre and radius. A point
    /// within it reaches no further in any direction, so it is passed over
    /// without the per-direction work, which is most of a print's moves.
    inside: ([f64; 2], f64),
}

impl Default for Reach {
    fn default() -> Self {
        Self {
            extent: [f64::NEG_INFINITY; OUTLINE_DIRECTIONS],
            any: false,
            inside: ([0.0, 0.0], -1.0),
        }
    }
}

/// The directions, computed once.
fn directions() -> &'static [[f64; 2]; OUTLINE_DIRECTIONS] {
    static HELD: std::sync::OnceLock<[[f64; 2]; OUTLINE_DIRECTIONS]> = std::sync::OnceLock::new();
    HELD.get_or_init(|| {
        let mut held = [[0.0; 2]; OUTLINE_DIRECTIONS];
        let mut k = 0;
        while k < OUTLINE_DIRECTIONS {
            held[k] = direction(k);
            k += 1;
        }
        held
    })
}

impl Reach {
    /// Push every direction's extent out to `(x, y)`; a point inside the
    /// cached inner circle cannot move any extent, so it is skipped.
    pub(crate) fn point(&mut self, x: f64, y: f64) {
        let ([cx, cy], radius) = self.inside;
        let (dx, dy) = (x - cx, y - cy);
        if radius > 0.0 && dx * dx + dy * dy < radius * radius {
            return;
        }
        let held = directions();
        self.any = true;
        // A plain loop: this runs for every extrusion move of a print that
        // the circle inside does not hold.
        let mut grew = false;
        let mut k = 0;
        while k < OUTLINE_DIRECTIONS {
            let along = held[k][0] * x + held[k][1] * y;
            if along > self.extent[k] {
                self.extent[k] = along;
                grew = true;
            }
            k += 1;
        }
        if grew {
            self.refit_inside();
        }
    }

    /// The circle inside the polygon about the middle of its extents: the
    /// nearest of its half-planes from that centre. The four axis directions
    /// are among the directions, a quarter turn apart.
    fn refit_inside(&mut self) {
        let quarter = OUTLINE_DIRECTIONS / 4;
        let (right, up) = (self.extent[0], self.extent[quarter]);
        let (left, down) = (-self.extent[2 * quarter], -self.extent[3 * quarter]);
        if !(right.is_finite() && up.is_finite() && left.is_finite() && down.is_finite()) {
            return;
        }
        let centre = [f64::midpoint(right, left), f64::midpoint(up, down)];
        let held = directions();
        let mut radius = f64::INFINITY;
        let mut k = 0;
        while k < OUTLINE_DIRECTIONS {
            let gap = self.extent[k] - (held[k][0] * centre[0] + held[k][1] * centre[1]);
            radius = radius.min(gap);
            k += 1;
        }
        self.inside = (centre, radius);
    }

    /// Push out the extents of the directions whose circle point the arc
    /// sweeps over: `sweep` radians counter-clockwise from the angle `from`
    /// about `centre`. The arc's ends are not reached here; the caller gives
    /// them to `point`.
    pub(crate) fn arc(&mut self, centre: [f64; 2], radius: f64, from: f64, sweep: f64) {
        let tau = core::f64::consts::TAU;
        let held = directions();
        for (k, unit) in held.iter().enumerate() {
            let angle = tau * f64::from(u32::try_from(k).unwrap_or(0))
                / f64::from(u32::try_from(OUTLINE_DIRECTIONS).unwrap_or(1));
            if (angle - from).rem_euclid(tau) <= sweep + 1e-9 {
                let along = unit[0] * centre[0] + unit[1] * centre[1] + radius;
                if along > self.extent[k] {
                    self.extent[k] = along;
                    self.any = true;
                }
            }
        }
        self.refit_inside();
    }

    /// The outline's polygon, counter-clockwise; nothing when no point was
    /// given.
    pub(crate) fn outline(&self) -> Option<ObjectOutline> {
        if !self.any {
            return None;
        }
        // A box far past any bed, clipped by each half-plane in turn.
        let far = 1e6;
        let mut polygon = vec![[-far, -far], [far, -far], [far, far], [-far, far]];
        for (unit, extent) in directions().iter().zip(self.extent) {
            polygon = clip(&polygon, *unit, extent);
            if polygon.is_empty() {
                return None;
            }
        }
        let mut hull: Vec<[f32; 2]> = Vec::with_capacity(polygon.len());
        for [x, y] in polygon {
            #[expect(
                clippy::cast_possible_truncation,
                reason = "bed millimetres are far inside f32's range; the outline is drawn, not measured"
            )]
            let vertex = [x as f32, y as f32];
            let repeats = hull.last().is_some_and(|last: &[f32; 2]| {
                (last[0] - vertex[0]).abs() < 1e-4 && (last[1] - vertex[1]).abs() < 1e-4
            });
            if !repeats {
                hull.push(vertex);
            }
        }
        while hull.len() > 1
            && hull.first().zip(hull.last()).is_some_and(|(first, last)| {
                (first[0] - last[0]).abs() < 1e-4 && (first[1] - last[1]).abs() < 1e-4
            })
        {
            hull.pop();
        }
        Some(ObjectOutline { hull_mm: hull })
    }
}

/// One Sutherland–Hodgman step: what of a convex polygon lies on the side of
/// `unit · p <= extent`.
fn clip(polygon: &[[f64; 2]], unit: [f64; 2], extent: f64) -> Vec<[f64; 2]> {
    let inside = |p: [f64; 2]| unit[0] * p[0] + unit[1] * p[1] - extent;
    let mut kept = Vec::with_capacity(polygon.len() + 1);
    for (at, point) in polygon.iter().enumerate() {
        let next = polygon[(at + 1) % polygon.len()];
        let (here, there) = (inside(*point), inside(next));
        if here <= 0.0 {
            kept.push(*point);
        }
        if (here <= 0.0) != (there <= 0.0) {
            let t = here / (here - there);
            kept.push([
                point[0] + t * (next[0] - point[0]),
                point[1] + t * (next[1] - point[1]),
            ]);
        }
    }
    kept
}

#[cfg(test)]
mod tests {
    use super::{ExtrusionKind, OUTLINE_DIRECTIONS, Reach};

    /// Signed area of a polygon: positive when counter-clockwise.
    fn area(hull: &[[f32; 2]]) -> f64 {
        let mut twice = 0.0;
        for (at, a) in hull.iter().enumerate() {
            let b = hull[(at + 1) % hull.len()];
            twice += f64::from(a[0]) * f64::from(b[1]) - f64::from(b[0]) * f64::from(a[1]);
        }
        twice / 2.0
    }

    #[test]
    fn an_outline_holds_every_point_counter_clockwise_and_is_bounded() {
        let mut reach = Reach::default();
        let points = [
            [10.0, 10.0],
            [30.0, 12.0],
            [25.0, 40.0],
            [12.0, 33.0],
            [20.0, 20.0],
        ];
        for [x, y] in points {
            reach.point(x, y);
        }
        let outline = reach.outline().expect("points were given");
        assert!(outline.hull_mm.len() <= OUTLINE_DIRECTIONS);
        assert!(area(&outline.hull_mm) > 0.0, "counter-clockwise");
        for [x, y] in points {
            for (at, a) in outline.hull_mm.iter().enumerate() {
                let b = outline.hull_mm[(at + 1) % outline.hull_mm.len()];
                let cross = (f64::from(b[0]) - f64::from(a[0])) * (y - f64::from(a[1]))
                    - (f64::from(b[1]) - f64::from(a[1])) * (x - f64::from(a[0]));
                assert!(cross >= -1e-3, "({x}, {y}) lies inside every edge");
            }
        }
    }

    #[test]
    fn an_arc_reaches_the_part_of_its_circle_it_sweeps() {
        let mut reach = Reach::default();
        reach.point(10.0, 0.0);
        reach.point(0.0, 10.0);
        reach.arc([0.0, 0.0], 10.0, 0.0, core::f64::consts::FRAC_PI_2);
        let outline = reach.outline().expect("points were given");
        let furthest = outline
            .hull_mm
            .iter()
            .map(|[x, y]| f64::from(*x).hypot(f64::from(*y)))
            .fold(0.0, f64::max);
        assert!((10.0..10.1).contains(&furthest), "{furthest}");
    }

    #[test]
    fn no_point_is_no_outline_and_types_map_to_kinds() {
        assert!(Reach::default().outline().is_none());
        assert_eq!(ExtrusionKind::of_type("Perimeter"), ExtrusionKind::Wall);
        assert_eq!(
            ExtrusionKind::of_type("Gap fill"),
            ExtrusionKind::SolidInfill
        );
        assert_eq!(
            ExtrusionKind::of_type("Internal infill"),
            ExtrusionKind::SparseInfill
        );
        assert_eq!(
            ExtrusionKind::of_type("Top solid infill"),
            ExtrusionKind::TopSolidInfill
        );
        assert_eq!(
            ExtrusionKind::of_type("Support material interface"),
            ExtrusionKind::Support
        );
        assert_eq!(ExtrusionKind::of_type("Skirt/Brim"), ExtrusionKind::Other);
    }
}