Skip to content

Commit

Permalink
fix: l2 norm not including rect under triangle
Browse files Browse the repository at this point in the history
  • Loading branch information
tph5595 committed Jan 27, 2025
1 parent aac2861 commit 61510cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn main() -> Result<(), Box<dyn Error>> {

let landscapes = fast_pl::rpls::pairs_to_landscape(bd_paris, args.k, args.debug)?;

if args.csv != ""{
if !args.csv.is_empty() {
let mut wtr = Writer::from_path(args.csv)?;
for landscape in &landscapes {
for point in landscape {
Expand All @@ -63,6 +63,7 @@ fn main() -> Result<(), Box<dyn Error>> {
if args.graph {
return fast_pl::plot::landscape(landscapes, args.height, args.width);
}
println!("{}", fast_pl::rpls::l2_norm(&landscapes));
Ok(())
}

Expand Down
11 changes: 10 additions & 1 deletion src/rpls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
clippy::cargo,
)]

use std::cmp;
use float_ord::FloatOrd;

use crate::birthdeath::BirthDeath;
use crate::persistencelandscape;
use crate::barcode;
Expand Down Expand Up @@ -41,7 +44,13 @@ pub fn pairs_to_landscape(bd_pairs: Vec<BirthDeath>, k:usize, debug:bool) -> Res
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).abs();
(height * base) / 2.0
let triangle = (height * base) / 2.0;

let s1 = base;
let s2 = cmp::min(FloatOrd(a.y.0), FloatOrd(b.y.0)).0;
let rectangle = s1 * s2;

triangle + rectangle
}

fn landscape_norm(landscape: &[persistencelandscape::PointOrd]) -> f32 {
Expand Down

0 comments on commit 61510cd

Please sign in to comment.