new Head constructor
This commit is contained in:
16
src/v0.rs
16
src/v0.rs
@@ -782,6 +782,8 @@ impl Head{
|
|||||||
pub const fn new()->Self{
|
pub const fn new()->Self{
|
||||||
Self([0;NUM_EVENT_TYPES])
|
Self([0;NUM_EVENT_TYPES])
|
||||||
}
|
}
|
||||||
|
/// Use `Head::partition_point` instead.
|
||||||
|
#[deprecated]
|
||||||
pub fn after_time(block:&Block,time:f64)->Self{
|
pub fn after_time(block:&Block,time:f64)->Self{
|
||||||
Self([
|
Self([
|
||||||
block.input_events.partition_point(|event|event.time<=time),
|
block.input_events.partition_point(|event|event.time<=time),
|
||||||
@@ -794,6 +796,20 @@ impl Head{
|
|||||||
block.setting_events.partition_point(|event|event.time<=time),
|
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.
|
// compare an event at the head of the plan to the best event collected so far.
|
||||||
fn collect_event<E>(
|
fn collect_event<E>(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
Reference in New Issue
Block a user