use crate::io::ConfigRepr;
#[cfg(feature = "python")]
use crate::python::PythonError;
#[cfg(feature = "python")]
use crate::NyxError;
#[cfg(feature = "python")]
use pyo3::class::basic::CompareOp;
#[cfg(feature = "python")]
use pyo3::prelude::*;
#[cfg(feature = "python")]
use pythonize::{depythonize, pythonize};
use serde_derive::{Deserialize, Serialize};
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)]
#[cfg_attr(feature = "python", pyclass)]
#[cfg_attr(feature = "python", pyo3(module = "nyx_space.orbit_determination"))]
pub struct FltResid {
pub min_accepted: usize,
pub num_sigmas: f64,
}
#[cfg(feature = "python")]
#[pymethods]
impl FltResid {
#[new]
#[pyo3(text_signature = "(min_accepted=None, num_sigmas=None)")]
fn py_new(min_accepted: Option<usize>, num_sigmas: Option<f64>) -> Self {
let mut me = Self::default();
if let Some(min_accepted) = min_accepted {
me.min_accepted = min_accepted;
}
if let Some(num_sigmas) = num_sigmas {
me.num_sigmas = num_sigmas;
}
me
}
#[getter]
fn get_min_accepted(&self) -> usize {
self.min_accepted
}
#[setter(orbit)]
fn py_set_min_accepted(&mut self, min_accepted: usize) -> PyResult<()> {
self.min_accepted = min_accepted;
Ok(())
}
#[getter]
fn get_num_sigmas(&self) -> f64 {
self.num_sigmas
}
#[setter(orbit)]
fn py_set_num_sigmas(&mut self, num_sigmas: f64) -> PyResult<()> {
self.num_sigmas = num_sigmas;
Ok(())
}
fn __repr__(&self) -> String {
format!("{self:?}")
}
fn __str__(&self) -> String {
format!("{self:?}")
}
fn dumps(&self, py: Python) -> Result<PyObject, NyxError> {
pythonize(py, &self).map_err(|e| NyxError::CustomError { msg: e.to_string() })
}
fn __getstate__(&self, py: Python) -> Result<PyObject, NyxError> {
self.dumps(py)
}
fn __setstate__(&mut self, state: &PyAny) -> Result<(), ConfigError> {
*self =
depythonize(state).map_err(|e| ConfigError::InvalidConfig { msg: e.to_string() })?;
Ok(())
}
fn __richcmp__(&self, other: &Self, op: CompareOp) -> Result<bool, PythonError> {
match op {
CompareOp::Eq => Ok(self == other),
CompareOp::Ne => Ok(self != other),
_ => Err(PythonError::OperationError { op }),
}
}
}
impl Default for FltResid {
fn default() -> Self {
Self {
min_accepted: 10,
num_sigmas: 3.0,
}
}
}
impl ConfigRepr for FltResid {}