use super::Band;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct IsophoteSample {
pub radius_arcsec: f64,
pub axis_ratio: f64,
pub position_angle_deg: f64,
}
pub trait IsophoteSeries {
fn isophote_samples(&self, band: Band) -> Option<&[IsophoteSample]>;
}
#[cfg(test)]
mod tests {
use super::*;
struct CheapTier {
samples: [IsophoteSample; 2],
}
impl IsophoteSeries for CheapTier {
fn isophote_samples(&self, _band: Band) -> Option<&[IsophoteSample]> {
Some(&self.samples)
}
}
#[test]
fn cheap_tier_returns_two_samples_in_radius_order() {
let s = CheapTier {
samples: [
IsophoteSample {
radius_arcsec: 1.5,
axis_ratio: 0.7,
position_angle_deg: 45.0,
},
IsophoteSample {
radius_arcsec: 4.0,
axis_ratio: 0.6,
position_angle_deg: 60.0,
},
],
};
let series = s.isophote_samples(Band::SdssR).unwrap();
assert_eq!(series.len(), 2);
assert!(series[0].radius_arcsec < series[1].radius_arcsec);
let other = s.isophote_samples(Band::GaiaG).unwrap();
assert_eq!(series.as_ptr(), other.as_ptr());
}
struct StokesTier {
r_band: Vec<IsophoteSample>,
g_band: Vec<IsophoteSample>,
}
impl IsophoteSeries for StokesTier {
fn isophote_samples(&self, band: Band) -> Option<&[IsophoteSample]> {
match band {
Band::SdssR => Some(&self.r_band),
Band::SdssG => Some(&self.g_band),
_ => None,
}
}
}
#[test]
fn stokes_tier_distinguishes_per_band_series_and_borrows() {
let s = StokesTier {
r_band: vec![
IsophoteSample {
radius_arcsec: 0.5,
axis_ratio: 0.8,
position_angle_deg: 10.0,
},
IsophoteSample {
radius_arcsec: 2.0,
axis_ratio: 0.7,
position_angle_deg: 25.0,
},
IsophoteSample {
radius_arcsec: 5.0,
axis_ratio: 0.6,
position_angle_deg: 40.0,
},
],
g_band: vec![
IsophoteSample {
radius_arcsec: 0.5,
axis_ratio: 0.85,
position_angle_deg: 12.0,
},
IsophoteSample {
radius_arcsec: 2.0,
axis_ratio: 0.75,
position_angle_deg: 28.0,
},
],
};
let r = s.isophote_samples(Band::SdssR).unwrap();
assert_eq!(r.len(), 3);
assert_eq!(r.as_ptr(), s.r_band.as_ptr());
let g = s.isophote_samples(Band::SdssG).unwrap();
assert_eq!(g.len(), 2);
assert_eq!(g.as_ptr(), s.g_band.as_ptr());
assert_ne!(r.as_ptr(), g.as_ptr());
assert!(s.isophote_samples(Band::SdssU).is_none());
}
}