Skip to main content

native_theme/model/
border.rs

1// Border specification sub-structs for defaults-level and widget-level border properties
2
3use crate::Rgba;
4use native_theme_derive::ThemeFields;
5use serde::{Deserialize, Serialize};
6
7/// Defaults-level border specification: color, geometry, and the platform's
8/// line opacity.
9///
10/// Used on [`ThemeDefaults`](crate::model::ThemeDefaults) for global border
11/// properties that are inherited by per-widget borders.
12///
13/// **No padding fields:** Padding lives exclusively on [`WidgetBorderSpec`]
14/// because padding is a widget-level layout concern, not a global default.
15/// This split eliminated the former
16/// "derives-from-presence" rule where the resolver would fill padding with
17/// `0.0` based on whether `line_width` or `corner_radius` was set -- a
18/// confusing proxy heuristic that is no longer needed.
19///
20/// All fields are optional to support partial overlays -- a DefaultsBorderSpec
21/// with only `color` set will only override the color when merged.
22#[serde_with::skip_serializing_none]
23#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, ThemeFields)]
24#[serde(default)]
25pub struct DefaultsBorderSpec {
26    /// Border color.
27    pub color: Option<Rgba>,
28    /// Corner radius in logical pixels.
29    #[serde(rename = "corner_radius_px")]
30    pub corner_radius: Option<f32>,
31    /// Large corner radius in logical pixels (defaults only).
32    #[serde(rename = "corner_radius_lg_px")]
33    pub corner_radius_lg: Option<f32>,
34    /// Border stroke width in logical pixels.
35    #[serde(rename = "line_width_px")]
36    pub line_width: Option<f32>,
37    /// The platform's line opacity, 0.0-1.0 (defaults only): the share of the
38    /// text colour that makes a border or separator line — KDE's
39    /// `frameContrast` 0.2, libadwaita's `--border-opacity` 0.15
40    /// (docs/platform-facts.md §2.1.6).
41    ///
42    /// It is already folded into every stated border colour, which is the
43    /// final line colour: no connector multiplies any colour by it. It
44    /// documents how the platform derives its lines.
45    pub opacity: Option<f32>,
46    /// Whether the bordered element has a drop shadow.
47    pub shadow_enabled: Option<bool>,
48}
49
50impl_merge!(DefaultsBorderSpec {
51    option { color, corner_radius, corner_radius_lg, line_width, opacity, shadow_enabled }
52});
53
54/// Widget-level border specification: color, geometry, and padding.
55///
56/// Used on per-widget structs for border properties specific to individual
57/// widgets. Unlike [`DefaultsBorderSpec`], includes the four padding sides
58/// (widget-level layout) but omits `corner_radius_lg` and `opacity`
59/// (defaults-only geometry).
60///
61/// Padding fields are widget-only because different widgets need different
62/// internal padding even when sharing the same border geometry from defaults.
63///
64/// **Padding is per side.** A platform states padding side by side, and some
65/// sides differ (Windows' input is 10 left / 6 right, docs/platform-facts.md
66/// §2.4), so the model stores the four sides and nothing else. `None` means
67/// the platform states no value for that side; `Some(0.0)` means it states
68/// zero.
69///
70/// **TOML.** The sides are `padding_top_px`, `padding_right_px`,
71/// `padding_bottom_px` and `padding_left_px`. `padding_horizontal_px` and
72/// `padding_vertical_px` are parse-time shorthand that set both sides of
73/// their axis. A table that states an axis key together with one of that
74/// axis's sides is a parse error naming both keys. Serialisation writes
75/// sides only.
76///
77/// All fields are optional to support partial overlays, and they merge per
78/// field, the overlay winning, so a reader's left side over a preset's
79/// shorthand replaces the left side alone.
80#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, ThemeFields)]
81#[serde(try_from = "WidgetBorderSpecRaw", into = "WidgetBorderSpecRaw")]
82// serde reads and writes this struct through WidgetBorderSpecRaw, which also
83// knows the two shorthand keys. The ThemeFields derive's introspection path
84// cannot see the proxy, so declare the wire-format field names explicitly
85// here, as FontSpec does. Keep in sync with WidgetBorderSpecRaw below.
86#[theme_layer(
87    fields = "color, corner_radius_px, line_width_px, shadow_enabled, padding_top_px, padding_right_px, padding_bottom_px, padding_left_px, padding_horizontal_px, padding_vertical_px"
88)]
89pub struct WidgetBorderSpec {
90    /// Border color.
91    pub color: Option<Rgba>,
92    /// Corner radius in logical pixels.
93    pub corner_radius: Option<f32>,
94    /// Border stroke width in logical pixels.
95    pub line_width: Option<f32>,
96    /// Whether the bordered element has a drop shadow.
97    pub shadow_enabled: Option<bool>,
98    /// Padding inside the border above the content, in logical pixels.
99    pub padding_top: Option<f32>,
100    /// Padding inside the border right of the content, in logical pixels.
101    pub padding_right: Option<f32>,
102    /// Padding inside the border below the content, in logical pixels.
103    pub padding_bottom: Option<f32>,
104    /// Padding inside the border left of the content, in logical pixels.
105    pub padding_left: Option<f32>,
106}
107
108/// Serde proxy for [`WidgetBorderSpec`]: the four side keys and the two axis
109/// shorthands.
110#[serde_with::skip_serializing_none]
111#[derive(Default, Serialize, Deserialize)]
112#[serde(default)]
113struct WidgetBorderSpecRaw {
114    color: Option<Rgba>,
115    corner_radius_px: Option<f32>,
116    line_width_px: Option<f32>,
117    shadow_enabled: Option<bool>,
118    padding_top_px: Option<f32>,
119    padding_right_px: Option<f32>,
120    padding_bottom_px: Option<f32>,
121    padding_left_px: Option<f32>,
122    padding_horizontal_px: Option<f32>,
123    padding_vertical_px: Option<f32>,
124}
125
126/// Expand one axis shorthand into its two sides, rejecting a table that also
127/// states either side.
128fn expand_axis(
129    axis: (&str, Option<f32>),
130    first: (&str, Option<f32>),
131    second: (&str, Option<f32>),
132) -> Result<(Option<f32>, Option<f32>), String> {
133    let Some(v) = axis.1 else {
134        return Ok((first.1, second.1));
135    };
136    for side in [first, second] {
137        if side.1.is_some() {
138            return Err(format!(
139                "border: set `{}` or `{}`, not both",
140                axis.0, side.0
141            ));
142        }
143    }
144    Ok((Some(v), Some(v)))
145}
146
147impl TryFrom<WidgetBorderSpecRaw> for WidgetBorderSpec {
148    type Error = String;
149    fn try_from(raw: WidgetBorderSpecRaw) -> Result<Self, Self::Error> {
150        let (padding_left, padding_right) = expand_axis(
151            ("padding_horizontal_px", raw.padding_horizontal_px),
152            ("padding_left_px", raw.padding_left_px),
153            ("padding_right_px", raw.padding_right_px),
154        )?;
155        let (padding_top, padding_bottom) = expand_axis(
156            ("padding_vertical_px", raw.padding_vertical_px),
157            ("padding_top_px", raw.padding_top_px),
158            ("padding_bottom_px", raw.padding_bottom_px),
159        )?;
160        Ok(WidgetBorderSpec {
161            color: raw.color,
162            corner_radius: raw.corner_radius_px,
163            line_width: raw.line_width_px,
164            shadow_enabled: raw.shadow_enabled,
165            padding_top,
166            padding_right,
167            padding_bottom,
168            padding_left,
169        })
170    }
171}
172
173impl From<WidgetBorderSpec> for WidgetBorderSpecRaw {
174    fn from(b: WidgetBorderSpec) -> Self {
175        WidgetBorderSpecRaw {
176            color: b.color,
177            corner_radius_px: b.corner_radius,
178            line_width_px: b.line_width,
179            shadow_enabled: b.shadow_enabled,
180            padding_top_px: b.padding_top,
181            padding_right_px: b.padding_right,
182            padding_bottom_px: b.padding_bottom,
183            padding_left_px: b.padding_left,
184            padding_horizontal_px: None,
185            padding_vertical_px: None,
186        }
187    }
188}
189
190impl_merge!(WidgetBorderSpec {
191    option {
192        color, corner_radius, line_width, shadow_enabled,
193        padding_top, padding_right, padding_bottom, padding_left
194    }
195});
196
197/// A widget's resolved padding, one field per side.
198///
199/// `None` means the theme states no value for that side, so a connector
200/// leaves the toolkit's own padding in place there; `Some(0.0)` means the
201/// theme states zero.
202#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)]
203pub struct ResolvedPadding {
204    /// Padding above the content, in logical pixels.
205    pub top: Option<f32>,
206    /// Padding right of the content, in logical pixels.
207    pub right: Option<f32>,
208    /// Padding below the content, in logical pixels.
209    pub bottom: Option<f32>,
210    /// Padding left of the content, in logical pixels.
211    pub left: Option<f32>,
212}
213
214/// The resolved `defaults.border`: the global border geometry and colour
215/// that widget borders inherit.
216///
217/// No `Default` derive: It is constructed from a fully
218/// populated unresolved source.
219#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
220#[non_exhaustive]
221pub struct ResolvedDefaultsBorder {
222    /// Border color.
223    pub color: Rgba,
224    /// Corner radius in logical pixels.
225    pub corner_radius: f32,
226    /// Large corner radius in logical pixels.
227    pub corner_radius_lg: f32,
228    /// Border stroke width in logical pixels.
229    pub line_width: f32,
230    /// The platform's line opacity, 0.0-1.0: the share of the text colour
231    /// already folded into every stated border colour. No connector
232    /// multiplies any colour by it (see [`DefaultsBorderSpec::opacity`]).
233    pub opacity: f32,
234    /// Whether the bordered element has a drop shadow.
235    pub shadow_enabled: bool,
236}
237
238/// A widget's resolved border: its colour, geometry and padding.
239///
240/// No `Default` derive: Any "zero" instance is a
241/// placeholder sentinel built manually (see
242/// `resolve::validate_helpers::resolved_widget_border_sentinel`).
243#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
244pub struct ResolvedWidgetBorder {
245    /// Border color.
246    pub color: Rgba,
247    /// Corner radius in logical pixels.
248    pub corner_radius: f32,
249    /// Border stroke width in logical pixels.
250    pub line_width: f32,
251    /// Whether the bordered element has a drop shadow.
252    pub shadow_enabled: bool,
253    /// Padding inside the border, per side; a side the theme does not state
254    /// is `None`.
255    #[serde(default)]
256    pub padding: ResolvedPadding,
257}
258
259impl ResolvedWidgetBorder {
260    /// The padding measured from the widget's outer edge: each side
261    /// [`padding`](Self::padding) states plus [`line_width`](Self::line_width),
262    /// and `None` where it states none, so the toolkit keeps its own padding
263    /// there.
264    ///
265    /// The theme's padding lies inside the border (outer size = border +
266    /// padding + content, `docs/platform-facts.md:904-906`). A toolkit that
267    /// lays a widget's content out its padding in from the widget's edge and
268    /// paints the border over that padding, as iced and egui do, takes this,
269    /// and the content sits where the platform puts it; one whose box model
270    /// lays the padding inside the border (gpui) takes
271    /// [`padding`](Self::padding).
272    ///
273    /// On a resolved theme every length is finite and non-negative
274    /// (validation rejects any other). A finite side plus a finite width can
275    /// only overflow upwards, and that sum is `f32::MAX`, so a finite padding
276    /// stays finite; a non-finite side or width gives the `f32` sum.
277    #[must_use]
278    pub fn padding_outside(&self) -> ResolvedPadding {
279        let width = self.line_width;
280        let side = |stated: Option<f32>| {
281            stated.map(|v| match v + width {
282                sum if v.is_finite() && width.is_finite() => sum.min(f32::MAX),
283                sum => sum,
284            })
285        };
286        ResolvedPadding {
287            top: side(self.padding.top),
288            right: side(self.padding.right),
289            bottom: side(self.padding.bottom),
290            left: side(self.padding.left),
291        }
292    }
293}
294
295#[cfg(test)]
296#[allow(clippy::unwrap_used, clippy::expect_used)]
297mod tests {
298    use super::*;
299
300    // === DefaultsBorderSpec tests ===
301
302    #[test]
303    fn defaults_border_spec_default_is_empty() {
304        assert!(DefaultsBorderSpec::default().is_empty());
305    }
306
307    #[test]
308    fn defaults_border_spec_not_empty_when_color_set() {
309        let bs = DefaultsBorderSpec {
310            color: Some(Rgba::rgb(100, 100, 100)),
311            ..Default::default()
312        };
313        assert!(!bs.is_empty());
314    }
315
316    #[test]
317    fn defaults_border_spec_toml_round_trip_full() {
318        let bs = DefaultsBorderSpec {
319            color: Some(Rgba::rgb(200, 200, 200)),
320            corner_radius: Some(4.0),
321            corner_radius_lg: Some(8.0),
322            line_width: Some(1.0),
323            opacity: Some(0.15),
324            shadow_enabled: Some(true),
325        };
326        let toml_str = toml::to_string(&bs).unwrap();
327        let deserialized: DefaultsBorderSpec = toml::from_str(&toml_str).unwrap();
328        assert_eq!(deserialized, bs);
329    }
330
331    #[test]
332    fn defaults_border_spec_toml_round_trip_partial() {
333        let bs = DefaultsBorderSpec {
334            color: Some(Rgba::rgb(100, 100, 100)),
335            corner_radius: Some(8.0),
336            corner_radius_lg: None,
337            line_width: None,
338            opacity: None,
339            shadow_enabled: None,
340        };
341        let toml_str = toml::to_string(&bs).unwrap();
342        let deserialized: DefaultsBorderSpec = toml::from_str(&toml_str).unwrap();
343        assert_eq!(deserialized, bs);
344        assert!(deserialized.corner_radius_lg.is_none());
345        assert!(deserialized.line_width.is_none());
346        assert!(deserialized.opacity.is_none());
347        assert!(deserialized.shadow_enabled.is_none());
348    }
349
350    #[test]
351    fn defaults_border_spec_merge_overlay_wins() {
352        let mut base = DefaultsBorderSpec {
353            color: Some(Rgba::rgb(100, 100, 100)),
354            corner_radius: Some(4.0),
355            ..Default::default()
356        };
357        let overlay = DefaultsBorderSpec {
358            color: Some(Rgba::rgb(200, 200, 200)),
359            ..Default::default()
360        };
361        base.merge(&overlay);
362        assert_eq!(base.color, Some(Rgba::rgb(200, 200, 200)));
363        // base corner_radius preserved since overlay corner_radius is None
364        assert_eq!(base.corner_radius, Some(4.0));
365    }
366
367    // === WidgetBorderSpec tests ===
368
369    #[test]
370    fn widget_border_spec_default_is_empty() {
371        assert!(WidgetBorderSpec::default().is_empty());
372    }
373
374    #[test]
375    fn widget_border_spec_not_empty_when_color_set() {
376        let bs = WidgetBorderSpec {
377            color: Some(Rgba::rgb(100, 100, 100)),
378            ..Default::default()
379        };
380        assert!(!bs.is_empty());
381    }
382
383    #[test]
384    fn widget_border_spec_toml_round_trip_full() {
385        let bs = WidgetBorderSpec {
386            color: Some(Rgba::rgb(200, 200, 200)),
387            corner_radius: Some(4.0),
388            line_width: Some(1.0),
389            shadow_enabled: Some(true),
390            padding_top: Some(5.0),
391            padding_right: Some(6.0),
392            padding_bottom: Some(7.0),
393            padding_left: Some(8.0),
394        };
395        let toml_str = toml::to_string(&bs).unwrap();
396        let deserialized: WidgetBorderSpec = toml::from_str(&toml_str).unwrap();
397        assert_eq!(deserialized, bs);
398    }
399
400    #[test]
401    fn widget_border_spec_toml_round_trip_partial() {
402        let bs = WidgetBorderSpec {
403            color: Some(Rgba::rgb(100, 100, 100)),
404            corner_radius: Some(8.0),
405            line_width: None,
406            shadow_enabled: None,
407            padding_top: None,
408            padding_right: None,
409            padding_bottom: None,
410            padding_left: None,
411        };
412        let toml_str = toml::to_string(&bs).unwrap();
413        let deserialized: WidgetBorderSpec = toml::from_str(&toml_str).unwrap();
414        assert_eq!(deserialized, bs);
415        assert!(deserialized.line_width.is_none());
416        assert!(deserialized.shadow_enabled.is_none());
417        assert!(deserialized.padding_top.is_none());
418        assert!(deserialized.padding_right.is_none());
419        assert!(deserialized.padding_bottom.is_none());
420        assert!(deserialized.padding_left.is_none());
421    }
422
423    #[test]
424    fn widget_border_spec_merge_overlay_wins() {
425        let mut base = WidgetBorderSpec {
426            color: Some(Rgba::rgb(100, 100, 100)),
427            corner_radius: Some(4.0),
428            ..Default::default()
429        };
430        let overlay = WidgetBorderSpec {
431            color: Some(Rgba::rgb(200, 200, 200)),
432            ..Default::default()
433        };
434        base.merge(&overlay);
435        assert_eq!(base.color, Some(Rgba::rgb(200, 200, 200)));
436        // base corner_radius preserved since overlay corner_radius is None
437        assert_eq!(base.corner_radius, Some(4.0));
438    }
439
440    // === Per-side padding and its TOML shorthand ===
441
442    #[test]
443    fn padding_horizontal_shorthand_sets_left_and_right_only() {
444        let bs: WidgetBorderSpec = toml::from_str("padding_horizontal_px = 10").unwrap();
445        assert_eq!(bs.padding_left, Some(10.0));
446        assert_eq!(bs.padding_right, Some(10.0));
447        assert_eq!(bs.padding_top, None);
448        assert_eq!(bs.padding_bottom, None);
449    }
450
451    #[test]
452    fn padding_vertical_shorthand_states_a_zero() {
453        let bs: WidgetBorderSpec = toml::from_str("padding_vertical_px = 0.0").unwrap();
454        assert_eq!(bs.padding_top, Some(0.0));
455        assert_eq!(bs.padding_bottom, Some(0.0));
456        assert_eq!(bs.padding_left, None);
457        assert_eq!(bs.padding_right, None);
458    }
459
460    #[test]
461    fn an_axis_key_with_one_of_its_sides_is_rejected_naming_the_table_and_both_keys() {
462        let src = "[light.button.border]\npadding_horizontal_px = 10\npadding_left_px = 4\n";
463        let err = toml::from_str::<toml::Table>(src)
464            .ok()
465            .and_then(|t| t.get("light").cloned())
466            .and_then(|l| l.get("button").cloned())
467            .and_then(|b| b.get("border").cloned())
468            .map(|border| border.try_into::<WidgetBorderSpec>())
469            .expect("the table parses as TOML")
470            .expect_err("an axis key with one of its sides must be rejected")
471            .to_string();
472        assert!(err.contains("padding_horizontal_px"), "{err}");
473        assert!(err.contains("padding_left_px"), "{err}");
474
475        // Through a whole theme, where the error also names the table.
476        let theme = format!("name = \"T\"\n{src}");
477        let err = crate::Theme::from_toml(&theme)
478            .expect_err("the theme must not load")
479            .to_string();
480        assert!(err.contains("padding_horizontal_px"), "{err}");
481        assert!(err.contains("padding_left_px"), "{err}");
482        assert!(err.contains("light.button.border"), "{err}");
483    }
484
485    #[test]
486    fn the_vertical_axis_key_with_a_side_is_rejected_too() {
487        let err =
488            toml::from_str::<WidgetBorderSpec>("padding_vertical_px = 2\npadding_bottom_px = 3")
489                .expect_err("rejected")
490                .to_string();
491        assert!(err.contains("padding_vertical_px"), "{err}");
492        assert!(err.contains("padding_bottom_px"), "{err}");
493    }
494
495    #[test]
496    fn serialisation_writes_sides_never_the_shorthand() {
497        let bs: WidgetBorderSpec =
498            toml::from_str("padding_horizontal_px = 10\npadding_top_px = 3").unwrap();
499        let out = toml::to_string(&bs).unwrap();
500        assert!(out.contains("padding_left_px = 10"), "{out}");
501        assert!(out.contains("padding_right_px = 10"), "{out}");
502        assert!(out.contains("padding_top_px = 3"), "{out}");
503        assert!(!out.contains("padding_horizontal_px"), "{out}");
504        assert!(!out.contains("padding_bottom_px"), "{out}");
505        let back: WidgetBorderSpec = toml::from_str(&out).unwrap();
506        assert_eq!(back, bs);
507    }
508
509    #[test]
510    fn a_readers_left_side_over_a_presets_shorthand_wins_for_left_only() {
511        let mut preset: WidgetBorderSpec = toml::from_str("padding_horizontal_px = 10").unwrap();
512        let reader = WidgetBorderSpec {
513            padding_left: Some(4.0),
514            ..Default::default()
515        };
516        preset.merge(&reader);
517        assert_eq!(preset.padding_left, Some(4.0));
518        assert_eq!(preset.padding_right, Some(10.0));
519        assert_eq!(preset.padding_top, None);
520        assert_eq!(preset.padding_bottom, None);
521    }
522
523    // === Resolved border tests ===
524
525    #[test]
526    fn resolved_border_struct_literals_compile() {
527        // Field-name compile guard: any rename/remove breaks these literals.
528        let defaults = ResolvedDefaultsBorder {
529            color: Rgba::new(0, 0, 0, 0),
530            corner_radius: 0.0,
531            corner_radius_lg: 0.0,
532            line_width: 0.0,
533            opacity: 0.0,
534            shadow_enabled: false,
535        };
536        assert_eq!(defaults.corner_radius_lg, 0.0);
537        let widget = ResolvedWidgetBorder {
538            color: Rgba::new(0, 0, 0, 0),
539            corner_radius: 0.0,
540            line_width: 0.0,
541            shadow_enabled: false,
542            padding: ResolvedPadding {
543                top: None,
544                right: Some(0.0),
545                bottom: None,
546                left: Some(4.0),
547            },
548        };
549        assert_eq!(widget.padding.left, Some(4.0));
550        assert_eq!(widget.padding.top, None);
551        assert_eq!(ResolvedPadding::default().right, None);
552    }
553
554    /// A resolved border serialised without its padding (by a version that
555    /// had none, or by hand) deserialises with every side unstated.
556    #[test]
557    fn resolved_widget_border_without_padding_deserialises_unstated() {
558        let src =
559            "color = \"#000000\"\ncorner_radius = 2.0\nline_width = 1.0\nshadow_enabled = false\n";
560        let border: ResolvedWidgetBorder = toml::from_str(src).unwrap();
561        assert_eq!(border.padding, ResolvedPadding::default());
562    }
563
564    // === padding_outside tests ===
565
566    fn bordered(line_width: f32, padding: [Option<f32>; 4]) -> ResolvedWidgetBorder {
567        let [top, right, bottom, left] = padding;
568        ResolvedWidgetBorder {
569            color: Rgba::rgb(0, 0, 0),
570            corner_radius: 0.0,
571            line_width,
572            shadow_enabled: false,
573            padding: ResolvedPadding {
574                top,
575                right,
576                bottom,
577                left,
578            },
579        }
580    }
581
582    #[test]
583    fn padding_outside_adds_the_line_width_to_each_stated_side() {
584        let border = bordered(1.5, [Some(4.0), Some(8.0), None, Some(0.0)]);
585        assert_eq!(
586            border.padding_outside(),
587            ResolvedPadding {
588                top: Some(5.5),
589                right: Some(9.5),
590                bottom: None,
591                left: Some(1.5),
592            }
593        );
594    }
595
596    #[test]
597    fn padding_outside_with_no_border_is_the_padding() {
598        let border = bordered(0.0, [Some(4.0), None, Some(2.0), None]);
599        assert_eq!(border.padding_outside(), border.padding);
600        assert_eq!(
601            bordered(2.0, [None; 4]).padding_outside(),
602            ResolvedPadding::default()
603        );
604    }
605
606    #[test]
607    fn padding_outside_with_a_huge_width_saturates() {
608        let border = bordered(f32::MAX, [Some(1.0), Some(f32::MAX), None, None]);
609        let padding = border.padding_outside();
610        assert_eq!(padding.top, Some(f32::MAX));
611        assert_eq!(padding.right, Some(f32::MAX));
612        assert_eq!((padding.bottom, padding.left), (None, None));
613        let side =
614            bordered(1.0, [Some(f32::INFINITY), Some(f32::NAN), None, None]).padding_outside();
615        assert_eq!(side.top, Some(f32::INFINITY));
616        assert!(side.right.is_some_and(f32::is_nan));
617    }
618}