Skip to content

Commit

Permalink
little speed ups
Browse files Browse the repository at this point in the history
  • Loading branch information
tph5595 committed Jan 29, 2025
1 parent b896e53 commit 6c2d751
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions src/persistencelandscape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct PersistenceMountain {
id: usize,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PointOrd {
pub x: FloatOrd<f32>,
pub y: FloatOrd<f32>,
Expand Down Expand Up @@ -139,19 +139,19 @@ fn generate_initial_events(mountains: &Vec<&mut PersistenceMountain>) -> Vec<Eve
}| {
vec![
Event {
value: *birth,
value: birth.clone(),
event_type: EventType::Up,
parent_mountain_id: *id,
parent_mountain2_id: None,
},
Event {
value: *middle,
value: middle.clone(),
event_type: EventType::Down,
parent_mountain_id: *id,
parent_mountain2_id: None,
},
Event {
value: *death,
value: death.clone(),
event_type: EventType::Death,
parent_mountain_id: *id,
parent_mountain2_id: None,
Expand Down Expand Up @@ -216,7 +216,7 @@ fn float_point_check(p1: PointOrd, p2:PointOrd)-> bool{

fn log_to_landscape(
mountain: &PersistenceMountain,
value: PointOrd,
value: & PointOrd,
landscapes: &mut [Vec<PointOrd>],
k: usize,
) {
Expand Down Expand Up @@ -267,7 +267,7 @@ fn log_to_landscape(
// );
// }
// }
landscapes[position].push(value);
landscapes[position].push(value.clone());
}
}

Expand Down Expand Up @@ -322,7 +322,7 @@ fn handle_up(state: &mut State, event: &Event){
// Add to output if needed
log_to_landscape(
state.mountains[event.parent_mountain_id],
event.value,
& event.value,
&mut state.landscapes,
state.k,
);
Expand All @@ -349,13 +349,13 @@ fn handle_intersection(state: &mut State, event: Event){
// Add to ouput if needed
log_to_landscape(
state.mountains[event.parent_mountain_id],
event.value,
& event.value,
&mut state.landscapes,
state.k,
);
log_to_landscape(
state.mountains[parent_mountain2_id],
event.value,
& event.value,
&mut state.landscapes,
state.k
);
Expand Down Expand Up @@ -413,7 +413,7 @@ fn handle_death(state: &mut State, event: &Event){
// Add to ouput if needed
log_to_landscape(
state.mountains[event.parent_mountain_id],
event.value,
& event.value,
&mut state.landscapes,
state.k,
);
Expand All @@ -440,7 +440,7 @@ fn handle_down(state: &mut State, event: &Event){
// Add to ouput if needed
log_to_landscape(
state.mountains[event.parent_mountain_id],
event.value,
& event.value,
&mut state.landscapes,
state.k,
);
Expand Down
4 changes: 2 additions & 2 deletions src/rpls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn pairs_to_landscape(bd_pairs: Vec<BirthDeath>, k:usize, debug:bool) -> Res
Ok(landscape)
}

fn area_under_line_segment(a: persistencelandscape::PointOrd, b: persistencelandscape::PointOrd) ->f32 {
fn area_under_line_segment(a: &persistencelandscape::PointOrd, b: &persistencelandscape::PointOrd) ->f32 {
let height = (a.y.0 - b.y.0).abs();
let base = a.x.0 - b.x.0;
let triangle = (height * base) / 2.0;
Expand All @@ -59,7 +59,7 @@ fn landscape_norm(landscape: &[persistencelandscape::PointOrd]) -> f32 {
landscape
.iter()
.zip(landscape.iter().skip(1))
.map(|(&a, &b)| area_under_line_segment(a, b))
.map(|(a, b)| area_under_line_segment(a, b))
.sum::<f32>()
}

Expand Down

0 comments on commit 6c2d751

Please sign in to comment.