Moved antiscion calculation code to GsweAntiscionData

This commit is contained in:
Gergely Polonkai 2013-10-04 17:01:15 +02:00
parent 8ae0c4de71
commit e81df2e4b0
2 changed files with 64 additions and 50 deletions

View File

@ -15,6 +15,7 @@
* 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 <math.h>
#include <glib-object.h>
#include "swe-glib-private.h"
@ -70,6 +71,62 @@ gswe_antiscion_data_new(void)
return ret;
}
static gboolean
find_antiscion(gpointer axis_p, GsweAntiscionAxisInfo *antiscion_axis_info, GsweAntiscionData *antiscion_data)
{
GsweAntiscionAxis axis;
gdouble start_point,
axis_position,
planet_orb;
if ((axis = GPOINTER_TO_INT(axis_p)) == GSWE_ANTISCION_AXIS_NONE) {
return FALSE;
}
planet_orb = fmin(antiscion_data->planet1->planet_info->orb, antiscion_data->planet2->planet_info->orb);
start_point = (antiscion_axis_info->start_sign->sign - 1) * 30.0;
start_point += antiscion_axis_info->sign_offset;
axis_position = 2 * start_point - antiscion_data->planet1->position;
if (axis_position < 0) {
axis_position += 360.0;
}
if ((antiscion_data->difference = fabs(antiscion_data->planet2->position - axis_position)) <= planet_orb) {
antiscion_data->antiscion_axis_info = antiscion_axis_info;
return TRUE;
} else {
antiscion_data->difference = 0.0;
}
return FALSE;
}
void
gswe_antiscion_data_calculate(GsweAntiscionData *antiscion_data)
{
if ((antiscion_data->antiscion_axis_info = g_hash_table_find(gswe_antiscion_axis_info_table, (GHRFunc)find_antiscion, antiscion_data)) == NULL) {
antiscion_data->antiscion_axis_info = g_hash_table_lookup(gswe_antiscion_axis_info_table, GINT_TO_POINTER(GSWE_ANTISCION_AXIS_NONE));
}
}
GsweAntiscionData *
gswe_antiscion_data_new_with_planets(GswePlanetData *planet1, GswePlanetData *planet2)
{
GsweAntiscionData *ret;
ret = gswe_antiscion_data_new();
ret->planet1 = planet1;
ret->planet2 = planet2;
gswe_antiscion_data_calculate(ret);
return ret;
}
/**
* gswe_antiscion_data_ref:
* @antiscion_data: (in): a #GsweAntiscionData

View File

@ -1109,40 +1109,6 @@ gswe_moment_get_planet_aspects(GsweMoment *moment, GswePlanet planet, GError **e
return ret;
}
static gboolean
find_antiscion(gpointer axis_p, GsweAntiscionAxisInfo *antiscion_axis_info, GsweAntiscionData *antiscion_data)
{
GsweAntiscionAxis axis;
gdouble start_point,
axis_position,
planet_orb;
if ((axis = GPOINTER_TO_INT(axis_p)) == GSWE_ANTISCION_AXIS_NONE) {
return FALSE;
}
planet_orb = fmin(antiscion_data->planet1->planet_info->orb, antiscion_data->planet2->planet_info->orb);
start_point = (antiscion_axis_info->start_sign->sign - 1) * 30.0;
start_point += antiscion_axis_info->sign_offset;
axis_position = 2 * start_point - antiscion_data->planet1->position;
if (axis_position < 0) {
axis_position += 360.0;
}
if ((antiscion_data->difference = fabs(antiscion_data->planet2->position - axis_position)) <= planet_orb) {
antiscion_data->antiscion_axis_info = antiscion_axis_info;
return TRUE;
} else {
antiscion_data->difference = 0.0;
}
return FALSE;
}
static gint
find_antiscion_by_both_planets(GsweAntiscionData *antiscion, struct GsweAspectFinder *antiscion_finder)
{
@ -1180,8 +1146,9 @@ gswe_moment_calculate_antiscia(GsweMoment *moment)
for (iplanet = moment->priv->planet_list; iplanet; iplanet = iplanet->next) {
GswePlanetData *outer_planet = oplanet->data,
*inner_planet = iplanet->data;
GsweAntiscionData *antiscion_data;
struct GsweAspectFinder antiscion_finder;
GsweAntiscionData *antiscion_data;
GList *antiscion_data_element;
if (outer_planet->planet_info->planet == inner_planet->planet_info->planet) {
continue;
@ -1190,22 +1157,12 @@ gswe_moment_calculate_antiscia(GsweMoment *moment)
antiscion_finder.planet1 = outer_planet->planet_info->planet;
antiscion_finder.planet2 = inner_planet->planet_info->planet;
if (g_list_find_custom(moment->priv->antiscia_list, &antiscion_finder, (GCompareFunc)find_antiscion_by_both_planets) != NULL) {
continue;
if ((antiscion_data_element = g_list_find_custom(moment->priv->antiscia_list, &antiscion_finder, (GCompareFunc)find_antiscion_by_both_planets)) != NULL) {
gswe_antiscion_data_calculate(antiscion_data_element->data);
} else {
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);
}
antiscion_data = gswe_antiscion_data_new();
antiscion_data->planet1 = outer_planet;
antiscion_data->planet2 = inner_planet;
antiscion_data->antiscion_axis_info = NULL;
(void)g_hash_table_find(gswe_antiscion_axis_info_table, (GHRFunc)find_antiscion, antiscion_data);
if (antiscion_data->antiscion_axis_info == NULL) {
antiscion_data->antiscion_axis_info = g_hash_table_lookup(gswe_antiscion_axis_info_table, GINT_TO_POINTER(GSWE_ANTISCION_AXIS_NONE));
}
moment->priv->antiscia_list = g_list_prepend(moment->priv->antiscia_list, antiscion_data);
}
}