polygeo-core 0.1.0

Proof-bearing native topology core for PolyGeo
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
//! Admitted topology, capabilities, incidence, subsets, and halfedge surfaces.

pub use crate::complex::{CandidateInput, ComplexCore as Complex};
pub use crate::evidence::{
    CodimensionOneRegularCapability, ConnectedCapability, ConnectedView, DiskView,
    OrientedCapability, OrientedView, RegularView, SimplicialCapability,
    TriangleManifoldCapability, TriangleView, WithBoundaryCapability, WithBoundaryView,
    WithoutBoundaryCapability, WithoutBoundaryView,
};
pub use crate::halfedge::{
    Edge, ExteriorHalfedge, FaceKind, FaceOrbit, Halfedge, HalfedgeInput,
    HalfedgeSurfaceCore as HalfedgeSurface, MaterialBoundaryHalfedge, MaterialFace,
    OrbitMaterialization, OrbitMaterializationParts, Vertex,
};
pub use crate::incidence::{
    Basis, BoundaryRef, CanonicalBoundary, ChainView, CoefficientSlice, ExactEntries,
};
pub use crate::subset::{CanonicalSelection as Selection, SimplexSubset as Subset, SubsetBuilder};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum TopologyErrorKind {
    CandidateShape,
    EmptyMaximalSimplices,
    NegativeIndex,
    IndexOverflow,
    RepeatedVertex,
    DuplicateMaximalSimplex,
    VertexExtent,
    CountOverflow,
    Allocation,
    MaskShape,
    MaskIndexOutside,
    SelectionNotStrict,
    SelectionIndexOutside,
    DegreeOutside,
    TriangleDimension,
    NotPure,
    CodimensionOneIncidence,
    VertexLink,
    Orientation,
    Disconnected,
    BoundaryPresent,
    BoundaryAbsent,
    DiskBoundaryComponents,
    DiskEulerCharacteristic,
    CapabilityNotAdmitted,
    OwnerMismatch,
    HalfedgeShape,
    HalfedgeRange,
    HalfedgePermutation,
    TwinLaw,
    ExteriorInconsistency,
    BoundaryCycle,
    ConversionNotSimplicial,
    CorrespondenceLaw,
    InternalInvariant,
}

/// Bounded structured counterexample carried across the language boundary.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum TopologyDetails {
    None,
    NegativeIndex {
        value: i128,
    },
    IndexOverflow {
        value: u128,
    },
    RepeatedVertex {
        vertex: usize,
    },
    VertexExtent {
        declared: usize,
        required: usize,
    },
    Degree {
        degree: usize,
    },
    ActualDimension {
        actual_dimension: usize,
    },
    Vertex {
        vertex: usize,
    },
    Incidence {
        degree: usize,
        simplex: usize,
        cofaces: usize,
    },
    CodimensionOneSimplex {
        codimension_one_simplex: usize,
    },
    UnreachableVertex {
        unreachable_vertex: usize,
    },
    BoundaryComponents {
        boundary_components: usize,
    },
    EulerCharacteristic {
        euler_characteristic: i128,
    },
    Capability {
        capability: &'static str,
    },
    HalfedgeEntry {
        relation: &'static str,
        halfedge: usize,
        value: usize,
        bound: usize,
    },
    Twin {
        halfedge: usize,
        twin: usize,
        twin_back: usize,
    },
    Exterior {
        halfedge: usize,
        related: usize,
    },
}

/// Scalar value in the stable named-field projection of topology details.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum TopologyDetailValue {
    Signed(i128),
    Unsigned(u128),
    Index(usize),
    Text(&'static str),
}

/// One named scalar in the stable projection of a topology counterexample.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TopologyDetailField {
    name: &'static str,
    value: TopologyDetailValue,
}

impl TopologyDetailField {
    #[must_use]
    pub const fn name(self) -> &'static str {
        self.name
    }

    #[must_use]
    pub const fn value(self) -> TopologyDetailValue {
        self.value
    }
}

impl TopologyDetails {
    /// Project variant-specific details into one adapter-facing field schema.
    // Keeping this one exhaustive match intact makes field names reviewable as
    // a single schema and prevents adapters from rebuilding variant knowledge.
    #[expect(
        clippy::too_many_lines,
        reason = "one exhaustive adapter schema keeps variant fields reviewable"
    )]
    pub fn fields(self) -> impl Iterator<Item = TopologyDetailField> {
        let field = |name, value| Some(TopologyDetailField { name, value });
        let none = None;
        match self {
            Self::None => [none, none, none, none],
            Self::NegativeIndex { value } => [
                field("value", TopologyDetailValue::Signed(value)),
                none,
                none,
                none,
            ],
            Self::IndexOverflow { value } => [
                field("value", TopologyDetailValue::Unsigned(value)),
                none,
                none,
                none,
            ],
            Self::RepeatedVertex { vertex } | Self::Vertex { vertex } => [
                field("vertex", TopologyDetailValue::Index(vertex)),
                none,
                none,
                none,
            ],
            Self::VertexExtent { declared, required } => [
                field("declared", TopologyDetailValue::Index(declared)),
                field("required", TopologyDetailValue::Index(required)),
                none,
                none,
            ],
            Self::Degree { degree } => [
                field("degree", TopologyDetailValue::Index(degree)),
                none,
                none,
                none,
            ],
            Self::ActualDimension { actual_dimension } => [
                field(
                    "actual_dimension",
                    TopologyDetailValue::Index(actual_dimension),
                ),
                none,
                none,
                none,
            ],
            Self::Incidence {
                degree,
                simplex,
                cofaces,
            } => [
                field("degree", TopologyDetailValue::Index(degree)),
                field("simplex", TopologyDetailValue::Index(simplex)),
                field("cofaces", TopologyDetailValue::Index(cofaces)),
                none,
            ],
            Self::CodimensionOneSimplex {
                codimension_one_simplex,
            } => [
                field(
                    "codimension_one_simplex",
                    TopologyDetailValue::Index(codimension_one_simplex),
                ),
                none,
                none,
                none,
            ],
            Self::UnreachableVertex { unreachable_vertex } => [
                field(
                    "unreachable_vertex",
                    TopologyDetailValue::Index(unreachable_vertex),
                ),
                none,
                none,
                none,
            ],
            Self::BoundaryComponents {
                boundary_components,
            } => [
                field(
                    "boundary_components",
                    TopologyDetailValue::Index(boundary_components),
                ),
                none,
                none,
                none,
            ],
            Self::EulerCharacteristic {
                euler_characteristic,
            } => [
                field(
                    "euler_characteristic",
                    TopologyDetailValue::Signed(euler_characteristic),
                ),
                none,
                none,
                none,
            ],
            Self::Capability { capability } => [
                field("capability", TopologyDetailValue::Text(capability)),
                none,
                none,
                none,
            ],
            Self::HalfedgeEntry {
                relation,
                halfedge,
                value,
                bound,
            } => [
                field("relation", TopologyDetailValue::Text(relation)),
                field("halfedge", TopologyDetailValue::Index(halfedge)),
                field("value", TopologyDetailValue::Index(value)),
                field("bound", TopologyDetailValue::Index(bound)),
            ],
            Self::Twin {
                halfedge,
                twin,
                twin_back,
            } => [
                field("halfedge", TopologyDetailValue::Index(halfedge)),
                field("twin", TopologyDetailValue::Index(twin)),
                field("twin_back", TopologyDetailValue::Index(twin_back)),
                none,
            ],
            Self::Exterior { halfedge, related } => [
                field("halfedge", TopologyDetailValue::Index(halfedge)),
                field("related", TopologyDetailValue::Index(related)),
                none,
                none,
            ],
        }
        .into_iter()
        .flatten()
    }
}

/// Stable reason, message, and optional mathematical counterexample.

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TopologyError {
    kind: TopologyErrorKind,
    details: TopologyDetails,
}

#[expect(
    non_upper_case_globals,
    reason = "legacy error constants retain their established public spelling"
)]
impl TopologyError {
    pub const CandidateShape: Self = Self::plain(TopologyErrorKind::CandidateShape);
    pub const EmptyMaximalSimplices: Self = Self::plain(TopologyErrorKind::EmptyMaximalSimplices);
    pub const NegativeIndex: Self = Self::plain(TopologyErrorKind::NegativeIndex);
    pub const IndexOverflow: Self = Self::plain(TopologyErrorKind::IndexOverflow);
    pub const RepeatedVertex: Self = Self::plain(TopologyErrorKind::RepeatedVertex);
    pub const DuplicateMaximalSimplex: Self =
        Self::plain(TopologyErrorKind::DuplicateMaximalSimplex);
    pub const VertexExtent: Self = Self::plain(TopologyErrorKind::VertexExtent);
    pub const CountOverflow: Self = Self::plain(TopologyErrorKind::CountOverflow);
    /// A fallible topology-buffer reservation failed.
    ///
    /// This does not promise recovery from allocator or process aborts outside
    /// Rust's fallible reservation APIs.
    pub const Allocation: Self = Self::plain(TopologyErrorKind::Allocation);
    pub const MaskShape: Self = Self::plain(TopologyErrorKind::MaskShape);
    pub const MaskIndexOutside: Self = Self::plain(TopologyErrorKind::MaskIndexOutside);
    pub const SelectionNotStrict: Self = Self::plain(TopologyErrorKind::SelectionNotStrict);
    pub const SelectionIndexOutside: Self = Self::plain(TopologyErrorKind::SelectionIndexOutside);
    pub const DegreeOutside: Self = Self::plain(TopologyErrorKind::DegreeOutside);
    pub const TriangleDimension: Self = Self::plain(TopologyErrorKind::TriangleDimension);
    pub const NotPure: Self = Self::plain(TopologyErrorKind::NotPure);
    pub const CodimensionOneIncidence: Self =
        Self::plain(TopologyErrorKind::CodimensionOneIncidence);
    pub const VertexLink: Self = Self::plain(TopologyErrorKind::VertexLink);
    pub const Orientation: Self = Self::plain(TopologyErrorKind::Orientation);
    pub const Disconnected: Self = Self::plain(TopologyErrorKind::Disconnected);
    pub const BoundaryPresent: Self = Self::plain(TopologyErrorKind::BoundaryPresent);
    pub const BoundaryAbsent: Self = Self::plain(TopologyErrorKind::BoundaryAbsent);
    pub const DiskBoundaryComponents: Self = Self::plain(TopologyErrorKind::DiskBoundaryComponents);
    pub const DiskEulerCharacteristic: Self =
        Self::plain(TopologyErrorKind::DiskEulerCharacteristic);
    pub const CapabilityNotAdmitted: Self = Self::plain(TopologyErrorKind::CapabilityNotAdmitted);
    pub const OwnerMismatch: Self = Self::plain(TopologyErrorKind::OwnerMismatch);
    pub const HalfedgeShape: Self = Self::plain(TopologyErrorKind::HalfedgeShape);
    pub const HalfedgePermutation: Self = Self::plain(TopologyErrorKind::HalfedgePermutation);
    pub const TwinLaw: Self = Self::plain(TopologyErrorKind::TwinLaw);
    pub const ExteriorInconsistency: Self = Self::plain(TopologyErrorKind::ExteriorInconsistency);
    pub const BoundaryCycle: Self = Self::plain(TopologyErrorKind::BoundaryCycle);
    pub const ConversionNotSimplicial: Self =
        Self::plain(TopologyErrorKind::ConversionNotSimplicial);
    pub const CorrespondenceLaw: Self = Self::plain(TopologyErrorKind::CorrespondenceLaw);
    pub const InternalInvariant: Self = Self::plain(TopologyErrorKind::InternalInvariant);

    const fn plain(kind: TopologyErrorKind) -> Self {
        Self {
            kind,
            details: TopologyDetails::None,
        }
    }

    #[must_use]
    pub const fn negative_index(value: i128) -> Self {
        Self {
            kind: TopologyErrorKind::NegativeIndex,
            details: TopologyDetails::NegativeIndex { value },
        }
    }

    #[must_use]
    pub const fn index_overflow(value: u128) -> Self {
        Self {
            kind: TopologyErrorKind::IndexOverflow,
            details: TopologyDetails::IndexOverflow { value },
        }
    }

    #[must_use]
    pub const fn repeated_vertex(vertex: usize) -> Self {
        Self {
            kind: TopologyErrorKind::RepeatedVertex,
            details: TopologyDetails::RepeatedVertex { vertex },
        }
    }

    #[must_use]
    pub const fn vertex_extent(declared: usize, required: usize) -> Self {
        Self {
            kind: TopologyErrorKind::VertexExtent,
            details: TopologyDetails::VertexExtent { declared, required },
        }
    }

    #[must_use]
    pub const fn degree_outside(degree: usize) -> Self {
        Self {
            kind: TopologyErrorKind::DegreeOutside,
            details: TopologyDetails::Degree { degree },
        }
    }

    #[must_use]
    pub const fn triangle_dimension(actual_dimension: usize) -> Self {
        Self {
            kind: TopologyErrorKind::TriangleDimension,
            details: TopologyDetails::ActualDimension { actual_dimension },
        }
    }

    #[must_use]
    pub const fn not_pure(vertex: usize) -> Self {
        Self {
            kind: TopologyErrorKind::NotPure,
            details: TopologyDetails::Vertex { vertex },
        }
    }

    #[must_use]
    pub const fn codimension_one_incidence(degree: usize, simplex: usize, cofaces: usize) -> Self {
        Self {
            kind: TopologyErrorKind::CodimensionOneIncidence,
            details: TopologyDetails::Incidence {
                degree,
                simplex,
                cofaces,
            },
        }
    }

    #[must_use]
    pub const fn vertex_link(vertex: usize) -> Self {
        Self {
            kind: TopologyErrorKind::VertexLink,
            details: TopologyDetails::Vertex { vertex },
        }
    }

    #[must_use]
    pub const fn orientation(codimension_one_simplex: usize) -> Self {
        Self {
            kind: TopologyErrorKind::Orientation,
            details: TopologyDetails::CodimensionOneSimplex {
                codimension_one_simplex,
            },
        }
    }

    #[must_use]
    pub const fn disconnected(unreachable_vertex: usize) -> Self {
        Self {
            kind: TopologyErrorKind::Disconnected,
            details: TopologyDetails::UnreachableVertex { unreachable_vertex },
        }
    }

    #[must_use]
    pub const fn disk_boundary_components(boundary_components: usize) -> Self {
        Self {
            kind: TopologyErrorKind::DiskBoundaryComponents,
            details: TopologyDetails::BoundaryComponents {
                boundary_components,
            },
        }
    }

    #[must_use]
    pub const fn disk_euler_characteristic(euler_characteristic: i128) -> Self {
        Self {
            kind: TopologyErrorKind::DiskEulerCharacteristic,
            details: TopologyDetails::EulerCharacteristic {
                euler_characteristic,
            },
        }
    }

    #[must_use]
    pub const fn boundary_present(codimension_one_simplex: usize) -> Self {
        Self {
            kind: TopologyErrorKind::BoundaryPresent,
            details: TopologyDetails::CodimensionOneSimplex {
                codimension_one_simplex,
            },
        }
    }

    #[must_use]
    pub const fn capability_not_admitted(capability: &'static str) -> Self {
        Self {
            kind: TopologyErrorKind::CapabilityNotAdmitted,
            details: TopologyDetails::Capability { capability },
        }
    }

    #[must_use]
    pub const fn halfedge_range(
        relation: &'static str,
        halfedge: usize,
        value: usize,
        bound: usize,
    ) -> Self {
        Self {
            kind: TopologyErrorKind::HalfedgeRange,
            details: TopologyDetails::HalfedgeEntry {
                relation,
                halfedge,
                value,
                bound,
            },
        }
    }

    #[must_use]
    pub const fn halfedge_permutation(
        relation: &'static str,
        halfedge: usize,
        value: usize,
        bound: usize,
    ) -> Self {
        Self {
            kind: TopologyErrorKind::HalfedgePermutation,
            details: TopologyDetails::HalfedgeEntry {
                relation,
                halfedge,
                value,
                bound,
            },
        }
    }

    #[must_use]
    pub const fn twin_law(halfedge: usize, twin: usize, twin_back: usize) -> Self {
        Self {
            kind: TopologyErrorKind::TwinLaw,
            details: TopologyDetails::Twin {
                halfedge,
                twin,
                twin_back,
            },
        }
    }

    #[must_use]
    pub const fn exterior_inconsistency(halfedge: usize, related: usize) -> Self {
        Self {
            kind: TopologyErrorKind::ExteriorInconsistency,
            details: TopologyDetails::Exterior { halfedge, related },
        }
    }

    #[must_use]
    pub const fn boundary_cycle(halfedge: usize, related: usize) -> Self {
        Self {
            kind: TopologyErrorKind::BoundaryCycle,
            details: TopologyDetails::Exterior { halfedge, related },
        }
    }

    #[must_use]
    pub const fn details(self) -> TopologyDetails {
        self.details
    }
}

impl TopologyError {
    /// Stable machine-readable reason class for adapter translation.
    #[must_use]
    pub const fn reason(self) -> &'static str {
        match self.kind {
            TopologyErrorKind::CandidateShape => "candidate_shape",
            TopologyErrorKind::EmptyMaximalSimplices => "empty_maximal_simplices",
            TopologyErrorKind::NegativeIndex => "negative_index",
            TopologyErrorKind::IndexOverflow => "index_overflow",
            TopologyErrorKind::RepeatedVertex => "repeated_vertex",
            TopologyErrorKind::DuplicateMaximalSimplex => "duplicate_maximal_simplex",
            TopologyErrorKind::VertexExtent => "vertex_extent",
            TopologyErrorKind::CountOverflow => "count_overflow",
            TopologyErrorKind::Allocation => "allocation",
            TopologyErrorKind::MaskShape => "mask_shape",
            TopologyErrorKind::MaskIndexOutside => "mask_index_outside",
            TopologyErrorKind::SelectionNotStrict => "selection_not_strict",
            TopologyErrorKind::SelectionIndexOutside => "selection_index_outside",
            TopologyErrorKind::DegreeOutside => "degree_outside",
            TopologyErrorKind::TriangleDimension => "triangle_dimension",
            TopologyErrorKind::NotPure => "not_pure",
            TopologyErrorKind::CodimensionOneIncidence => "codimension_one_incidence",
            TopologyErrorKind::VertexLink => "vertex_link",
            TopologyErrorKind::Orientation => "orientation",
            TopologyErrorKind::Disconnected => "disconnected",
            TopologyErrorKind::BoundaryPresent => "boundary_present",
            TopologyErrorKind::BoundaryAbsent => "boundary_absent",
            TopologyErrorKind::DiskBoundaryComponents => "disk_boundary_components",
            TopologyErrorKind::DiskEulerCharacteristic => "disk_euler_characteristic",
            TopologyErrorKind::CapabilityNotAdmitted => "capability_not_admitted",
            TopologyErrorKind::OwnerMismatch => "owner_mismatch",
            TopologyErrorKind::HalfedgeShape => "halfedge_shape",
            TopologyErrorKind::HalfedgeRange => "halfedge_range",
            TopologyErrorKind::HalfedgePermutation => "halfedge_permutation",
            TopologyErrorKind::TwinLaw => "twin_law",
            TopologyErrorKind::ExteriorInconsistency => "exterior_inconsistency",
            TopologyErrorKind::BoundaryCycle => "boundary_cycle",
            TopologyErrorKind::ConversionNotSimplicial => "conversion_not_simplicial",
            TopologyErrorKind::CorrespondenceLaw => "correspondence_law",
            TopologyErrorKind::InternalInvariant => "internal_invariant",
        }
    }

    const fn message(self) -> &'static str {
        match self.kind {
            TopologyErrorKind::CandidateShape => {
                "candidate storage does not match its declared shape"
            }
            TopologyErrorKind::EmptyMaximalSimplices => {
                "maximal simplices must be a nonempty matrix"
            }
            TopologyErrorKind::NegativeIndex => "vertex indices must be nonnegative",
            TopologyErrorKind::IndexOverflow => "vertex index is outside the native index domain",
            TopologyErrorKind::RepeatedVertex => "a simplex cannot repeat a vertex",
            TopologyErrorKind::DuplicateMaximalSimplex => "duplicate maximal simplex identity",
            TopologyErrorKind::VertexExtent => "vertex_count does not contain every index",
            TopologyErrorKind::CountOverflow => "topology size exceeds the supported count domain",
            TopologyErrorKind::Allocation => "a fallible topology buffer reservation failed",
            TopologyErrorKind::MaskShape => {
                "packed mask does not align with canonical degree counts"
            }
            TopologyErrorKind::MaskIndexOutside => "mask index is outside its canonical degree",
            TopologyErrorKind::SelectionNotStrict => {
                "selection indices must be strictly increasing"
            }
            TopologyErrorKind::SelectionIndexOutside => {
                "selection index is outside its degree basis"
            }
            TopologyErrorKind::DegreeOutside => "degree is outside the complex",
            TopologyErrorKind::TriangleDimension => {
                "triangle-manifold refinement requires dimension two"
            }
            TopologyErrorKind::NotPure => "codimension-one regular input must be pure",
            TopologyErrorKind::CodimensionOneIncidence => {
                "every codimension-one simplex needs one or two top cofaces"
            }
            TopologyErrorKind::VertexLink => "a vertex link must be one path or one cycle",
            TopologyErrorKind::Orientation => "top-simplex orientations are not coherent",
            TopologyErrorKind::Disconnected => "the complex is disconnected",
            TopologyErrorKind::BoundaryPresent => "the complex has a nonempty topological boundary",
            TopologyErrorKind::BoundaryAbsent => "the complex has an empty topological boundary",
            TopologyErrorKind::DiskBoundaryComponents => {
                "a disk boundary must have exactly one connected component"
            }
            TopologyErrorKind::DiskEulerCharacteristic => {
                "a disk must have Euler characteristic one"
            }
            TopologyErrorKind::CapabilityNotAdmitted => {
                "the required capability has not been admitted"
            }
            TopologyErrorKind::OwnerMismatch => "values belong to different admitted complexes",
            TopologyErrorKind::HalfedgeShape => {
                "next and twin storage must match the declared halfedge count"
            }
            TopologyErrorKind::HalfedgeRange => {
                "a halfedge relation points outside its admitted domain"
            }
            TopologyErrorKind::HalfedgePermutation => "a halfedge relation is not a permutation",
            TopologyErrorKind::TwinLaw => "twin must be a fixed-point-free involution",
            TopologyErrorKind::ExteriorInconsistency => {
                "exterior face classification is inconsistent"
            }
            TopologyErrorKind::BoundaryCycle => {
                "exterior face orbits do not define disjoint boundary cycles"
            }
            TopologyErrorKind::ConversionNotSimplicial => {
                "halfedge presentation has no admitted simplicial reverse conversion"
            }
            TopologyErrorKind::CorrespondenceLaw => {
                "signed basis correspondence does not commute with the boundary"
            }
            TopologyErrorKind::InternalInvariant => "internal canonical topology invariant failed",
        }
    }
}

impl std::fmt::Display for TopologyError {
    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        formatter.write_str(self.message())
    }
}

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