{-# LANGUAGE DeriveGeneric #-}
module SwissEphemeris.Internal where
import Data.Bits
import Data.Char (ord)
import Foreign (Int32)
import Foreign.C.Types
import Foreign.SwissEphemeris
import GHC.Generics
data Planet
= Sun
| Moon
| Mercury
| Venus
| Mars
| Jupiter
| Saturn
| Uranus
| Neptune
| Pluto
| MeanNode
| TrueNode
| MeanApog
| OscuApog
| Earth
| Chiron
deriving (Show, Eq, Ord, Enum, Generic)
data HouseSystem
= Placidus
| Koch
| Porphyrius
| Regiomontanus
| Campanus
| Equal
| WholeSign
deriving (Show, Eq, Ord, Enum, Generic)
data ZodiacSignName
= Aries
| Taurus
| Gemini
| Cancer
| Leo
| Virgo
| Libra
| Scorpio
| Sagittarius
| Capricorn
| Aquarius
| Pisces
deriving (Eq, Show, Enum, Generic)
data NakshatraName
= Ashvini
| Bharani
| Krittika
| Rohini
| Mrigashirsha
| Ardra
| Punarvasu
| Pushya
| Ashlesha
| Magha
| PurvaPhalghuni
| UttaraPhalguni
| Hasta
| Chitra
| Swati
| Vishakha
| Anuradha
| Jyeshtha
| Mula
| PurvaAshadha
| UttaraAshadha
| Sravana
| Dhanishta
| Shatabhisha
| PurvaBhadrapada
| UttaraBhadrapada
| Revati
deriving (Eq, Show, Enum, Generic)
data SplitDegreesOption
= RoundSeconds
| RoundMinutes
| RoundDegrees
| SplitZodiacal
| SplitNakshatra
| KeepSign
| KeepDegrees
deriving (Eq, Show, Enum, Generic)
newtype JulianTime = JulianTime {unJulianTime :: Double}
deriving (Show, Eq, Ord)
newtype SiderealTime = SiderealTime {unSiderealTime :: Double}
deriving (Show, Eq, Ord)
type HouseCusp = Double
data EclipticPosition = EclipticPosition
{ lng :: Double,
lat :: Double,
distance :: Double,
lngSpeed :: Double,
latSpeed :: Double,
distSpeed :: Double
}
deriving (Show, Eq, Generic)
data GeographicPosition = GeographicPosition
{ geoLat :: Double,
geoLng :: Double
}
deriving (Show, Eq, Generic)
data EquatorialPosition = EquatorialPosition
{ rightAscension :: Double,
declination :: Double,
eqDistance :: Double,
ascensionSpeed :: Double,
declinationSpeed :: Double,
eqDistanceSpeed :: Double
}
deriving (Show, Eq, Generic)
data ObliquityInformation = ObliquityInformation
{ eclipticObliquity :: Double,
eclipticMeanObliquity :: Double,
nutationLongitude :: Double,
nutationObliquity :: Double
}
deriving (Show, Eq, Generic)
data HousePosition = HousePosition
{ houseNumber :: Int,
houseCuspDistance :: Double
}
deriving (Show, Eq, Generic)
data Angles = Angles
{ ascendant :: Double,
mc :: Double,
armc :: Double,
vertex :: Double,
equatorialAscendant :: Double,
coAscendantKoch :: Double,
coAscendantMunkasey :: Double,
polarAscendant :: Double
}
deriving (Show, Eq, Generic)
data CuspsCalculation = CuspsCalculation
{ houseCusps :: [HouseCusp],
angles :: Angles,
systemUsed :: HouseSystem
}
deriving (Show, Eq, Generic)
data LongitudeComponents = LongitudeComponents
{ longitudeZodiacSign :: Maybe ZodiacSignName,
longitudeDegrees :: Integer,
longitudeMinutes :: Integer,
longitudeSeconds :: Integer,
longitudeSecondsFraction :: Double,
longitudeSignum :: Maybe Int,
longitudeNakshatra :: Maybe NakshatraName
}
deriving (Show, Eq, Generic)
mkCalculationOptions :: [CalcFlag] -> CalcFlag
mkCalculationOptions = CalcFlag . foldr ((.|.) . unCalcFlag) 0
defaultCalculationOptions :: [CalcFlag]
defaultCalculationOptions = [speed, swissEph]
foldSplitDegOptions :: [SplitDegFlag] -> SplitDegFlag
foldSplitDegOptions = SplitDegFlag . foldr ((.|.) . unSplitDegFlag) 0
splitOptionToFlag :: SplitDegreesOption -> SplitDegFlag
splitOptionToFlag RoundSeconds = splitRoundSec
splitOptionToFlag RoundMinutes = splitRoundMin
splitOptionToFlag RoundDegrees = splitRoundDeg
splitOptionToFlag SplitZodiacal = splitZodiacal
splitOptionToFlag SplitNakshatra = splitNakshatra
splitOptionToFlag KeepSign = splitKeepSign
splitOptionToFlag KeepDegrees = splitKeepDeg
defaultSplitDegreesOptions :: [SplitDegreesOption]
defaultSplitDegreesOptions = [KeepSign, KeepDegrees]
toHouseSystemFlag :: HouseSystem -> Int
toHouseSystemFlag Placidus = ord 'P'
toHouseSystemFlag Koch = ord 'K'
toHouseSystemFlag Porphyrius = ord 'O'
toHouseSystemFlag Regiomontanus = ord 'R'
toHouseSystemFlag Campanus = ord 'C'
toHouseSystemFlag Equal = ord 'A'
toHouseSystemFlag WholeSign = ord 'W'
coordinatesFromList :: [Double] -> EclipticPosition
coordinatesFromList (sLng : sLat : c : d : e : f : _) = EclipticPosition sLng sLat c d e f
coordinatesFromList _ = EclipticPosition 0 0 0 0 0 0
eclipticFromList :: [Double] -> EclipticPosition
eclipticFromList = coordinatesFromList
eclipticToList :: EclipticPosition -> [Double]
eclipticToList (EclipticPosition sLng sLat c d e f) = (sLng : sLat : c : d : e : f : [])
equatorialFromList :: [Double] -> EquatorialPosition
equatorialFromList (a : b : c : d : e : f : _) = EquatorialPosition a b c d e f
equatorialFromList _ = EquatorialPosition 0 0 0 0 0 0
equatorialToList :: EquatorialPosition -> [Double]
equatorialToList (EquatorialPosition a b c d e f) = (a : b : c : d : e : f : [])
obliquityNutationFromList :: [Double] -> ObliquityInformation
obliquityNutationFromList (a : b : c : d : _ : _ : _) = ObliquityInformation a b c d
obliquityNutationFromList _ = ObliquityInformation 0 0 0 0
anglesFromList :: [Double] -> Angles
anglesFromList (a : _mc : _armc : vtx : ea : cak : cam : pa : _ : _) =
Angles a _mc _armc vtx ea cak cam pa
anglesFromList _ = Angles 0 0 0 0 0 0 0 0
planetNumber :: Planet -> PlanetNumber
planetNumber p = PlanetNumber $ CInt y
where
y = fromIntegral $ fromEnum p :: Int32