Skip to content

Commit

Permalink
Add documentation of ClipBic
Browse files Browse the repository at this point in the history
Refer to Arxiv paper and mention bicyclic semigroups.
  • Loading branch information
raphlinus committed Oct 6, 2023
1 parent 79d4fd9 commit b46609d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/encoding/src/clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
use bytemuck::{Pod, Zeroable};

/// Clip stack element.
///
/// This is the bicyclic semigroup, a monoid useful for representing
/// stack depth. There is considerably more detail in the draft paper
/// [Fast GPU bounding boxes on tree-structured scenes].
///
/// [Fast GPU bounding boxes on tree-structured scenes]: https://arxiv.org/abs/2205.11659
#[derive(Copy, Clone, Pod, Zeroable, Debug, Default)]
#[repr(C)]
pub struct ClipBic {
/// When interpreted as a stack operation, the number of pop operations.
pub a: u32,
/// When interpreted as a stack operation, the number of push operations.
pub b: u32,
}

Expand Down Expand Up @@ -47,6 +55,12 @@ impl ClipBic {
ClipBic { a, b }
}

/// The bicyclic semigroup operation.
///
/// This operation is associative. When interpreted as a stack
/// operation, it represents doing the pops of `self`, the pushes of
/// `self`, the pops of `other`, and the pushes of `other`. The middle
/// two can cancel each other out.
pub fn combine(self, other: ClipBic) -> Self {
let m = self.b.min(other.a);
ClipBic::new(self.a + other.a - m, self.b + other.b - m)
Expand Down

0 comments on commit b46609d

Please sign in to comment.