Moved GswePlanetData to its own source files

This commit is contained in:
Gergely Polonkai 2013-09-23 21:18:41 +02:00
parent 9a788f8164
commit 3fd8c200e0
13 changed files with 305 additions and 62 deletions

View File

@ -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

View File

@ -19,6 +19,7 @@
<chapter>
<title>SWE-GLib</title>
<xi:include href="xml/gswe-types.xml"/>
<xi:include href="xml/gswe-planet-data.xml" />
<xi:include href="xml/gswe-moon-phase-data.xml"/>
<xi:include href="xml/gswe-aspect-data.xml" />
<xi:include href="xml/swe-glib.xml"/>

View File

@ -55,6 +55,20 @@ GSWE_TYPE_MOON_PHASE_DATA
gswe_moon_phase_data_get_type
</SECTION>
<SECTION>
<FILE>gswe-planet-data</FILE>
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
<SUBSECTION Standard>
GSWE_TYPE_PLANET_DATA
gswe_planet_data_get_type
</SECTION>
<SECTION>
<FILE>gswe-aspect-data</FILE>
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
</SECTION>
<SECTION>

View File

@ -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 \

View File

@ -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);
}
}

View File

@ -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())

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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__ */

162
src/gswe-planet-data.c Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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;
}
}

50
src/gswe-planet-data.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef __SWE_GLIB_GSWE_PLANET_DATA_H__
#define __SWE_GLIB_GSWE_PLANET_DATA_H__
#include <glib-object.h>
#include "gswe-types.h"
G_BEGIN_DECLS
/**
* GswePlanetData:
*
* <structname>GswePlanetData</structname> 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__ */

View File

@ -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)
{

View File

@ -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

View File

@ -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;

View File

@ -21,6 +21,7 @@
#include <glib.h>
#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"