Skip to content

Commit

Permalink
caught edge cases with clamps in to_grid and to_equitorial
Browse files Browse the repository at this point in the history
  • Loading branch information
LLO918 committed Sep 11, 2024
1 parent 371a4eb commit 4c646a2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/types/coords.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

use serde::{Deserialize, Serialize};
use std::f64::consts::PI;
use std::hash::{Hash, Hasher};
Expand All @@ -20,14 +21,14 @@ impl CartesianCoords {
let ra: f64;

if self.y < 0.0 {
ra = (2.0 * PI) - self.x.acos();
ra = (2.0 * PI) - self.x.clamp(-1.0, 1.0).acos();
} else {
ra = self.x.acos();
ra = self.x.clamp(-1.0, 1.0).acos();
}

EquatorialCoords {
ra,
dec: self.z.asin(),
dec: self.z.clamp(-1.0, 1.0).asin(),
}
}
}
Expand Down Expand Up @@ -67,9 +68,10 @@ impl EquatorialCoords {
}

pub fn to_grid(&self, fov_size: f64) -> EquatorialCoords {
let clamped_size = fov_size.clamp(0.02, 1);
EquatorialCoords {
ra: (self.ra / (2.0 * PI) * (1.0 - (2.0 * self.dec.abs() / PI)).powf(0.5) / fov_size).round(),
dec: (self.dec / 2.0 / fov_size).round(),
ra: (self.ra / (2.0 * PI) * (1.0 - (2.0 * self.dec.abs() / PI)).powf(0.5) / clamped_size).round(),
dec: (self.dec / (2.0 * PI) / clamped_size).round(),
}
}
}
Expand All @@ -88,5 +90,4 @@ impl Hash for EquatorialCoords {
(self.ra as i32).hash(state);
(self.dec as i32).hash(state);
}
}

}

0 comments on commit 4c646a2

Please sign in to comment.