diff --git a/src/astrognome.c b/src/astrognome.c index 1266944..1695324 100644 --- a/src/astrognome.c +++ b/src/astrognome.c @@ -122,23 +122,6 @@ const mirrorpointData_t mirrorpointData[] = { (v)->fall = (fal); \ g_hash_table_replace((ht), GINT_TO_POINTER(i), (v)); -#define INCREASE_POINTS(dts, dte, dtt, vsd, s, p, val) (vsd) = g_hash_table_lookup((dts), GINT_TO_POINTER(s)); \ - g_assert((vsd) != NULL); \ - \ - if (((p) = g_hash_table_lookup((dte), GINT_TO_POINTER((vsd)->element))) == NULL) { \ - (p) = g_new0(guint, 1); \ - } \ - \ - *(p) += (val); \ - g_hash_table_replace((dte), GINT_TO_POINTER((vsd)->element), (p)); \ - \ - if (((p) = g_hash_table_lookup((dtt), GINT_TO_POINTER((vsd)->type))) == NULL) { \ - (p) = g_new0(guint, 1); \ - } \ - \ - *(p) += (val); \ - g_hash_table_replace((dtt), GINT_TO_POINTER((vsd)->type), (p)); - struct aspect_check_data { GList *planetIdList; guint currentOuterPlanetId; @@ -331,7 +314,6 @@ main(int argc, char *argv[]) min = 39, sec = 34, p; - guint *point; double timezone = 1.0, lon = 20.766666, lat = 48.2, @@ -343,8 +325,6 @@ main(int argc, char *argv[]) moonPhase *phase; GHashTable *signDataTable, *planetDataTable, - *elementPointsTable, - *typePointsTable, *planetInfoTable; planetData_t *planetData; signData_t *signData; @@ -366,8 +346,6 @@ main(int argc, char *argv[]) signDataTable = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free); planetDataTable = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_planet_data); - elementPointsTable = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL); - typePointsTable = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL); planetInfoTable = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free); // Initialize planet data table @@ -437,7 +415,6 @@ main(int argc, char *argv[]) planetInfo->retrograde = FALSE; g_hash_table_replace(planetInfoTable, GINT_TO_POINTER(SE_NPLANETS + SE_ASC), planetInfo); printf("Asc.......: %s (%f)\n", signName[planetInfo->sign], planetInfo->position); - INCREASE_POINTS(signDataTable, elementPointsTable, typePointsTable, signData, planetInfo->sign, point, 2); planetInfo = g_new0(planetInfo_t, 1); planetInfo->position = ascmc[1]; @@ -446,7 +423,6 @@ main(int argc, char *argv[]) planetInfo->retrograde = FALSE; g_hash_table_replace(planetInfoTable, GINT_TO_POINTER(SE_NPLANETS + SE_MC), planetInfo); printf("MC........: %s (%f)\n", signName[planetInfo->sign], planetInfo->position); - INCREASE_POINTS(signDataTable, elementPointsTable, typePointsTable, signData, planetInfo->sign, point, 1); planetInfo = g_new0(planetInfo_t, 1); planetInfo->position = ascmc[3]; @@ -455,59 +431,48 @@ main(int argc, char *argv[]) planetInfo->retrograde = FALSE; g_hash_table_replace(planetInfoTable, GINT_TO_POINTER(SE_NPLANETS + SE_VERTEX), planetInfo); printf("Vertex....: %s (%f)\n", signName[planetInfo->sign], planetInfo->position); - INCREASE_POINTS(signDataTable, elementPointsTable, typePointsTable, signData, planetInfo->sign, point, 1); planetInfo = get_planet_info(SE_SUN, te, cusps); g_hash_table_replace(planetInfoTable, GINT_TO_POINTER(SE_SUN), planetInfo); printf("Sun.......: %s, House: %d (%f%s)\n", signName[planetInfo->sign], planetInfo->house, planetInfo->position, (planetInfo->retrograde) ? ", retrograde" : ""); - INCREASE_POINTS(signDataTable, elementPointsTable, typePointsTable, signData, planetInfo->sign, point, 2); planetInfo = get_planet_info(SE_MOON, te, cusps); g_hash_table_replace(planetInfoTable, GINT_TO_POINTER(SE_MOON), planetInfo); phase = get_moon_phase(year, month, day, hour, min, sec); printf("Moon......: %s (%.2f%% visibility), %s, House: %d (%f%s)\n", moonStateName[phase->phase], phase->visiblePercentage, signName[planetInfo->sign], planetInfo->house, planetInfo->position, (planetInfo->retrograde) ? ", retrograde" : ""); - INCREASE_POINTS(signDataTable, elementPointsTable, typePointsTable, signData, planetInfo->sign, point, 2); g_free(phase); planetInfo = get_planet_info(SE_MERCURY, te, cusps); g_hash_table_replace(planetInfoTable, GINT_TO_POINTER(SE_MERCURY), planetInfo); printf("Mercury...: %s, House: %d (%f%s)\n", signName[planetInfo->sign], planetInfo->house, planetInfo->position, (planetInfo->retrograde) ? ", retrograde" : ""); - INCREASE_POINTS(signDataTable, elementPointsTable, typePointsTable, signData, planetInfo->sign, point, 2); planetInfo = get_planet_info (SE_VENUS, te, cusps); g_hash_table_replace(planetInfoTable, GINT_TO_POINTER(SE_VENUS), planetInfo); printf("Venus.....: %s, House: %d (%f%s)\n", signName[planetInfo->sign], planetInfo->house, planetInfo->position, (planetInfo->retrograde) ? ", retrograde" : ""); - INCREASE_POINTS(signDataTable, elementPointsTable, typePointsTable, signData, planetInfo->sign, point, 1); planetInfo = get_planet_info(SE_MARS, te, cusps); g_hash_table_replace(planetInfoTable, GINT_TO_POINTER(SE_MARS), planetInfo); printf("Mars......: %s, House: %d (%f%s)\n", signName[planetInfo->sign], planetInfo->house, planetInfo->position, (planetInfo->retrograde) ? ", retrograde" : ""); - INCREASE_POINTS(signDataTable, elementPointsTable, typePointsTable, signData, planetInfo->sign, point, 1); planetInfo = get_planet_info(SE_JUPITER, te, cusps); g_hash_table_replace(planetInfoTable, GINT_TO_POINTER(SE_JUPITER), planetInfo); printf("Jupiter...: %s, House: %d (%f%s)\n", signName[planetInfo->sign], planetInfo->house, planetInfo->position, (planetInfo->retrograde) ? ", retrograde" : ""); - INCREASE_POINTS(signDataTable, elementPointsTable, typePointsTable, signData, planetInfo->sign, point, 1); planetInfo = get_planet_info(SE_SATURN, te, cusps); g_hash_table_replace(planetInfoTable, GINT_TO_POINTER(SE_SATURN), planetInfo); printf("Saturn....: %s, House: %d (%f%s)\n", signName[planetInfo->sign], planetInfo->house, planetInfo->position, (planetInfo->retrograde) ? ", retrograde" : ""); - INCREASE_POINTS(signDataTable, elementPointsTable, typePointsTable, signData, planetInfo->sign, point, 1); planetInfo = get_planet_info(SE_URANUS, te, cusps); g_hash_table_replace(planetInfoTable, GINT_TO_POINTER(SE_URANUS), planetInfo); printf("Uranus....: %s, House: %d (%f%s)\n", signName[planetInfo->sign], planetInfo->house, planetInfo->position, (planetInfo->retrograde) ? ", retrograde" : ""); - INCREASE_POINTS(signDataTable, elementPointsTable, typePointsTable, signData, planetInfo->sign, point, 1); planetInfo = get_planet_info(SE_NEPTUNE, te, cusps); g_hash_table_replace(planetInfoTable, GINT_TO_POINTER(SE_NEPTUNE), planetInfo); printf("Neptune...: %s, House: %d (%f%s)\n", signName[planetInfo->sign], planetInfo->house, planetInfo->position, (planetInfo->retrograde) ? ", retrograde" : ""); - INCREASE_POINTS(signDataTable, elementPointsTable, typePointsTable, signData, planetInfo->sign, point, 1); planetInfo = get_planet_info(SE_PLUTO, te, cusps); g_hash_table_replace(planetInfoTable, GINT_TO_POINTER(SE_PLUTO), planetInfo); printf("Pluto.....: %s, House: %d (%f%s)\n", signName[planetInfo->sign], planetInfo->house, planetInfo->position, (planetInfo->retrograde) ? ", retrograde" : ""); - INCREASE_POINTS(signDataTable, elementPointsTable, typePointsTable, signData, planetInfo->sign, point, 1); planetInfo = get_planet_info(SE_CHIRON, te, cusps); g_hash_table_replace(planetInfoTable, GINT_TO_POINTER(SE_CHIRON), planetInfo); @@ -516,7 +481,6 @@ main(int argc, char *argv[]) planetInfo = get_planet_info(SE_MEAN_NODE, te, cusps); g_hash_table_replace(planetInfoTable, GINT_TO_POINTER(SE_MEAN_NODE), planetInfo); printf("North Node: %s, House: %d (%f%s)\n", signName[planetInfo->sign], planetInfo->house, planetInfo->position, (planetInfo->retrograde) ? ", retrograde" : ""); - INCREASE_POINTS(signDataTable, elementPointsTable, typePointsTable, signData, planetInfo->sign, point, 1); planetInfo = get_planet_info(SE_MEAN_APOG, te, cusps); g_hash_table_replace(planetInfoTable, GINT_TO_POINTER(SE_MEAN_APOG), planetInfo); @@ -540,23 +504,16 @@ main(int argc, char *argv[]) printf("\nELEMENTS\n========\n\n"); - point = g_hash_table_lookup(elementPointsTable, GINT_TO_POINTER(ELEMENT_FIRE)); - printf("Fire.: %d\n", (point == NULL) ? 0 : *point); - point = g_hash_table_lookup(elementPointsTable, GINT_TO_POINTER(ELEMENT_EARTH)); - printf("Earth: %d\n", (point == NULL) ? 0 : *point); - point = g_hash_table_lookup(elementPointsTable, GINT_TO_POINTER(ELEMENT_AIR)); - printf("Air..: %d\n", (point == NULL) ? 0 : *point); - point = g_hash_table_lookup(elementPointsTable, GINT_TO_POINTER(ELEMENT_WATER)); - printf("Water: %d\n", (point == NULL) ? 0 : *point); + printf("Fire: %d\n", gswe_moment_get_element_points(moment, GSWE_ELEMENT_FIRE)); + printf("Earth: %d\n", gswe_moment_get_element_points(moment, GSWE_ELEMENT_EARTH)); + printf("Air: %d\n", gswe_moment_get_element_points(moment, GSWE_ELEMENT_AIR)); + printf("Water: %d\n", gswe_moment_get_element_points(moment, GSWE_ELEMENT_WATER)); - printf("\nTYPES\n=====\n\n"); + printf("\nQUALITIES\n=========\n\n"); - point = g_hash_table_lookup(typePointsTable, GINT_TO_POINTER(TYPE_CARDINAL)); - printf("Cardinal: %d\n", (point == NULL) ? 0 : *point); - point = g_hash_table_lookup(typePointsTable, GINT_TO_POINTER(TYPE_FIX)); - printf("Fix.....: %d\n", (point == NULL) ? 0 : *point); - point = g_hash_table_lookup(typePointsTable, GINT_TO_POINTER(TYPE_MUTABLE)); - printf("Mutable.: %d\n", (point == NULL) ? 0 : *point); + printf("Cardinal: %d\n", gswe_moment_get_quality_points(moment, GSWE_QUALITY_CARDINAL)); + printf("Fix: %d\n", gswe_moment_get_quality_points(moment, GSWE_QUALITY_FIX)); + printf("Mutable: %d\n", gswe_moment_get_quality_points(moment, GSWE_QUALITY_MUTABLE)); printf("\nASPECTS\n=======\n\n"); @@ -577,8 +534,6 @@ main(int argc, char *argv[]) g_list_free(planetIdList); g_hash_table_unref(planetInfoTable); - g_hash_table_unref(typePointsTable); - g_hash_table_unref(elementPointsTable); g_hash_table_unref(planetDataTable); g_hash_table_unref(signDataTable); diff --git a/swe-glib/src/gswe-moment.c b/swe-glib/src/gswe-moment.c index a86c37c..1b83a2a 100644 --- a/swe-glib/src/gswe-moment.c +++ b/swe-glib/src/gswe-moment.c @@ -24,6 +24,9 @@ struct _GsweMomentPrivate { GList *house_list; guint house_revision; GList *planet_list; + guint points_revision; + GHashTable *element_points; + GHashTable *quality_points; }; enum { @@ -87,9 +90,11 @@ gswe_moment_init(GsweMoment *moment) moment->priv->timestamp = NULL; moment->priv->house_list = NULL; moment->priv->planet_list = NULL; + moment->priv->element_points = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL); + moment->priv->quality_points = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL); + moment->priv->house_revision = 0; + moment->priv->points_revision = 0; moment->priv->revision = 1; - - //moment->priv->a_string = g_strdup("Maman"); } static void @@ -117,6 +122,7 @@ gswe_moment_finalize(GObject *gobject) GsweMoment *moment = GSWE_MOMENT(gobject); g_list_free_full(moment->priv->house_list, g_free); + g_list_free_full(moment->priv->planet_list, g_free); G_OBJECT_CLASS(gswe_moment_parent_class)->finalize(gobject); } @@ -370,37 +376,6 @@ gswe_moment_add_all_planets(GsweMoment *moment) g_hash_table_foreach(gswe_planet_info_table, planet_add, moment); } -GList * -gswe_moment_get_planets(GsweMoment *moment) -{ - return moment->priv->planet_list; -} - -gint -gswe_moment_get_house(GsweMoment *moment, gdouble position) -{ - gint i; - gswe_moment_calculate_house_positions(moment); - - for (i = 1; i <= 12; i++) { - gint j = (i < 12) ? i + 1 : 1; - gdouble cusp_i = *(gdouble *)g_list_nth_data(moment->priv->house_list, i - 1), - cusp_j = *(gdouble *)g_list_nth_data(moment->priv->house_list, j - 1); - - if (cusp_j < cusp_i) { - if ((position >= cusp_i) || (position < cusp_j)) { - return i; - } - } else { - if ((position >= cusp_i) && (position < cusp_j)) { - return i; - } - } - } - - return 0; -} - static void gswe_moment_calculate_planet(GsweMoment *moment, GswePlanet planet) { @@ -437,6 +412,52 @@ gswe_moment_calculate_planet(GsweMoment *moment, GswePlanet planet) planet_data->retrograde = (x2[3] < 0); } +void +calculate_planet(gpointer data, gpointer user_data) +{ + GswePlanetData *planet_data = data; + GsweMoment *moment = user_data; + + gswe_moment_calculate_planet(moment, planet_data->planet_id); +} + +void +gswe_moment_calculate_all_planets(GsweMoment *moment) +{ + g_list_foreach(moment->priv->planet_list, calculate_planet, moment); +} + +GList * +gswe_moment_get_planets(GsweMoment *moment) +{ + return moment->priv->planet_list; +} + +gint +gswe_moment_get_house(GsweMoment *moment, gdouble position) +{ + gint i; + gswe_moment_calculate_house_positions(moment); + + for (i = 1; i <= 12; i++) { + gint j = (i < 12) ? i + 1 : 1; + gdouble cusp_i = *(gdouble *)g_list_nth_data(moment->priv->house_list, i - 1), + cusp_j = *(gdouble *)g_list_nth_data(moment->priv->house_list, j - 1); + + if (cusp_j < cusp_i) { + if ((position >= cusp_i) || (position < cusp_j)) { + return i; + } + } else { + if ((position >= cusp_i) && (position < cusp_j)) { + return i; + } + } + } + + return 0; +} + GswePlanetData * gswe_moment_get_planet(GsweMoment *moment, GswePlanet planet) { @@ -451,3 +472,58 @@ gswe_moment_get_planet(GsweMoment *moment, GswePlanet planet) return planet_data; } +static void +add_points(GswePlanetData *planet_data, GsweMoment *moment) +{ + guint point; + + gswe_moment_calculate_planet(moment, planet_data->planet_id); + + point = GPOINTER_TO_INT(g_hash_table_lookup(moment->priv->element_points, GINT_TO_POINTER(planet_data->sign->element))) + planet_data->planet_info->points; + g_hash_table_replace(moment->priv->element_points, GINT_TO_POINTER(planet_data->sign->element), GINT_TO_POINTER(point)); + + point = GPOINTER_TO_INT(g_hash_table_lookup(moment->priv->quality_points, GINT_TO_POINTER(planet_data->sign->quality))); + + point += planet_data->planet_info->points; + g_hash_table_replace(moment->priv->quality_points, GINT_TO_POINTER(planet_data->sign->quality), GINT_TO_POINTER(point)); +} + +static void +gswe_moment_calculate_points(GsweMoment *moment) +{ + if (moment->priv->points_revision == moment->priv->revision) { + return; + } + + g_hash_table_remove_all(moment->priv->element_points); + g_hash_table_remove_all(moment->priv->quality_points); + + g_list_foreach(moment->priv->planet_list, (GFunc)add_points, moment); + + moment->priv->points_revision = moment->priv->revision; +} + +guint +gswe_moment_get_element_points(GsweMoment *moment, GsweElement element) +{ + guint point; + + gswe_moment_calculate_points(moment); + + point = GPOINTER_TO_INT(g_hash_table_lookup(moment->priv->element_points, GINT_TO_POINTER(element))); + + return point; +} + +guint +gswe_moment_get_quality_points(GsweMoment *moment, GsweQuality quality) +{ + guint point; + + gswe_moment_calculate_points(moment); + + point = GPOINTER_TO_INT(g_hash_table_lookup(moment->priv->quality_points, GINT_TO_POINTER(quality))); + + return point; +} + diff --git a/swe-glib/src/gswe-moment.h b/swe-glib/src/gswe-moment.h index e658b68..97ae484 100644 --- a/swe-glib/src/gswe-moment.h +++ b/swe-glib/src/gswe-moment.h @@ -94,6 +94,8 @@ void gswe_moment_add_planet(GsweMoment *moment, GswePlanet planet); void gswe_moment_add_all_planets(GsweMoment *moment); GList *gswe_moment_get_planets(GsweMoment *moment); GswePlanetData *gswe_moment_get_planet(GsweMoment *moment, GswePlanet planet); +guint gswe_moment_get_element_points(GsweMoment *moment, GsweElement element); +guint gswe_moment_get_quality_points(GsweMoment *moment, GsweQuality quality); #endif /* __GSWE_MOMENT_H__ */