From 3fd8c200e0d045aa90cd579033d901275f318e18 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 23 Sep 2013 21:18:41 +0200 Subject: [PATCH] Moved GswePlanetData to its own source files --- docs/reference/swe-glib/Makefile.am | 7 +- docs/reference/swe-glib/swe-glib-docs.xml | 1 + docs/reference/swe-glib/swe-glib-sections.txt | 17 +- src/Makefile.am | 2 + src/gswe-moment.c | 30 ++-- src/gswe-moment.h | 1 + src/gswe-planet-data-private.h | 52 ++++++ src/gswe-planet-data.c | 162 ++++++++++++++++++ src/gswe-planet-data.h | 50 ++++++ src/gswe-types.c | 18 -- src/gswe-types.h | 25 --- src/swe-glib-private.h | 1 + src/swe-glib.h | 1 + 13 files changed, 305 insertions(+), 62 deletions(-) create mode 100644 src/gswe-planet-data-private.h create mode 100644 src/gswe-planet-data.c create mode 100644 src/gswe-planet-data.h diff --git a/docs/reference/swe-glib/Makefile.am b/docs/reference/swe-glib/Makefile.am index 8cf15c4..6425572 100644 --- a/docs/reference/swe-glib/Makefile.am +++ b/docs/reference/swe-glib/Makefile.am @@ -58,7 +58,12 @@ EXTRA_HFILES= # Header files or dirs to ignore when scanning. Use base file/dir names # e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h private_code -IGNORE_HFILES=swe-glib-private.h gswe-enumtypes.h gswe-moon-phase-data-private.h gswe-aspect-data-private.h +IGNORE_HFILES = \ + swe-glib-private.h \ + gswe-enumtypes.h \ + gswe-moon-phase-data-private.h \ + gswe-aspect-data-private.h \ + gswe-planet-data-private.h # Images to copy into HTML directory. # e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png diff --git a/docs/reference/swe-glib/swe-glib-docs.xml b/docs/reference/swe-glib/swe-glib-docs.xml index 0867198..b9720e8 100644 --- a/docs/reference/swe-glib/swe-glib-docs.xml +++ b/docs/reference/swe-glib/swe-glib-docs.xml @@ -19,6 +19,7 @@ SWE-GLib + diff --git a/docs/reference/swe-glib/swe-glib-sections.txt b/docs/reference/swe-glib/swe-glib-sections.txt index 4083d9d..cd34f3b 100644 --- a/docs/reference/swe-glib/swe-glib-sections.txt +++ b/docs/reference/swe-glib/swe-glib-sections.txt @@ -55,6 +55,20 @@ GSWE_TYPE_MOON_PHASE_DATA gswe_moon_phase_data_get_type +
+gswe-planet-data +GswePlanetData +gswe_planet_data_get_planet +gswe_planet_data_get_planet_info +gswe_planet_data_get_position +gswe_planet_data_get_retrograde +gswe_planet_data_get_house +gswe_planet_data_get_sign + +GSWE_TYPE_PLANET_DATA +gswe_planet_data_get_type +
+
gswe-aspect-data GsweAspectData @@ -127,7 +141,6 @@ GsweSignInfo GsweHouseSystemInfo GsweAspectInfo GsweAntiscionAxisInfo -GswePlanetData GsweCoordinates GsweHouseData GsweAntiscionData @@ -135,11 +148,9 @@ GsweAntiscionData GSWE_TYPE_ANTISCION_DATA GSWE_TYPE_COORDINATES GSWE_TYPE_HOUSE_DATA -GSWE_TYPE_PLANET_DATA gswe_antiscion_data_get_type gswe_coordinates_get_type gswe_house_data_get_type -gswe_planet_data_get_type
diff --git a/src/Makefile.am b/src/Makefile.am index ef43843..1ed2ecb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,6 +8,7 @@ INST_H_SRC_FILES = \ gswe-types.h \ gswe-moon-phase-data.h \ gswe-aspect-data.h \ + gswe-planet-data.h \ gswe-moment.h \ gswe-timestamp.h @@ -20,6 +21,7 @@ libswe_glib_1_0_la_SOURCES = \ swe-glib.c \ gswe-types.c \ gswe-moon-phase-data.c \ + gswe-planet-data.c \ gswe-aspect-data.c \ gswe-moment.c \ gswe-timestamp.c \ diff --git a/src/gswe-moment.c b/src/gswe-moment.c index c5279b8..43cb7ac 100644 --- a/src/gswe-moment.c +++ b/src/gswe-moment.c @@ -445,7 +445,7 @@ find_by_planet_id(gconstpointer a, gconstpointer b) const GswePlanetData *planet_data = a; const GswePlanet *planet = b; - if (planet_data->planet_id == *planet) { + if (planet_data->planet == *planet) { return 0; } @@ -626,7 +626,7 @@ gswe_moment_add_planet(GsweMoment *moment, GswePlanet planet) return; } - planet_data->planet_id = planet; + planet_data->planet = planet; planet_data->planet_info = planet_info; planet_data->position = 0.0; planet_data->house = 0; @@ -713,7 +713,7 @@ gswe_moment_calculate_planet(GsweMoment *moment, GswePlanet planet, GError **err static void calculate_planet(GswePlanetData *planet_data, GsweMoment *moment) { - gswe_moment_calculate_planet(moment, planet_data->planet_id, NULL); + gswe_moment_calculate_planet(moment, planet_data->planet, NULL); } static void @@ -883,7 +883,7 @@ add_points(GswePlanetData *planet_data, GsweMoment *moment) { guint point; - gswe_moment_calculate_planet(moment, planet_data->planet_id, NULL); + gswe_moment_calculate_planet(moment, planet_data->planet, NULL); 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)); @@ -1025,7 +1025,7 @@ gswe_moment_get_moon_phase(GsweMoment *moment, GError **err) static gint find_aspect_by_both_planets(GsweAspectData *aspect, struct GsweAspectFinder *aspect_finder) { - if (((aspect->planet1->planet_id == aspect_finder->planet1) && (aspect->planet2->planet_id == aspect_finder->planet2)) || ((aspect->planet1->planet_id == aspect_finder->planet2) && (aspect->planet2->planet_id == aspect_finder->planet1))) { + if (((aspect->planet1->planet == aspect_finder->planet1) && (aspect->planet2->planet == aspect_finder->planet2)) || ((aspect->planet1->planet == aspect_finder->planet2) && (aspect->planet2->planet == aspect_finder->planet1))) { return 0; } @@ -1087,12 +1087,12 @@ gswe_moment_calculate_aspects(GsweMoment *moment) struct GsweAspectFinder aspect_finder; GsweAspectData *aspect_data; - if (outer_planet->planet_id == inner_planet->planet_id) { + if (outer_planet->planet == inner_planet->planet) { continue; } - aspect_finder.planet1 = outer_planet->planet_id; - aspect_finder.planet2 = inner_planet->planet_id; + aspect_finder.planet1 = outer_planet->planet; + aspect_finder.planet2 = inner_planet->planet; if (g_list_find_custom(moment->priv->aspect_list, &aspect_finder, (GCompareFunc)find_aspect_by_both_planets) != NULL) { continue; @@ -1167,7 +1167,7 @@ gswe_moment_get_planet_aspects(GsweMoment *moment, GswePlanet planet, GError **e for (aspect = moment->priv->aspect_list; aspect; aspect = aspect->next) { GsweAspectData *aspect_data = aspect->data; - if ((aspect_data->planet1->planet_id == planet) || (aspect_data->planet2->planet_id == planet)) { + if ((aspect_data->planet1->planet == planet) || (aspect_data->planet2->planet == planet)) { ret = g_list_prepend(ret, aspect_data); } } @@ -1215,7 +1215,7 @@ find_antiscion(gpointer axis_p, GsweAntiscionAxisInfo *antiscion_info, GsweAntis static gint find_antiscion_by_both_planets(GsweAntiscionData *antiscion, struct GsweAspectFinder *antiscion_finder) { - if (((antiscion->planet1->planet_id == antiscion_finder->planet1) && (antiscion->planet2->planet_id == antiscion_finder->planet2)) || ((antiscion->planet1->planet_id == antiscion_finder->planet2) && (antiscion->planet2->planet_id == antiscion_finder->planet1))) { + if (((antiscion->planet1->planet == antiscion_finder->planet1) && (antiscion->planet2->planet == antiscion_finder->planet2)) || ((antiscion->planet1->planet == antiscion_finder->planet2) && (antiscion->planet2->planet == antiscion_finder->planet1))) { return 0; } @@ -1243,12 +1243,12 @@ gswe_moment_calculate_antiscia(GsweMoment *moment) GsweAntiscionData *antiscion_data; struct GsweAspectFinder antiscion_finder; - if (outer_planet->planet_id == inner_planet->planet_id) { + if (outer_planet->planet == inner_planet->planet) { continue; } - antiscion_finder.planet1 = outer_planet->planet_id; - antiscion_finder.planet2 = inner_planet->planet_id; + antiscion_finder.planet1 = outer_planet->planet; + antiscion_finder.planet2 = inner_planet->planet; if (g_list_find_custom(moment->priv->antiscia_list, &antiscion_finder, (GCompareFunc)find_antiscion_by_both_planets) != NULL) { continue; @@ -1320,7 +1320,7 @@ gswe_moment_get_all_planet_antiscia(GsweMoment *moment, GswePlanet planet, GErro for (antiscion = moment->priv->antiscia_list; antiscion; antiscion = g_list_next(antiscion)) { GsweAntiscionData *antiscion_data = antiscion->data; - if ((antiscion_data->planet1->planet_id == planet) || (antiscion_data->planet2->planet_id == planet)) { + if ((antiscion_data->planet1->planet == planet) || (antiscion_data->planet2->planet == planet)) { ret = g_list_prepend(ret, antiscion_data); } } @@ -1391,7 +1391,7 @@ gswe_moment_get_axis_planet_antiscia(GsweMoment *moment, GsweAntiscionAxis axis, for (antiscion_l = moment->priv->antiscia_list; antiscion_l; antiscion_l = g_list_next(antiscion_l)) { GsweAntiscionData *antiscion_data = antiscion_l->data; - if (((antiscion_data->planet1->planet_id == planet) || (antiscion_data->planet2->planet_id == planet)) && (antiscion_data->axis == axis)) { + if (((antiscion_data->planet1->planet == planet) || (antiscion_data->planet2->planet == planet)) && (antiscion_data->axis == axis)) { ret = g_list_prepend(ret, antiscion_data); } } diff --git a/src/gswe-moment.h b/src/gswe-moment.h index 90d4e6e..dd4a6df 100644 --- a/src/gswe-moment.h +++ b/src/gswe-moment.h @@ -22,6 +22,7 @@ #include "gswe-timestamp.h" #include "gswe-moon-phase-data.h" +#include "gswe-planet-data.h" #include "gswe-types.h" #define GSWE_TYPE_MOMENT (gswe_moment_get_type()) diff --git a/src/gswe-planet-data-private.h b/src/gswe-planet-data-private.h new file mode 100644 index 0000000..2bfdfb6 --- /dev/null +++ b/src/gswe-planet-data-private.h @@ -0,0 +1,52 @@ +/* gswe-planet-data-private.h: Private parts of GswePlanetData + * + * Copyright © 2013 Gergely Polonkai + * + * SWE-GLib is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * SWE-GLib is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this library; if not, see . + */ +#ifdef __SWE_GLIB_BUILDING__ +#ifndef __SWE_GLIB_GSWE_PLANET_DATA_PRIVATE_H__ +#define __SWE_GLIB_GSWE_PLANET_DATA_PRIVATE_H__ + +#include "gswe-planet-data.h" + +struct _GswePlanetData { + /* A GswePlanet, the identifier of the planet */ + GswePlanet planet; + + /* A GswePlanetInfo structure, holding every information about the planet */ + GswePlanetInfo *planet_info; + + /* The longitude position of the planet */ + gdouble position; + + /* TRUE if the planet is in retrograde motion */ + gboolean retrograde; + + /* Number of the house in which the planet is in */ + gint house; + + /* A GsweSignInfo structure, holding every information about the sign the planet is in */ + GsweSignInfo *sign; + + /* An internal version number of the calculation */ + guint revision; +}; + +GswePlanetData *gswe_planet_data_copy(GswePlanetData *planet_data); + +#endif /* __SWE_GLIB_GSWE_PLANET_DATA_PRIVATE_H__ */ +#else /* not defined __SWE_GLIB_BUILDING__ */ +#error __FILE__ "Can not be included, unless building SWE-GLib" +#endif /* __SWE_GLIB_BUILDING__ */ diff --git a/src/gswe-planet-data.c b/src/gswe-planet-data.c new file mode 100644 index 0000000..112a5ce --- /dev/null +++ b/src/gswe-planet-data.c @@ -0,0 +1,162 @@ +/* gswe-planet-data.c: Planetary positions + * + * Copyright © 2013 Gergely Polonkai + * + * SWE-GLib is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * SWE-GLib is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this library; if not, see . + */ +#include "gswe-types.h" + +#include "gswe-planet-data.h" +#include "gswe-planet-data-private.h" + +/** + * SECTION:gswe-planet-data + * @short_description: a structure representing a planet's position-related data + * @title: GswePlanetData + * @stability: Stable + * @include: swe-glib.h + * @see_also: #GswePlanetInfo + * + * #GswePlanetData is a structure that represents a planet's position-related + * data, like its actual position on the sky or the house and sign the planet + * is in. + */ + +G_DEFINE_BOXED_TYPE(GswePlanetData, gswe_planet_data, (GBoxedCopyFunc)gswe_planet_data_copy, (GBoxedFreeFunc)g_free); + +GswePlanetData * +gswe_planet_data_copy(GswePlanetData *planet_data) +{ + GswePlanetData *ret = g_new0(GswePlanetData, 1); + + ret->planet = planet_data->planet; + ret->planet_info = planet_data->planet_info; + ret->position = planet_data->position; + ret->retrograde = planet_data->retrograde; + ret->house = planet_data->house; + ret->sign = planet_data->sign; + ret->revision = planet_data->revision; + + return ret; +} + +/** + * gswe_planet_data_get_planet: + * @planet_data: (in) (allow-none): a #GswePlanetData + * + * Gets the planet ID for this #GswePlanetData. + * + * Returns: the planet ID + */ +GswePlanet +gswe_planet_data_get_planet(GswePlanetData *planet_data) +{ + if (planet_data) { + return planet_data->planet; + } else { + return GSWE_PLANET_NONE; + } +} + +/** + * gswe_planet_data_get_planet_info: + * @planet_data: (in) (allow-none): a #GswePlanetData + * + * Gets the planet info related to this #GswePlanetData. + * + * Returns: (transfer none): the #GswePlanetInfo associated with this planet + */ +GswePlanetInfo * +gswe_planet_data_get_planet_info(GswePlanetData *planet_data) +{ + if (planet_data) { + return planet_data->planet_info; + } else { + return NULL; + } +} + +/** + * gswe_planet_data_get_position: + * @planet_data: (in) (allow-none): a #GswePlanetData + * + * Gets the position of the planet on the sky. + * + * Returns: the position, in degrees + */ +gdouble +gswe_planet_data_get_position(GswePlanetData *planet_data) +{ + if (planet_data) { + return planet_data->position; + } else { + return -1.0; + } +} + +/** + * gswe_planet_data_get_retrograde: + * @planet_data: (in) (allow-none): a #GswePlanetData + * + * Returns the planet's retrograde status, e.g. if it looks like it moves + * backwards on the sky. + * + * Returns: TRUE, if the planet is in retrograde motion; FALSE otherwise + */ +gboolean +gswe_planet_data_get_retrograde(GswePlanetData *planet_data) +{ + if (planet_data) { + return planet_data->retrograde; + } else { + return FALSE; + } +} + +/** + * gswe_planet_data_get_house: + * @planet_data: (in) (allow-none): a #GswePlanetData + * + * Gets the house number which the planet is in. + * + * Returns: a house number + */ +gint +gswe_planet_data_get_house(GswePlanetData *planet_data) +{ + if (planet_data) { + return planet_data->house; + } else { + return 0; + } +} + +/** + * gswe_planet_data_get_sign: + * @planet_data: (in) (allow-none): a #GswePlanetData + * + * Gets the sign which the planet is in. + * + * Returns: (transfer none): a #GsweSignInfo + */ +GsweSignInfo * +gswe_planet_data_get_sign(GswePlanetData *planet_data) +{ + if (planet_data) { + return planet_data->sign; + } else { + return NULL; + } +} + diff --git a/src/gswe-planet-data.h b/src/gswe-planet-data.h new file mode 100644 index 0000000..55fa71a --- /dev/null +++ b/src/gswe-planet-data.h @@ -0,0 +1,50 @@ +/* gswe-planet-data.h: Planetary positions + * + * Copyright © 2013 Gergely Polonkai + * + * SWE-GLib is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * SWE-GLib is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this library; if not, see . + */ +#ifndef __SWE_GLIB_GSWE_PLANET_DATA_H__ +#define __SWE_GLIB_GSWE_PLANET_DATA_H__ + +#include + +#include "gswe-types.h" + +G_BEGIN_DECLS + +/** + * GswePlanetData: + * + * GswePlanetData is an opaque structure whose members + * cannot be accessed directly. + * + * Since: 1.1 + */ +typedef struct _GswePlanetData GswePlanetData; + +GType gswe_planet_data_get_type(void); +#define GSWE_TYPE_PLANET_DATA (gswe_planet_data_get_type()) + +GswePlanet gswe_planet_data_get_planet(GswePlanetData *planet_data); +GswePlanetInfo *gswe_planet_data_get_planet_info(GswePlanetData *planet_data); +gdouble gswe_planet_data_get_position(GswePlanetData *planet_data); +gboolean gswe_planet_data_get_retrograde(GswePlanetData *planet_data); +gint gswe_planet_data_get_house(GswePlanetData *planet_data); +GsweSignInfo *gswe_planet_data_get_sign(GswePlanetData *planet_data); + +G_END_DECLS + +#endif /* __SWE_GLIB_GSWE_PLANET_DATA_H__ */ + diff --git a/src/gswe-types.c b/src/gswe-types.c index 7372aed..d341773 100644 --- a/src/gswe-types.c +++ b/src/gswe-types.c @@ -18,24 +18,6 @@ #include "gswe-types.h" -static GswePlanetData * -gswe_planet_data_copy(GswePlanetData *planet_data) -{ - GswePlanetData *ret = g_new0(GswePlanetData, 1); - - ret->planet_id = planet_data->planet_id; - ret->planet_info = planet_data->planet_info; - ret->position = planet_data->position; - ret->retrograde = planet_data->retrograde; - ret->house = planet_data->house; - ret->sign = planet_data->sign; - ret->revision = planet_data->revision; - - return ret; -} - -G_DEFINE_BOXED_TYPE(GswePlanetData, gswe_planet_data, (GBoxedCopyFunc)gswe_planet_data_copy, (GBoxedFreeFunc)g_free); - GsweCoordinates * gswe_coordinates_copy(GsweCoordinates *coordinates) { diff --git a/src/gswe-types.h b/src/gswe-types.h index 2e5fb1d..c2bb430 100644 --- a/src/gswe-types.h +++ b/src/gswe-types.h @@ -353,31 +353,6 @@ typedef struct { gboolean middle_axis; } GsweAntiscionAxisInfo; -/** - * GswePlanetData: - * @planet_id: A GswePlanet, the identifier of the planet - * @planet_info: A GswePlanetInfo structure, holding every information about the planet - * @position: The longitude position of the planet - * @retrograde: TRUE if the planet is in retrograde motion - * @house: Number of the house in which the planet is in - * @sign: A GsweSignInfo structure, holding every information about the sign the planet is in - * @revision: An internal version number of the calculation - * - * Holds information of a given planet. - */ -typedef struct { - GswePlanet planet_id; - GswePlanetInfo *planet_info; - gdouble position; - gboolean retrograde; - gint house; - GsweSignInfo *sign; - guint revision; -} GswePlanetData; - -GType gswe_planet_data_get_type(void); -#define GSWE_TYPE_PLANET_DATA (gswe_planet_data_get_type()) - /** * GsweCoordinates: * @longitude: longitude part of the coordinates diff --git a/src/swe-glib-private.h b/src/swe-glib-private.h index a6e8f76..913a517 100644 --- a/src/swe-glib-private.h +++ b/src/swe-glib-private.h @@ -20,6 +20,7 @@ #include "gswe-timestamp.h" #include "gswe-types.h" #include "gswe-moon-phase-data-private.h" +#include "gswe-planet-data-private.h" #include "gswe-aspect-data-private.h" extern gchar *gswe_ephe_path; diff --git a/src/swe-glib.h b/src/swe-glib.h index 31c3b35..2bfc814 100644 --- a/src/swe-glib.h +++ b/src/swe-glib.h @@ -21,6 +21,7 @@ #include #include "gswe-types.h" #include "gswe-moon-phase-data.h" +#include "gswe-planet-data.h" #include "gswe-aspect-data.h" #include "gswe-timestamp.h" #include "gswe-moment.h"