Skip to main content

molgfx_math/bounds/
bvh_error.rs

1//! Typed limits of the compact GPU BVH layout.
2
3use std::fmt;
4
5/// A hierarchy offset cannot be represented by the GPU node layout.
6#[derive(Clone, Copy, PartialEq, Eq, Debug)]
7pub struct BvhBuildError {
8    pub(super) resource: &'static str,
9    pub(super) index: u64,
10    pub(super) maximum: u32,
11}
12
13impl BvhBuildError {
14    /// The table whose offset overflowed.
15    #[must_use]
16    pub const fn resource(self) -> &'static str {
17        self.resource
18    }
19
20    /// The rejected offset or source row.
21    #[must_use]
22    pub const fn index(self) -> u64 {
23        self.index
24    }
25
26    /// Largest value accepted by that GPU field.
27    #[must_use]
28    pub const fn maximum(self) -> u32 {
29        self.maximum
30    }
31}
32
33impl fmt::Display for BvhBuildError {
34    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
35        write!(
36            formatter,
37            "{} index {} exceeds the GPU limit {}",
38            self.resource, self.index, self.maximum
39        )
40    }
41}
42
43impl std::error::Error for BvhBuildError {}