1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
//! Ayanamsa types: [`Ayanamsa`] and [`CustomAyanamsa`].
use core::fmt;
use crate::angles::Angle;
use crate::custom_bodies::{validate_canonical_text, CustomDefinitionValidationError};
use crate::time::JulianDay;
/// A built-in or custom ayanamsa selection.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum Ayanamsa {
/// Lahiri.
Lahiri,
/// Raman.
Raman,
/// Krishnamurti.
Krishnamurti,
/// Fagan/Bradley.
FaganBradley,
/// True Chitra.
TrueChitra,
/// True Citra.
TrueCitra,
/// Suryasiddhanta (Revati) / SS Revati.
SuryasiddhantaRevati,
/// Suryasiddhanta (Citra) / SS Citra.
SuryasiddhantaCitra,
/// J2000.0 reference-frame mode.
J2000,
/// J1900.0 reference-frame mode.
J1900,
/// B1950.0 reference-frame mode.
B1950,
/// True Revati.
TrueRevati,
/// True Mula.
TrueMula,
/// True Pushya.
TruePushya,
/// Udayagiri.
Udayagiri,
/// Djwhal Khul.
DjwhalKhul,
/// J. N. Bhasin.
JnBhasin,
/// Suryasiddhanta mean-sun variant.
Suryasiddhanta499MeanSun,
/// Aryabhata mean-sun variant.
Aryabhata499MeanSun,
/// The 1956 Indian Astronomical Ephemeris / ICRC Lahiri definition.
LahiriIcrc,
/// Lahiri's 1940 zero-date variant.
Lahiri1940,
/// Usha/Shashi, anchored to the Revati tradition.
UshaShashi,
/// Suryasiddhanta-equinox variant anchored in 499 CE.
Suryasiddhanta499,
/// Aryabhata-equinox variant anchored in 499 CE.
Aryabhata499,
/// Sassanian zero-point variant anchored in 564 CE.
Sassanian,
/// DeLuce ayanamsa.
DeLuce,
/// Yukteshwar ayanamsa.
Yukteshwar,
/// P.V.R. Narasimha Rao's Pushya-paksha ayanamsa.
PvrPushyaPaksha,
/// Sheoran ayanamsa.
Sheoran,
/// Hipparchus / Hipparchos ayanamsa.
Hipparchus,
/// Babylonian (Kugler 1).
BabylonianKugler1,
/// Babylonian (Kugler 2).
BabylonianKugler2,
/// Babylonian (Kugler 3).
BabylonianKugler3,
/// Babylonian (Huber).
BabylonianHuber,
/// Babylonian (Eta Piscium).
BabylonianEtaPiscium,
/// Babylonian (Aldebaran / 15 Tau).
BabylonianAldebaran,
/// Babylonian (House).
BabylonianHouse,
/// Babylonian (Sissy).
BabylonianSissy,
/// Babylonian (True Geoc).
BabylonianTrueGeoc,
/// Babylonian (True Topc).
BabylonianTrueTopc,
/// Babylonian (True Obs).
BabylonianTrueObs,
/// Babylonian (House Obs).
BabylonianHouseObs,
/// Babylonian (Britton).
BabylonianBritton,
/// Aryabhata (522 CE).
Aryabhata522,
/// Lahiri (VP285).
LahiriVP285,
/// Krishnamurti (VP291).
KrishnamurtiVP291,
/// True Sheoran.
TrueSheoran,
/// Galactic Center.
GalacticCenter,
/// Galactic Center (Rgilbrand).
GalacticCenterRgilbrand,
/// Galactic Center (Mardyks).
GalacticCenterMardyks,
/// Galactic Center (Mula/Wilhelm).
GalacticCenterMulaWilhelm,
/// Dhruva Galactic Center (Middle Mula).
DhruvaGalacticCenterMula,
/// Galactic Center (Cochrane).
GalacticCenterCochrane,
/// Galactic Equator.
GalacticEquator,
/// Galactic Equator (IAU 1958).
GalacticEquatorIau1958,
/// Galactic Equator (True).
GalacticEquatorTrue,
/// Galactic Equator (Mula).
GalacticEquatorMula,
/// Galactic Equator (Fiorenza).
GalacticEquatorFiorenza,
/// Valens Moon.
ValensMoon,
/// A custom ayanamsa formula or offset table.
Custom(CustomAyanamsa),
}
impl fmt::Display for Ayanamsa {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Custom(custom) => write!(f, "{custom}"),
_ => write!(f, "{self:?}"),
}
}
}
impl Ayanamsa {
/// Validates the custom ayanamsa definition when this is a custom variant.
///
/// Built-in ayanamsas are always valid; only structured custom labels and
/// offset metadata are checked. This keeps malformed sidereal definitions
/// from leaking into request validation or release-facing text.
pub fn validate(&self) -> Result<(), CustomDefinitionValidationError> {
match self {
Self::Custom(custom) => custom.validate(),
_ => Ok(()),
}
}
/// Validates the custom ayanamsa definition against reserved built-in labels.
///
/// Built-in ayanamsas are always valid; custom entries are checked with the
/// same structural rules as [`validate`](Self::validate) and are then compared
/// against a caller-supplied built-in label resolver.
pub fn validate_against_reserved_labels(
&self,
is_reserved_label: impl Fn(&str) -> bool,
) -> Result<(), CustomDefinitionValidationError> {
match self {
Self::Custom(custom) => custom.validate_against_reserved_labels(is_reserved_label),
_ => Ok(()),
}
}
}
/// A structured custom ayanamsa definition.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct CustomAyanamsa {
/// Stable human-readable name.
pub name: String,
/// Optional description of the formula or offset policy.
pub description: Option<String>,
/// Optional epoch the definition is tied to.
pub epoch: Option<JulianDay>,
/// Optional fixed offset in degrees for simple offset-based variants.
pub offset_degrees: Option<Angle>,
}
impl CustomAyanamsa {
/// Creates a custom ayanamsa definition.
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
description: None,
epoch: None,
offset_degrees: None,
}
}
/// Validates the custom ayanamsa definition.
///
/// The canonical name and optional description must be non-empty and free
/// of leading or trailing whitespace. If one of `epoch` or
/// `offset_degrees` is supplied, the other must be supplied too so the
/// sidereal offset can be reconstructed deterministically. Any supplied
/// numeric values must also be finite.
pub fn validate(&self) -> Result<(), CustomDefinitionValidationError> {
validate_canonical_text("custom ayanamsa", "name", &self.name)?;
if let Some(description) = &self.description {
validate_canonical_text("custom ayanamsa", "description", description)?;
}
match (self.epoch, self.offset_degrees) {
(Some(epoch), Some(offset_degrees)) => {
if !epoch.days().is_finite() {
return Err(CustomDefinitionValidationError::non_finite(
"custom ayanamsa",
"epoch",
));
}
if !offset_degrees.is_finite() {
return Err(CustomDefinitionValidationError::non_finite(
"custom ayanamsa",
"offset_degrees",
));
}
}
(None, None) => {}
(Some(_), None) => {
return Err(CustomDefinitionValidationError::incomplete_pair(
"custom ayanamsa",
"epoch",
"offset_degrees",
));
}
(None, Some(_)) => {
return Err(CustomDefinitionValidationError::incomplete_pair(
"custom ayanamsa",
"offset_degrees",
"epoch",
));
}
}
Ok(())
}
/// Validates the custom ayanamsa definition against reserved built-in labels.
///
/// This is a stricter form of [`validate`](Self::validate) that also rejects
/// a canonical name that collides with a published built-in ayanamsa label.
/// That keeps user-defined sidereal definitions distinguishable from the
/// built-in compatibility catalog when request validation or release profiles
/// surface them.
pub fn validate_against_reserved_labels(
&self,
is_reserved_label: impl Fn(&str) -> bool,
) -> Result<(), CustomDefinitionValidationError> {
self.validate()?;
if is_reserved_label(&self.name) {
return Err(CustomDefinitionValidationError::reserved_label(
"custom ayanamsa",
"name",
&self.name,
));
}
Ok(())
}
}
impl fmt::Display for CustomAyanamsa {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.name)?;
let mut details = Vec::new();
if let Some(epoch) = self.epoch {
details.push(format!("epoch: {epoch}"));
}
if let Some(offset_degrees) = self.offset_degrees {
details.push(format!("offset: {offset_degrees}"));
}
if let Some(description) = &self.description {
details.push(description.clone());
}
if !details.is_empty() {
write!(f, " [{}]", details.join(", "))?;
}
Ok(())
}
}