1extern crate serde;
2extern crate serde_derive;
3extern crate serde_json;
4extern crate strum;
5use crate::swerust::handler_swe17::{split_deg, SplitDegResult};
6use num_derive::FromPrimitive;
7use serde::{Deserialize, Serialize};
9use strum::AsStaticRef;
10
11#[derive(Debug, Clone, Copy, PartialEq, FromPrimitive)]
13pub enum Language {
14 English = 0,
15 French = 1,
16}
17
18#[derive(Debug, Clone, Copy, PartialEq)]
20pub enum Theme {
21 Light = 0,
22 Dark = 1,
23}
24
25pub enum Colors {
27 Primary,
28 Secondary,
29 Background,
31}
32
33impl Theme {
34 pub fn color(self, color: Colors) -> i32 {
36 match color {
37 Colors::Primary => match self {
38 Theme::Light => 0x000000, Theme::Dark => 0xFFFFFF, },
41 Colors::Secondary => match self {
42 Theme::Light => 0xFFFFFF, Theme::Dark => 0x000000, },
45 Colors::Background => match self {
46 Theme::Light => 0xFFFFFF, Theme::Dark => 0x000000, },
49 }
50 }
51}
52
53#[derive(Debug, Clone, Display, EnumIter)]
55pub enum Signs {
56 Aries = 1,
57 Taurus = 2,
58 Gemini = 3,
59 Cancer = 4,
60 Leo = 5,
61 Virgo = 6,
62 Libra = 7,
63 Scorpio = 8,
64 Sagittarius = 9,
65 Capricorn = 10,
66 Aquarius = 11,
67 Pisces = 12,
68}
69
70impl Signs {
71 pub fn text(self, lang: Language) -> String {
73 match lang {
74 Language::English => match self {
75 Signs::Aries => "Aries".to_string(),
76 Signs::Taurus => "Taurus".to_string(),
77 Signs::Gemini => "Gemini".to_string(),
78 Signs::Cancer => "Cancer".to_string(),
79 Signs::Leo => "Leo".to_string(),
80 Signs::Virgo => "Virgo".to_string(),
81 Signs::Libra => "Libra".to_string(),
82 Signs::Scorpio => "Scorpio".to_string(),
83 Signs::Sagittarius => "Sagittarius".to_string(),
84 Signs::Capricorn => "Capricorn".to_string(),
85 Signs::Aquarius => "Aquarius".to_string(),
86 Signs::Pisces => "Pisces".to_string(),
87 },
88 Language::French => match self {
89 Signs::Aries => "Belier".to_string(),
90 Signs::Taurus => "Taureau".to_string(),
91 Signs::Gemini => "Gemaux".to_string(),
92 Signs::Cancer => "Cancer".to_string(),
93 Signs::Leo => "Lio".to_string(),
94 Signs::Virgo => "Vierge".to_string(),
95 Signs::Libra => "Balance".to_string(),
96 Signs::Scorpio => "Scorpion".to_string(),
97 Signs::Sagittarius => "Sagittaire".to_string(),
98 Signs::Capricorn => "Capricorne".to_string(),
99 Signs::Aquarius => "Verseau".to_string(),
100 Signs::Pisces => "Poisson".to_string(),
101 },
102 }
103 }
104
105 pub fn element(self) -> Element {
107 match self {
108 Signs::Aries => Element::Fire,
109 Signs::Taurus => Element::Earth,
110 Signs::Gemini => Element::Wind,
111 Signs::Cancer => Element::Water,
112 Signs::Leo => Element::Fire,
113 Signs::Virgo => Element::Earth,
114 Signs::Libra => Element::Wind,
115 Signs::Scorpio => Element::Water,
116 Signs::Sagittarius => Element::Fire,
117 Signs::Capricorn => Element::Earth,
118 Signs::Aquarius => Element::Wind,
119 Signs::Pisces => Element::Water,
120 }
121 }
122
123 pub fn color(self, theme: Theme) -> u32 {
125 self.element().color(theme)
126 }
127}
128
129#[derive(Debug, Clone, Copy, PartialEq, AsStaticStr)]
131pub enum Element {
132 Fire,
133 Earth,
134 Wind,
135 Water,
136}
137
138impl Element {
139 pub fn text(self, lang: Language) -> String {
141 match lang {
142 Language::English => match self {
143 Element::Fire => "Fire".to_string(),
144 Element::Earth => "Earth".to_string(),
145 Element::Wind => "Wind".to_string(),
146 Element::Water => "Water".to_string(),
147 },
148 Language::French => match self {
149 Element::Fire => "Feu".to_string(),
150 Element::Earth => "Terre".to_string(),
151 Element::Wind => "Wind".to_string(),
152 Element::Water => "Water".to_string(),
153 },
154 }
155 }
156
157 pub fn color(self, theme: Theme) -> u32 {
159 match theme {
160 Theme::Light => match self {
161 Element::Fire => 0xFF0000, Element::Earth => 0xFFC200, Element::Wind => 0x00C42A, Element::Water => 0x0B34FF, },
166 Theme::Dark => match self {
168 Element::Fire => 0xFF0000, Element::Earth => 0xFFC200, Element::Wind => 0x00C42A, Element::Water => 0x0B34FF, },
173 }
174 }
175}
176
177#[derive(Debug, Clone, Copy, PartialEq, Display, EnumIter, AsStaticStr)]
179pub enum Bodies {
180 EclNut = -1,
181 Sun = 0,
182 Moon = 1,
183 Mercury = 2,
184 Venus = 3,
185 Mars = 4,
186 Jupiter = 5,
187 Saturn = 6,
188 Uranus = 7,
189 Neptune = 8,
190 Pluto = 9,
191 MeanNode = 10,
192 TrueNode = 11,
193 MeanApog = 12,
194 OscuApog = 13,
195 Earth = 14,
196 Chiron = 15,
197 Pholus = 16,
198 Ceres = 17,
199 Pallas = 18,
200 Juno = 19,
201 Vesta = 20,
202 IntpApog = 21,
203 IntpPerg = 22,
204 NPlanets = 23,
205 SouthNode = 24,
206 FortunaPart = 25,
207 Cupido = 40,
212 Hades = 41,
213 Zeus = 42,
214 Kronos = 43,
215 Apollon = 44,
216 Admetos = 45,
217 Vulkanus = 46,
218 Poseidon = 47,
219 Isis = 48,
221 Nibiru = 49,
222 Harrington = 50,
223 NeptuneLeverrier = 51,
224 NeptuneAdams = 52,
225 PlutoLowell = 53,
226 PlutoPickering = 54,
227 AsteroidAstera = 10000 + 5,
229 AsteroidHebe = 10000 + 6,
230 AsteroidIris = 10000 + 7,
231 AsteroidFlora = 10000 + 8,
232 AsteroidMetis = 10000 + 9,
233 AsteroidHygiea = 10000 + 10,
234 AsteroidUrania = 10000 + 30,
235 AsteroidIsis = 10000 + 42,
236 AsteroidHilda = 10000 + 153,
237 AsteroidPhilosophia = 10000 + 227,
238 AsteroidSophia = 10000 + 251,
239 AsteroidAletheia = 10000 + 259,
240 AsteroidSapientia = 10000 + 275,
241 AsteroidThule = 10000 + 279,
242 AsteroidUrsula = 10000 + 375,
243 AsteroidEros = 10000 + 433,
244 AsteroidCupido = 10000 + 763,
245 AsteroidHidalgo = 10000 + 944,
246 AsteroidLilith = 10000 + 1181,
247 AsteroidAmor = 10000 + 1221,
248 AsteroidKama = 10000 + 1387,
249 AsteroidAphrodite = 10000 + 1388,
250 AsteroidApollo = 10000 + 1862,
251 AsteroidDamocles = 10000 + 3553,
252 AsteroidCruithne = 10000 + 3753,
253 AsteroidPoseidon = 10000 + 4341,
254 AsteroidVulcano = 10000 + 4464,
255 AsteroidZeus = 10000 + 5731,
256 AsteroidNessus = 10000 + 7066,
257}
258
259#[derive(Debug, Clone, PartialEq, Display, EnumIter)]
261pub enum ObjectType {
262 Unknown,
263 PlanetOrStar,
264 Earth,
265 Fiction,
266 Asteroid,
267}
268
269impl Bodies {
270 pub fn object_type(self) -> ObjectType {
272 match self {
273 Bodies::EclNut => ObjectType::Unknown,
274 Bodies::Sun => ObjectType::PlanetOrStar,
275 Bodies::Moon => ObjectType::PlanetOrStar,
276 Bodies::Mercury => ObjectType::PlanetOrStar,
277 Bodies::Venus => ObjectType::PlanetOrStar,
278 Bodies::Mars => ObjectType::PlanetOrStar,
279 Bodies::Jupiter => ObjectType::PlanetOrStar,
280 Bodies::Saturn => ObjectType::PlanetOrStar,
281 Bodies::Uranus => ObjectType::PlanetOrStar,
282 Bodies::Neptune => ObjectType::PlanetOrStar,
283 Bodies::Pluto => ObjectType::PlanetOrStar,
284 Bodies::MeanNode => ObjectType::PlanetOrStar,
285 Bodies::TrueNode => ObjectType::PlanetOrStar,
286 Bodies::MeanApog => ObjectType::PlanetOrStar,
287 Bodies::OscuApog => ObjectType::PlanetOrStar,
288 Bodies::Earth => ObjectType::Earth,
289 Bodies::Chiron => ObjectType::Fiction,
290 Bodies::Pholus => ObjectType::Fiction,
291 Bodies::Ceres => ObjectType::Fiction,
292 Bodies::Pallas => ObjectType::Fiction,
293 Bodies::Juno => ObjectType::Fiction,
294 Bodies::Vesta => ObjectType::Fiction,
295 Bodies::IntpApog => ObjectType::Fiction,
296 Bodies::IntpPerg => ObjectType::Fiction,
297 Bodies::NPlanets => ObjectType::Fiction,
298 Bodies::SouthNode => ObjectType::Fiction,
299 Bodies::FortunaPart => ObjectType::Fiction,
300 Bodies::Cupido => ObjectType::Fiction,
301 Bodies::Hades => ObjectType::Fiction,
302 Bodies::Zeus => ObjectType::Fiction,
303 Bodies::Kronos => ObjectType::Fiction,
304 Bodies::Apollon => ObjectType::Fiction,
305 Bodies::Admetos => ObjectType::Fiction,
306 Bodies::Vulkanus => ObjectType::Fiction,
307 Bodies::Poseidon => ObjectType::Fiction,
308 Bodies::Isis => ObjectType::Fiction,
309 Bodies::Nibiru => ObjectType::Fiction,
310 Bodies::Harrington => ObjectType::Fiction,
311 Bodies::NeptuneLeverrier => ObjectType::Fiction,
312 Bodies::NeptuneAdams => ObjectType::Fiction,
313 Bodies::PlutoLowell => ObjectType::Fiction,
314 Bodies::PlutoPickering => ObjectType::Fiction,
315 Bodies::AsteroidAstera => ObjectType::Asteroid,
316 Bodies::AsteroidHebe => ObjectType::Asteroid,
317 Bodies::AsteroidIris => ObjectType::Asteroid,
318 Bodies::AsteroidFlora => ObjectType::Asteroid,
319 Bodies::AsteroidMetis => ObjectType::Asteroid,
320 Bodies::AsteroidHygiea => ObjectType::Asteroid,
321 Bodies::AsteroidUrania => ObjectType::Asteroid,
322 Bodies::AsteroidIsis => ObjectType::Asteroid,
323 Bodies::AsteroidHilda => ObjectType::Asteroid,
324 Bodies::AsteroidPhilosophia => ObjectType::Asteroid,
325 Bodies::AsteroidSophia => ObjectType::Asteroid,
326 Bodies::AsteroidAletheia => ObjectType::Asteroid,
327 Bodies::AsteroidSapientia => ObjectType::Asteroid,
328 Bodies::AsteroidThule => ObjectType::Asteroid,
329 Bodies::AsteroidUrsula => ObjectType::Asteroid,
330 Bodies::AsteroidEros => ObjectType::Asteroid,
331 Bodies::AsteroidCupido => ObjectType::Asteroid,
332 Bodies::AsteroidHidalgo => ObjectType::Asteroid,
333 Bodies::AsteroidLilith => ObjectType::Asteroid,
334 Bodies::AsteroidAmor => ObjectType::Asteroid,
335 Bodies::AsteroidKama => ObjectType::Asteroid,
336 Bodies::AsteroidAphrodite => ObjectType::Asteroid,
337 Bodies::AsteroidApollo => ObjectType::Asteroid,
338 Bodies::AsteroidDamocles => ObjectType::Asteroid,
339 Bodies::AsteroidCruithne => ObjectType::Asteroid,
340 Bodies::AsteroidPoseidon => ObjectType::Asteroid,
341 Bodies::AsteroidVulcano => ObjectType::Asteroid,
342 Bodies::AsteroidZeus => ObjectType::Asteroid,
343 Bodies::AsteroidNessus => ObjectType::Asteroid,
344 }
345 }
346
347 pub fn object_color(self, theme: Theme) -> i32 {
349 match theme {
350 Theme::Light => match self {
351 Bodies::Sun => 0xFFA300, Bodies::Moon => 0xB5B510, Bodies::Mercury => 0x6900FF, Bodies::Venus => 0xFF009E, Bodies::Mars => 0xFF1212, Bodies::Jupiter => 0x12A5FF, Bodies::Saturn => 0xCC0000, Bodies::Uranus => 0xA89402, Bodies::Neptune => 0x00B526, Bodies::Pluto => 0xBF3A3A, _ => 0x6B6B6B, },
363 Theme::Dark => match self {
365 Bodies::Sun => 0xFFA300, Bodies::Moon => 0xB5B510, Bodies::Mercury => 0x6900FF, Bodies::Venus => 0xFF009E, Bodies::Mars => 0xFF1212, Bodies::Jupiter => 0x12A5FF, Bodies::Saturn => 0xCC0000, Bodies::Uranus => 0xA89402, Bodies::Neptune => 0x00B526, Bodies::Pluto => 0xBF3A3A, _ => 0x6B6B6B, },
377 }
378 }
379
380 pub fn text(self, lang: Language) -> String {
382 match lang {
383 Language::English => match self {
384 Bodies::TrueNode => "North node".to_string(),
385 Bodies::SouthNode => "South node".to_string(),
386 Bodies::FortunaPart => "Fortuna part".to_string(),
387 _ => self.as_static().to_string(),
388 },
389 Language::French => match self {
390 Bodies::Sun => "Soleil".to_string(),
391 Bodies::Moon => "Lune".to_string(),
392 Bodies::Mercury => "Mercure".to_string(),
393 Bodies::Venus => "Venus".to_string(),
394 Bodies::Mars => "Mars".to_string(),
395 Bodies::Jupiter => "Jupiter".to_string(),
396 Bodies::Saturn => "Saturne".to_string(),
397 Bodies::Uranus => "Uranus".to_string(),
398 Bodies::Neptune => "Neptune".to_string(),
399 Bodies::Pluto => "Pluton".to_string(),
400 Bodies::TrueNode => "Noeud nord".to_string(),
401 Bodies::Chiron => "Chiron".to_string(),
402 Bodies::Ceres => "Ceres".to_string(),
403 Bodies::SouthNode => "Noeud sud".to_string(),
404 Bodies::FortunaPart => "Part de fortune".to_string(),
405 _ => self.as_static().to_string(),
406 },
407 }
408 }
409}
410
411#[derive(Debug, Clone, PartialEq)]
413pub enum ObjectPos {
414 Stationary,
415 Direct,
416 Retrograde,
417}
418
419#[derive(Debug, Clone)]
421pub struct Object {
422 pub object_enum: Bodies,
423 pub object_name: String,
424 pub object_type: ObjectType,
425 pub longitude: f64,
426 pub latitude: f64,
427 pub speed_longitude: f64,
428 pub object_pos: ObjectPos,
429 pub split: SplitDegResult,
430}
431
432impl Object {
433 pub fn new(
435 object_enum: Bodies,
436 object_name: &str,
437 object_type: ObjectType,
438 longitude: f64,
439 latitude: f64,
440 speed_longitude: f64,
441 ) -> Object {
442 let object_pos;
443 if f64::abs(speed_longitude) < 0.0003 {
444 object_pos = ObjectPos::Stationary;
445 } else if speed_longitude > 0.0 {
446 object_pos = ObjectPos::Direct;
447 } else {
448 object_pos = ObjectPos::Retrograde;
449 }
450 Object {
451 object_enum,
452 object_name: object_name.to_string(),
453 object_type,
454 longitude,
455 latitude,
456 speed_longitude,
457 object_pos,
458 split: split_deg(longitude, 0),
459 }
460 }
461}
462
463#[derive(Debug, Clone)]
465pub struct House {
466 pub object_id: i32,
467 pub longitude: f64,
468 pub split: SplitDegResult,
469 pub angle: Angle,
470}
471
472impl House {
473 pub fn new(object_id: i32, longitude: f64, angle: Angle) -> House {
475 House {
476 object_id,
477 longitude,
478 split: split_deg(longitude, 0),
479 angle,
480 }
481 }
482}
483
484#[derive(Debug, Clone, Copy, PartialEq, EnumIter)]
486pub enum Angle {
487 Nothing = 0,
488 Asc = 1,
489 Fc = 2,
490 Desc = 3,
491 Mc = 4,
492}
493
494pub enum Calandar {
496 Julian = 0,
497 Gregorian = 1,
498}
499
500#[allow(clippy::upper_case_acronyms)]
501pub enum OptionalFlag {
503 JplEph = 1,
504 SwissEph = 2,
505 Moshier = 4,
506 Heliocentric = 8,
507 TruePosition = 16,
508 J2000Equinox = 32,
509 NoNutation = 64,
510 Speed3 = 128,
511 Speed = 256,
512 NoGravitanionalDeflection = 512,
513 NoAnnualAberration = 1024,
514 AstronomicPosition = 1024 | 512,
515 EquatorialPosition = 2 * 1024,
518 XYZCartesianNotPolarCoordinate = 4 * 1024,
519 Radians = 8 * 1024,
520 BarycentricPosition = 16 * 1024,
521 TopocentricPosition = 32 * 1024,
522 SideralPosition = 64 * 1024,
523 ICRS = 128 * 1024,
524 Dpsideps1980 = 256 * 1024,
525 JplHorApprox = 512 * 1024,
526}
527
528pub enum HouseSystem {
532 Campanus,
533 Equal,
534 Koch,
535 Placidus,
536 Porphyrius,
537 Regiomontanus,
538 WholeSign,
539}
540
541#[derive(
543 Debug,
544 Clone,
545 Copy,
546 PartialEq,
547 Display,
548 EnumIter,
549 AsStaticStr,
550 Serialize,
551 Deserialize,
552)]
553pub enum Aspects {
554 Conjunction = 0,
555 Opposition = 1,
556 Trine = 2,
557 Square = 3,
558 Sextile = 4,
559 Inconjunction = 5,
560 Sesquisquare = 6,
561 Semisquare = 7,
562 Semisextile = 8,
563}
564
565impl Aspects {
566 pub fn angle(self) -> (u16, u16) {
568 match self {
569 Aspects::Conjunction => (0, 10),
570 Aspects::Opposition => (180, 8),
571 Aspects::Trine => (120, 7),
572 Aspects::Square => (90, 6),
573 Aspects::Sextile => (60, 5),
574 Aspects::Inconjunction => (150, 2),
575 Aspects::Sesquisquare => (135, 1),
576 Aspects::Semisquare => (45, 1),
577 Aspects::Semisextile => (30, 1),
578 }
579 }
580
581 pub fn maj(self) -> bool {
583 use Aspects::*;
584 matches!(self, Conjunction | Opposition | Trine | Square | Sextile)
585 }
586
587 pub fn text(self, lang: Language) -> String {
588 match lang {
589 Language::English => match self {
590 Aspects::Conjunction => "Conjunction".to_string(),
591 Aspects::Opposition => "Opposition".to_string(),
592 Aspects::Trine => "Trine".to_string(),
593 Aspects::Square => "Square".to_string(),
594 Aspects::Sextile => "Sextile".to_string(),
595 Aspects::Inconjunction => "Inconjunction".to_string(),
596 Aspects::Sesquisquare => "Sesquisquare".to_string(),
597 Aspects::Semisquare => "Semisquare".to_string(),
598 Aspects::Semisextile => "Semisextile".to_string(),
599 },
600 Language::French => match self {
601 Aspects::Conjunction => "Conjonction".to_string(),
602 Aspects::Opposition => "Opposition".to_string(),
603 Aspects::Trine => "Trigone".to_string(),
604 Aspects::Square => "Quadrature".to_string(),
605 Aspects::Sextile => "Sextile".to_string(),
606 Aspects::Inconjunction => "Quinconce".to_string(),
607 Aspects::Sesquisquare => "Sesqui-carré".to_string(),
608 Aspects::Semisquare => "Demi-carré".to_string(),
609 Aspects::Semisextile => "Demi-sextile".to_string(),
610 },
611 }
612 }
613}
614
615#[derive(
617 Debug,
618 Clone,
619 Copy,
620 PartialEq,
621 Display,
622 EnumIter,
623 AsStaticStr,
624 Serialize,
625 Deserialize,
626 FromPrimitive,
627)]
628pub enum AspectsFilter {
629 AllAspects = 0,
630 AllMajorsAspects = 1,
631 Conjunction = 2,
632 Opposition = 3,
633 Trine = 4,
634 Square = 5,
635 Sextile = 6,
636 AllMinorsAspect = 7,
637 Inconjunction = 8,
638 Sesquisquare = 9,
639 Semisquare = 10,
640 Semisextile = 11,
641 NoAspects = 12,
642}
643
644impl AspectsFilter {
645 pub fn vec_aspects(self) -> Vec<Aspects> {
647 match self {
648 AspectsFilter::AllAspects => vec![
649 Aspects::Conjunction,
650 Aspects::Opposition,
651 Aspects::Trine,
652 Aspects::Square,
653 Aspects::Sextile,
654 Aspects::Inconjunction,
655 Aspects::Sesquisquare,
656 Aspects::Semisquare,
657 Aspects::Semisextile,
658 ],
659 AspectsFilter::AllMajorsAspects => vec![
660 Aspects::Conjunction,
661 Aspects::Opposition,
662 Aspects::Trine,
663 Aspects::Square,
664 Aspects::Sextile,
665 ],
666 AspectsFilter::Conjunction => vec![Aspects::Conjunction],
667 AspectsFilter::Opposition => vec![Aspects::Opposition],
668 AspectsFilter::Trine => vec![Aspects::Trine],
669 AspectsFilter::Square => vec![Aspects::Square],
670 AspectsFilter::Sextile => vec![Aspects::Sextile],
671 AspectsFilter::AllMinorsAspect => vec![
672 Aspects::Inconjunction,
673 Aspects::Sesquisquare,
674 Aspects::Semisquare,
675 Aspects::Semisextile,
676 ],
677 AspectsFilter::Inconjunction => vec![Aspects::Inconjunction],
678 AspectsFilter::Sesquisquare => vec![Aspects::Sesquisquare],
679 AspectsFilter::Semisquare => vec![Aspects::Semisquare],
680 AspectsFilter::Semisextile => vec![Aspects::Semisextile],
681 _ => Vec::new(),
682 }
683 }
684}