sgp4-predict 0.3.2__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/Cargo.lock +3 -3
  2. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/PKG-INFO +1 -1
  3. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/CHANGELOG.md +10 -0
  4. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/Cargo.toml +1 -1
  5. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/src/aoi.rs +3 -3
  6. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/src/apsides.rs +3 -3
  7. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/src/arg_lat.rs +3 -3
  8. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/src/detect.rs +178 -39
  9. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/src/illumination.rs +3 -3
  10. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/src/lib.rs +1 -1
  11. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/src/roots.rs +17 -0
  12. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/src/transits.rs +10 -9
  13. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/detect.rs +2 -2
  14. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/CHANGELOG.md +2 -0
  15. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/Cargo.toml +2 -2
  16. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/Cargo.toml +0 -0
  17. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/LICENSE-APACHE +0 -0
  18. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/LICENSE-MIT +0 -0
  19. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/README.md +0 -0
  20. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/pyproject.toml +0 -0
  21. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/python/sgp4_predict/__init__.py +0 -0
  22. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/python/sgp4_predict/__init__.pyi +0 -0
  23. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/python/sgp4_predict/_sgp4_predict/__init__.pyi +0 -0
  24. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/python/sgp4_predict/py.typed +0 -0
  25. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/CLAUDE.md +0 -0
  26. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/LICENSE-APACHE +0 -0
  27. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/LICENSE-MIT +0 -0
  28. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/README.md +0 -0
  29. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/src/angle.rs +0 -0
  30. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/src/fallible.rs +0 -0
  31. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/src/frames.rs +0 -0
  32. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/src/observe.rs +0 -0
  33. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/src/predict.rs +0 -0
  34. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/src/time.rs +0 -0
  35. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/src/types.rs +0 -0
  36. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/src/vectors.rs +0 -0
  37. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/aoi.rs +0 -0
  38. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/apsides.rs +0 -0
  39. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/arg_lat.rs +0 -0
  40. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/common/mod.rs +0 -0
  41. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/data/.gitignore +0 -0
  42. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/data/illumination/sentinel-2c-illumination.csv +0 -0
  43. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/data/observations/sentinel-2c-christchurch-obs.csv +0 -0
  44. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/data/observations/sentinel-2c-glasgow-obs.csv +0 -0
  45. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/data/observations/sentinel-2c-svalbard-obs.csv +0 -0
  46. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/data/test_vectors.yaml +0 -0
  47. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/data/transits/sentinel-2c-christchurch.csv +0 -0
  48. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/data/transits/sentinel-2c-glasgow.csv +0 -0
  49. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/data/transits/sentinel-2c-svalbard.csv +0 -0
  50. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/data/validation.py +0 -0
  51. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/examples.rs +0 -0
  52. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/fallible.rs +0 -0
  53. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/illumination.rs +0 -0
  54. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/observations.rs +0 -0
  55. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/pointing.rs +0 -0
  56. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/propagate.rs +0 -0
  57. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/results/SENTINEL-2C_apsides_20251220T120000_20251223T120000.csv +0 -0
  58. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/results/SENTINEL-2C_illumination_20251222T160333_20251225T160333.csv +0 -0
  59. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/results/SENTINEL-2C_observations_20251220T122811.csv +0 -0
  60. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/results/SENTINEL-2C_observations_20251220T122812.csv +0 -0
  61. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/results/SENTINEL-2C_transits_20251220T120000_20251223T120000.csv +0 -0
  62. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/transits.rs +0 -0
  63. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict/tests/validation.rs +0 -0
  64. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/CLAUDE.md +0 -0
  65. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/LICENSE-APACHE +0 -0
  66. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/LICENSE-MIT +0 -0
  67. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/Makefile +0 -0
  68. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/README.md +0 -0
  69. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/area.rs +0 -0
  70. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/bin/stub_gen.rs +0 -0
  71. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/convert.rs +0 -0
  72. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/elements.rs +0 -0
  73. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/errors.rs +0 -0
  74. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/lib.rs +0 -0
  75. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/predictor.rs +0 -0
  76. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/tle.rs +0 -0
  77. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/types/aoi.rs +0 -0
  78. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/types/apsis.rs +0 -0
  79. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/types/arg_lat.rs +0 -0
  80. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/types/illumination.rs +0 -0
  81. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/types/mod.rs +0 -0
  82. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/types/observation.rs +0 -0
  83. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/types/pointing.rs +0 -0
  84. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/types/transit.rs +0 -0
  85. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/types/window.rs +0 -0
  86. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/src/vectors.rs +0 -0
  87. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/tests/test_aoi.py +0 -0
  88. {sgp4_predict-0.3.2 → sgp4_predict-0.4.0}/sgp4-predict-py/tests/test_predictor.py +0 -0
@@ -1044,7 +1044,7 @@ dependencies = [
1044
1044
 
1045
1045
  [[package]]
1046
1046
  name = "sgp4-predict"
1047
- version = "0.3.2"
1047
+ version = "0.4.0"
1048
1048
  dependencies = [
1049
1049
  "chrono",
1050
1050
  "humantime",
@@ -1058,7 +1058,7 @@ dependencies = [
1058
1058
 
1059
1059
  [[package]]
1060
1060
  name = "sgp4-predict-cli"
1061
- version = "0.3.2"
1061
+ version = "0.4.0"
1062
1062
  dependencies = [
1063
1063
  "anyhow",
1064
1064
  "assert_approx_eq",
@@ -1077,7 +1077,7 @@ dependencies = [
1077
1077
 
1078
1078
  [[package]]
1079
1079
  name = "sgp4-predict-py"
1080
- version = "0.3.2"
1080
+ version = "0.4.0"
1081
1081
  dependencies = [
1082
1082
  "chrono",
1083
1083
  "ouroboros",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sgp4-predict
3
- Version: 0.3.2
3
+ Version: 0.4.0
4
4
  Classifier: Development Status :: 4 - Beta
5
5
  Classifier: Intended Audience :: Science/Research
6
6
  Classifier: Programming Language :: Python :: 3
@@ -10,6 +10,16 @@ publishes it verbatim as the GitHub Release body — see `docs/RELEASING.md`.
10
10
 
11
11
  ## [Unreleased]
12
12
 
13
+ ## [0.4.0] - 2026-11-11
14
+
15
+ ### Changed
16
+
17
+ - **Breaking:** `EventFunction::sample` returns `Result<Option<Sample>>`, and the closures passed to
18
+ `function` and `function_with_rate` return `Result<Option<f64>>` and
19
+ `Result<Option<(f64, f64)>>`. `None` means the function has no value at that time and reads as
20
+ negative, so a window closes at the edge of the function's domain. Wrap existing results in
21
+ `Some`.
22
+
13
23
  ## [0.3.2] - 2026-11-11
14
24
 
15
25
  ### Added
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "sgp4-predict"
3
- version = "0.3.2"
3
+ version = "0.4.0"
4
4
  edition = "2024"
5
5
  rust-version = "1.85"
6
6
  license = "MIT OR Apache-2.0"
@@ -800,7 +800,7 @@ impl<'a, A: Area> AreaInView<'a, A> {
800
800
  }
801
801
 
802
802
  impl<'a, A: Area> EventFunction for AreaInView<'a, A> {
803
- fn sample(&mut self, t: DateTime<Utc>) -> Result<Sample> {
803
+ fn sample(&mut self, t: DateTime<Utc>) -> Result<Option<Sample>> {
804
804
  let ecef = self.predictor.propagate(t)?.to_ecef(t);
805
805
  let geodetic = ecef.to_geodetic();
806
806
  let position = ecef.position;
@@ -815,11 +815,11 @@ impl<'a, A: Area> EventFunction for AreaInView<'a, A> {
815
815
  Coverage::Any => self.area.signed_angular_offset(point).to_f64() + reach,
816
816
  Coverage::Full => reach - self.area.max_angular_distance(point).to_f64(),
817
817
  };
818
- Ok(Sample {
818
+ Ok(Some(Sample {
819
819
  time: t,
820
820
  value,
821
821
  rate: None,
822
- })
822
+ }))
823
823
  }
824
824
  }
825
825
 
@@ -67,12 +67,12 @@ pub(crate) struct RadialVelocity {
67
67
  }
68
68
 
69
69
  impl EventFunction for RadialVelocity {
70
- fn sample(&mut self, t: DateTime<Utc>) -> Result<Sample> {
71
- Ok(Sample {
70
+ fn sample(&mut self, t: DateTime<Utc>) -> Result<Option<Sample>> {
71
+ Ok(Some(Sample {
72
72
  time: t,
73
73
  value: self.predictor.propagate(t)?.radial_velocity(),
74
74
  rate: None,
75
- })
75
+ }))
76
76
  }
77
77
  }
78
78
 
@@ -68,13 +68,13 @@ pub(crate) struct ArgLatFn {
68
68
  }
69
69
 
70
70
  impl EventFunction for ArgLatFn {
71
- fn sample(&mut self, t: DateTime<Utc>) -> Result<Sample> {
71
+ fn sample(&mut self, t: DateTime<Utc>) -> Result<Option<Sample>> {
72
72
  let (sin_u, cos_u) = self.predictor.sin_cos_argument_of_latitude(t)?;
73
- Ok(Sample {
73
+ Ok(Some(Sample {
74
74
  time: t,
75
75
  value: sin_u * self.cos_u0 - cos_u * self.sin_u0,
76
76
  rate: None,
77
- })
77
+ }))
78
78
  }
79
79
  }
80
80
 
@@ -37,6 +37,14 @@ pub struct Sample {
37
37
 
38
38
  /// A scalar function of time whose zero crossings define events.
39
39
  ///
40
+ /// `sample` returns `None` where the function has no value at `t`; that reads
41
+ /// as a negative value, so a positive window ends at the edge of the
42
+ /// function's domain. An [`EventIter`] likewise reports a [`Crossing`] where an
43
+ /// undefined stretch borders a positive sample, and none against a negative
44
+ /// one. An adaptive [`StepStrategy`] has no rate to go on there,
45
+ /// so [`ThresholdStep`] takes its largest step; use [`FixedStep`] if the
46
+ /// defined region can be shorter than that.
47
+ ///
40
48
  /// Plain closures are adapted with [`ValueFn`] / [`RateFn`] (the
41
49
  /// [`EventIterBuilder::function`] and
42
50
  /// [`EventIterBuilder::function_with_rate`] builder methods do this for
@@ -44,10 +52,10 @@ pub struct Sample {
44
52
  /// type.
45
53
  pub trait EventFunction {
46
54
  /// Evaluate the function at `t`.
47
- fn sample(&mut self, t: DateTime<Utc>) -> Result<Sample>;
55
+ fn sample(&mut self, t: DateTime<Utc>) -> Result<Option<Sample>>;
48
56
  }
49
57
 
50
- /// Adapts a `FnMut(DateTime<Utc>) -> Result<f64>` closure into an
58
+ /// Adapts a `FnMut(DateTime<Utc>) -> Result<Option<f64>>` closure into an
51
59
  /// [`EventFunction`] with no derivative.
52
60
  #[derive(Clone, Copy)]
53
61
  pub struct ValueFn<F>(pub F);
@@ -60,17 +68,17 @@ impl<F> fmt::Debug for ValueFn<F> {
60
68
  }
61
69
  }
62
70
 
63
- impl<F: FnMut(DateTime<Utc>) -> Result<f64>> EventFunction for ValueFn<F> {
64
- fn sample(&mut self, t: DateTime<Utc>) -> Result<Sample> {
65
- Ok(Sample {
71
+ impl<F: FnMut(DateTime<Utc>) -> Result<Option<f64>>> EventFunction for ValueFn<F> {
72
+ fn sample(&mut self, t: DateTime<Utc>) -> Result<Option<Sample>> {
73
+ Ok((self.0)(t)?.map(|value| Sample {
66
74
  time: t,
67
- value: (self.0)(t)?,
75
+ value,
68
76
  rate: None,
69
- })
77
+ }))
70
78
  }
71
79
  }
72
80
 
73
- /// Adapts a `FnMut(DateTime<Utc>) -> Result<(f64, f64)>` closure returning
81
+ /// Adapts a `FnMut(DateTime<Utc>) -> Result<Option<(f64, f64)>>` closure returning
74
82
  /// `(value, rate)` into an [`EventFunction`] with a derivative.
75
83
  #[derive(Clone, Copy)]
76
84
  pub struct RateFn<F>(pub F);
@@ -81,14 +89,13 @@ impl<F> fmt::Debug for RateFn<F> {
81
89
  }
82
90
  }
83
91
 
84
- impl<F: FnMut(DateTime<Utc>) -> Result<(f64, f64)>> EventFunction for RateFn<F> {
85
- fn sample(&mut self, t: DateTime<Utc>) -> Result<Sample> {
86
- let (value, rate) = (self.0)(t)?;
87
- Ok(Sample {
92
+ impl<F: FnMut(DateTime<Utc>) -> Result<Option<(f64, f64)>>> EventFunction for RateFn<F> {
93
+ fn sample(&mut self, t: DateTime<Utc>) -> Result<Option<Sample>> {
94
+ Ok((self.0)(t)?.map(|(value, rate)| Sample {
88
95
  time: t,
89
96
  value,
90
97
  rate: Some(rate),
91
- })
98
+ }))
92
99
  }
93
100
  }
94
101
 
@@ -97,8 +104,9 @@ pub trait StepStrategy {
97
104
  /// Return the next sample time after `current`.
98
105
  ///
99
106
  /// `sample` is the function evaluation taken at `current`, when that
100
- /// evaluation succeeded; strategies must still advance when it is `None`
101
- /// (e.g. after an evaluation error) so iteration cannot stall.
107
+ /// evaluation succeeded and the function was defined there; strategies must
108
+ /// still advance when it is `None` (an evaluation error, or an undefined
109
+ /// stretch that may last many steps) so iteration cannot stall.
102
110
  fn next_time(&mut self, current: DateTime<Utc>, sample: Option<&Sample>) -> DateTime<Utc>;
103
111
  }
104
112
 
@@ -270,9 +278,9 @@ impl<D: Detector> Iterator for DetectIter<D> {
270
278
  /// The direction of a zero crossing.
271
279
  #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
272
280
  pub enum Direction {
273
- /// The function value went from negative to positive.
281
+ /// The function value went from negative (or undefined) to positive.
274
282
  Rising,
275
- /// The function value went from positive to negative.
283
+ /// The function value went from positive to negative (or undefined).
276
284
  Falling,
277
285
  }
278
286
 
@@ -285,6 +293,16 @@ pub struct Crossing {
285
293
  pub direction: Direction,
286
294
  }
287
295
 
296
+ /// A sample's value, with an undefined sample reading as negative.
297
+ fn value_or_negative(sample: &Option<Sample>) -> f64 {
298
+ sample.map_or(f64::NEG_INFINITY, |s| s.value)
299
+ }
300
+
301
+ /// Whether a sample lies outside a positive window: negative, or undefined.
302
+ fn is_outside(sample: &Option<Sample>) -> bool {
303
+ value_or_negative(sample) < 0.0
304
+ }
305
+
288
306
  /// Adapts an [`EventFunction`] bracket to [`Refinement::solve`], which does
289
307
  /// the actual root finding: converts the `DateTime` bracket to the solver's
290
308
  /// f64-seconds domain (and the root back) and reshapes samples into
@@ -304,9 +322,11 @@ fn refine_crossing<F: EventFunction>(
304
322
  ) -> Result<DateTime<Utc>> {
305
323
  let a = time::datetime_to_f64(t0);
306
324
  let b = time::datetime_to_f64(t1);
325
+ // `-inf` reads as negative; with no rate and a NaN secant step, the solver
326
+ // bisects to the edge of the function's domain.
307
327
  let root = refinement.solve(a, b, |x| {
308
328
  f.sample(time::f64_to_datetime(x))
309
- .map(|s| (s.value, s.rate))
329
+ .map(|s| s.map_or((f64::NEG_INFINITY, None), |s| (s.value, s.rate)))
310
330
  })?;
311
331
  Ok(time::f64_to_datetime(root))
312
332
  }
@@ -352,7 +372,7 @@ fn walk_to_crossing<F: EventFunction>(
352
372
  return Err(on_give_up().into());
353
373
  }
354
374
 
355
- if f.sample(next)?.value < 0.0 {
375
+ if is_outside(&f.sample(next)?) {
356
376
  let refined = refine_crossing(f, refinement, prev, next)?;
357
377
  return Ok((refined, next));
358
378
  }
@@ -390,7 +410,7 @@ pub fn detect_window<F: EventFunction>(
390
410
  max_window_duration: Duration,
391
411
  refinement: &Refinement,
392
412
  ) -> Result<Option<Window>> {
393
- if f.sample(t)?.value < 0.0 {
413
+ if is_outside(&f.sample(t)?) {
394
414
  return Ok(None);
395
415
  }
396
416
  let (window, _) =
@@ -457,7 +477,8 @@ pub struct CrossingDetector<F, S> {
457
477
  f: F,
458
478
  step: S,
459
479
  refinement: Refinement,
460
- prev: Option<Sample>,
480
+ /// The last sample time, and the sample if it was defined.
481
+ prev: Option<(DateTime<Utc>, Option<Sample>)>,
461
482
  }
462
483
 
463
484
  impl<F: EventFunction, S: StepStrategy> CrossingDetector<F, S> {
@@ -481,25 +502,30 @@ impl<F: EventFunction, S: StepStrategy> Detector for CrossingDetector<F, S> {
481
502
  type Event = Crossing;
482
503
 
483
504
  fn next_time(&mut self, current: DateTime<Utc>) -> DateTime<Utc> {
484
- let sample = self.prev.as_ref().filter(|s| s.time == current);
505
+ let sample = self
506
+ .prev
507
+ .as_ref()
508
+ .filter(|(t, _)| *t == current)
509
+ .and_then(|(_, s)| s.as_ref());
485
510
  self.step.next_time(current, sample)
486
511
  }
487
512
 
488
513
  fn detect_event(&mut self, t: DateTime<Utc>) -> Result<Option<Crossing>> {
489
514
  let s = self.f.sample(t)?;
515
+ let value = value_or_negative(&s);
490
516
  let result = match self.prev {
491
- Some(p) if p.value * s.value < 0.0 => {
492
- let direction = if p.value < 0.0 {
517
+ Some((p_time, p)) if value_or_negative(&p) * value < 0.0 => {
518
+ let direction = if is_outside(&p) {
493
519
  Direction::Rising
494
520
  } else {
495
521
  Direction::Falling
496
522
  };
497
- refine_crossing(&mut self.f, &self.refinement, p.time, s.time)
523
+ refine_crossing(&mut self.f, &self.refinement, p_time, t)
498
524
  .map(|time| Some(Crossing { time, direction }))
499
525
  }
500
526
  _ => Ok(None),
501
527
  };
502
- self.prev = Some(s);
528
+ self.prev = Some((t, s));
503
529
  result
504
530
  }
505
531
  }
@@ -675,11 +701,11 @@ impl<F: EventFunction, S: StepStrategy> Detector for WindowDetector<F, S> {
675
701
  }
676
702
  let first = self.last_boundary.is_none();
677
703
  let s = self.f.sample(t)?;
678
- if s.value < 0.0 {
704
+ if is_outside(&s) {
679
705
  if first {
680
706
  self.last_boundary = Some(t);
681
707
  }
682
- self.prev = Some(s);
708
+ self.prev = s;
683
709
  return Ok(None);
684
710
  }
685
711
  if first && self.skip_leading_partial {
@@ -710,7 +736,7 @@ impl<F: EventFunction, S: StepStrategy> Detector for WindowDetector<F, S> {
710
736
  // A crossing may still lie between the last coarse-scan sample and
711
737
  // the exact interval end.
712
738
  let s = self.f.sample(end)?;
713
- if s.value < 0.0 {
739
+ if is_outside(&s) {
714
740
  return Ok((!self.positive_only).then_some(Window {
715
741
  start: last_boundary,
716
742
  end,
@@ -793,7 +819,7 @@ impl<F, S> EventIterBuilder<F, S> {
793
819
  /// [`event_function`](Self::event_function) is used instead).
794
820
  pub fn function<F2>(self, f: F2) -> EventIterBuilder<ValueFn<F2>, S>
795
821
  where
796
- F2: FnMut(DateTime<Utc>) -> Result<f64>,
822
+ F2: FnMut(DateTime<Utc>) -> Result<Option<f64>>,
797
823
  {
798
824
  self.event_function(ValueFn(f))
799
825
  }
@@ -802,7 +828,7 @@ impl<F, S> EventIterBuilder<F, S> {
802
828
  /// enables Newton-Raphson refinement of crossings.
803
829
  pub fn function_with_rate<F2>(self, f: F2) -> EventIterBuilder<RateFn<F2>, S>
804
830
  where
805
- F2: FnMut(DateTime<Utc>) -> Result<(f64, f64)>,
831
+ F2: FnMut(DateTime<Utc>) -> Result<Option<(f64, f64)>>,
806
832
  {
807
833
  self.event_function(RateFn(f))
808
834
  }
@@ -904,7 +930,7 @@ impl<F, S> WindowIterBuilder<F, S> {
904
930
  /// [`event_function`](Self::event_function) is used instead).
905
931
  pub fn function<F2>(self, f: F2) -> WindowIterBuilder<ValueFn<F2>, S>
906
932
  where
907
- F2: FnMut(DateTime<Utc>) -> Result<f64>,
933
+ F2: FnMut(DateTime<Utc>) -> Result<Option<f64>>,
908
934
  {
909
935
  self.event_function(ValueFn(f))
910
936
  }
@@ -913,7 +939,7 @@ impl<F, S> WindowIterBuilder<F, S> {
913
939
  /// enables Newton-Raphson refinement of crossings.
914
940
  pub fn function_with_rate<F2>(self, f: F2) -> WindowIterBuilder<RateFn<F2>, S>
915
941
  where
916
- F2: FnMut(DateTime<Utc>) -> Result<(f64, f64)>,
942
+ F2: FnMut(DateTime<Utc>) -> Result<Option<(f64, f64)>>,
917
943
  {
918
944
  self.event_function(RateFn(f))
919
945
  }
@@ -1082,8 +1108,8 @@ mod tests {
1082
1108
 
1083
1109
  /// A sine wave with the given period in seconds: rising crossings at
1084
1110
  /// integer multiples of `period`, falling crossings at half-periods.
1085
- fn sine(period: f64) -> impl FnMut(DateTime<Utc>) -> Result<f64> {
1086
- move |t| Ok((secs(t) * std::f64::consts::TAU / period).sin())
1111
+ fn sine(period: f64) -> impl FnMut(DateTime<Utc>) -> Result<Option<f64>> {
1112
+ move |t| Ok(Some((secs(t) * std::f64::consts::TAU / period).sin()))
1087
1113
  }
1088
1114
 
1089
1115
  // --- EventIter / CrossingDetector ---
@@ -1122,7 +1148,7 @@ mod tests {
1122
1148
  // crossing at 500 s, refinable by Newton-Raphson in one step.
1123
1149
  let iter = EventIter::builder()
1124
1150
  .interval(t0()..t0() + Duration::seconds(1000))
1125
- .function_with_rate(|t| Ok((secs(t) - 500.0, 1.0)))
1151
+ .function_with_rate(|t| Ok(Some((secs(t) - 500.0, 1.0))))
1126
1152
  .step(FixedStep(Duration::seconds(300)))
1127
1153
  .build()
1128
1154
  .unwrap();
@@ -1344,7 +1370,7 @@ mod tests {
1344
1370
  // give up after the max_window_duration.
1345
1371
  let iter = WindowIter::builder()
1346
1372
  .interval(t0()..t0() + Duration::seconds(600))
1347
- .function(|t| Ok(secs(t) - 100.0))
1373
+ .function(|t| Ok(Some(secs(t) - 100.0)))
1348
1374
  .step(FixedStep(Duration::seconds(60)))
1349
1375
  .max_window_duration(Duration::minutes(5))
1350
1376
  .build()
@@ -1371,11 +1397,11 @@ mod tests {
1371
1397
  WindowIter::builder()
1372
1398
  .interval(interval)
1373
1399
  .function(|t| {
1374
- Ok(match secs(t) {
1400
+ Ok(Some(match secs(t) {
1375
1401
  x if x < 100.0 => -2.0,
1376
1402
  x if x < 300.0 => 1.0,
1377
1403
  _ => -1.0,
1378
- })
1404
+ }))
1379
1405
  })
1380
1406
  .step(FixedStep(Duration::seconds(60)))
1381
1407
  .refinement(Refinement {
@@ -1430,6 +1456,119 @@ mod tests {
1430
1456
  assert!(window.is_none());
1431
1457
  }
1432
1458
 
1459
+ // --- Undefined samples ---
1460
+
1461
+ /// `sine(600)` where `from <= t <= to` (seconds from `t0`), undefined elsewhere.
1462
+ struct Gated {
1463
+ from: f64,
1464
+ to: f64,
1465
+ }
1466
+
1467
+ impl EventFunction for Gated {
1468
+ fn sample(&mut self, t: DateTime<Utc>) -> Result<Option<Sample>> {
1469
+ let x = secs(t);
1470
+ Ok((self.from..=self.to).contains(&x).then(|| Sample {
1471
+ time: t,
1472
+ value: (x * std::f64::consts::TAU / 600.0).sin(),
1473
+ rate: None,
1474
+ }))
1475
+ }
1476
+ }
1477
+
1478
+ #[test]
1479
+ fn test_detect_window_returns_none_where_undefined() {
1480
+ let mut f = Gated {
1481
+ from: 100.0,
1482
+ to: 1000.0,
1483
+ };
1484
+ let window = detect_window(
1485
+ &mut f,
1486
+ t0() + Duration::seconds(50),
1487
+ Duration::seconds(30),
1488
+ Duration::hours(1),
1489
+ &Refinement::default(),
1490
+ )
1491
+ .unwrap();
1492
+
1493
+ assert!(window.is_none());
1494
+ }
1495
+
1496
+ #[test]
1497
+ fn test_window_closes_at_the_edge_of_the_domain() {
1498
+ // sine is positive on (0, 300) and (600, 900); the domain clips the
1499
+ // first window at its start and ends past the interval's last window.
1500
+ let windows: Vec<_> = WindowIter::builder()
1501
+ .interval(t0()..t0() + Duration::seconds(1500))
1502
+ .event_function(Gated {
1503
+ from: 100.0,
1504
+ to: 1000.0,
1505
+ })
1506
+ .step(FixedStep(Duration::seconds(60)))
1507
+ .build()
1508
+ .unwrap()
1509
+ .map(|w| w.unwrap())
1510
+ .collect();
1511
+
1512
+ let bounds: Vec<_> = windows
1513
+ .iter()
1514
+ .map(|w| (secs(w.start), secs(w.end)))
1515
+ .collect();
1516
+ assert_eq!(bounds.len(), 2, "{bounds:?}");
1517
+ assert!((bounds[0].0 - 100.0).abs() < 0.01 && (bounds[0].1 - 300.0).abs() < 0.01);
1518
+ assert!((bounds[1].0 - 600.0).abs() < 0.01 && (bounds[1].1 - 900.0).abs() < 0.01);
1519
+ }
1520
+
1521
+ #[test]
1522
+ fn test_event_iter_reports_no_crossing_between_negative_and_undefined() {
1523
+ // sine is negative at the domain's end, so leaving it is not an edge.
1524
+ let found: Vec<_> = EventIter::builder()
1525
+ .interval(t0()..t0() + Duration::seconds(1500))
1526
+ .event_function(Gated {
1527
+ from: 100.0,
1528
+ to: 1000.0,
1529
+ })
1530
+ .step(FixedStep(Duration::seconds(60)))
1531
+ .build()
1532
+ .unwrap()
1533
+ .map(|c| secs(c.unwrap().time))
1534
+ .collect();
1535
+
1536
+ assert_eq!(found.len(), 4, "{found:?}");
1537
+ assert!(found.iter().all(|&t| t < 950.0), "{found:?}");
1538
+ }
1539
+
1540
+ #[test]
1541
+ fn test_event_iter_reads_undefined_as_negative() {
1542
+ // Entering the domain on a positive value rises; leaving it falls.
1543
+ let crossings: Vec<_> = EventIter::builder()
1544
+ .interval(t0()..t0() + Duration::seconds(1500))
1545
+ .event_function(Gated {
1546
+ from: 100.0,
1547
+ to: 780.0,
1548
+ })
1549
+ .step(FixedStep(Duration::seconds(60)))
1550
+ .build()
1551
+ .unwrap()
1552
+ .map(|c| c.unwrap())
1553
+ .collect();
1554
+
1555
+ let found: Vec<_> = crossings
1556
+ .iter()
1557
+ .map(|c| (secs(c.time), c.direction))
1558
+ .collect();
1559
+ let expected = [
1560
+ (100.0, Direction::Rising),
1561
+ (300.0, Direction::Falling),
1562
+ (600.0, Direction::Rising),
1563
+ (780.0, Direction::Falling),
1564
+ ];
1565
+ assert_eq!(found.len(), expected.len(), "{found:?}");
1566
+ for ((time, direction), (want, want_direction)) in found.iter().zip(expected) {
1567
+ assert!((time - want).abs() < 0.01, "{found:?}");
1568
+ assert_eq!(*direction, want_direction);
1569
+ }
1570
+ }
1571
+
1433
1572
  // --- ThresholdStep (ported from transits.rs step_size tests) ---
1434
1573
 
1435
1574
  fn threshold_sample(value: f64, rate: f64) -> Sample {
@@ -109,12 +109,12 @@ pub(crate) struct ShadowFunction {
109
109
  }
110
110
 
111
111
  impl EventFunction for ShadowFunction {
112
- fn sample(&mut self, t: DateTime<Utc>) -> Result<Sample> {
113
- Ok(Sample {
112
+ fn sample(&mut self, t: DateTime<Utc>) -> Result<Option<Sample>> {
113
+ Ok(Some(Sample {
114
114
  time: t,
115
115
  value: shadow_value(&self.predictor, t)?,
116
116
  rate: None,
117
- })
117
+ }))
118
118
  }
119
119
  }
120
120
 
@@ -111,7 +111,7 @@
111
111
  //!
112
112
  //! let crossings = EventIter::builder()
113
113
  //! .interval(start..start + Duration::days(1))
114
- //! .function(move |t| Ok(predictor.propagate(t)?.position.z))
114
+ //! .function(move |t| Ok(Some(predictor.propagate(t)?.position.z)))
115
115
  //! .step(FixedStep(Duration::seconds(60)))
116
116
  //! .build()
117
117
  //! .unwrap();
@@ -212,6 +212,23 @@ mod tests {
212
212
  assert!((root - 2.0).abs() < r.time_tolerance);
213
213
  }
214
214
 
215
+ #[test]
216
+ fn test_refinement_solve_bisects_to_an_infinite_endpoint() {
217
+ // Undefined (-inf) below x = 2: the secant step is NaN, so the solver
218
+ // bisects to the edge where the value becomes defined.
219
+ let r = Refinement::default();
220
+ let root = r
221
+ .solve(0.0, 5.0, |x| {
222
+ Ok::<_, Infallible>(if x < 2.0 {
223
+ (f64::NEG_INFINITY, None)
224
+ } else {
225
+ (1.0, None)
226
+ })
227
+ })
228
+ .unwrap();
229
+ assert!((root - 2.0).abs() < r.time_tolerance);
230
+ }
231
+
215
232
  #[test]
216
233
  fn test_refinement_solve_intermittent_rate() {
217
234
  // The rate is only available on every other evaluation; each
@@ -82,18 +82,18 @@ pub(crate) struct ElevationAboveMin {
82
82
  }
83
83
 
84
84
  impl EventFunction for ElevationAboveMin {
85
- fn sample(&mut self, t: DateTime<Utc>) -> Result<Sample> {
85
+ fn sample(&mut self, t: DateTime<Utc>) -> Result<Option<Sample>> {
86
86
  let (el, el_rate) = self
87
87
  .predictor
88
88
  .propagate(t)?
89
89
  .to_ecef(t)
90
90
  .to_enu(self.observer)
91
91
  .elevation_and_rate();
92
- Ok(Sample {
92
+ Ok(Some(Sample {
93
93
  time: t,
94
94
  value: el - self.min_elevation,
95
95
  rate: Some(el_rate),
96
- })
96
+ }))
97
97
  }
98
98
  }
99
99
 
@@ -346,12 +346,13 @@ impl Predictor {
346
346
  .interval(interval)
347
347
  // Check for crossings when elevation rate is zero
348
348
  .function(|t| {
349
- Ok(self
350
- .propagate(t)?
351
- .to_ecef(t)
352
- .to_enu(observer)
353
- .elevation_and_rate()
354
- .1)
349
+ Ok(Some(
350
+ self.propagate(t)?
351
+ .to_ecef(t)
352
+ .to_enu(observer)
353
+ .elevation_and_rate()
354
+ .1,
355
+ ))
355
356
  })
356
357
  .step(FixedStep(opts.scan_step.max(MIN_POSITIVE_STEP)))
357
358
  .refinement(self.refinement)
@@ -26,7 +26,7 @@ fn test_equator_crossings() {
26
26
  let predictor = p.clone();
27
27
  let crossings = EventIter::builder()
28
28
  .interval(start..end)
29
- .function(move |t| Ok(predictor.propagate(t)?.position.z))
29
+ .function(move |t| Ok(Some(predictor.propagate(t)?.position.z)))
30
30
  .step(FixedStep(Duration::seconds(60)))
31
31
  .build()
32
32
  .unwrap()
@@ -87,7 +87,7 @@ fn test_closure_built_iter_is_debug_and_clone() {
87
87
  let start = common::datetime("2025-12-20T12:00:00Z");
88
88
  let iter = EventIter::builder()
89
89
  .interval(start..start + Duration::hours(1))
90
- .function(|_t| Ok(0.0))
90
+ .function(|_t| Ok(Some(0.0)))
91
91
  .step(FixedStep(Duration::seconds(60)))
92
92
  .build()
93
93
  .unwrap();
@@ -11,6 +11,8 @@ publishes it verbatim as the GitHub Release body — see `docs/RELEASING.md`.
11
11
 
12
12
  ## [Unreleased]
13
13
 
14
+ ## [0.4.0] - 2026-11-11
15
+
14
16
  ## [0.3.2] - 2026-11-11
15
17
 
16
18
  ### Added
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "sgp4-predict-py"
3
- version = "0.3.2"
3
+ version = "0.4.0"
4
4
  edition = "2024"
5
5
  rust-version = "1.90"
6
6
  publish = false
@@ -12,7 +12,7 @@ readme = "README.md"
12
12
  crate-type = ["cdylib", "rlib"]
13
13
 
14
14
  [dependencies]
15
- sgp4-predict = { path = "../sgp4-predict", version = "0.3.2" }
15
+ sgp4-predict = { path = "../sgp4-predict", version = "0.4.0" }
16
16
  pyo3 = { version = "0.29", features = ["chrono", "abi3-py310"] }
17
17
  chrono = { workspace = true }
18
18
  ouroboros = "0.18"
File without changes
File without changes
File without changes