2013-09-16 07:16:49 +00:00
|
|
|
|
/* gswe-moment.c - Planetary moment object for SWE-GLib
|
|
|
|
|
*
|
2013-09-22 16:22:13 +00:00
|
|
|
|
* Copyright © 2013 Gergely Polonkai
|
2013-09-16 07:16:49 +00:00
|
|
|
|
*
|
2013-09-22 16:22:13 +00:00
|
|
|
|
* 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.
|
2013-09-16 07:16:49 +00:00
|
|
|
|
*
|
2013-09-22 16:22:13 +00:00
|
|
|
|
* 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.
|
2013-09-16 07:16:49 +00:00
|
|
|
|
*
|
2013-09-22 16:22:13 +00:00
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2013-09-16 07:16:49 +00:00
|
|
|
|
*/
|
2013-09-01 20:30:51 +00:00
|
|
|
|
#include "swe-glib.h"
|
2013-09-02 21:12:56 +00:00
|
|
|
|
#include "swe-glib-private.h"
|
2013-09-01 11:52:18 +00:00
|
|
|
|
|
2013-09-05 10:25:58 +00:00
|
|
|
|
#include "../swe/src/swephexp.h"
|
2013-09-01 20:30:51 +00:00
|
|
|
|
|
2013-10-08 22:06:08 +00:00
|
|
|
|
#define glforeach(a, b) for ((a) = (b); (a); (a) = g_list_next((a)))
|
|
|
|
|
|
2013-09-16 09:34:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* SECTION:gswe-moment
|
|
|
|
|
* @short_description: an exact moment of the sky, as seen from a given point
|
|
|
|
|
* of Earth at a given time
|
|
|
|
|
* @title: GsweMoment
|
|
|
|
|
* @stability: Stable
|
|
|
|
|
* @include: swe-glib/swe-glib.h
|
|
|
|
|
*
|
|
|
|
|
* This class represents an exact moment of the sky, as it can be seen from
|
|
|
|
|
* one given point on Earth at a given time.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
#define GSWE_MOMENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE( \
|
|
|
|
|
(obj), \
|
|
|
|
|
GSWE_TYPE_MOMENT, \
|
|
|
|
|
GsweMomentPrivate))
|
2013-09-01 11:52:18 +00:00
|
|
|
|
|
2013-09-01 20:30:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* GsweMomentPrivate:
|
|
|
|
|
* @timestamp: a #GsweTimestmp object representing the current local time at
|
|
|
|
|
* the given position specified by @coordinates. Be warned though,
|
|
|
|
|
* that the time zone is NOT checked against the coordinates!
|
|
|
|
|
* @coordinates: the coordinates of the observers position
|
2013-09-11 01:32:49 +00:00
|
|
|
|
* @house_system: the house system this object uses
|
2013-09-01 20:30:51 +00:00
|
|
|
|
* @revision: an internal counter which is incremented whenever the timestamp
|
2013-09-11 01:32:49 +00:00
|
|
|
|
* or the coordinates change. When this number changes, every data
|
|
|
|
|
* that has a *_revision value here will be recalculated before the
|
|
|
|
|
* data is served
|
|
|
|
|
* @house_list: (element-type GsweHouseData): the list of house data
|
|
|
|
|
* @house_revision: the revision of the calculated house data
|
|
|
|
|
* @planet_list: (element-type GswePlanetData): the list of planets
|
|
|
|
|
* @points_revision: the revision of the points
|
|
|
|
|
* @element_points: the table of the element points
|
|
|
|
|
* @quality_points: the table of the quality points
|
|
|
|
|
* @moon_phase_revision: the revision of the Moon phase data
|
|
|
|
|
* @moon_phase: the calculated Moon phase data
|
|
|
|
|
* @aspect_list: (element-type GsweAspectData): the list of calculated aspects
|
|
|
|
|
* @aspect_revision: the revision of the aspect data
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* @antiscia_list: (element-type GsweAntisciaData): the list of calculated
|
|
|
|
|
* antiscia (mirror points)
|
|
|
|
|
* @antiscia_revision: the revision of the antiscia data
|
2013-09-16 12:00:06 +00:00
|
|
|
|
*
|
|
|
|
|
* The private parts of #GsweMoment
|
2013-09-01 20:30:51 +00:00
|
|
|
|
*/
|
2013-09-01 11:52:18 +00:00
|
|
|
|
struct _GsweMomentPrivate {
|
2013-09-01 12:31:23 +00:00
|
|
|
|
GsweTimestamp *timestamp;
|
2013-09-01 11:52:18 +00:00
|
|
|
|
GsweCoordinates coordinates;
|
2013-09-01 20:30:51 +00:00
|
|
|
|
GsweHouseSystem house_system;
|
|
|
|
|
guint revision;
|
|
|
|
|
GList *house_list;
|
|
|
|
|
guint house_revision;
|
2013-09-02 14:19:45 +00:00
|
|
|
|
GList *planet_list;
|
2013-09-02 21:10:35 +00:00
|
|
|
|
guint points_revision;
|
|
|
|
|
GHashTable *element_points;
|
|
|
|
|
GHashTable *quality_points;
|
2013-09-02 21:12:56 +00:00
|
|
|
|
guint moon_phase_revision;
|
2013-09-30 20:39:46 +00:00
|
|
|
|
GsweMoonPhaseData *moon_phase;
|
2013-09-02 23:11:18 +00:00
|
|
|
|
GList *aspect_list;
|
|
|
|
|
guint aspect_revision;
|
2013-09-16 08:13:25 +00:00
|
|
|
|
GList *antiscia_list;
|
|
|
|
|
guint antiscia_revision;
|
2014-10-07 21:24:11 +00:00
|
|
|
|
gulong timestamp_signal_handler;
|
2013-09-01 11:52:18 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
2013-09-01 12:18:57 +00:00
|
|
|
|
SIGNAL_CHANGED,
|
2014-10-07 21:25:24 +00:00
|
|
|
|
SIGNAL_PLANET_ADDED,
|
2013-09-01 11:52:18 +00:00
|
|
|
|
SIGNAL_LAST
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
2013-09-14 14:31:22 +00:00
|
|
|
|
PROP_TIMESTAMP,
|
|
|
|
|
PROP_COORDINATES,
|
2014-09-28 22:04:20 +00:00
|
|
|
|
PROP_HOUSE_SYSTEM,
|
|
|
|
|
PROP_COUNT
|
2013-09-01 11:52:18 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-09-02 23:11:18 +00:00
|
|
|
|
struct GsweAspectFinder {
|
|
|
|
|
GswePlanet planet1;
|
|
|
|
|
GswePlanet planet2;
|
|
|
|
|
};
|
|
|
|
|
|
2013-09-01 11:52:18 +00:00
|
|
|
|
static guint gswe_moment_signals[SIGNAL_LAST] = {0};
|
|
|
|
|
|
|
|
|
|
static void gswe_moment_dispose(GObject *gobject);
|
2014-07-08 08:43:54 +00:00
|
|
|
|
|
2013-09-01 11:52:18 +00:00
|
|
|
|
static void gswe_moment_finalize(GObject *gobject);
|
2014-07-08 08:43:54 +00:00
|
|
|
|
|
|
|
|
|
static void gswe_moment_set_property(
|
|
|
|
|
GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
|
|
static void gswe_moment_get_property(
|
|
|
|
|
GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
2013-09-01 11:52:18 +00:00
|
|
|
|
|
2014-09-28 22:04:20 +00:00
|
|
|
|
static GParamSpec *properties[PROP_COUNT];
|
|
|
|
|
|
2013-09-01 11:52:18 +00:00
|
|
|
|
G_DEFINE_TYPE(GsweMoment, gswe_moment, G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gswe_moment_class_init(GsweMomentClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
|
|
|
|
|
|
|
|
|
g_type_class_add_private(klass, sizeof(GsweMomentPrivate));
|
|
|
|
|
|
|
|
|
|
gobject_class->dispose = gswe_moment_dispose;
|
|
|
|
|
gobject_class->finalize = gswe_moment_finalize;
|
|
|
|
|
gobject_class->set_property = gswe_moment_set_property;
|
|
|
|
|
gobject_class->get_property = gswe_moment_get_property;
|
|
|
|
|
|
|
|
|
|
/**
|
2013-09-01 12:18:57 +00:00
|
|
|
|
* GsweMoment::changed:
|
2013-09-01 11:52:18 +00:00
|
|
|
|
* @moment: the GsweMoment object that received the signal
|
|
|
|
|
*
|
2014-10-07 21:22:18 +00:00
|
|
|
|
* The ::changed signal is emitted each time the time, coordinates
|
|
|
|
|
* or the house system changes.
|
2013-09-01 11:52:18 +00:00
|
|
|
|
*/
|
2014-07-08 08:43:54 +00:00
|
|
|
|
gswe_moment_signals[SIGNAL_CHANGED] = g_signal_new(
|
|
|
|
|
"changed",
|
2014-10-07 21:22:18 +00:00
|
|
|
|
G_TYPE_FROM_CLASS(klass),
|
2014-07-08 08:43:54 +00:00
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
g_cclosure_marshal_generic,
|
|
|
|
|
G_TYPE_NONE,
|
|
|
|
|
0
|
|
|
|
|
);
|
2013-09-01 11:52:18 +00:00
|
|
|
|
|
2014-10-07 21:25:24 +00:00
|
|
|
|
/**
|
|
|
|
|
* GsweMoment::planet-added:
|
|
|
|
|
* @moment: the GsweMoment object that received the signal
|
|
|
|
|
* @planet: the planet that was just added to @moment
|
|
|
|
|
*
|
|
|
|
|
* The ::planet-added signal is emitted each time a planet is
|
|
|
|
|
* added to @moment.
|
|
|
|
|
*/
|
|
|
|
|
gswe_moment_signals[SIGNAL_PLANET_ADDED] = g_signal_new(
|
|
|
|
|
"planet-added",
|
|
|
|
|
G_TYPE_FROM_CLASS(klass),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
g_cclosure_marshal_generic,
|
|
|
|
|
G_TYPE_NONE,
|
|
|
|
|
1,
|
|
|
|
|
GSWE_TYPE_PLANET
|
|
|
|
|
);
|
|
|
|
|
|
2013-09-01 11:52:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* GsweMoment:timestamp:
|
|
|
|
|
*
|
|
|
|
|
* The timestamp associated with this moment
|
|
|
|
|
*/
|
2014-09-28 22:04:20 +00:00
|
|
|
|
properties[PROP_TIMESTAMP] = g_param_spec_object(
|
|
|
|
|
"timestamp",
|
|
|
|
|
"Timestamp",
|
|
|
|
|
"Timestamp of this moment",
|
|
|
|
|
GSWE_TYPE_TIMESTAMP,
|
|
|
|
|
G_PARAM_STATIC_NICK
|
|
|
|
|
| G_PARAM_STATIC_NAME
|
|
|
|
|
| G_PARAM_STATIC_BLURB
|
|
|
|
|
| G_PARAM_READABLE
|
|
|
|
|
| G_PARAM_WRITABLE
|
|
|
|
|
);
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_object_class_install_property(
|
|
|
|
|
gobject_class,
|
|
|
|
|
PROP_TIMESTAMP,
|
2014-09-28 22:04:20 +00:00
|
|
|
|
properties[PROP_TIMESTAMP]
|
2014-07-08 08:43:54 +00:00
|
|
|
|
);
|
2013-09-14 14:31:22 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GsweMoment:coordinates:
|
|
|
|
|
*
|
|
|
|
|
* The geographical coordinates associated with this moment
|
|
|
|
|
*/
|
2014-09-28 22:04:20 +00:00
|
|
|
|
properties[PROP_COORDINATES] = g_param_spec_boxed(
|
|
|
|
|
"coordinates",
|
|
|
|
|
"Coordinates",
|
|
|
|
|
"Geographical coordinates",
|
|
|
|
|
GSWE_TYPE_COORDINATES,
|
|
|
|
|
G_PARAM_STATIC_NICK
|
|
|
|
|
| G_PARAM_STATIC_NAME
|
|
|
|
|
| G_PARAM_STATIC_BLURB
|
|
|
|
|
| G_PARAM_READABLE
|
|
|
|
|
| G_PARAM_WRITABLE
|
|
|
|
|
);
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_object_class_install_property(
|
|
|
|
|
gobject_class,
|
|
|
|
|
PROP_COORDINATES,
|
2014-09-28 22:04:20 +00:00
|
|
|
|
properties[PROP_COORDINATES]
|
2014-07-08 08:43:54 +00:00
|
|
|
|
);
|
2013-09-14 14:31:22 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GsweMoment:house-system:
|
|
|
|
|
*
|
|
|
|
|
* The house system associated with this moment
|
|
|
|
|
*/
|
2014-09-28 22:04:20 +00:00
|
|
|
|
properties[PROP_HOUSE_SYSTEM] = g_param_spec_enum(
|
|
|
|
|
"house-system",
|
|
|
|
|
"House System",
|
|
|
|
|
"Astrological house system",
|
|
|
|
|
GSWE_TYPE_HOUSE_SYSTEM,
|
|
|
|
|
GSWE_HOUSE_SYSTEM_PLACIDUS,
|
|
|
|
|
G_PARAM_STATIC_NICK
|
|
|
|
|
| G_PARAM_STATIC_NAME
|
|
|
|
|
| G_PARAM_STATIC_BLURB
|
|
|
|
|
| G_PARAM_READABLE
|
|
|
|
|
| G_PARAM_WRITABLE
|
|
|
|
|
);
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_object_class_install_property(
|
|
|
|
|
gobject_class,
|
|
|
|
|
PROP_HOUSE_SYSTEM,
|
2014-09-28 22:04:20 +00:00
|
|
|
|
properties[PROP_HOUSE_SYSTEM]
|
2014-07-08 08:43:54 +00:00
|
|
|
|
);
|
2013-09-01 11:52:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-01 12:18:57 +00:00
|
|
|
|
gswe_moment_emit_changed(GsweMoment *moment)
|
2013-09-01 11:52:18 +00:00
|
|
|
|
{
|
2013-09-01 12:18:57 +00:00
|
|
|
|
g_signal_emit(moment, gswe_moment_signals[SIGNAL_CHANGED], 0);
|
2013-09-01 11:52:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 01:37:00 +00:00
|
|
|
|
static void
|
2013-09-01 12:31:23 +00:00
|
|
|
|
gswe_moment_init(GsweMoment *moment)
|
2013-09-01 11:52:18 +00:00
|
|
|
|
{
|
2013-09-01 12:31:23 +00:00
|
|
|
|
moment->priv = GSWE_MOMENT_GET_PRIVATE(moment);
|
2013-09-01 11:52:18 +00:00
|
|
|
|
|
2013-09-01 12:31:23 +00:00
|
|
|
|
moment->priv->timestamp = NULL;
|
2013-09-01 20:30:51 +00:00
|
|
|
|
moment->priv->house_list = NULL;
|
|
|
|
|
moment->priv->planet_list = NULL;
|
2013-09-02 23:11:18 +00:00
|
|
|
|
moment->priv->aspect_list = NULL;
|
2013-09-16 08:13:25 +00:00
|
|
|
|
moment->priv->antiscia_list = NULL;
|
2013-09-30 20:39:46 +00:00
|
|
|
|
moment->priv->moon_phase = gswe_moon_phase_data_new();
|
2014-07-08 08:43:54 +00:00
|
|
|
|
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
|
|
|
|
|
);
|
2013-09-02 21:10:35 +00:00
|
|
|
|
moment->priv->house_revision = 0;
|
|
|
|
|
moment->priv->points_revision = 0;
|
2013-09-02 21:12:56 +00:00
|
|
|
|
moment->priv->moon_phase_revision = 0;
|
2013-09-02 23:11:18 +00:00
|
|
|
|
moment->priv->aspect_revision = 0;
|
2013-09-16 08:13:25 +00:00
|
|
|
|
moment->priv->antiscia_revision = 0;
|
2013-09-01 20:30:51 +00:00
|
|
|
|
moment->priv->revision = 1;
|
2013-09-01 12:31:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-09 08:51:50 +00:00
|
|
|
|
gswe_moment_timestamp_changed(GsweTimestamp *timestamp, GsweMoment *moment)
|
2013-09-01 12:31:23 +00:00
|
|
|
|
{
|
2013-09-01 20:30:51 +00:00
|
|
|
|
moment->priv->revision++;
|
|
|
|
|
gswe_moment_emit_changed(moment);
|
2013-09-01 11:52:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 17:43:53 +00:00
|
|
|
|
/* Dispose object */
|
2013-09-01 11:52:18 +00:00
|
|
|
|
static void
|
|
|
|
|
gswe_moment_dispose(GObject *gobject)
|
|
|
|
|
{
|
2013-09-01 12:31:23 +00:00
|
|
|
|
GsweMoment *moment = GSWE_MOMENT(gobject);
|
|
|
|
|
|
2014-10-07 21:24:11 +00:00
|
|
|
|
g_signal_handler_disconnect(
|
2014-07-08 08:43:54 +00:00
|
|
|
|
moment->priv->timestamp,
|
2014-10-07 21:24:11 +00:00
|
|
|
|
moment->priv->timestamp_signal_handler
|
2014-07-08 08:43:54 +00:00
|
|
|
|
);
|
2013-09-01 11:52:18 +00:00
|
|
|
|
|
2013-09-01 12:31:23 +00:00
|
|
|
|
g_clear_object(&moment->priv->timestamp);
|
2013-09-01 11:52:18 +00:00
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS(gswe_moment_parent_class)->dispose(gobject);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 17:43:53 +00:00
|
|
|
|
/* Reset object to the initialized state */
|
2013-09-01 11:52:18 +00:00
|
|
|
|
static void
|
|
|
|
|
gswe_moment_finalize(GObject *gobject)
|
|
|
|
|
{
|
2013-09-01 20:30:51 +00:00
|
|
|
|
GsweMoment *moment = GSWE_MOMENT(gobject);
|
2013-09-01 11:52:18 +00:00
|
|
|
|
|
2014-10-31 17:43:53 +00:00
|
|
|
|
g_clear_object(&moment->priv->timestamp);
|
|
|
|
|
|
2014-10-31 18:10:48 +00:00
|
|
|
|
g_list_free_full(
|
|
|
|
|
moment->priv->house_list,
|
|
|
|
|
(GDestroyNotify)gswe_house_data_unref
|
|
|
|
|
);
|
2014-10-31 17:43:53 +00:00
|
|
|
|
moment->priv->house_list = NULL;
|
|
|
|
|
|
2014-10-31 18:10:48 +00:00
|
|
|
|
g_list_free_full(
|
|
|
|
|
moment->priv->planet_list,
|
|
|
|
|
(GDestroyNotify)gswe_planet_data_unref
|
|
|
|
|
);
|
2014-10-31 17:43:53 +00:00
|
|
|
|
moment->priv->planet_list = NULL;
|
|
|
|
|
|
2014-10-31 18:10:48 +00:00
|
|
|
|
g_list_free_full(
|
|
|
|
|
moment->priv->aspect_list,
|
|
|
|
|
(GDestroyNotify)gswe_aspect_data_unref
|
|
|
|
|
);
|
2014-10-31 17:43:53 +00:00
|
|
|
|
moment->priv->aspect_list = NULL;
|
|
|
|
|
|
2014-10-31 18:10:48 +00:00
|
|
|
|
g_list_free_full(
|
|
|
|
|
moment->priv->antiscia_list,
|
|
|
|
|
(GDestroyNotify)gswe_antiscion_data_unref
|
|
|
|
|
);
|
2014-10-31 17:43:53 +00:00
|
|
|
|
moment->priv->antiscia_list = NULL;
|
|
|
|
|
|
|
|
|
|
g_hash_table_remove_all(moment->priv->element_points);
|
|
|
|
|
|
|
|
|
|
g_hash_table_remove_all(moment->priv->quality_points);
|
|
|
|
|
|
|
|
|
|
moment->priv->house_revision = 0;
|
|
|
|
|
moment->priv->points_revision = 0;
|
|
|
|
|
moment->priv->moon_phase_revision = 0;
|
|
|
|
|
moment->priv->aspect_revision = 0;
|
|
|
|
|
moment->priv->antiscia_revision = 0;
|
|
|
|
|
moment->priv->revision = 1;
|
|
|
|
|
|
2013-09-01 11:52:18 +00:00
|
|
|
|
G_OBJECT_CLASS(gswe_moment_parent_class)->finalize(gobject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-07-08 08:43:54 +00:00
|
|
|
|
gswe_moment_set_property(
|
|
|
|
|
GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2013-09-01 11:52:18 +00:00
|
|
|
|
{
|
|
|
|
|
GsweMoment *moment = GSWE_MOMENT(object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_TIMESTAMP:
|
|
|
|
|
gswe_moment_set_timestamp(moment, (g_value_get_object(value)));
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2013-09-14 14:31:22 +00:00
|
|
|
|
case PROP_COORDINATES:
|
|
|
|
|
{
|
|
|
|
|
GsweCoordinates *coords = g_value_get_boxed(value);
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
gswe_moment_set_coordinates(
|
|
|
|
|
moment,
|
|
|
|
|
coords->longitude,
|
|
|
|
|
coords->latitude,
|
|
|
|
|
coords->altitude
|
|
|
|
|
);
|
2013-09-14 14:31:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case PROP_HOUSE_SYSTEM:
|
|
|
|
|
gswe_moment_set_house_system(moment, g_value_get_enum(value));
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2013-09-01 11:52:18 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-07-08 08:43:54 +00:00
|
|
|
|
gswe_moment_get_property(
|
|
|
|
|
GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec
|
|
|
|
|
)
|
2013-09-01 11:52:18 +00:00
|
|
|
|
{
|
|
|
|
|
GsweMoment *moment = GSWE_MOMENT(object);
|
|
|
|
|
GsweMomentPrivate *priv = moment->priv;
|
|
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_TIMESTAMP:
|
|
|
|
|
g_value_set_object(value, priv->timestamp);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2013-09-14 14:31:22 +00:00
|
|
|
|
case PROP_COORDINATES:
|
|
|
|
|
{
|
2014-07-08 08:43:54 +00:00
|
|
|
|
GsweCoordinates *coords = gswe_coordinates_copy(
|
|
|
|
|
&(priv->coordinates)
|
|
|
|
|
);
|
2014-03-29 13:55:29 +00:00
|
|
|
|
|
2013-09-14 14:31:22 +00:00
|
|
|
|
g_value_set_boxed(value, coords);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_HOUSE_SYSTEM:
|
|
|
|
|
g_value_set_enum(value, priv->house_system);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2013-09-01 11:52:18 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-02 14:17:23 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_set_timestamp:
|
|
|
|
|
* @moment: A GsweMoment object
|
|
|
|
|
* @timestamp: A GsweTimestamp object. The moment object holds a reference on
|
|
|
|
|
* timestamp, which is cleared when a new timestamp is set, or the
|
|
|
|
|
* moment object is disposed.
|
|
|
|
|
*
|
|
|
|
|
* Sets a new timestamp for this planetary moment. Also emits the ::changed
|
|
|
|
|
* signal to notify owner of this change. This helps redrawing screen data
|
|
|
|
|
* according to the new time value.
|
|
|
|
|
*/
|
2013-09-01 11:52:18 +00:00
|
|
|
|
void
|
|
|
|
|
gswe_moment_set_timestamp(GsweMoment *moment, GsweTimestamp *timestamp)
|
|
|
|
|
{
|
2014-09-28 22:04:20 +00:00
|
|
|
|
if (moment->priv->timestamp == timestamp) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-01 12:31:23 +00:00
|
|
|
|
if (moment->priv->timestamp != NULL) {
|
2014-10-07 21:24:11 +00:00
|
|
|
|
g_signal_handler_disconnect(
|
2014-07-08 08:43:54 +00:00
|
|
|
|
moment->priv->timestamp,
|
2014-10-07 21:24:11 +00:00
|
|
|
|
moment->priv->timestamp_signal_handler
|
2014-07-08 08:43:54 +00:00
|
|
|
|
);
|
2013-09-01 12:31:23 +00:00
|
|
|
|
g_clear_object(&moment->priv->timestamp);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 01:34:43 +00:00
|
|
|
|
moment->priv->revision++;
|
2013-09-01 12:31:23 +00:00
|
|
|
|
moment->priv->timestamp = timestamp;
|
|
|
|
|
g_object_ref(timestamp);
|
2014-10-07 21:24:11 +00:00
|
|
|
|
moment->priv->timestamp_signal_handler = g_signal_connect(
|
2014-07-08 08:43:54 +00:00
|
|
|
|
G_OBJECT(timestamp),
|
|
|
|
|
"changed",
|
|
|
|
|
G_CALLBACK(gswe_moment_timestamp_changed),
|
|
|
|
|
moment
|
|
|
|
|
);
|
2013-09-01 11:52:18 +00:00
|
|
|
|
|
2013-09-01 12:18:57 +00:00
|
|
|
|
/* Emit the changed signal to notify registrants of the change */
|
|
|
|
|
gswe_moment_emit_changed(moment);
|
2014-09-28 22:04:20 +00:00
|
|
|
|
g_object_notify_by_pspec(G_OBJECT(moment), properties[PROP_TIMESTAMP]);
|
2013-09-01 11:52:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-01 12:31:23 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_get_timestamp:
|
2013-09-11 01:28:15 +00:00
|
|
|
|
* @moment: a GsweMoment object
|
2013-09-01 12:31:23 +00:00
|
|
|
|
*
|
2013-09-11 01:28:15 +00:00
|
|
|
|
* Gets the #GsweTimestamp object associated with @moment
|
2013-09-02 14:17:23 +00:00
|
|
|
|
*
|
2013-09-11 01:28:15 +00:00
|
|
|
|
* Returns: (transfer none): the GsweTimestamp object associated with @moment.
|
|
|
|
|
* The returned object is used by @moment exclusively. If you need it even
|
|
|
|
|
* after @moment is destroyed, call g_object_ref() on it.
|
2013-09-01 12:31:23 +00:00
|
|
|
|
*/
|
|
|
|
|
GsweTimestamp *
|
|
|
|
|
gswe_moment_get_timestamp(GsweMoment *moment)
|
|
|
|
|
{
|
|
|
|
|
return moment->priv->timestamp;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 01:34:07 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_set_coordinates:
|
|
|
|
|
* @moment: a GsweMoment
|
|
|
|
|
* @longitude: the longitude part of the coordinates, in degrees
|
|
|
|
|
* @latitude: the latitude part of the coordinates, in degrees
|
|
|
|
|
* @altitude: the altitude part of the coordinates, in meters. As also noted in
|
|
|
|
|
* the README, it is safe to pass a value of around 400.0, unless
|
|
|
|
|
* you want to create a *really* precise chart
|
|
|
|
|
*
|
|
|
|
|
* Sets the coordinates associated with @moment. Emits the ::changed signal on
|
|
|
|
|
* @moment. All values depending on the coordinates (planetary and house cusp
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* positions, aspects, antiscion, so basically everything) should be
|
2013-09-11 01:34:07 +00:00
|
|
|
|
* re-fetched after changing it.
|
|
|
|
|
*/
|
|
|
|
|
void
|
2014-07-08 08:43:54 +00:00
|
|
|
|
gswe_moment_set_coordinates(
|
|
|
|
|
GsweMoment *moment,
|
|
|
|
|
gdouble longitude,
|
|
|
|
|
gdouble latitude,
|
|
|
|
|
gdouble altitude)
|
2013-09-11 01:34:07 +00:00
|
|
|
|
{
|
2014-09-28 22:04:20 +00:00
|
|
|
|
GsweCoordinates *current_coords = &(moment->priv->coordinates);
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
(current_coords->longitude == longitude)
|
|
|
|
|
&& (current_coords->latitude == latitude)
|
|
|
|
|
&& (current_coords->altitude == altitude)
|
|
|
|
|
) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 01:34:07 +00:00
|
|
|
|
moment->priv->coordinates.longitude = longitude;
|
|
|
|
|
moment->priv->coordinates.latitude = latitude;
|
|
|
|
|
moment->priv->coordinates.altitude = altitude;
|
|
|
|
|
moment->priv->revision++;
|
|
|
|
|
gswe_moment_emit_changed(moment);
|
2014-09-28 22:04:20 +00:00
|
|
|
|
g_object_notify_by_pspec(G_OBJECT(moment), properties[PROP_COORDINATES]);
|
2013-09-11 01:34:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_get_coordinates:
|
|
|
|
|
* @moment: a GsweMoment
|
|
|
|
|
*
|
|
|
|
|
* Gets the coordinates associated with @moment.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full): a newly allocated GsweCoordinates structure with
|
|
|
|
|
* the coordinates associated with @moment. The returned pointer
|
|
|
|
|
* should be freed with g_free if you don't need it any more.
|
|
|
|
|
*/
|
|
|
|
|
GsweCoordinates *
|
|
|
|
|
gswe_moment_get_coordinates(GsweMoment *moment)
|
|
|
|
|
{
|
|
|
|
|
return gswe_coordinates_copy(&(moment->priv->coordinates));
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 01:41:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_set_house_system:
|
|
|
|
|
* @moment: a GsweMoment object
|
|
|
|
|
* @house_system: the new house system to associate with @moment
|
|
|
|
|
*
|
|
|
|
|
* Associates a new house system with @moment. Emits the ::changed signal.
|
|
|
|
|
* House cusp positions are recalculated upon next fetch.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gswe_moment_set_house_system(GsweMoment *moment, GsweHouseSystem house_system)
|
|
|
|
|
{
|
2014-09-28 22:04:20 +00:00
|
|
|
|
if (moment->priv->house_system != house_system) {
|
|
|
|
|
moment->priv->house_system = house_system;
|
|
|
|
|
moment->priv->revision++;
|
|
|
|
|
gswe_moment_emit_changed(moment);
|
|
|
|
|
g_object_notify_by_pspec(G_OBJECT(moment), properties[PROP_HOUSE_SYSTEM]);
|
|
|
|
|
}
|
2013-09-11 01:41:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_get_house_system:
|
|
|
|
|
* @moment: a GsweMoment object
|
|
|
|
|
*
|
2013-09-16 12:00:06 +00:00
|
|
|
|
* Gets the house system associated with @moment.
|
|
|
|
|
*
|
2013-09-11 01:41:42 +00:00
|
|
|
|
* Returns: The house system currently associated with @moment
|
|
|
|
|
*/
|
|
|
|
|
GsweHouseSystem
|
|
|
|
|
gswe_moment_get_house_system(GsweMoment *moment)
|
|
|
|
|
{
|
|
|
|
|
return moment->priv->house_system;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 01:35:45 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_new:
|
|
|
|
|
*
|
|
|
|
|
* Creates a new, empty GsweMoment object. The object created this way can not
|
|
|
|
|
* be used for any calculations yet, you need to call various gswe_moment_set_*
|
|
|
|
|
* functions first. It is preferred to call gswe_moment_new_full() instead.
|
|
|
|
|
*
|
2013-09-16 12:00:06 +00:00
|
|
|
|
* Returns: (transfer full): a new GsweMoment object
|
2013-09-11 01:35:45 +00:00
|
|
|
|
*/
|
2013-09-01 11:52:18 +00:00
|
|
|
|
GsweMoment *
|
|
|
|
|
gswe_moment_new(void)
|
|
|
|
|
{
|
2013-09-27 01:49:51 +00:00
|
|
|
|
gswe_init();
|
|
|
|
|
|
2013-09-01 11:52:18 +00:00
|
|
|
|
return (GsweMoment *)g_object_new(GSWE_TYPE_MOMENT, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 01:35:45 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_new_full:
|
|
|
|
|
* @timestamp: a #GsweTimestamp, the exact time of your calculations
|
|
|
|
|
* @longitude: the longitude part of the observer's position, in degrees
|
|
|
|
|
* @latitude: the latitude part of the observer's position, in degrees
|
|
|
|
|
* @altitude: the altitude part of the coordinates, in meters. As also noted in
|
|
|
|
|
* the README, it is safe to pass a value of around 400.0, unless
|
|
|
|
|
* you want to create a *really* precise chart
|
2013-09-22 16:59:01 +00:00
|
|
|
|
* @house_system: the house system you want to use
|
2013-09-11 01:35:45 +00:00
|
|
|
|
*
|
2014-07-08 08:43:54 +00:00
|
|
|
|
* Creates a new GsweMoment object with the timestamp, coordinates and house
|
|
|
|
|
* system set. This is the preferred way to create a GsweMoment object.
|
2013-09-11 01:35:45 +00:00
|
|
|
|
*
|
2014-07-08 08:43:54 +00:00
|
|
|
|
* Returns: (transfer full): a new GsweMoment object, which is usable out of
|
|
|
|
|
* the box
|
2013-09-11 01:35:45 +00:00
|
|
|
|
*/
|
2013-09-01 20:30:51 +00:00
|
|
|
|
GsweMoment *
|
2014-07-08 08:43:54 +00:00
|
|
|
|
gswe_moment_new_full(
|
|
|
|
|
GsweTimestamp *timestamp,
|
|
|
|
|
gdouble longitude,
|
|
|
|
|
gdouble latitude,
|
|
|
|
|
gdouble altitude,
|
|
|
|
|
GsweHouseSystem house_system)
|
2013-09-01 20:30:51 +00:00
|
|
|
|
{
|
|
|
|
|
GsweMoment *moment = gswe_moment_new();
|
|
|
|
|
|
|
|
|
|
moment->priv->timestamp = timestamp;
|
|
|
|
|
g_object_ref(timestamp);
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_signal_connect(
|
|
|
|
|
G_OBJECT(timestamp),
|
|
|
|
|
"changed",
|
|
|
|
|
G_CALLBACK(gswe_moment_timestamp_changed),
|
|
|
|
|
moment
|
|
|
|
|
);
|
2013-09-01 20:30:51 +00:00
|
|
|
|
moment->priv->coordinates.longitude = longitude;
|
|
|
|
|
moment->priv->coordinates.latitude = latitude;
|
|
|
|
|
moment->priv->coordinates.altitude = altitude;
|
|
|
|
|
moment->priv->house_system = house_system;
|
|
|
|
|
|
|
|
|
|
return moment;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-02 14:19:45 +00:00
|
|
|
|
static gint
|
2013-09-30 20:13:37 +00:00
|
|
|
|
find_planet_by_id(GswePlanetData *planet_data, GswePlanet *planet)
|
2013-09-02 14:19:45 +00:00
|
|
|
|
{
|
2013-09-30 20:13:37 +00:00
|
|
|
|
if (planet_data->planet_info == NULL) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2013-09-02 14:19:45 +00:00
|
|
|
|
|
2013-09-30 20:13:37 +00:00
|
|
|
|
if (planet_data->planet_info->planet == *planet) {
|
2013-09-02 14:19:45 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-07-08 08:43:54 +00:00
|
|
|
|
calculate_data_by_position(
|
|
|
|
|
GsweMoment *moment,
|
|
|
|
|
GswePlanet planet,
|
|
|
|
|
gdouble position,
|
|
|
|
|
GError **err)
|
2013-09-02 14:19:45 +00:00
|
|
|
|
{
|
2013-09-30 20:13:37 +00:00
|
|
|
|
GswePlanetData *planet_data;
|
2013-09-02 14:19:45 +00:00
|
|
|
|
GsweZodiac sign;
|
|
|
|
|
GsweSignInfo *sign_info;
|
2013-09-30 20:13:37 +00:00
|
|
|
|
GList *result;
|
2013-09-02 14:19:45 +00:00
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
if ((result = g_list_find_custom(
|
|
|
|
|
moment->priv->planet_list,
|
|
|
|
|
&planet,
|
|
|
|
|
(GCompareFunc)find_planet_by_id
|
|
|
|
|
)) == NULL) {
|
2013-09-30 20:13:37 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((planet_data = (GswePlanetData *)(result->data)) == NULL) {
|
2013-09-02 14:19:45 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (planet_data->revision == moment->priv->revision) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sign = (GsweZodiac)ceil(position / 30.0);
|
|
|
|
|
|
2013-09-17 07:43:10 +00:00
|
|
|
|
// If position happens to be exactly 0, this calculation yields
|
|
|
|
|
// GSWE_SIGN_NONE, but should be GSWE_SIGN_ARIES
|
2013-09-22 16:56:55 +00:00
|
|
|
|
if (sign == GSWE_SIGN_NONE) {
|
|
|
|
|
sign = GSWE_SIGN_ARIES;
|
2013-09-17 07:43:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
if ((sign_info = g_hash_table_lookup(
|
|
|
|
|
gswe_sign_info_table,
|
|
|
|
|
GINT_TO_POINTER(sign)
|
|
|
|
|
)) == NULL) {
|
2013-09-02 14:19:45 +00:00
|
|
|
|
g_error("Calculations brought an unknown sign!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
planet_data->position = position;
|
|
|
|
|
planet_data->retrograde = FALSE;
|
2013-09-10 23:08:35 +00:00
|
|
|
|
planet_data->house = gswe_moment_get_house(moment, position, err);
|
2013-09-30 20:13:37 +00:00
|
|
|
|
planet_data->sign_info = gswe_sign_info_ref(sign_info);
|
2013-09-02 14:19:45 +00:00
|
|
|
|
planet_data->revision = moment->priv->revision;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-01 20:30:51 +00:00
|
|
|
|
static void
|
2013-09-10 23:08:35 +00:00
|
|
|
|
gswe_moment_calculate_house_positions(GsweMoment *moment, GError **err)
|
2013-09-01 20:30:51 +00:00
|
|
|
|
{
|
|
|
|
|
gdouble cusps[13],
|
2013-09-10 23:08:35 +00:00
|
|
|
|
ascmc[10],
|
|
|
|
|
jd;
|
2013-09-01 20:30:51 +00:00
|
|
|
|
gint i;
|
2013-09-30 20:53:44 +00:00
|
|
|
|
GsweHouseSystemInfo *house_system_info;
|
2013-09-01 20:30:51 +00:00
|
|
|
|
|
2013-09-02 14:19:45 +00:00
|
|
|
|
if (moment->priv->house_revision == moment->priv->revision) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_list_free_full(
|
|
|
|
|
moment->priv->house_list,
|
|
|
|
|
(GDestroyNotify)gswe_house_data_unref
|
|
|
|
|
);
|
2013-09-22 16:59:01 +00:00
|
|
|
|
moment->priv->house_list = NULL;
|
|
|
|
|
|
|
|
|
|
// If no house system is set, we need no calculations at all. Just leave
|
|
|
|
|
// the list empty and return
|
2013-09-22 20:58:18 +00:00
|
|
|
|
if (moment->priv->house_system == GSWE_HOUSE_SYSTEM_NONE) {
|
2013-09-22 16:59:01 +00:00
|
|
|
|
moment->priv->house_revision = moment->priv->revision;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
if ((house_system_info = g_hash_table_lookup(
|
|
|
|
|
gswe_house_system_info_table,
|
|
|
|
|
GINT_TO_POINTER(moment->priv->house_system)
|
|
|
|
|
)) == NULL) {
|
|
|
|
|
g_set_error(
|
|
|
|
|
err,
|
|
|
|
|
GSWE_ERROR, GSWE_ERROR_UNKNOWN_HSYS,
|
|
|
|
|
"Unknown house system"
|
|
|
|
|
);
|
2013-09-10 23:08:35 +00:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-11 13:38:21 +00:00
|
|
|
|
jd = gswe_timestamp_get_julian_day_et(moment->priv->timestamp, err);
|
2013-09-10 23:08:35 +00:00
|
|
|
|
|
2013-09-22 16:59:19 +00:00
|
|
|
|
// If Julian Day calculation yields error, we don't do anything. err is
|
|
|
|
|
// already filled with the error message, so let's just return
|
2013-09-10 23:08:35 +00:00
|
|
|
|
if ((err) && (*err)) {
|
|
|
|
|
return;
|
2013-09-01 20:30:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
swe_houses(
|
|
|
|
|
jd,
|
|
|
|
|
moment->priv->coordinates.latitude,
|
|
|
|
|
moment->priv->coordinates.longitude,
|
|
|
|
|
house_system_info->sweph_id,
|
|
|
|
|
cusps,
|
|
|
|
|
ascmc
|
|
|
|
|
);
|
2013-09-01 20:30:51 +00:00
|
|
|
|
|
2013-09-10 23:08:35 +00:00
|
|
|
|
/* TODO: SWE house system 'G' (Gauquelin sector cusps) have 36 houses; we
|
|
|
|
|
* should detect that somehow (house system 'G' is not implemented yet in
|
|
|
|
|
* GsweHouseSystem, and all other house systems have exactly 12 houses, so
|
|
|
|
|
* this should not cause trouble yet, though) */
|
2013-09-01 20:30:51 +00:00
|
|
|
|
for (i = 12; i >= 1; i--) {
|
2013-09-30 20:17:52 +00:00
|
|
|
|
GsweSignInfo *sign_info;
|
2013-09-30 21:11:52 +00:00
|
|
|
|
GsweHouseData *house_data = gswe_house_data_new();
|
2013-09-01 20:30:51 +00:00
|
|
|
|
|
2013-09-02 21:29:58 +00:00
|
|
|
|
house_data->house = i;
|
|
|
|
|
house_data->cusp_position = cusps[i];
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
if ((sign_info = g_hash_table_lookup(
|
|
|
|
|
gswe_sign_info_table,
|
|
|
|
|
GINT_TO_POINTER((gint)ceilf(cusps[i] / 30.0))
|
|
|
|
|
)) == NULL) {
|
|
|
|
|
g_list_free_full(
|
|
|
|
|
moment->priv->house_list,
|
|
|
|
|
(GDestroyNotify)gswe_house_data_unref
|
|
|
|
|
);
|
2013-09-18 19:55:49 +00:00
|
|
|
|
moment->priv->house_list = NULL;
|
|
|
|
|
moment->priv->house_revision = 0;
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_set_error(
|
|
|
|
|
err,
|
|
|
|
|
GSWE_ERROR, GSWE_ERROR_UNKNOWN_SIGN,
|
|
|
|
|
"Calculation brought an unknown sign"
|
|
|
|
|
);
|
2013-09-10 23:08:35 +00:00
|
|
|
|
|
|
|
|
|
return;
|
2013-09-02 21:29:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-30 20:17:52 +00:00
|
|
|
|
house_data->sign_info = gswe_sign_info_ref(sign_info);
|
2014-07-08 08:43:54 +00:00
|
|
|
|
moment->priv->house_list = g_list_prepend(
|
|
|
|
|
moment->priv->house_list,
|
|
|
|
|
house_data
|
|
|
|
|
);
|
2013-09-01 20:30:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
moment->priv->house_revision = moment->priv->revision;
|
2013-09-02 14:19:45 +00:00
|
|
|
|
|
2013-10-03 21:09:55 +00:00
|
|
|
|
// The Ascendant, MC and Vertex points are also calculated by swe_houses(),
|
2013-09-22 16:59:19 +00:00
|
|
|
|
// so let's update them.
|
2013-10-03 21:09:55 +00:00
|
|
|
|
if (gswe_moment_has_planet(moment, GSWE_PLANET_ASCENDANT)) {
|
2014-07-08 08:43:54 +00:00
|
|
|
|
calculate_data_by_position(
|
|
|
|
|
moment,
|
|
|
|
|
GSWE_PLANET_ASCENDANT,
|
|
|
|
|
ascmc[0],
|
|
|
|
|
err
|
|
|
|
|
);
|
2013-09-02 14:19:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gswe_moment_has_planet(moment, GSWE_PLANET_MC)) {
|
2013-09-30 20:13:37 +00:00
|
|
|
|
calculate_data_by_position(moment, GSWE_PLANET_MC, ascmc[1], err);
|
2013-09-02 14:19:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gswe_moment_has_planet(moment, GSWE_PLANET_VERTEX)) {
|
2013-09-30 20:13:37 +00:00
|
|
|
|
calculate_data_by_position(moment, GSWE_PLANET_VERTEX, ascmc[3], err);
|
2013-09-02 14:19:45 +00:00
|
|
|
|
}
|
2013-09-01 20:30:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 17:50:57 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_get_house_cusps:
|
|
|
|
|
* @moment: The GsweMoment object to operate on
|
2013-09-10 23:55:10 +00:00
|
|
|
|
* @err: a #GError
|
2013-09-05 17:50:57 +00:00
|
|
|
|
*
|
2014-07-08 08:43:54 +00:00
|
|
|
|
* Calculate house cusp positions based on the house system, location and time
|
|
|
|
|
* set in @moment.
|
2013-09-05 17:50:57 +00:00
|
|
|
|
*
|
2014-07-08 08:43:54 +00:00
|
|
|
|
* Returns: (element-type GsweHouseData) (transfer none): a GList of
|
|
|
|
|
* #GsweHouseData
|
2013-09-05 17:50:57 +00:00
|
|
|
|
*/
|
2013-09-01 20:30:51 +00:00
|
|
|
|
GList *
|
2013-09-10 23:08:35 +00:00
|
|
|
|
gswe_moment_get_house_cusps(GsweMoment *moment, GError **err)
|
2013-09-01 20:30:51 +00:00
|
|
|
|
{
|
|
|
|
|
if (moment->priv->house_revision != moment->priv->revision) {
|
2013-09-10 23:08:35 +00:00
|
|
|
|
gswe_moment_calculate_house_positions(moment, err);
|
2013-09-01 20:30:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return moment->priv->house_list;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 01:35:45 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_has_planet:
|
|
|
|
|
* @moment: a GsweMoment
|
|
|
|
|
* @planet: the planet whose existence is queried
|
|
|
|
|
*
|
2014-07-08 08:43:54 +00:00
|
|
|
|
* Checks if @planet is added to @moment, e.g. its position and related data is
|
|
|
|
|
* calculated.
|
2013-09-11 01:35:45 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns: #TRUE if @planet is already added to @moment, #FALSE otherwise
|
|
|
|
|
*/
|
2013-09-02 14:19:45 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gswe_moment_has_planet(GsweMoment *moment, GswePlanet planet)
|
|
|
|
|
{
|
2014-07-08 08:43:54 +00:00
|
|
|
|
return (g_list_find_custom(
|
|
|
|
|
moment->priv->planet_list,
|
|
|
|
|
&planet,
|
|
|
|
|
(GCompareFunc)find_planet_by_id
|
|
|
|
|
) != NULL);
|
2013-09-02 14:19:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 01:35:45 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_add_planet:
|
|
|
|
|
* @moment: a GsweMoment object
|
|
|
|
|
* @planet: the planet to add
|
2013-09-30 20:13:37 +00:00
|
|
|
|
* @err: a #GError
|
2013-09-11 01:35:45 +00:00
|
|
|
|
*
|
2013-09-30 20:13:37 +00:00
|
|
|
|
* Adds @planet to the calculated planets of @moment. @err is populated with
|
|
|
|
|
* GSWE_ERROR_UNKNOWN_PLANET if the given planet is not known to SWE-GLib.
|
2013-09-11 01:35:45 +00:00
|
|
|
|
*/
|
2013-09-02 14:19:45 +00:00
|
|
|
|
void
|
2013-09-30 20:13:37 +00:00
|
|
|
|
gswe_moment_add_planet(GsweMoment *moment, GswePlanet planet, GError **err)
|
2013-09-02 14:19:45 +00:00
|
|
|
|
{
|
2013-09-30 20:13:37 +00:00
|
|
|
|
GswePlanetData *planet_data;
|
2013-09-02 14:19:45 +00:00
|
|
|
|
GswePlanetInfo *planet_info;
|
|
|
|
|
|
|
|
|
|
if (gswe_moment_has_planet(moment, planet)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
if ((planet_info = g_hash_table_lookup(
|
|
|
|
|
gswe_planet_info_table,
|
|
|
|
|
GINT_TO_POINTER(planet)
|
|
|
|
|
)) == NULL) {
|
|
|
|
|
g_set_error(
|
|
|
|
|
err,
|
|
|
|
|
GSWE_ERROR, GSWE_ERROR_UNKNOWN_PLANET,
|
|
|
|
|
"Unknown planet"
|
|
|
|
|
);
|
2013-09-02 14:19:45 +00:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-30 20:13:37 +00:00
|
|
|
|
planet_data = gswe_planet_data_new();
|
2014-03-15 17:38:27 +00:00
|
|
|
|
planet_data->planet_info = gswe_planet_info_ref(planet_info);
|
2013-09-02 14:19:45 +00:00
|
|
|
|
planet_data->revision = 0;
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
moment->priv->planet_list = g_list_append(
|
|
|
|
|
moment->priv->planet_list,
|
|
|
|
|
planet_data
|
|
|
|
|
);
|
2014-10-07 21:25:24 +00:00
|
|
|
|
|
|
|
|
|
g_signal_emit(moment, gswe_moment_signals[SIGNAL_PLANET_ADDED], 0, planet);
|
2013-09-02 14:19:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-03-16 08:20:10 +00:00
|
|
|
|
planet_add(gpointer key, gpointer value, GsweMoment *moment)
|
2013-09-02 14:19:45 +00:00
|
|
|
|
{
|
|
|
|
|
GswePlanet planet = (GswePlanet)GPOINTER_TO_INT(key);
|
|
|
|
|
|
2013-09-30 20:13:37 +00:00
|
|
|
|
gswe_moment_add_planet(moment, planet, NULL);
|
2013-09-02 14:19:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 01:35:45 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_add_all_planets:
|
|
|
|
|
* @moment: a GsweMoment object
|
|
|
|
|
*
|
|
|
|
|
* Adds all known planets to @moment.
|
|
|
|
|
*/
|
2013-09-02 14:19:45 +00:00
|
|
|
|
void
|
|
|
|
|
gswe_moment_add_all_planets(GsweMoment *moment)
|
|
|
|
|
{
|
2014-03-16 08:20:10 +00:00
|
|
|
|
g_hash_table_foreach(gswe_planet_info_table, (GHFunc)planet_add, moment);
|
2013-09-02 14:19:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-02 21:10:35 +00:00
|
|
|
|
static void
|
2014-09-02 10:53:37 +00:00
|
|
|
|
gswe_moment_calculate_planet(GsweMoment *moment,
|
|
|
|
|
GswePlanet planet,
|
|
|
|
|
GError **err)
|
2013-09-02 21:10:35 +00:00
|
|
|
|
{
|
2014-09-02 10:53:37 +00:00
|
|
|
|
GswePlanetData *planet_data;
|
|
|
|
|
gpointer data = g_list_find_custom(
|
|
|
|
|
moment->priv->planet_list,
|
|
|
|
|
&planet,
|
|
|
|
|
(GCompareFunc)find_planet_by_id
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
|
|
|
|
|
planet_data = (GswePlanetData *)(g_list_find_custom(
|
2014-07-08 08:43:54 +00:00
|
|
|
|
moment->priv->planet_list,
|
|
|
|
|
&planet,
|
|
|
|
|
(GCompareFunc)find_planet_by_id
|
|
|
|
|
)->data);
|
2013-09-02 21:10:35 +00:00
|
|
|
|
gchar serr[AS_MAXCH];
|
|
|
|
|
gint ret;
|
2013-09-10 23:08:35 +00:00
|
|
|
|
gdouble x2[6],
|
|
|
|
|
jd;
|
|
|
|
|
GError *calc_err = NULL;
|
2013-09-02 21:10:35 +00:00
|
|
|
|
|
|
|
|
|
if (planet_data == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (planet_data->revision == moment->priv->revision) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
swe_set_topo(
|
|
|
|
|
moment->priv->coordinates.longitude,
|
|
|
|
|
moment->priv->coordinates.latitude,
|
|
|
|
|
moment->priv->coordinates.altitude
|
|
|
|
|
);
|
2014-06-11 13:38:21 +00:00
|
|
|
|
jd = gswe_timestamp_get_julian_day_et(moment->priv->timestamp, err);
|
2013-09-30 23:48:43 +00:00
|
|
|
|
|
2013-09-02 21:10:35 +00:00
|
|
|
|
if (planet_data->planet_info->real_body == FALSE) {
|
2013-09-30 23:48:43 +00:00
|
|
|
|
if (
|
2013-10-03 21:09:55 +00:00
|
|
|
|
(planet_data->planet_info->planet != GSWE_PLANET_ASCENDANT)
|
2013-09-30 23:48:43 +00:00
|
|
|
|
&& (planet_data->planet_info->planet != GSWE_PLANET_MC)
|
|
|
|
|
&& (planet_data->planet_info->planet != GSWE_PLANET_VERTEX)
|
|
|
|
|
) {
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_warning(
|
|
|
|
|
"The position data of planet %d can not be "
|
|
|
|
|
"calculated by this function",
|
|
|
|
|
planet
|
|
|
|
|
);
|
2013-09-02 21:10:35 +00:00
|
|
|
|
|
2013-09-30 23:48:43 +00:00
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
// gswe_moment_calculate_house_positions() calculates house cusp
|
|
|
|
|
// positions, together with Ascendant, MC and Vertex points
|
|
|
|
|
gswe_moment_calculate_house_positions(moment, err);
|
2013-09-02 21:10:35 +00:00
|
|
|
|
|
2013-09-30 23:48:43 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-10 23:08:35 +00:00
|
|
|
|
|
|
|
|
|
if ((err) && (*err)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
if ((ret = swe_calc(
|
|
|
|
|
jd,
|
|
|
|
|
planet_data->planet_info->sweph_id,
|
|
|
|
|
SEFLG_SPEED | SEFLG_TOPOCTR,
|
|
|
|
|
x2,
|
|
|
|
|
serr
|
|
|
|
|
)) < 0) {
|
2014-09-24 16:54:43 +00:00
|
|
|
|
g_warning("Swiss Ephemeris error: %s", serr);
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_set_error(
|
|
|
|
|
err,
|
|
|
|
|
GSWE_ERROR, GSWE_ERROR_SWE_FATAL,
|
2014-09-24 16:54:43 +00:00
|
|
|
|
"Swiss Ephemeris fatal error: %s",
|
2014-07-08 08:43:54 +00:00
|
|
|
|
serr
|
|
|
|
|
);
|
2013-09-02 21:10:35 +00:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
} else if (ret != (SEFLG_SPEED | SEFLG_TOPOCTR)) {
|
2014-09-24 16:54:43 +00:00
|
|
|
|
g_warning("Swiss Ephemeris non-fatal error: %s", serr);
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_set_error(
|
|
|
|
|
err,
|
|
|
|
|
GSWE_ERROR, GSWE_ERROR_SWE_NONFATAL,
|
|
|
|
|
"Swiss Ephemeris error: %s",
|
|
|
|
|
serr
|
|
|
|
|
);
|
2013-09-02 21:10:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-20 13:23:47 +00:00
|
|
|
|
// The south node is actually on the opposite side of the chart,
|
|
|
|
|
// so let’s invert the position.
|
|
|
|
|
if (planet == GSWE_PLANET_MOON_SOUTH_NODE) {
|
|
|
|
|
x2[0] = fmod(x2[0] + 180.0, 180.0);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-30 20:13:37 +00:00
|
|
|
|
calculate_data_by_position(moment, planet, x2[0], &calc_err);
|
2013-09-10 23:08:35 +00:00
|
|
|
|
|
|
|
|
|
if (calc_err != NULL) {
|
|
|
|
|
g_clear_error(err);
|
|
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
*err = calc_err;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-02 21:10:35 +00:00
|
|
|
|
|
|
|
|
|
planet_data->retrograde = (x2[3] < 0);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 23:08:35 +00:00
|
|
|
|
static void
|
|
|
|
|
calculate_planet(GswePlanetData *planet_data, GsweMoment *moment)
|
2013-09-02 21:10:35 +00:00
|
|
|
|
{
|
2013-10-03 23:45:16 +00:00
|
|
|
|
if (planet_data->planet_info) {
|
2014-07-08 08:43:54 +00:00
|
|
|
|
gswe_moment_calculate_planet(
|
|
|
|
|
moment,
|
|
|
|
|
planet_data->planet_info->planet,
|
|
|
|
|
NULL
|
|
|
|
|
);
|
2013-10-03 23:45:16 +00:00
|
|
|
|
} else {
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_warning(
|
|
|
|
|
"planet_data holds no planet. This is a possible "
|
|
|
|
|
"bug in SWE-GLib, or in your application."
|
|
|
|
|
);
|
2013-10-03 23:45:16 +00:00
|
|
|
|
}
|
2013-09-02 21:10:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 23:08:35 +00:00
|
|
|
|
static void
|
2013-09-02 21:10:35 +00:00
|
|
|
|
gswe_moment_calculate_all_planets(GsweMoment *moment)
|
|
|
|
|
{
|
2013-09-10 23:08:35 +00:00
|
|
|
|
g_list_foreach(moment->priv->planet_list, (GFunc)calculate_planet, moment);
|
2013-09-02 21:10:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 17:50:57 +00:00
|
|
|
|
/**
|
2013-09-16 12:19:39 +00:00
|
|
|
|
* gswe_moment_get_all_planets:
|
2013-09-05 17:50:57 +00:00
|
|
|
|
* @moment: The GsweMoment to operate on
|
|
|
|
|
*
|
|
|
|
|
* Get all the planets added to @moment.
|
|
|
|
|
*
|
2014-07-08 08:43:54 +00:00
|
|
|
|
* Returns: (element-type GswePlanetData) (transfer none): A #GList of
|
|
|
|
|
* #GswePlanetData.
|
2013-09-05 17:50:57 +00:00
|
|
|
|
*/
|
2013-09-02 14:19:45 +00:00
|
|
|
|
GList *
|
2013-09-16 12:19:39 +00:00
|
|
|
|
gswe_moment_get_all_planets(GsweMoment *moment)
|
2013-09-02 14:19:45 +00:00
|
|
|
|
{
|
2013-09-18 09:55:26 +00:00
|
|
|
|
gswe_moment_calculate_all_planets(moment);
|
|
|
|
|
|
2013-09-02 14:19:45 +00:00
|
|
|
|
return moment->priv->planet_list;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-16 12:20:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_get_sign_planets:
|
|
|
|
|
* @moment: a GsweMoment
|
|
|
|
|
* @sign: the sign of whose planets are requested
|
|
|
|
|
*
|
|
|
|
|
* Gets the list of planets in @sign.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer container) (element-type GswePlanetData): a #GList of
|
|
|
|
|
* #GswePlanetData.
|
|
|
|
|
*/
|
|
|
|
|
GList *
|
|
|
|
|
gswe_moment_get_sign_planets(GsweMoment *moment, GsweZodiac sign)
|
|
|
|
|
{
|
|
|
|
|
GList *ret = NULL,
|
|
|
|
|
*planet;
|
|
|
|
|
|
|
|
|
|
gswe_moment_calculate_all_planets(moment);
|
|
|
|
|
|
2013-10-08 22:06:08 +00:00
|
|
|
|
glforeach (planet, moment->priv->planet_list) {
|
2013-09-16 12:20:49 +00:00
|
|
|
|
GswePlanetData *pd = planet->data;
|
|
|
|
|
|
2013-09-30 20:17:52 +00:00
|
|
|
|
if (pd->sign_info->sign == sign) {
|
2013-09-16 12:20:49 +00:00
|
|
|
|
ret = g_list_prepend(ret, pd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_get_house_planets:
|
|
|
|
|
* @moment: a GsweMoment
|
|
|
|
|
* @house: a house number
|
|
|
|
|
*
|
|
|
|
|
* Gets the list of planets in house @house.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer container) (element-type GswePlanetData): a #GList of
|
|
|
|
|
* #GswePlanetData
|
|
|
|
|
*/
|
|
|
|
|
GList *
|
|
|
|
|
gswe_moment_get_house_planets(GsweMoment *moment, guint house)
|
|
|
|
|
{
|
|
|
|
|
GList *ret = NULL,
|
|
|
|
|
*planet;
|
|
|
|
|
|
2013-09-22 16:59:01 +00:00
|
|
|
|
// If the house system is none, we always return NULL
|
|
|
|
|
if (moment->priv->house_system == GSWE_HOUSE_SYSTEM_NONE) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-16 12:20:49 +00:00
|
|
|
|
gswe_moment_calculate_all_planets(moment);
|
|
|
|
|
|
2013-10-08 22:06:08 +00:00
|
|
|
|
glforeach (planet, moment->priv->planet_list) {
|
2013-09-16 12:20:49 +00:00
|
|
|
|
GswePlanetData *pd = planet->data;
|
|
|
|
|
|
|
|
|
|
if (pd->house == house) {
|
|
|
|
|
ret = g_list_prepend(ret, pd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 01:36:39 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_get_house:
|
|
|
|
|
* @moment: a GsweMoment object
|
|
|
|
|
* @position: an ecliptic position
|
2013-09-11 08:38:06 +00:00
|
|
|
|
* @err: a #GError
|
2013-09-11 01:36:39 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns the number of the house in which @position is.
|
|
|
|
|
*
|
2014-07-08 08:43:54 +00:00
|
|
|
|
* Returns: the number of the house in which @position is. This function always
|
|
|
|
|
* yields 0 if the associated house system is #GSWE_HOUSE_SYSTEM_NONE.
|
2013-09-11 01:36:39 +00:00
|
|
|
|
*/
|
2013-09-02 14:19:45 +00:00
|
|
|
|
gint
|
2013-09-10 23:08:35 +00:00
|
|
|
|
gswe_moment_get_house(GsweMoment *moment, gdouble position, GError **err)
|
2013-09-02 14:19:45 +00:00
|
|
|
|
{
|
|
|
|
|
gint i;
|
2013-09-11 01:36:19 +00:00
|
|
|
|
|
|
|
|
|
if (moment->priv->house_system == GSWE_HOUSE_SYSTEM_NONE) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 23:08:35 +00:00
|
|
|
|
gswe_moment_calculate_house_positions(moment, err);
|
2013-09-02 14:19:45 +00:00
|
|
|
|
|
2013-09-10 23:08:35 +00:00
|
|
|
|
/* TODO: SWE house system 'G' (Gauquelin sector cusps) have 36 houses; we
|
|
|
|
|
* should detect that somehow (house system 'G' is not implemented yet in
|
|
|
|
|
* GsweHouseSystem, and all other house systems have exactly 12 houses, so
|
|
|
|
|
* this should not cause trouble yet, though) */
|
2013-09-02 14:19:45 +00:00
|
|
|
|
for (i = 1; i <= 12; i++) {
|
|
|
|
|
gint j = (i < 12) ? i + 1 : 1;
|
2014-07-08 08:43:54 +00:00
|
|
|
|
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
|
|
|
|
|
);
|
2013-09-02 14:19:45 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-16 12:00:06 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_get_planet:
|
|
|
|
|
* @moment: a GsweMoment
|
|
|
|
|
* @planet: the planet whose data is requested
|
|
|
|
|
* @err: a #GError
|
|
|
|
|
*
|
|
|
|
|
* Gets @planet's data, like its position, house number, sign, etc. @err is
|
|
|
|
|
* populated if the planetary information can not be calculated.
|
|
|
|
|
*
|
|
|
|
|
* WARNING! @err may be populated if the Swiss Ephemeris data files are not
|
|
|
|
|
* found. For some planets, position data still can be calculated (the results
|
|
|
|
|
* will not be that exact, though). @err is populatet only to carry this
|
|
|
|
|
* warning. Thus, you should always provide a non-NULL value for @err, and
|
|
|
|
|
* always check it after calling this function.
|
|
|
|
|
*
|
2013-10-03 22:19:11 +00:00
|
|
|
|
* Returns: (transfer full): @planet's data
|
2013-09-16 12:00:06 +00:00
|
|
|
|
*/
|
2013-10-03 22:19:11 +00:00
|
|
|
|
GswePlanetData *
|
2013-09-10 23:08:35 +00:00
|
|
|
|
gswe_moment_get_planet(GsweMoment *moment, GswePlanet planet, GError **err)
|
2013-09-02 14:19:45 +00:00
|
|
|
|
{
|
2014-04-05 20:38:43 +00:00
|
|
|
|
GList *planet_element;
|
|
|
|
|
GswePlanetData *planet_data;
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
if ((planet_element = g_list_find_custom(
|
|
|
|
|
moment->priv->planet_list,
|
|
|
|
|
&planet,
|
|
|
|
|
(GCompareFunc)find_planet_by_id
|
|
|
|
|
)) == NULL) {
|
2014-04-05 20:38:43 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
planet_data = (GswePlanetData *)(planet_element->data);
|
2013-09-02 14:19:45 +00:00
|
|
|
|
|
|
|
|
|
if (planet_data == NULL) {
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_set_error(
|
|
|
|
|
err,
|
|
|
|
|
GSWE_ERROR, GSWE_ERROR_UNKNOWN_PLANET,
|
|
|
|
|
"Specified planet is not added to the moment object"
|
|
|
|
|
);
|
2013-09-10 23:08:35 +00:00
|
|
|
|
|
2013-09-02 21:10:35 +00:00
|
|
|
|
return NULL;
|
2013-09-02 14:19:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 23:08:35 +00:00
|
|
|
|
gswe_moment_calculate_planet(moment, planet, err);
|
2013-09-02 14:19:45 +00:00
|
|
|
|
|
2013-10-03 22:19:11 +00:00
|
|
|
|
return gswe_planet_data_ref(planet_data);
|
2013-09-02 21:10:35 +00:00
|
|
|
|
}
|
2013-09-02 14:19:45 +00:00
|
|
|
|
|
2013-09-02 21:10:35 +00:00
|
|
|
|
static void
|
|
|
|
|
add_points(GswePlanetData *planet_data, GsweMoment *moment)
|
|
|
|
|
{
|
2014-09-02 09:51:03 +00:00
|
|
|
|
guint point;
|
|
|
|
|
GsweSignInfo *sign_info;
|
|
|
|
|
GswePlanetInfo *planet_info;
|
|
|
|
|
GsweElement element;
|
|
|
|
|
GsweQuality quality;
|
2013-09-02 14:19:45 +00:00
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
gswe_moment_calculate_planet(
|
|
|
|
|
moment,
|
|
|
|
|
planet_data->planet_info->planet,
|
|
|
|
|
NULL
|
|
|
|
|
);
|
|
|
|
|
|
2014-09-02 09:51:03 +00:00
|
|
|
|
sign_info = gswe_planet_data_get_sign_info(planet_data);
|
2014-09-02 09:56:10 +00:00
|
|
|
|
|
|
|
|
|
if (G_UNLIKELY(sign_info == NULL)) {
|
|
|
|
|
g_error("Planet data calculation failed");
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-02 09:51:03 +00:00
|
|
|
|
planet_info = gswe_planet_data_get_planet_info(planet_data);
|
2014-09-02 09:56:10 +00:00
|
|
|
|
|
|
|
|
|
if (G_UNLIKELY(planet_info == NULL)) {
|
|
|
|
|
g_error("Planet data calculation failed. No planet info.");
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-02 09:51:03 +00:00
|
|
|
|
element = gswe_sign_info_get_element(sign_info);
|
|
|
|
|
point = GPOINTER_TO_INT(g_hash_table_lookup(
|
2014-07-08 08:43:54 +00:00
|
|
|
|
moment->priv->element_points,
|
2014-09-02 09:51:03 +00:00
|
|
|
|
GINT_TO_POINTER(element)
|
|
|
|
|
)) + gswe_planet_info_get_points(planet_info);
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_hash_table_replace(
|
|
|
|
|
moment->priv->element_points,
|
2014-09-02 09:51:03 +00:00
|
|
|
|
GINT_TO_POINTER(element),
|
2014-07-08 08:43:54 +00:00
|
|
|
|
GINT_TO_POINTER(point)
|
|
|
|
|
);
|
|
|
|
|
|
2014-09-02 09:51:03 +00:00
|
|
|
|
quality = gswe_sign_info_get_quality(sign_info);
|
|
|
|
|
point = GPOINTER_TO_INT(g_hash_table_lookup(
|
2014-07-08 08:43:54 +00:00
|
|
|
|
moment->priv->quality_points,
|
2014-09-02 09:51:03 +00:00
|
|
|
|
GINT_TO_POINTER(quality)
|
|
|
|
|
)) + gswe_planet_info_get_points(planet_info);
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_hash_table_replace(
|
|
|
|
|
moment->priv->quality_points,
|
2014-09-02 09:51:03 +00:00
|
|
|
|
GINT_TO_POINTER(quality),
|
2014-07-08 08:43:54 +00:00
|
|
|
|
GINT_TO_POINTER(point)
|
|
|
|
|
);
|
2013-09-02 21:10:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gswe_moment_calculate_points(GsweMoment *moment)
|
|
|
|
|
{
|
|
|
|
|
if (moment->priv->points_revision == moment->priv->revision) {
|
2013-09-02 14:19:45 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-02 21:10:35 +00:00
|
|
|
|
g_hash_table_remove_all(moment->priv->element_points);
|
|
|
|
|
g_hash_table_remove_all(moment->priv->quality_points);
|
2013-09-02 14:19:45 +00:00
|
|
|
|
|
2013-09-02 21:10:35 +00:00
|
|
|
|
g_list_foreach(moment->priv->planet_list, (GFunc)add_points, moment);
|
|
|
|
|
|
|
|
|
|
moment->priv->points_revision = moment->priv->revision;
|
2013-09-02 14:19:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-16 12:00:06 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_get_element_points:
|
|
|
|
|
* @moment: a GsweMoment
|
|
|
|
|
* @element: the element whose point value is requested
|
|
|
|
|
*
|
|
|
|
|
* Gets the point value of the @element element.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the point value
|
|
|
|
|
*/
|
2013-09-02 21:10:35 +00:00
|
|
|
|
guint
|
|
|
|
|
gswe_moment_get_element_points(GsweMoment *moment, GsweElement element)
|
2013-09-02 14:19:45 +00:00
|
|
|
|
{
|
2013-09-02 21:10:35 +00:00
|
|
|
|
guint point;
|
2013-09-02 14:19:45 +00:00
|
|
|
|
|
2013-09-02 21:10:35 +00:00
|
|
|
|
gswe_moment_calculate_points(moment);
|
2013-09-02 14:19:45 +00:00
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
point = GPOINTER_TO_INT(g_hash_table_lookup(
|
|
|
|
|
moment->priv->element_points,
|
|
|
|
|
GINT_TO_POINTER(element)
|
|
|
|
|
));
|
2013-09-02 14:19:45 +00:00
|
|
|
|
|
2013-09-02 21:10:35 +00:00
|
|
|
|
return point;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-16 12:00:06 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_get_quality_points:
|
|
|
|
|
* @moment: a GsweMoment
|
|
|
|
|
* @quality: the quality whose point value is requested
|
|
|
|
|
*
|
|
|
|
|
* Gets the point value of the @quality quality.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the point value
|
|
|
|
|
*/
|
2013-09-02 21:10:35 +00:00
|
|
|
|
guint
|
|
|
|
|
gswe_moment_get_quality_points(GsweMoment *moment, GsweQuality quality)
|
|
|
|
|
{
|
|
|
|
|
guint point;
|
|
|
|
|
|
|
|
|
|
gswe_moment_calculate_points(moment);
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
point = GPOINTER_TO_INT(g_hash_table_lookup(
|
|
|
|
|
moment->priv->quality_points,
|
|
|
|
|
GINT_TO_POINTER(quality)
|
|
|
|
|
));
|
2013-09-02 21:10:35 +00:00
|
|
|
|
|
|
|
|
|
return point;
|
2013-09-02 14:19:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-16 12:00:06 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_get_moon_phase:
|
|
|
|
|
* @moment: a GsweMoment
|
|
|
|
|
* @err: a #GError
|
|
|
|
|
*
|
|
|
|
|
* Gets the phase of the Moon.
|
|
|
|
|
*
|
2014-07-08 08:43:54 +00:00
|
|
|
|
* Returns: (transfer full): a #GsweMoonPhaseData representing the phase of the
|
|
|
|
|
* Moon
|
2013-09-16 12:00:06 +00:00
|
|
|
|
*/
|
2013-10-03 22:19:11 +00:00
|
|
|
|
GsweMoonPhaseData *
|
2013-09-10 23:08:35 +00:00
|
|
|
|
gswe_moment_get_moon_phase(GsweMoment *moment, GError **err)
|
2013-09-02 21:12:56 +00:00
|
|
|
|
{
|
|
|
|
|
if (moment->priv->moon_phase_revision == moment->priv->revision) {
|
2013-09-30 20:39:46 +00:00
|
|
|
|
return moment->priv->moon_phase;
|
2013-09-02 21:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
gswe_moon_phase_data_calculate_by_timestamp(
|
|
|
|
|
moment->priv->moon_phase,
|
|
|
|
|
moment->priv->timestamp,
|
|
|
|
|
err
|
|
|
|
|
);
|
2013-09-02 21:12:56 +00:00
|
|
|
|
|
2013-10-03 23:18:34 +00:00
|
|
|
|
if (!err || !*err) {
|
|
|
|
|
moment->priv->moon_phase_revision = moment->priv->revision;
|
2013-09-02 21:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-03 22:19:11 +00:00
|
|
|
|
return gswe_moon_phase_data_ref(moment->priv->moon_phase);
|
2013-09-02 21:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-02 23:11:18 +00:00
|
|
|
|
static gint
|
2014-07-08 08:43:54 +00:00
|
|
|
|
find_aspect_by_both_planets(
|
|
|
|
|
GsweAspectData *aspect,
|
|
|
|
|
struct GsweAspectFinder *aspect_finder)
|
2013-09-02 23:11:18 +00:00
|
|
|
|
{
|
2013-09-30 20:13:37 +00:00
|
|
|
|
if (
|
|
|
|
|
(
|
|
|
|
|
(aspect->planet1->planet_info->planet == aspect_finder->planet1)
|
|
|
|
|
&& (aspect->planet2->planet_info->planet == aspect_finder->planet2)
|
|
|
|
|
)
|
|
|
|
|
|| (
|
|
|
|
|
(aspect->planet1->planet_info->planet == aspect_finder->planet2)
|
|
|
|
|
&& (aspect->planet2->planet_info->planet == aspect_finder->planet1)
|
|
|
|
|
)
|
|
|
|
|
) {
|
2013-09-02 23:11:18 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gswe_moment_calculate_aspects(GsweMoment *moment)
|
|
|
|
|
{
|
|
|
|
|
GList *oplanet,
|
|
|
|
|
*iplanet;
|
|
|
|
|
|
|
|
|
|
if (moment->priv->aspect_revision == moment->priv->revision) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gswe_moment_calculate_all_planets(moment);
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_list_free_full(
|
|
|
|
|
moment->priv->aspect_list,
|
|
|
|
|
(GDestroyNotify)gswe_aspect_data_unref
|
|
|
|
|
);
|
2013-09-18 19:55:49 +00:00
|
|
|
|
moment->priv->aspect_list = NULL;
|
2013-09-02 23:11:18 +00:00
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
for (
|
|
|
|
|
oplanet = moment->priv->planet_list;
|
|
|
|
|
oplanet;
|
|
|
|
|
oplanet = g_list_next(oplanet)) {
|
|
|
|
|
for (
|
|
|
|
|
iplanet = moment->priv->planet_list;
|
|
|
|
|
iplanet;
|
|
|
|
|
iplanet = g_list_next(iplanet)) {
|
2013-09-02 23:11:18 +00:00
|
|
|
|
GswePlanetData *outer_planet = oplanet->data,
|
|
|
|
|
*inner_planet = iplanet->data;
|
|
|
|
|
struct GsweAspectFinder aspect_finder;
|
|
|
|
|
GsweAspectData *aspect_data;
|
2013-09-30 19:42:19 +00:00
|
|
|
|
GList *aspect_data_element;
|
2013-09-02 23:11:18 +00:00
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
if (outer_planet->planet_info->planet
|
|
|
|
|
== inner_planet->planet_info->planet
|
|
|
|
|
) {
|
2013-09-02 23:11:18 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-30 19:42:19 +00:00
|
|
|
|
aspect_finder.planet1 = outer_planet->planet_info->planet;
|
|
|
|
|
aspect_finder.planet2 = inner_planet->planet_info->planet;
|
2013-09-02 23:11:18 +00:00
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
if ((aspect_data_element = g_list_find_custom(
|
|
|
|
|
moment->priv->aspect_list,
|
|
|
|
|
&aspect_finder,
|
|
|
|
|
(GCompareFunc)find_aspect_by_both_planets
|
|
|
|
|
)) != NULL) {
|
2013-09-30 19:42:19 +00:00
|
|
|
|
gswe_aspect_data_calculate(aspect_data_element->data);
|
|
|
|
|
} else {
|
2014-07-08 08:43:54 +00:00
|
|
|
|
aspect_data = gswe_aspect_data_new_with_planets(
|
|
|
|
|
inner_planet,
|
|
|
|
|
outer_planet
|
|
|
|
|
);
|
|
|
|
|
moment->priv->aspect_list = g_list_prepend(
|
|
|
|
|
moment->priv->aspect_list,
|
|
|
|
|
aspect_data
|
|
|
|
|
);
|
2013-09-02 23:11:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
moment->priv->aspect_revision = moment->priv->revision;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-03 09:26:53 +00:00
|
|
|
|
/**
|
2013-09-10 22:17:23 +00:00
|
|
|
|
* gswe_moment_get_all_aspects:
|
2013-09-03 09:26:53 +00:00
|
|
|
|
* @moment: the GsweMoment to operate on
|
|
|
|
|
*
|
|
|
|
|
* Gets all planetary aspects between the planets added by
|
|
|
|
|
* gswe_moment_add_planet() or gswe_moment_add_all_planets().
|
|
|
|
|
*
|
2013-09-05 17:50:57 +00:00
|
|
|
|
* Returns: (element-type GsweAspectData) (transfer none): a GList of
|
|
|
|
|
* #GsweAspectData. Both the GList and GsweAspectData objects belong
|
|
|
|
|
* to @moment, and should not be freed or modified.
|
2013-09-03 09:26:53 +00:00
|
|
|
|
*/
|
2013-09-02 23:11:18 +00:00
|
|
|
|
GList *
|
2013-09-10 22:17:23 +00:00
|
|
|
|
gswe_moment_get_all_aspects(GsweMoment *moment)
|
2013-09-02 23:11:18 +00:00
|
|
|
|
{
|
|
|
|
|
gswe_moment_calculate_aspects(moment);
|
|
|
|
|
|
|
|
|
|
return moment->priv->aspect_list;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-03 09:26:53 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_get_planet_aspects:
|
|
|
|
|
* @moment: the GsweMoment to operate on
|
|
|
|
|
* @planet: the planet whose aspects you want to get
|
2013-09-10 23:55:10 +00:00
|
|
|
|
* @err: a #GError
|
2013-09-03 09:26:53 +00:00
|
|
|
|
*
|
|
|
|
|
* Get all the aspects between @planet and all the other planets added with
|
|
|
|
|
* gswe_moment_add_planet() or gswe_moment_add_all_planets().
|
|
|
|
|
*
|
2013-09-05 17:50:57 +00:00
|
|
|
|
* Returns: (element-type GsweAspectData) (transfer container): a #GList of
|
|
|
|
|
* #GsweAspectData. The GsweAspectData structures belong to @moment,
|
|
|
|
|
* but the GList should be freed using g_list_free(). If the planet
|
|
|
|
|
* has no aspects, or the planet has not been added to @moment,
|
2013-09-03 09:26:53 +00:00
|
|
|
|
* returns NULL.
|
|
|
|
|
*/
|
2013-09-02 23:11:18 +00:00
|
|
|
|
GList *
|
2014-07-08 08:43:54 +00:00
|
|
|
|
gswe_moment_get_planet_aspects(
|
|
|
|
|
GsweMoment *moment,
|
|
|
|
|
GswePlanet planet,
|
|
|
|
|
GError **err)
|
2013-09-02 23:11:18 +00:00
|
|
|
|
{
|
2013-09-03 09:26:37 +00:00
|
|
|
|
GList *ret = NULL,
|
|
|
|
|
*aspect;
|
|
|
|
|
|
2013-09-10 23:08:35 +00:00
|
|
|
|
if (!gswe_moment_has_planet(moment, planet)) {
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_set_error(
|
|
|
|
|
err,
|
|
|
|
|
GSWE_ERROR, GSWE_ERROR_UNKNOWN_PLANET,
|
|
|
|
|
"Specified planet is not added to the moment object"
|
|
|
|
|
);
|
2013-09-10 23:08:35 +00:00
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-03 09:26:37 +00:00
|
|
|
|
gswe_moment_calculate_aspects(moment);
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
for (
|
|
|
|
|
aspect = moment->priv->aspect_list;
|
|
|
|
|
aspect;
|
|
|
|
|
aspect = g_list_next(aspect)
|
|
|
|
|
) {
|
2013-09-03 09:26:37 +00:00
|
|
|
|
GsweAspectData *aspect_data = aspect->data;
|
|
|
|
|
|
2013-09-30 20:13:37 +00:00
|
|
|
|
if (
|
|
|
|
|
(aspect_data->planet1->planet_info->planet == planet)
|
|
|
|
|
|| (aspect_data->planet2->planet_info->planet == planet)
|
|
|
|
|
) {
|
2013-09-03 09:26:37 +00:00
|
|
|
|
ret = g_list_prepend(ret, aspect_data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
2013-09-02 23:11:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-07 07:32:21 +00:00
|
|
|
|
/**
|
|
|
|
|
* 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 *
|
2014-07-08 08:43:54 +00:00
|
|
|
|
gswe_moment_get_aspect_by_planets(
|
|
|
|
|
GsweMoment *moment,
|
|
|
|
|
GswePlanet planet1,
|
|
|
|
|
GswePlanet planet2,
|
|
|
|
|
GError **err)
|
2014-05-07 07:32:21 +00:00
|
|
|
|
{
|
|
|
|
|
struct GsweAspectFinder aspect_finder;
|
|
|
|
|
GList *aspect_data_element;
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
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"
|
|
|
|
|
);
|
2014-05-07 07:32:21 +00:00
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aspect_finder.planet1 = planet1;
|
|
|
|
|
aspect_finder.planet2 = planet2;
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
if ((aspect_data_element = g_list_find_custom(
|
|
|
|
|
moment->priv->aspect_list,
|
|
|
|
|
&aspect_finder,
|
|
|
|
|
(GCompareFunc)find_aspect_by_both_planets
|
|
|
|
|
)) != NULL) {
|
2014-05-07 07:32:21 +00:00
|
|
|
|
return aspect_data_element->data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-03 10:59:32 +00:00
|
|
|
|
static gint
|
2014-07-08 08:43:54 +00:00
|
|
|
|
find_antiscion_by_both_planets(
|
|
|
|
|
GsweAntiscionData *antiscion,
|
|
|
|
|
struct GsweAspectFinder *antiscion_finder)
|
2013-09-03 10:59:32 +00:00
|
|
|
|
{
|
2013-09-30 20:13:37 +00:00
|
|
|
|
if (
|
|
|
|
|
(
|
2014-07-08 08:43:54 +00:00
|
|
|
|
(antiscion->planet1->planet_info->planet
|
|
|
|
|
== antiscion_finder->planet1)
|
|
|
|
|
&& (antiscion->planet2->planet_info->planet
|
|
|
|
|
== antiscion_finder->planet2)
|
2013-09-30 20:13:37 +00:00
|
|
|
|
)
|
|
|
|
|
|| (
|
2014-07-08 08:43:54 +00:00
|
|
|
|
(antiscion->planet1->planet_info->planet
|
|
|
|
|
== antiscion_finder->planet2)
|
|
|
|
|
&& (antiscion->planet2->planet_info->planet
|
|
|
|
|
== antiscion_finder->planet1)
|
2013-09-30 20:13:37 +00:00
|
|
|
|
)
|
|
|
|
|
) {
|
2013-09-03 10:59:32 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-16 08:13:25 +00:00
|
|
|
|
gswe_moment_calculate_antiscia(GsweMoment *moment)
|
2013-09-03 10:59:32 +00:00
|
|
|
|
{
|
|
|
|
|
GList *oplanet,
|
|
|
|
|
*iplanet;
|
|
|
|
|
|
2013-09-16 08:13:25 +00:00
|
|
|
|
if (moment->priv->antiscia_revision == moment->priv->revision) {
|
2013-09-03 10:59:32 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gswe_moment_calculate_all_planets(moment);
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_list_free_full(
|
|
|
|
|
moment->priv->antiscia_list,
|
|
|
|
|
(GDestroyNotify)gswe_antiscion_data_unref
|
|
|
|
|
);
|
2013-09-18 19:55:49 +00:00
|
|
|
|
moment->priv->antiscia_list = NULL;
|
2013-09-03 10:59:32 +00:00
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
for (
|
|
|
|
|
oplanet = moment->priv->planet_list;
|
|
|
|
|
oplanet;
|
|
|
|
|
oplanet = g_list_next(oplanet)
|
|
|
|
|
) {
|
|
|
|
|
for (
|
|
|
|
|
iplanet = moment->priv->planet_list;
|
|
|
|
|
iplanet;
|
|
|
|
|
iplanet = g_list_next(iplanet)
|
|
|
|
|
) {
|
2013-09-03 10:59:32 +00:00
|
|
|
|
GswePlanetData *outer_planet = oplanet->data,
|
|
|
|
|
*inner_planet = iplanet->data;
|
2013-09-16 08:13:25 +00:00
|
|
|
|
struct GsweAspectFinder antiscion_finder;
|
2013-10-04 15:01:15 +00:00
|
|
|
|
GsweAntiscionData *antiscion_data;
|
|
|
|
|
GList *antiscion_data_element;
|
2013-09-03 10:59:32 +00:00
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
if (outer_planet->planet_info->planet
|
|
|
|
|
== inner_planet->planet_info->planet
|
|
|
|
|
) {
|
2013-09-03 10:59:32 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-30 20:13:37 +00:00
|
|
|
|
antiscion_finder.planet1 = outer_planet->planet_info->planet;
|
|
|
|
|
antiscion_finder.planet2 = inner_planet->planet_info->planet;
|
2013-09-03 10:59:32 +00:00
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
if ((antiscion_data_element = g_list_find_custom(
|
|
|
|
|
moment->priv->antiscia_list,
|
|
|
|
|
&antiscion_finder,
|
|
|
|
|
(GCompareFunc)find_antiscion_by_both_planets)
|
|
|
|
|
) != NULL) {
|
2013-10-04 15:01:15 +00:00
|
|
|
|
gswe_antiscion_data_calculate(antiscion_data_element->data);
|
|
|
|
|
} else {
|
2014-07-08 08:43:54 +00:00
|
|
|
|
antiscion_data = gswe_antiscion_data_new_with_planets(
|
|
|
|
|
inner_planet,
|
|
|
|
|
outer_planet
|
|
|
|
|
);
|
|
|
|
|
moment->priv->antiscia_list = g_list_prepend(
|
|
|
|
|
moment->priv->antiscia_list,
|
|
|
|
|
antiscion_data
|
|
|
|
|
);
|
2013-09-03 10:59:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-16 08:13:25 +00:00
|
|
|
|
moment->priv->antiscia_revision = moment->priv->revision;
|
2013-09-03 10:59:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 17:50:57 +00:00
|
|
|
|
/**
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* gswe_moment_get_all_antiscia:
|
2013-09-05 17:50:57 +00:00
|
|
|
|
* @moment: The GsweMoment object to operate on.
|
|
|
|
|
*
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* Get all found antiscia between planets in @moment.
|
2013-09-05 17:50:57 +00:00
|
|
|
|
*
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* Returns: (element-type GsweAntiscionData) (transfer none): A #GList of
|
|
|
|
|
* #GsweAntiscionData.
|
2013-09-05 17:50:57 +00:00
|
|
|
|
*/
|
2013-09-03 10:59:32 +00:00
|
|
|
|
GList *
|
2013-09-16 08:13:25 +00:00
|
|
|
|
gswe_moment_get_all_antiscia(GsweMoment *moment)
|
2013-09-03 10:59:32 +00:00
|
|
|
|
{
|
2013-09-16 08:13:25 +00:00
|
|
|
|
gswe_moment_calculate_antiscia(moment);
|
2013-09-03 10:59:32 +00:00
|
|
|
|
|
2013-09-16 08:13:25 +00:00
|
|
|
|
return moment->priv->antiscia_list;
|
2013-09-03 10:59:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 17:50:57 +00:00
|
|
|
|
/**
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* gswe_moment_get_all_planet_antiscia:
|
2013-09-05 17:50:57 +00:00
|
|
|
|
* @moment: The GsweMoment object to operate on.
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* @planet: The planet whose antiscion planets are requested.
|
2013-09-10 23:55:10 +00:00
|
|
|
|
* @err: a #GError
|
2013-09-05 17:50:57 +00:00
|
|
|
|
*
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* Get all the antiscion planets on all registered axes for @planet.
|
2013-09-05 17:50:57 +00:00
|
|
|
|
*
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* Returns: (element-type GsweAntiscionData) (transfer container): a #GList of
|
|
|
|
|
* #GsweAntiscionData. The GsweAntiscionData structures belong to
|
|
|
|
|
* @moment, but the GList should be freed using g_list_free(). If no
|
|
|
|
|
* planet has any antiscia, or the planet has not been added to
|
|
|
|
|
* @moment, returns NULL.
|
2013-09-05 17:50:57 +00:00
|
|
|
|
*/
|
2013-09-03 10:59:32 +00:00
|
|
|
|
GList *
|
2014-07-08 08:43:54 +00:00
|
|
|
|
gswe_moment_get_all_planet_antiscia(
|
|
|
|
|
GsweMoment *moment,
|
|
|
|
|
GswePlanet planet,
|
|
|
|
|
GError **err)
|
2013-09-03 10:59:32 +00:00
|
|
|
|
{
|
|
|
|
|
GList *ret = NULL,
|
2013-10-08 22:06:08 +00:00
|
|
|
|
*antiscion_l;
|
2013-09-03 10:59:32 +00:00
|
|
|
|
|
2013-09-10 23:08:35 +00:00
|
|
|
|
if (!gswe_moment_has_planet(moment, planet)) {
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_set_error(
|
|
|
|
|
err,
|
|
|
|
|
GSWE_ERROR, GSWE_ERROR_UNKNOWN_PLANET,
|
|
|
|
|
"Specified planet is not added to the moment object"
|
|
|
|
|
);
|
2013-09-10 23:08:35 +00:00
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-16 08:13:25 +00:00
|
|
|
|
gswe_moment_calculate_antiscia(moment);
|
2013-09-03 10:59:32 +00:00
|
|
|
|
|
2013-10-08 22:06:08 +00:00
|
|
|
|
glforeach (antiscion_l, moment->priv->antiscia_list) {
|
|
|
|
|
GsweAntiscionData *antiscion_data = antiscion_l->data;
|
2013-09-03 10:59:32 +00:00
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
if (
|
|
|
|
|
(antiscion_data->planet1->planet_info->planet == planet)
|
|
|
|
|
|| (antiscion_data->planet2->planet_info->planet == planet)
|
|
|
|
|
) {
|
2013-09-16 08:13:25 +00:00
|
|
|
|
ret = g_list_prepend(ret, antiscion_data);
|
2013-09-03 10:59:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 17:50:57 +00:00
|
|
|
|
/**
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* gswe_moment_get_axis_all_antiscia:
|
2013-09-05 17:50:57 +00:00
|
|
|
|
* @moment: The GsweMoment object to operate on.
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* @axis: The axis on which you want to search for antiscion planets.
|
2013-09-05 17:50:57 +00:00
|
|
|
|
*
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* Get all the antiscion planets on the specified axis @axis.
|
2013-09-05 17:50:57 +00:00
|
|
|
|
*
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* Returns: (element-type GsweAntiscionData) (transfer container): a #GList of
|
2014-07-08 08:43:54 +00:00
|
|
|
|
* #GsweAntiscionData. The GsweAntiscionData structures belong to
|
|
|
|
|
* @moment, but the GList should be freed using g_list_free(). If
|
|
|
|
|
* there are no antiscion planets on the given axis, returns NULL.
|
2013-09-05 17:50:57 +00:00
|
|
|
|
*/
|
2013-09-03 10:59:32 +00:00
|
|
|
|
GList *
|
2013-09-16 08:13:25 +00:00
|
|
|
|
gswe_moment_get_axis_all_antiscia(GsweMoment *moment, GsweAntiscionAxis axis)
|
2013-09-03 10:59:32 +00:00
|
|
|
|
{
|
|
|
|
|
GList *ret = NULL,
|
2013-09-16 08:13:25 +00:00
|
|
|
|
*antiscion_l;
|
2013-09-03 10:59:32 +00:00
|
|
|
|
|
2013-09-16 08:13:25 +00:00
|
|
|
|
gswe_moment_calculate_antiscia(moment);
|
2013-09-03 10:59:32 +00:00
|
|
|
|
|
2013-10-08 22:06:08 +00:00
|
|
|
|
glforeach (antiscion_l, moment->priv->antiscia_list) {
|
2013-09-16 08:13:25 +00:00
|
|
|
|
GsweAntiscionData *antiscion_data = antiscion_l->data;
|
2013-09-03 10:59:32 +00:00
|
|
|
|
|
2013-09-30 21:02:18 +00:00
|
|
|
|
if (antiscion_data->antiscion_axis_info->axis == axis) {
|
2013-09-16 08:13:25 +00:00
|
|
|
|
ret = g_list_prepend(ret, antiscion_data);
|
2013-09-03 10:59:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 17:50:57 +00:00
|
|
|
|
/**
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* gswe_moment_get_axis_planet_antiscia:
|
2013-09-05 17:50:57 +00:00
|
|
|
|
* @moment: the GsweMoment object to operate on
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* @axis: the axis on which you want to search for antiscion planets
|
|
|
|
|
* @planet: the planet whose antiscion planets are requested
|
2013-09-10 23:55:10 +00:00
|
|
|
|
* @err: a #GError
|
2013-09-05 17:50:57 +00:00
|
|
|
|
*
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* Get the antiscion planets of @planet as seen in @axis.
|
2013-09-05 17:50:57 +00:00
|
|
|
|
*
|
2013-09-16 08:13:25 +00:00
|
|
|
|
* Returns: (element-type GsweAntiscionData) (transfer container): a #GList of
|
2014-07-08 08:43:54 +00:00
|
|
|
|
* #GsweAntiscionData. The GsweAntiscionData structires belong to
|
|
|
|
|
* @moment, but the GList should be freed using g_list_free(). If the
|
|
|
|
|
* planet has no antiscia, or the planet has not been added to
|
|
|
|
|
* @moment, returns NULL.
|
2013-09-05 17:50:57 +00:00
|
|
|
|
*/
|
2013-09-03 10:59:32 +00:00
|
|
|
|
GList *
|
2014-07-08 08:43:54 +00:00
|
|
|
|
gswe_moment_get_axis_planet_antiscia(
|
|
|
|
|
GsweMoment *moment,
|
|
|
|
|
GsweAntiscionAxis axis,
|
|
|
|
|
GswePlanet planet,
|
|
|
|
|
GError **err)
|
2013-09-03 10:59:32 +00:00
|
|
|
|
{
|
|
|
|
|
GList *ret = NULL,
|
2013-09-16 08:13:25 +00:00
|
|
|
|
*antiscion_l;
|
2013-09-03 10:59:32 +00:00
|
|
|
|
|
2013-09-10 23:08:35 +00:00
|
|
|
|
if (!gswe_moment_has_planet(moment, planet)) {
|
2014-07-08 08:43:54 +00:00
|
|
|
|
g_set_error(
|
|
|
|
|
err,
|
|
|
|
|
GSWE_ERROR, GSWE_ERROR_UNKNOWN_PLANET,
|
|
|
|
|
"Specified planet is not added to the moment object"
|
|
|
|
|
);
|
2013-09-10 23:08:35 +00:00
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-16 08:13:25 +00:00
|
|
|
|
gswe_moment_calculate_antiscia(moment);
|
2013-09-03 10:59:32 +00:00
|
|
|
|
|
2013-10-08 22:06:08 +00:00
|
|
|
|
glforeach (antiscion_l, moment->priv->antiscia_list) {
|
2013-09-16 08:13:25 +00:00
|
|
|
|
GsweAntiscionData *antiscion_data = antiscion_l->data;
|
2013-09-03 10:59:32 +00:00
|
|
|
|
|
2013-09-30 20:13:37 +00:00
|
|
|
|
if (
|
|
|
|
|
(
|
|
|
|
|
(antiscion_data->planet1->planet_info->planet == planet)
|
|
|
|
|
|| (antiscion_data->planet2->planet_info->planet == planet)
|
|
|
|
|
)
|
|
|
|
|
&& (antiscion_data->antiscion_axis_info->axis == axis)
|
|
|
|
|
) {
|
2013-09-16 08:13:25 +00:00
|
|
|
|
ret = g_list_prepend(ret, antiscion_data);
|
2013-09-03 10:59:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-07 07:52:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* gswe_moment_get_antiscion_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.
|
|
|
|
|
*/
|
|
|
|
|
GsweAntiscionData *
|
2014-07-08 08:43:54 +00:00
|
|
|
|
gswe_moment_get_antiscion_by_planets(
|
|
|
|
|
GsweMoment *moment,
|
|
|
|
|
GswePlanet planet1,
|
|
|
|
|
GswePlanet planet2,
|
|
|
|
|
GError **err)
|
2014-05-07 07:52:38 +00:00
|
|
|
|
{
|
|
|
|
|
struct GsweAspectFinder antiscion_finder;
|
|
|
|
|
GList *antiscion_data_element;
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
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 planets is not found in the planet list"
|
|
|
|
|
);
|
2014-05-07 07:52:38 +00:00
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
antiscion_finder.planet1 = planet1;
|
|
|
|
|
antiscion_finder.planet2 = planet2;
|
|
|
|
|
|
2014-07-08 08:43:54 +00:00
|
|
|
|
if ((antiscion_data_element = g_list_find_custom(
|
|
|
|
|
moment->priv->antiscia_list,
|
|
|
|
|
&antiscion_finder,
|
|
|
|
|
(GCompareFunc)find_antiscion_by_both_planets
|
|
|
|
|
)) != NULL) {
|
2014-05-07 07:52:38 +00:00
|
|
|
|
return antiscion_data_element->data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|