new Head constructor

This commit is contained in:
2026-03-18 08:58:20 -07:00
parent 0cd02fbb75
commit d108697552

View File

@@ -782,6 +782,8 @@ impl Head{
pub const fn new()->Self{
Self([0;NUM_EVENT_TYPES])
}
/// Use `Head::partition_point` instead.
#[deprecated]
pub fn after_time(block:&Block,time:f64)->Self{
Self([
block.input_events.partition_point(|event|event.time<=time),
@@ -794,6 +796,20 @@ impl Head{
block.setting_events.partition_point(|event|event.time<=time),
])
}
/// Uses a binary search to initialize the head positions according to a predicate.
/// You probably want `|event_time|event_time<=time`
pub fn partition_point(block:&Block,pred:impl Fn(f64)->bool)->Self{
Self([
block.input_events.partition_point(|event|pred(event.time)),
block.output_events.partition_point(|event|pred(event.time)),
block.sound_events.partition_point(|event|pred(event.time)),
block.world_events.partition_point(|event|pred(event.time)),
block.gravity_events.partition_point(|event|pred(event.time)),
block.run_events.partition_point(|event|pred(event.time)),
block.camera_events.partition_point(|event|pred(event.time)),
block.setting_events.partition_point(|event|pred(event.time)),
])
}
// compare an event at the head of the plan to the best event collected so far.
fn collect_event<E>(
&self,