Skip to content

Commit 8f28b2d

Browse files
committed
Fix comparison with NaN for float like skymaps when making the view
1 parent 9d717cf commit 8f28b2d

1 file changed

Lines changed: 39 additions & 4 deletions

File tree

src/nested/map/img.rs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
cmp::Ordering,
23
error::Error,
34
f64::consts::PI,
45
fs::File,
@@ -388,6 +389,7 @@ where
388389
/// * `pos_convert`: to handle a different coordinate system between the skymap and the image.
389390
/// * `color_map`:
390391
/// * `color_map_func`: the color map fonction, build it using:
392+
// TODO: take in input the value coding NULL
391393
pub fn to_skymap_img<'a, P, S>(
392394
skymap: &'a S,
393395
img_size: (u16, u16),
@@ -410,8 +412,24 @@ where
410412
let first_value = iter.next().unwrap();
411413
let (min, max) = iter.fold((first_value, first_value), |(min, max), val| {
412414
(
413-
std::cmp::min_by(val, min, |a, b| a.partial_cmp(b).unwrap()),
414-
std::cmp::max_by(val, max, |a, b| a.partial_cmp(b).unwrap()),
415+
std::cmp::min_by(val, min, |a, b| {
416+
a.partial_cmp(b).unwrap_or_else(move || {
417+
if a != a {
418+
Ordering::Greater
419+
} else {
420+
Ordering::Less
421+
}
422+
})
423+
}),
424+
std::cmp::max_by(val, max, |a, b| {
425+
a.partial_cmp(b).unwrap_or_else(move || {
426+
if a != a {
427+
Ordering::Greater
428+
} else {
429+
Ordering::Less
430+
}
431+
})
432+
}),
415433
)
416434
});
417435
let (min, max) = (min.to_f64(), max.to_f64());
@@ -550,6 +568,7 @@ where
550568
/// * `pos_convert`: to handle a different coordinate system between the skymap and the image.
551569
/// * `color_map`:
552570
/// * `color_map_func`: the color map fonction, build it using:
571+
// TODO: take in input the value coding NULL
553572
pub fn to_mom_img<'a, P, M>(
554573
mom: &'a M,
555574
img_size: (u16, u16),
@@ -572,8 +591,24 @@ where
572591
let first_value = iter.next().unwrap();
573592
let (min, max) = iter.fold((first_value, first_value), |(min, max), val| {
574593
(
575-
std::cmp::min_by(val, min, |a, b| a.partial_cmp(b).unwrap()),
576-
std::cmp::max_by(val, max, |a, b| a.partial_cmp(b).unwrap()),
594+
std::cmp::min_by(val, min, |a, b| {
595+
a.partial_cmp(b).unwrap_or_else(move || {
596+
if a != a {
597+
Ordering::Greater
598+
} else {
599+
Ordering::Less
600+
}
601+
})
602+
}),
603+
std::cmp::max_by(val, max, |a, b| {
604+
a.partial_cmp(b).unwrap_or_else(move || {
605+
if a != a {
606+
Ordering::Greater
607+
} else {
608+
Ordering::Less
609+
}
610+
})
611+
}),
577612
)
578613
});
579614
let (min, max) = (min.to_f64(), max.to_f64());

0 commit comments

Comments
 (0)