Skip to content

Commit

Permalink
Merge pull request #40 from lfborjas/rc
Browse files Browse the repository at this point in the history
Rc: 1.4.1.0
  • Loading branch information
lfborjas authored Nov 27, 2021
2 parents c850c2f + 17ad66f commit 300116c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ghc: ['8.2.2', '8.4.4', '8.6.5', '8.8.3', '8.10.4', '9.0.1']
ghc: ['8.2.2', '8.4.4', '8.6.5', '8.8.3', '8.10.4', '9.0.1', '9.2.1']
cabal: ['3.2']
os: [ubuntu-latest, macos-latest]
env:
Expand Down
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

* Export `utcToJulianDays`, to obtain a product of `(TT, UT1)` Julian Days from a `UTCTime` value --
saves you one IO trip vs. getting them separately.
* Support for GHC 9.2.1
* Fix minor bug in `directionChange` that made lookups starting <=30 minutes before the event fail
(due to an artifact of the original C function that explicitly excludes such lookup bounds.)

## v1.4.0.0 (2021-11-11)

Expand Down
21 changes: 14 additions & 7 deletions csrc/interpolate.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,24 @@ int swe_next_direction_change(double jd0, int ipl, int iflag, double *jdx, int *
);
}

// modified version of fn shared by Alois in: https://groups.io/g/swisseph/message/7781
int swe_next_direction_change_between(double jd0, double jd_end, int ipl, int iflag, double *jdx, int *idir, char *serr)
{
double jd_step = 1;
double xx[6], d1, d2, y0, y1, y2, a, b, jd, tx;
double xx[6], d1, d2, y0, y1, y2, a, b, jd, tx, orig_start, orig_end;
int rval, is;
if (jd_step <= 0) jd_step = 1.0;
// NOTE(luis) adding a couple of days to the end of the search since 3 positions
// are needed for interpolation, at least.
double orig_end = jd_end;
// NOTE(luis) adding some padding to the beginning and end since intervals that are too
// small won't produce the 3 points necessary for parabolic interpolation;
// also, as noted by Alois, the `jd0` moment must be at least 30 mins before
// the actual occurrence.
orig_start = jd0;
orig_end = jd_end;
jd0 -= 1;
if (fabs(jd_end - jd0) < 3){
jd_end += 3;
}
// end of ugliness
rval = swe_calc(jd0, ipl, iflag, xx, serr);
if (rval < 0) return rval;
y0 = xx[0];
Expand Down Expand Up @@ -107,15 +113,16 @@ int swe_next_direction_change_between(double jd0, double jd_end, int ipl, int if
*idir = 1;
else
*idir = -1;
if (*jdx > orig_end){
sprintf(serr, "swe_next_direction_change: no change within %lf days", (orig_end - jd0));
// NOTE(luis) compensate for the fake bounds created for parabolic approximation
if (*jdx > orig_end || *jdx < orig_start){
sprintf(serr, "swe_next_direction_change: no change within %lf days", (orig_end - orig_start));
return ERR;
}
return rval;
}
// come here only if no change found in loop
if (serr != NULL)
sprintf(serr, "swe_next_direction_change: no change within %lf days", (orig_end - jd0));
sprintf(serr, "swe_next_direction_change: no change within %lf days", (orig_end - orig_start));
return ERR;
}

Expand Down
4 changes: 2 additions & 2 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: swiss-ephemeris
version: 1.4.0.0
version: 1.4.1.0
github: "lfborjas/swiss-ephemeris"
license: AGPL-3
author: "Luis Borjas Reyes"
Expand All @@ -21,7 +21,7 @@ category: Data, Astrology
description: Please see the README on GitHub at <https://github.com/lfborjas/swiss-ephemeris#readme>

dependencies:
- base >= 4.10 && < 4.16
- base >= 4.10 && < 4.17
- vector >= 0.12 && < 0.13
- time >= 1.9 && < 1.13

Expand Down
8 changes: 4 additions & 4 deletions swiss-ephemeris.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 1f78f55bc113fd41d97119660086ed24ad498a24fc93d13d8e09a0449e0e3e60
-- hash: 0feead7e44aba9915159eab5ab88bf44fc083266e7fbefe092fe08f1572f95b2

name: swiss-ephemeris
version: 1.4.0.0
version: 1.4.1.0
synopsis: Haskell bindings for the Swiss Ephemeris C library
description: Please see the README on GitHub at <https://github.com/lfborjas/swiss-ephemeris#readme>
category: Data, Astrology
Expand Down Expand Up @@ -79,7 +79,7 @@ library
csrc/configurable_sweephe4.c
csrc/interpolate.c
build-depends:
base >=4.10 && <4.16
base >=4.10 && <4.17
, time >=1.9 && <1.13
, vector >=0.12 && <0.13
default-language: Haskell2010
Expand All @@ -102,7 +102,7 @@ test-suite swiss-ephemeris-test
hspec-discover:hspec-discover >=2.7 && <2.8
build-depends:
QuickCheck >=2.12 && <=2.15
, base >=4.10 && <4.16
, base >=4.10 && <4.17
, directory >=1.3 && <1.4
, hspec >=2.7 && <2.8
, random
Expand Down
7 changes: 7 additions & 0 deletions test/SwissEphemerisSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,13 @@ spec = do
getJulianDay crossingJD `shouldBe` expectedCrossing
motion `shouldBe` expectedMotion

it "calculates a known direction change happening less than 30 mins after lookup starts" $ do
let startJD = mkJulianDay STT 2459266.500800741
endJD = mkJulianDay STT 2459267.500800741
Right (crossingJD, motion) <- directionChangeBetween Mercury startJD endJD
getJulianDay crossingJD `shouldBe` 2459266.536910611
motion `shouldBe` DirectMotion

it "fails to calculate direction change if outside of the interval" $ do
let startTime = mkJulian 2021 7 14 0.0
endTime = mkJulian 2021 7 15 0.0
Expand Down

0 comments on commit 300116c

Please sign in to comment.