From d10869755250ab60469092c17421ab1ecef8a623 Mon Sep 17 00:00:00 2001 From: Rhys Lloyd Date: Wed, 18 Mar 2026 08:58:20 -0700 Subject: [PATCH] new Head constructor --- src/v0.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/v0.rs b/src/v0.rs index ef07e73..d8fb5d8 100644 --- a/src/v0.rs +++ b/src/v0.rs @@ -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( &self,