From 6566e5356a7f5d58c826cab4765a6bf731ae9523 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 7 May 2014 09:32:21 +0200 Subject: [PATCH] Add gswe_moment_get_aspect_by_planets() function --- docs/reference/swe-glib/swe-glib-sections.txt | 1 + src/gswe-moment.c | 37 +++++++++++++++++++ src/gswe-moment.h | 1 + 3 files changed, 39 insertions(+) diff --git a/docs/reference/swe-glib/swe-glib-sections.txt b/docs/reference/swe-glib/swe-glib-sections.txt index 30ecafb..306fb27 100644 --- a/docs/reference/swe-glib/swe-glib-sections.txt +++ b/docs/reference/swe-glib/swe-glib-sections.txt @@ -25,6 +25,7 @@ gswe_moment_get_quality_points gswe_moment_get_moon_phase gswe_moment_get_all_aspects gswe_moment_get_planet_aspects +gswe_moment_get_aspect_by_planets gswe_moment_get_all_antiscia gswe_moment_get_all_planet_antiscia gswe_moment_get_axis_all_antiscia diff --git a/src/gswe-moment.c b/src/gswe-moment.c index 7722f9e..435fd4b 100644 --- a/src/gswe-moment.c +++ b/src/gswe-moment.c @@ -1121,6 +1121,43 @@ gswe_moment_get_planet_aspects(GsweMoment *moment, GswePlanet planet, GError **e return ret; } +/** + * gswe_moment_get_aspect_by_planets: + * @moment: the GsweMoment to operate on + * @planet1: the first planet + * @planet2: the second planet + * @err: a #GError + * + * Get the aspect between two given planets. The order of @planet1 and @planet2 + * doesn’t matter. + * + * Returns: (transfer none): a #GsweAspectData containing the aspect data of the + * two planets. If an error occurs, like when one of the planets are + * not added to the planet list, returns NULL, and @err is set + * accordingly. + */ +GsweAspectData * +gswe_moment_get_aspect_by_planets(GsweMoment *moment, GswePlanet planet1, GswePlanet planet2, GError **err) +{ + struct GsweAspectFinder aspect_finder; + GList *aspect_data_element; + + if (!gswe_moment_has_planet(moment, planet1) || !gswe_moment_has_planet(moment, planet2)) { + g_set_error(err, GSWE_ERROR, GSWE_ERROR_UNKNOWN_PLANET, "One of the requested planets is not found in the planet list"); + + return NULL; + } + + aspect_finder.planet1 = planet1; + aspect_finder.planet2 = planet2; + + if ((aspect_data_element = g_list_find_custom(moment->priv->aspect_list, &aspect_finder, (GCompareFunc)find_aspect_by_both_planets)) != NULL) { + return aspect_data_element->data; + } + + return NULL; +} + static gint find_antiscion_by_both_planets(GsweAntiscionData *antiscion, struct GsweAspectFinder *antiscion_finder) { diff --git a/src/gswe-moment.h b/src/gswe-moment.h index 965aff5..b366b05 100644 --- a/src/gswe-moment.h +++ b/src/gswe-moment.h @@ -119,6 +119,7 @@ GsweMoonPhaseData *gswe_moment_get_moon_phase(GsweMoment *moment, GError **err); GList *gswe_moment_get_all_aspects(GsweMoment *moment); GList *gswe_moment_get_planet_aspects(GsweMoment *moment, GswePlanet planet, GError **err); +GsweAspectData *gswe_moment_get_aspect_by_planets(GsweMoment *moment, GswePlanet planet1, GswePlanet planet2, GError **err); GList *gswe_moment_get_all_antiscia(GsweMoment *moment); GList *gswe_moment_get_all_planet_antiscia(GsweMoment *moment, GswePlanet planet, GError **err);