astro_chart 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a9e05e60924337f22af516c0830b2d569d802f09d1d39658b9a8633141553a11
4
+ data.tar.gz: 4b479272b7a20c2a979d3db48983c1da9260ec9c2908274dee1f03326c4ac7da
5
+ SHA512:
6
+ metadata.gz: fa3265f1725729216373b9be2737f3958f4e743fb2f6731f5bbbdeaae183045091fdbfb5ea16647ed9c63b88c395047b72f5e580351364c8bc9697df8a626282
7
+ data.tar.gz: 5af130c80b00a0715e520652eebb25dfbc533603360e38a3f6803e9c133f47fdbe8f345c116f7be75f43356b957bfe093d7369048a95ff06816142daff403531
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ GNU AFFERO GENERAL PUBLIC LICENSE
2
+ Version 3, 19 November 2007
3
+
4
+ Copyright (C) 2025 AstroChart Contributors
5
+
6
+ This program is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Affero General Public License as published
8
+ by the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Affero General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Affero General Public License
17
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
18
+
19
+ This software includes the Swiss Ephemeris library, which is also
20
+ licensed under AGPL-3.0. See https://www.astro.com/swisseph/ for details.
@@ -0,0 +1,22 @@
1
+ require_relative "lib/astro_chart/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "astro_chart"
5
+ spec.version = AstroChart::VERSION
6
+ spec.authors = ["Huang Yudi"]
7
+ spec.summary = "Natal chart calculation using Swiss Ephemeris"
8
+ spec.description = "A Ruby gem for natal astrology chart calculation, powered by Swiss Ephemeris C library with Moshier ephemeris. No external data files needed."
9
+ spec.homepage = "https://github.com/morriedig/astro_chart"
10
+ spec.license = "AGPL-3.0"
11
+ spec.required_ruby_version = ">= 3.0"
12
+
13
+ spec.files = Dir["lib/**/*.rb", "ext/**/*.{rb,c,h}", "LICENSE", "astro_chart.gemspec"]
14
+ spec.require_paths = ["lib"]
15
+ spec.extensions = ["ext/astro_chart/extconf.rb"]
16
+
17
+ spec.add_dependency "tzinfo", "~> 2.0"
18
+
19
+ spec.add_development_dependency "rspec", "~> 3.0"
20
+ spec.add_development_dependency "rake", "~> 13.0"
21
+ spec.add_development_dependency "rake-compiler", "~> 1.2"
22
+ end
@@ -0,0 +1,99 @@
1
+ #include <ruby.h>
2
+ #include "swephexp.h"
3
+
4
+ static VALUE mAstroChart;
5
+ static VALUE mExt;
6
+
7
+ /*
8
+ * AstroChart::Ext.julday(year, month, day, hour) -> Float
9
+ *
10
+ * Convert a date/time to Julian Day number using Gregorian calendar.
11
+ */
12
+ static VALUE rb_julday(VALUE self, VALUE year, VALUE month, VALUE day, VALUE hour) {
13
+ int y = NUM2INT(year);
14
+ int m = NUM2INT(month);
15
+ int d = NUM2INT(day);
16
+ double h = NUM2DBL(hour);
17
+
18
+ double jd = swe_julday(y, m, d, h, SE_GREG_CAL);
19
+ return DBL2NUM(jd);
20
+ }
21
+
22
+ /*
23
+ * AstroChart::Ext.calc_ut(jd, planet_id) -> Float
24
+ *
25
+ * Calculate planet ecliptic longitude using Moshier ephemeris.
26
+ * Returns the longitude in degrees (0-360).
27
+ */
28
+ static VALUE rb_calc_ut(VALUE self, VALUE jd, VALUE planet_id) {
29
+ double tjd = NUM2DBL(jd);
30
+ int ipl = NUM2INT(planet_id);
31
+ double xx[6];
32
+ char serr[256];
33
+
34
+ int32 ret = swe_calc_ut(tjd, ipl, SEFLG_MOSEPH, xx, serr);
35
+ if (ret < 0) {
36
+ rb_raise(rb_eRuntimeError, "swe_calc_ut failed: %s", serr);
37
+ }
38
+
39
+ return DBL2NUM(xx[0]); /* ecliptic longitude */
40
+ }
41
+
42
+ /*
43
+ * AstroChart::Ext.houses(jd, latitude, longitude, system) -> Hash
44
+ *
45
+ * Calculate house cusps and ascendant/MC.
46
+ * system: ASCII code for house system (e.g. 'P' = 80 for Placidus)
47
+ *
48
+ * Returns a Hash with:
49
+ * "cusps" => Array of 12 house cusp degrees
50
+ * "ascendant" => Ascendant degree
51
+ * "mc" => MC degree
52
+ */
53
+ static VALUE rb_houses(VALUE self, VALUE jd, VALUE lat, VALUE lon, VALUE hsys) {
54
+ double tjd = NUM2DBL(jd);
55
+ double geolat = NUM2DBL(lat);
56
+ double geolon = NUM2DBL(lon);
57
+ int system = NUM2INT(hsys);
58
+
59
+ double cusps[13]; /* cusps[0] unused, cusps[1..12] */
60
+ double ascmc[10];
61
+
62
+ swe_houses(tjd, geolat, geolon, system, cusps, ascmc);
63
+
64
+ VALUE result = rb_hash_new();
65
+ VALUE cusps_ary = rb_ary_new_capa(12);
66
+
67
+ int i;
68
+ for (i = 1; i <= 12; i++) {
69
+ rb_ary_push(cusps_ary, DBL2NUM(cusps[i]));
70
+ }
71
+
72
+ rb_hash_aset(result, rb_str_new_cstr("cusps"), cusps_ary);
73
+ rb_hash_aset(result, rb_str_new_cstr("ascendant"), DBL2NUM(ascmc[0]));
74
+ rb_hash_aset(result, rb_str_new_cstr("mc"), DBL2NUM(ascmc[1]));
75
+
76
+ return result;
77
+ }
78
+
79
+ void Init_astro_chart_ext(void) {
80
+ mAstroChart = rb_define_module("AstroChart");
81
+ mExt = rb_define_module_under(mAstroChart, "Ext");
82
+
83
+ rb_define_module_function(mExt, "julday", rb_julday, 4);
84
+ rb_define_module_function(mExt, "calc_ut", rb_calc_ut, 2);
85
+ rb_define_module_function(mExt, "houses", rb_houses, 4);
86
+
87
+ /* Planet ID constants */
88
+ rb_define_const(mExt, "SUN", INT2NUM(SE_SUN));
89
+ rb_define_const(mExt, "MOON", INT2NUM(SE_MOON));
90
+ rb_define_const(mExt, "MERCURY", INT2NUM(SE_MERCURY));
91
+ rb_define_const(mExt, "VENUS", INT2NUM(SE_VENUS));
92
+ rb_define_const(mExt, "MARS", INT2NUM(SE_MARS));
93
+ rb_define_const(mExt, "JUPITER", INT2NUM(SE_JUPITER));
94
+ rb_define_const(mExt, "SATURN", INT2NUM(SE_SATURN));
95
+ rb_define_const(mExt, "URANUS", INT2NUM(SE_URANUS));
96
+ rb_define_const(mExt, "NEPTUNE", INT2NUM(SE_NEPTUNE));
97
+ rb_define_const(mExt, "PLUTO", INT2NUM(SE_PLUTO));
98
+ rb_define_const(mExt, "TRUE_NODE", INT2NUM(SE_TRUE_NODE));
99
+ }
@@ -0,0 +1,8 @@
1
+ require "mkmf"
2
+
3
+ # Swiss Ephemeris source files to compile alongside our extension
4
+ $srcs = Dir.glob("#{$srcdir}/*.c").map { |f| File.basename(f) }
5
+
6
+ $CFLAGS << " -DNO_SWE_GLP"
7
+
8
+ create_makefile("astro_chart/astro_chart_ext")