Skip to content

Commit

Permalink
Test release 4.0-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Grégoire Henry committed Dec 6, 2023
1 parent b78c7d9 commit 68da2e7
Show file tree
Hide file tree
Showing 17 changed files with 488 additions and 303 deletions.
9 changes: 9 additions & 0 deletions examples/default-viewer-body/cfg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
window:
ambient: [0.0, 0.0, 0.0]

scene:
sun: [1.0, 0.0, 0.0]
camera: [5.0, 0.0, 0.0]

bodies:
- id: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
window:
export_frames: true

spice:
kernel: C:/data/SPICE/dart-520/mk/d520_v01.tm
frame: J2000

simulation:
start: 2022-09-26 23:14:24.000
step: 60
duration: 8136
export:
step: 60
duration: 8136
pause_after_first_iteration: true

scene:
sun:
position:
!spice
camera:
position:
!spice Earth
distance: 5.0

bodies:
- id: didymos
mesh:
shape: sphere
factor: [0.4095, 0.4005, 0.3035]
smooth: true
material:
albedo: 0.1
state:
!spice
frame_from: didymos_fixed

- id: dimorphos
mesh:
shape: sphere
factor: [0.0895165, 0.0825, 0.0575]
smooth: true
material:
albedo: 0.1
state:
!spice
origin: didymos
frame_from: dimorphos_fixed

- id: dart
mesh:
shape: cube
factor: [0.01, 0.01, 0.01]
state:
!cartesian
position: [-0.00831, 0.0832, 0.013]
reference: dimorphos
37 changes: 28 additions & 9 deletions examples/ground-based-lightcurve-didymos-spice/cfg/cfg.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
window:
export_frames: true


spice:
kernel: C:/data/SPICE/dart-520/mk/d520_v01.tm
frame: J2000

simulation:
start: 2022-09-26
start: 2022-09-26 22:30:00
step: 60
duration: 8136
export:
step: 60
duration: 8136
pause_after_first_iteration: true

scene:
spice: /Users/gregoireh/data/spice/dart/mk/d420.tm
sun:
position:
!spice
camera:
from: Earth
distance: 2
position:
!spice Earth
distance: 5.0

bodies:
- id: Didymos
- id: didymos
mesh:
shape: sphere
factor: [0.4095, 0.4005, 0.3035]
smooth: true
material:
albedo: 0.1
spin:
period: 8136
state:
!spice
frame_from: didymos_fixed

- id: dimorphos
mesh:
shape: sphere
factor: [0.0895165, 0.0825, 0.0575]
smooth: true
material:
albedo: 0.1
state:
!spice
origin: didymos
frame_from: dimorphos_fixed
25 changes: 13 additions & 12 deletions examples/ground-based-lightcurve-didymos/cfg/cfg.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
window:
export_frames: true

simulation:
step: 60
duration: 8136
export:
step: 60
duration: 8136
pause_after_first_iteration: true

scene:
camera:
!earth 2.0
sun:
type: equatorial
ra: 12h12m22.42s
dec: -01°20'20.3"
position:
!equatorial
ra: 12h12m22.42s
dec: -01°20'20.3"
camera:
!reference

bodies:
- mesh:
- id: didymos
mesh:
shape: sphere
factor: [0.4095, 0.4005, 0.3035]
smooth: true
material:
albedo: 0.1
spin:
period: 8136
state:
type: equatorial
ra: 03h21m43.477s
dec: -33°22'44.57"
!equatorial
ra: 03h21m43.477s
dec: -33°22'44.57"
5 changes: 4 additions & 1 deletion preferences.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
no_check: true
no_check: true

debug_cfg: true
debug: false
46 changes: 38 additions & 8 deletions src/body/orbit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use uom::{
str::ParseQuantityError,
};

pub type OrbitResult<T, E = AstronomicalAngleConversionError> = std::result::Result<T, E>;
pub type AstronomicalAngleResult<T, E = AstronomicalAngleConversionError> =
std::result::Result<T, E>;

#[derive(Debug, Snafu)]
pub enum AstronomicalAngleConversionError {
Expand Down Expand Up @@ -43,6 +44,13 @@ pub enum AstronomicalAngleConversionError {
},
}

pub type EquatorialResult<T, E = EquatorialError> = std::result::Result<T, E>;

#[derive(Debug, Snafu)]
pub enum EquatorialError {
DistanceNotDefined {},
}

#[derive(Debug, Clone)]
pub enum DMS {
D,
Expand Down Expand Up @@ -74,7 +82,7 @@ impl AstronomicalAngle {
Self(angle)
}

pub fn parse(s: &str) -> OrbitResult<Self> {
pub fn parse(s: &str) -> AstronomicalAngleResult<Self> {
match Self::from_value(s) {
Ok(angle) => return Ok(angle),
Err(_) => {}
Expand All @@ -95,13 +103,13 @@ impl AstronomicalAngle {
})
}

pub fn from_value(s: &str) -> OrbitResult<Self> {
pub fn from_value(s: &str) -> AstronomicalAngleResult<Self> {
s.parse::<Angle>()
.context(AngleParsingSnafu {})
.and_then(|angle| Ok(Self::new(angle)))
}

pub fn from_hms(s: &str) -> OrbitResult<Self> {
pub fn from_hms(s: &str) -> AstronomicalAngleResult<Self> {
// To find the int hours: \d{1,2}h
// To find the int minutes: \d{1,2}m
// To find the float seconds: [+-]?(\d+([.]\d*)?([eE][+-]?\d+)?|[.]\d+([eE][+-]?\d+)?)s
Expand Down Expand Up @@ -136,7 +144,7 @@ impl AstronomicalAngle {
Ok(Self::new(Angle::new::<radian>(radians)))
}

pub fn from_dms(s: &str) -> OrbitResult<Self> {
pub fn from_dms(s: &str) -> AstronomicalAngleResult<Self> {
// To find the int degrees: [+-]?\d{1,2}°
// To find the int minutes: \d{1,2}'
// To find the float seconds: [+-]?(\d+([.]\d*)?([eE][+-]?\d+)?|[.]\d+([eE][+-]?\d+)?)"
Expand Down Expand Up @@ -175,7 +183,7 @@ impl AstronomicalAngle {
impl FromStr for AstronomicalAngle {
type Err = AstronomicalAngleConversionError;

fn from_str(s: &str) -> OrbitResult<Self> {
fn from_str(s: &str) -> AstronomicalAngleResult<Self> {
Self::parse(s)
}
}
Expand Down Expand Up @@ -227,16 +235,38 @@ orientation: [
*/
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
pub struct Equatorial {
#[serde(default)]
pub ra: AstronomicalAngle,

#[serde(default)]
pub dec: AstronomicalAngle,

#[serde(default)]
pub distance: Option<Float>,
}

impl Equatorial {
pub fn new(ra: AstronomicalAngle, dec: AstronomicalAngle) -> Self {
Self { ra, dec }
Self {
ra,
dec,
distance: None,
}
}

pub fn with_distance(self, distance: Float) -> Self {
Self {
ra: self.ra,
dec: self.dec,
distance: Some(distance),
}
}

pub fn xyz(&self) -> EquatorialResult<Vec3> {
Ok(self.xyz_with_distance(self.distance.context(DistanceNotDefinedSnafu {})?))
}

pub fn xyz(&self, distance: Float) -> Vec3 {
pub fn xyz_with_distance(&self, distance: Float) -> Vec3 {
distance
* vec3(
(self.ra.cos() * self.dec.cos()).value,
Expand Down
37 changes: 7 additions & 30 deletions src/cfg/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::{
Shapes,
};

use core::panic;
use serde::{Deserialize, Serialize};
use serde_yaml::Value;
use snafu::{prelude::*, Location};
Expand Down Expand Up @@ -518,7 +517,6 @@ e: 0.5
*/
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum CfgState {
#[serde(rename = "cartesian")]
Cartesian(CfgStateCartesian),
Expand All @@ -527,7 +525,7 @@ pub enum CfgState {
Equatorial(Equatorial),

#[serde(rename = "orbit")]
Orbit(CfgOrbitKepler),
Orbit(CfgStateOrbit),

#[serde(rename = "file")]
File(PathBuf),
Expand All @@ -536,15 +534,6 @@ pub enum CfgState {
Spice(CfgStateSpice),
}

impl CfgState {
pub fn as_equatorial(&self) -> BodyResult<&Equatorial> {
match self {
Self::Equatorial(coords) => Ok(coords),
_ => panic!("nono"),
}
}
}

impl Default for CfgState {
fn default() -> Self {
Self::Cartesian(CfgStateCartesian::default())
Expand Down Expand Up @@ -577,29 +566,17 @@ pub struct CfgStateCartesian {
/// Default is: `[1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]`
#[serde(default = "default_orientation")]
pub orientation: Mat3,
}

impl CfgStateCartesian {
pub fn position_only(position: Vec3) -> Self {
Self {
position,
orientation: Mat3::identity(),
}
}

pub fn orientation_only(orientation: Mat3) -> Self {
Self {
position: Vec3::zeros(),
orientation,
}
}
#[serde(default)]
pub reference: Option<String>,
}

impl Default for CfgStateCartesian {
fn default() -> Self {
Self {
position: Vec3::zeros(),
orientation: default_orientation(),
reference: None,
}
}
}
Expand Down Expand Up @@ -633,7 +610,7 @@ In this sense, just [`a`][CfgOrbitKepler::a] and [`e`][CfgOrbitKepler::e] are us
*/
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CfgOrbitKepler {
pub struct CfgStateOrbit {
/// Heliocentric distance.
/// The units are determined automatically depending on the center of the frame:
///
Expand Down Expand Up @@ -674,7 +651,7 @@ pub struct CfgOrbitKepler {
pub control: CfgOrbitSpeedControl,
}

impl Default for CfgOrbitKepler {
impl Default for CfgStateOrbit {
fn default() -> Self {
Self {
a: default_orbit_a(),
Expand Down Expand Up @@ -766,7 +743,7 @@ pub struct CfgStateSpice {
pub origin: Option<String>,

#[serde(default)]
pub frame: Option<String>,
pub frame_from: Option<String>,

#[serde(default)]
pub frame_to: Option<String>,
Expand Down
Loading

0 comments on commit 68da2e7

Please sign in to comment.