cranpose-ui 0.28.0

Composable widgets, text, layouts and input for Cranpose apps
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
// A layout node's chain of coordinators: its layout modifiers, each
// measuring the next and the last its measure policy, with the sizes and
// offsets each measure leaves on them.

use std::{
    cell::{Cell, RefCell},
    rc::Rc,
};

use cranpose_core::{NodeId, PackedU64};
use cranpose_foundation::{
    InvalidationKind, ModifierNodeContext, NodeCapabilities, PLAIN_WORDS_MAX, PlainIntrinsic,
    PlainLayoutFns, PrepareAt,
};
use cranpose_ui_layout::{AlignmentLines, Constraints, Measurables, MeasurePolicy, Placement};
use smallvec::SmallVec;

use super::{
    LayoutNodeContext, ModifierChainInputs,
    core::{Measurable, Placeable},
    inherited_alignment_lines,
    layout_child_measurable::LayoutChildMeasurable,
    policy_intrinsic,
};
use crate::{
    modifier::{Point, Rect as GeometryRect, Size},
    widgets::nodes::{IntrinsicKind, LayoutNode},
};

/// The intrinsic size `kind` names, of a measurable.
fn measurable_intrinsic(measurable: &dyn Measurable, kind: IntrinsicKind) -> f32 {
    match kind {
        IntrinsicKind::MinWidth(height) => measurable.min_intrinsic_width(height),
        IntrinsicKind::MaxWidth(height) => measurable.max_intrinsic_width(height),
        IntrinsicKind::MinHeight(width) => measurable.min_intrinsic_height(width),
        IntrinsicKind::MaxHeight(width) => measurable.max_intrinsic_height(width),
    }
}

/// The intrinsic size `kind` names, of a layout modifier around `wrapped`.
fn layout_modifier_intrinsic(
    node: &dyn cranpose_foundation::LayoutModifierNode,
    wrapped: &dyn Measurable,
    kind: IntrinsicKind,
    density: f32,
) -> f32 {
    match kind {
        IntrinsicKind::MinWidth(height) => node.min_intrinsic_width(wrapped, height, density),
        IntrinsicKind::MaxWidth(height) => node.max_intrinsic_width(wrapped, height, density),
        IntrinsicKind::MinHeight(width) => node.min_intrinsic_height(wrapped, width, density),
        IntrinsicKind::MaxHeight(width) => node.max_intrinsic_height(wrapped, width, density),
    }
}

fn plain_intrinsic(kind: IntrinsicKind) -> PlainIntrinsic {
    match kind {
        IntrinsicKind::MinWidth(height) => PlainIntrinsic::MinWidth(height),
        IntrinsicKind::MaxWidth(height) => PlainIntrinsic::MaxWidth(height),
        IntrinsicKind::MinHeight(width) => PlainIntrinsic::MinHeight(width),
        IntrinsicKind::MaxHeight(width) => PlainIntrinsic::MaxHeight(width),
    }
}

pub(super) struct CoordinatorFrame<'a> {
    measure_policy: &'a Rc<dyn MeasurePolicy>,
    scope: &'a dyn cranpose_ui_layout::MeasureScope,
    measurables: Measurables<'a>,
    child_states: &'a [LayoutChildMeasurable],
    placements: RefCell<&'a mut Vec<Placement>>,
    placement_indices: RefCell<&'a mut Vec<usize>>,
    context: RefCell<LayoutNodeContext>,
}

impl<'a> CoordinatorFrame<'a> {
    pub(super) fn new(
        measure_policy: &'a Rc<dyn MeasurePolicy>,
        scope: &'a dyn cranpose_ui_layout::MeasureScope,
        measurables: Measurables<'a>,
        child_states: &'a [LayoutChildMeasurable],
        placements: &'a mut Vec<Placement>,
        placement_indices: &'a mut Vec<usize>,
    ) -> Self {
        Self {
            measure_policy,
            scope,
            measurables,
            child_states,
            placements: RefCell::new(placements),
            placement_indices: RefCell::new(placement_indices),
            context: RefCell::new(LayoutNodeContext::new(scope.density())),
        }
    }

    pub(super) fn take_invalidations(&self) -> Vec<InvalidationKind> {
        self.context.borrow_mut().take_invalidations()
    }
}

struct CoordinatorLink<'chain, 'frame_ref, 'frame_data> {
    chain: &'chain CoordinatorChain,
    frame: &'frame_ref CoordinatorFrame<'frame_data>,
    index: usize,
    alignment_lines: Cell<AlignmentLines>,
}

impl<'chain, 'frame_ref, 'frame_data> CoordinatorLink<'chain, 'frame_ref, 'frame_data> {
    fn new(
        chain: &'chain CoordinatorChain,
        frame: &'frame_ref CoordinatorFrame<'frame_data>,
        index: usize,
    ) -> Self {
        Self {
            chain,
            frame,
            index,
            alignment_lines: Cell::default(),
        }
    }
}

impl Measurable for CoordinatorLink<'_, '_, '_> {
    fn measure(&self, constraints: Constraints) -> Placeable {
        let placeable = self.chain.measure_from(self.index, self.frame, constraints);
        self.alignment_lines.set(placeable.alignment_lines());
        placeable
    }

    fn min_intrinsic_width(&self, height: f32) -> f32 {
        self.chain
            .intrinsic_from(self.index, self.frame, IntrinsicKind::MinWidth(height))
    }

    fn max_intrinsic_width(&self, height: f32) -> f32 {
        self.chain
            .intrinsic_from(self.index, self.frame, IntrinsicKind::MaxWidth(height))
    }

    fn min_intrinsic_height(&self, width: f32) -> f32 {
        self.chain
            .intrinsic_from(self.index, self.frame, IntrinsicKind::MinHeight(width))
    }

    fn max_intrinsic_height(&self, width: f32) -> f32 {
        self.chain
            .intrinsic_from(self.index, self.frame, IntrinsicKind::MaxHeight(width))
    }
}

struct CoordinatorNode {
    modifier_index: usize,
    source: Source,
    measured_size: Cell<Size>,
    /// The constraints this node last measured under.
    measured_constraints: Cell<Constraints>,
    accumulated_offset: Cell<Point>,
}

// What a coordinator measures with. A measure runs while the applier is
// free for the children's measures, so the coordinator keeps what it needs
// of its modifier: the node, or a plain element's table and its words as
// the last sync read them, prepared for the sync's density and direction.
enum Source {
    Node(Rc<RefCell<dyn cranpose_foundation::ModifierNode>>),
    Plain {
        // `None` for a plain element that measures nothing itself.
        layout: Option<&'static PlainLayoutFns>,
        words: [u32; PLAIN_WORDS_MAX],
    },
}

// The layout modifier at an entry of a chain, as a walk reads it.
enum Found<'a> {
    Node(&'a Rc<RefCell<dyn cranpose_foundation::ModifierNode>>),
    Plain(Option<&'static PlainLayoutFns>, &'a [u32; PLAIN_WORDS_MAX]),
}

impl<'a> Found<'a> {
    fn at(chain: &'a cranpose_foundation::ModifierNodeChain, index: usize) -> Option<Self> {
        match chain.get_node_rc(index) {
            Some(node) => Some(Self::Node(node)),
            None => chain
                .plain_layout(index)
                .map(|(layout, words)| Self::Plain(layout, words)),
        }
    }

    fn source(&self, at: PrepareAt) -> Source {
        match *self {
            Self::Node(node) => Source::Node(Rc::clone(node)),
            Self::Plain(layout, words) => Source::Plain {
                layout,
                words: prepared(layout, words, at),
            },
        }
    }
}

// The words a coordinator keeps of a plain element's `words` for the
// measures `at` tells.
fn prepared(
    layout: Option<&'static PlainLayoutFns>,
    words: &[u32; PLAIN_WORDS_MAX],
    at: PrepareAt,
) -> [u32; PLAIN_WORDS_MAX] {
    layout.map_or([0; PLAIN_WORDS_MAX], |layout| layout.prepare(words, at))
}

impl CoordinatorNode {
    fn new(modifier_index: usize, source: Source) -> Self {
        Self {
            modifier_index,
            source,
            measured_size: Cell::new(Size::default()),
            measured_constraints: Cell::new(Constraints::tight(0.0, 0.0)),
            accumulated_offset: Cell::new(Point::default()),
        }
    }

    // Takes the words of the coordinator's plain element again from `chain`,
    // whose entries stand where the last walk found them.
    fn read_plain(&mut self, chain: &cranpose_foundation::ModifierNodeChain, at: PrepareAt) {
        if let Source::Plain { layout, words } = &mut self.source
            && let Some((_, found)) = chain.plain_layout(self.modifier_index)
        {
            *words = prepared(*layout, found, at);
        }
    }

    // Whether the coordinator stands for `found` at `modifier_index`: the
    // same node, or a plain element of the same measure, whose words it
    // then takes.
    fn takes(&mut self, modifier_index: usize, found: &Found<'_>, at: PrepareAt) -> bool {
        if self.modifier_index != modifier_index {
            return false;
        }
        match (&mut self.source, found) {
            (Source::Node(held), Found::Node(node)) => Rc::ptr_eq(held, node),
            (Source::Plain { layout, words }, Found::Plain(found_layout, found_words)) => {
                let same = match (*layout, *found_layout) {
                    (Some(held), Some(found)) => std::ptr::eq(held, found),
                    (None, None) => true,
                    _ => false,
                };
                if same {
                    *words = prepared(*layout, found_words, at);
                }
                same
            }
            _ => false,
        }
    }
}

// What a walk of a chain gave, with the chain revision it read: the inputs
// but the density, which the node holds, and the density's scale, which
// put the offsets on the device grid.
#[derive(Clone, Copy)]
struct SyncedInputs {
    revision: PackedU64,
    scale: f32,
    offset: Point,
    window_root: bool,
    uses_chain: bool,
}

impl SyncedInputs {
    fn of(revision: u64, inputs: ModifierChainInputs) -> Self {
        Self {
            revision: PackedU64::new(revision),
            scale: inputs.density.density(),
            offset: inputs.offset,
            window_root: inputs.window_root,
            uses_chain: inputs.uses_chain,
        }
    }

    fn inputs(self, density: crate::density::Density) -> ModifierChainInputs {
        ModifierChainInputs {
            density,
            window_root: self.window_root,
            offset: self.offset,
            uses_chain: self.uses_chain,
        }
    }
}

#[derive(Default)]
pub(super) struct CoordinatorChain {
    nodes: Vec<CoordinatorNode>,
    /// The size the node's own measure policy measured its content at.
    inner_size: Cell<Size>,
    /// The constraints the node's own measure policy last measured under.
    inner_constraints: Cell<Option<Constraints>>,
    /// The chain revision the nodes were last synced at and what the walk
    /// gave: a node whose modifiers did not change since measures again
    /// without walking its chain.
    synced: Option<SyncedInputs>,
    // Whether a measure placed the coordinators, whose rects the nodes'
    // sizes and offsets give, and whether one of them moved since the scene
    // last heard of the node.
    placed: Cell<bool>,
    moved: Cell<bool>,
}

impl CoordinatorChain {
    pub(super) fn sync(&mut self, node: &LayoutNode) -> ModifierChainInputs {
        let density = node.density();
        let chain = node.modifier_chain();
        let at = PrepareAt {
            density: density.density(),
            direction: chain.layout_direction(),
        };
        let revision = chain.revision();
        // A walk reads every entry, so it takes the changes too.
        let changed = chain.take_changed_in_place();
        if let Some(synced) = self.synced
            && synced.revision.get() == revision
            && synced.scale.to_bits() == at.density.to_bits()
        {
            // Values changed in place: the entries stand where they were,
            // and the coordinators of those entries take their words again.
            if changed != 0 {
                self.read_changed(chain.chain(), changed, at);
            }
            return synced.inputs(density);
        }
        let inputs = self.walk(node, density, at);
        self.synced = Some(SyncedInputs::of(revision, inputs));
        // Other modifiers may place other coordinators.
        self.moved.set(true);
        inputs
    }

    // Out of line: most syncs find nothing changed.
    #[inline(never)]
    fn read_changed(
        &mut self,
        chain: &cranpose_foundation::ModifierNodeChain,
        changed: u64,
        at: PrepareAt,
    ) {
        for coordinator in &mut self.nodes {
            let index = u32::try_from(coordinator.modifier_index).unwrap_or(u32::MAX);
            if changed.checked_shr(index).is_some_and(|rest| rest & 1 == 1) {
                coordinator.read_plain(chain, at);
            }
        }
    }

    /// Syncs the nodes with the layout nodes of `node`'s chain and sums
    /// its offsets.
    fn walk(
        &mut self,
        node: &LayoutNode,
        density: crate::density::Density,
        at: PrepareAt,
    ) -> ModifierChainInputs {
        let mut inputs = ModifierChainInputs {
            density,
            window_root: node.is_window_root(),
            offset: Point::default(),
            uses_chain: false,
        };
        let chain_handle = node.modifier_chain();
        if !chain_handle.has_layout_nodes() {
            return inputs;
        }

        let chain = chain_handle.chain();
        // The layout modifiers of the chain in order, with their entries,
        // which a rebuild reads again: a chain holds a few.
        let mut layouts: SmallVec<[(usize, Found<'_>); 8]> = SmallVec::new();
        chain.for_each_forward_matching(NodeCapabilities::LAYOUT, |node_ref| {
            let Some(index) = node_ref.entry_index() else {
                return;
            };
            if let Some(found) = Found::at(chain, index) {
                layouts.push((index, found));
            }
            if let Some(offset) = node_ref.plain::<crate::modifier_nodes::OffsetElement>() {
                let delta = offset.placed(at);
                inputs.offset.x += delta.x;
                inputs.offset.y += delta.y;
            }
        });

        inputs.uses_chain = !layouts.is_empty();
        let matches = layouts.len() == self.nodes.len()
            && self
                .nodes
                .iter_mut()
                .zip(&layouts)
                .all(|(candidate, (index, found))| candidate.takes(*index, found, at));
        if inputs.uses_chain && !matches {
            self.rebuild(&layouts, at);
        }
        inputs
    }

    fn rebuild(&mut self, layouts: &[(usize, Found<'_>)], at: PrepareAt) {
        let mut previous_nodes = std::mem::take(&mut self.nodes);
        // Exactly: most chains hold one layout modifier, where growth would
        // make room for four.
        self.nodes.reserve_exact(layouts.len());
        for (index, found) in layouts {
            match previous_nodes
                .iter_mut()
                .position(|candidate| candidate.takes(*index, found, at))
            {
                Some(position) => self.nodes.push(previous_nodes.swap_remove(position)),
                None => self
                    .nodes
                    .push(CoordinatorNode::new(*index, found.source(at))),
            }
        }
    }

    /// What the last measure through this chain holds for: the policy's own
    /// range, then each layout modifier from the innermost out turns its
    /// content's range into its own; any other node passes its constraints
    /// through.
    pub(super) fn measured_hold(
        &self,
        density: f32,
        policy: &dyn MeasurePolicy,
        measurables: Measurables<'_>,
    ) -> Option<cranpose_ui_layout::ConstraintsHold> {
        let inner_size = self.inner_size.get();
        let mut wrapped = cranpose_ui_layout::WrappedHold {
            size: inner_size,
            hold: self
                .inner_constraints
                .get()
                .and_then(|constraints| policy.measure_hold(measurables, constraints, inner_size)),
        };
        for node in self.nodes.iter().rev() {
            let size = node.measured_size.get();
            let constraints = node.measured_constraints.get();
            let hold = match &node.source {
                Source::Node(held) => match held.borrow().as_layout_node() {
                    Some(layout) => layout.measure_hold(density, constraints, size, wrapped),
                    None => wrapped.hold,
                },
                Source::Plain {
                    layout: Some(layout),
                    words,
                } => layout.measure_hold(words, density, constraints, size, wrapped),
                Source::Plain { layout: None, .. } => wrapped.hold,
            };
            wrapped = cranpose_ui_layout::WrappedHold { size, hold };
        }
        wrapped.hold
    }

    /// Whether the policy's last measure through this chain ignored its
    /// children's sizes. The layout modifiers around it see only its size,
    /// which then stays as it is.
    pub(super) fn ignores_child_sizes(
        &self,
        policy: &dyn MeasurePolicy,
        measurables: Measurables<'_>,
    ) -> bool {
        self.inner_constraints
            .get()
            .is_some_and(|constraints| policy.ignores_child_sizes(measurables, constraints))
    }

    pub(super) fn measure_from(
        &self,
        index: usize,
        frame: &CoordinatorFrame<'_>,
        constraints: Constraints,
    ) -> Placeable {
        let Some(node) = self.nodes.get(index) else {
            let mut placements = frame.placements.borrow_mut();
            let measurement = frame.measure_policy.measure_into(
                frame.scope,
                frame.measurables,
                constraints,
                &mut placements,
            );
            self.place(&self.inner_size, measurement.size);
            self.inner_constraints.set(Some(constraints));
            return Placeable::value(
                measurement.size.width,
                measurement.size.height,
                NodeId::default(),
            )
            .with_alignment_lines(
                inherited_alignment_lines(
                    frame.child_states,
                    &placements,
                    &mut frame.placement_indices.borrow_mut(),
                )
                .with_overrides(measurement.alignment_lines),
            );
        };

        let wrapped = CoordinatorLink::new(self, frame, index + 1);
        node.measured_constraints.set(constraints);
        let measure = |context: &mut LayoutNodeContext| match &node.source {
            Source::Node(held) => held
                .borrow()
                .as_layout_node()
                .map(|layout| layout.measure(context, &wrapped, constraints)),
            Source::Plain { layout, words } => {
                layout.map(|layout| layout.measure(words, context, &wrapped, constraints))
            }
        };
        let measured = match frame.context.try_borrow_mut() {
            Ok(mut context) => measure(&mut context),
            Err(_) => {
                let mut temp = LayoutNodeContext::new(frame.scope.density());
                let measured = measure(&mut temp);
                if let Ok(mut context) = frame.context.try_borrow_mut() {
                    for kind in temp.take_invalidations() {
                        context.invalidate(kind);
                    }
                }
                measured
            }
        };
        // A modifier that measures nothing itself passes its content's
        // measure through.
        let Some(result) = measured else {
            let placeable = wrapped.measure(constraints);
            self.place(
                &node.measured_size,
                Size {
                    width: placeable.width(),
                    height: placeable.height(),
                },
            );
            let child_accumulated = self.total_content_offset_from(index + 1);
            self.place(&node.accumulated_offset, child_accumulated);
            return placeable;
        };

        self.place(&node.measured_size, result.size);
        let local_offset = Point {
            x: result.placement_offset_x,
            y: result.placement_offset_y,
        };
        let child_accumulated = self.total_content_offset_from(index + 1);
        let accumulated = Point {
            x: local_offset.x + child_accumulated.x,
            y: local_offset.y + child_accumulated.y,
        };
        self.place(&node.accumulated_offset, accumulated);

        Placeable::value_with_offset(
            result.size.width,
            result.size.height,
            NodeId::default(),
            (accumulated.x, accumulated.y),
        )
        .with_alignment_lines(
            wrapped
                .alignment_lines
                .get()
                .translated(local_offset.y)
                .with_overrides(result.alignment_lines),
        )
    }

    pub(super) fn intrinsic_from(
        &self,
        index: usize,
        frame: &CoordinatorFrame<'_>,
        kind: IntrinsicKind,
    ) -> f32 {
        let Some(node) = self.nodes.get(index) else {
            return policy_intrinsic(frame.measure_policy.as_ref(), frame.measurables, kind);
        };
        let wrapped = CoordinatorLink::new(self, frame, index + 1);
        let density = frame.scope.density();
        match &node.source {
            Source::Node(held) => held.borrow().as_layout_node().map_or_else(
                || measurable_intrinsic(&wrapped, kind),
                |layout_node| layout_modifier_intrinsic(layout_node, &wrapped, kind, density),
            ),
            Source::Plain {
                layout: Some(layout),
                words,
            } => layout.intrinsic(words, &wrapped, plain_intrinsic(kind), density),
            Source::Plain { layout: None, .. } => measurable_intrinsic(&wrapped, kind),
        }
    }

    // Sets a size or an offset the coordinators' rects come from, noting a
    // coordinator that moved: a layer bounded by an inner coordinator
    // changes when that coordinator does, though the node's size may not.
    fn place<T: Copy + PartialEq>(&self, cell: &Cell<T>, value: T) {
        if cell.replace(value) != value {
            self.moved.set(true);
        }
    }

    // Notes that a measure placed the coordinators, and says whether one of
    // them moved since the last note.
    pub(super) fn take_moved(&self) -> bool {
        self.placed.set(true);
        self.moved.take()
    }

    // Where the last measure put the coordinator `ordinal`, relative to the
    // node drawn at its offset: for each layout modifier, from the outermost
    // in, where it was placed and its size, then the node's content. A node
    // of `node_size` without layout modifiers has its content alone, which
    // fills it. `None` before a measure placed them.
    pub(super) fn placed_rect(&self, ordinal: usize, node_size: Size) -> Option<GeometryRect> {
        let inputs = self.synced.filter(|_| self.placed.get())?;
        if !inputs.uses_chain {
            return (ordinal == 0).then(|| GeometryRect::from_size(node_size));
        }
        let content = self.total_content_offset_from(0);
        let placed = |inner_offset: Point, size: Size| GeometryRect {
            x: content.x - inner_offset.x - inputs.offset.x,
            y: content.y - inner_offset.y - inputs.offset.y,
            width: size.width,
            height: size.height,
        };
        match self.nodes.get(ordinal) {
            Some(node) => Some(placed(
                node.accumulated_offset.get(),
                node.measured_size.get(),
            )),
            None => (ordinal == self.nodes.len())
                .then(|| placed(Point::default(), self.inner_size.get())),
        }
    }

    fn total_content_offset_from(&self, index: usize) -> Point {
        self.nodes
            .get(index)
            .map_or_default(|node| node.accumulated_offset.get())
    }
}