Skip to content

Commit

Permalink
fix: ending on same point.
Browse files Browse the repository at this point in the history
  • Loading branch information
tph5595 committed Jan 28, 2025
1 parent 43fb05a commit 22af89d
Show file tree
Hide file tree
Showing 8 changed files with 2,070 additions and 30 deletions.
1,999 changes: 1,999 additions & 0 deletions dsphere-2000-2.barcodes

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions simpleBarcodes.fast_pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
0,0
1,1
1.5,0.5
2,1
3,0
,
1,0
1.5,0.5
2,0
,
75 changes: 45 additions & 30 deletions src/persistencelandscape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,16 @@ struct Event {
impl Ord for Event {
// Compare points then event_type
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
if self.value == other.value{
if self.value != other.value{
return self.value.cmp(&other.value).reverse()
}
if self.event_type != other.event_type{
return self.event_type.cmp(&other.event_type).reverse();
}
self.value.cmp(&other.value).reverse()
if self.parent_mountain_id != other.parent_mountain_id {
return self.parent_mountain_id.cmp(&other.parent_mountain_id).reverse();
}
self.parent_mountain2_id.cmp(&other.parent_mountain2_id).reverse()
}
}

Expand Down Expand Up @@ -225,20 +231,29 @@ fn log_to_landscape(
landscapes[position].last().unwrap().x.0,
value.x.0);
}
// Ensure birth/death is in bottom most landscape
// Ensure birth/death is in bottom most landscape (exception if the nearest is a tie, they
// are just dieing out of order and the other must die right after)
let below = position + 1;
if value.y.0 == 0.0 &&
below < landscapes.len() &&
! landscapes[below].is_empty(){
assert!(landscapes[below].last().unwrap().y.0 == 0.0,
"Attempting to add a birth/death ({},{}) to higher landscape {} when {} is non zero ({},{})",
value.x.0,
value.y.0,
position,
below,
landscapes[below].last().unwrap().x.0,
landscapes[below].last().unwrap().y.0,
);
if landscapes[below].last().unwrap() == landscapes[position].last().unwrap(){
// This is fine, ignore. See above comment
}
else{
// println!("{:?}", landscapes[below].last().unwrap());
// println!("{:?}", landscapes[position].last().unwrap());
// println!("{:?}", mountain);
assert!(landscapes[below].last().unwrap().y.0 == 0.0,
"Attempting to add a birth/death ({},{}) to higher landscape {} when {} is non zero ({},{})",
value.x.0,
value.y.0,
position,
below,
landscapes[below].last().unwrap().x.0,
landscapes[below].last().unwrap().y.0,
);
}
}
landscapes[position].push(value);
}
Expand Down Expand Up @@ -361,17 +376,17 @@ fn handle_intersection(state: &mut State, event: &Event) -> Option<Event>{


fn handle_death(state: &mut State, event: &Event){
let pos = state.mountains[event.parent_mountain_id]
let _pos = state.mountains[event.parent_mountain_id]
.position
.expect("Death of dead mountain");
// Check for floating point mess up on death/intersection Ordering
// TODO: What is this???? feels like a bug and a bad hotfix
let weird_q = &mut VecDeque::new();
if pos != state.status.len() - 1 {
while pos < state.status.len() - 1 {
weird_q.push_back(state.status.pop_back().unwrap());
}
}
// let weird_q = &mut VecDeque::new();
// if pos != state.status.len() - 1 {
// while pos < state.status.len() - 1 {
// weird_q.push_back(state.status.pop_back().unwrap());
// }
// }
// Add to ouput if needed
log_to_landscape(
state.mountains[event.parent_mountain_id],
Expand All @@ -383,17 +398,17 @@ fn handle_death(state: &mut State, event: &Event){
state.status.pop_back();
state.mountains[event.parent_mountain_id].position = None;
// TODO: Same here???? L -17
while !weird_q.is_empty() {
let element = weird_q.pop_back().unwrap();
state.mountains[element].position = Some(state.mountains[element].position.unwrap() - 1);
log_to_landscape(
state.mountains[element],
event.value,
&mut state.landscapes,
state.k,
);
state.status.push_back(element);
}
// while !weird_q.is_empty() {
// let element = weird_q.pop_back().unwrap();
// state.mountains[element].position = Some(state.mountains[element].position.unwrap() - 1);
// log_to_landscape(
// state.mountains[element],
// event.value,
// &mut state.landscapes,
// state.k,
// );
// state.status.push_back(element);
// }
}

fn handle_down(state: &mut State, event: &Event){
Expand Down
3 changes: 3 additions & 0 deletions src/rpls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ where
data.windows(2).all(|w| w[0] <= w[1])
}

/// # Panics
///
/// Will panic if areas are not strictly decreasing or equal
#[must_use]
pub fn l2_norm(landscapes: &[Vec<persistencelandscape::PointOrd>]) -> f64 {
let areas = landscapes
Expand Down
3 changes: 3 additions & 0 deletions test.barcodes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0 3
1 3

4 changes: 4 additions & 0 deletions test_broken.barcodes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1 8
3 7
4 9
4.2 10
2 changes: 2 additions & 0 deletions torus-2000-0.barcodes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0.0 1
0.0 2
4 changes: 4 additions & 0 deletions uniform-100-29.barcodes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0.03923958028657748 0.4454062567808664
0.014296262174615215 0.38652553119911814
0.11771808496965763 0.48622751418407106
0.01673025014984808 0.3861296058085172

0 comments on commit 22af89d

Please sign in to comment.