Moved antiscion calculation code to GsweAntiscionData
This commit is contained in:
parent
8ae0c4de71
commit
e81df2e4b0
@ -15,6 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this library; if not, see <http://www.gnu.org/licenses/>.
|
* along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
#include <math.h>
|
||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
|
|
||||||
#include "swe-glib-private.h"
|
#include "swe-glib-private.h"
|
||||||
@ -70,6 +71,62 @@ gswe_antiscion_data_new(void)
|
|||||||
return ret;
|
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:
|
* gswe_antiscion_data_ref:
|
||||||
* @antiscion_data: (in): a #GsweAntiscionData
|
* @antiscion_data: (in): a #GsweAntiscionData
|
||||||
|
@ -1109,40 +1109,6 @@ gswe_moment_get_planet_aspects(GsweMoment *moment, GswePlanet planet, GError **e
|
|||||||
return ret;
|
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
|
static gint
|
||||||
find_antiscion_by_both_planets(GsweAntiscionData *antiscion, struct GsweAspectFinder *antiscion_finder)
|
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) {
|
for (iplanet = moment->priv->planet_list; iplanet; iplanet = iplanet->next) {
|
||||||
GswePlanetData *outer_planet = oplanet->data,
|
GswePlanetData *outer_planet = oplanet->data,
|
||||||
*inner_planet = iplanet->data;
|
*inner_planet = iplanet->data;
|
||||||
GsweAntiscionData *antiscion_data;
|
|
||||||
struct GsweAspectFinder antiscion_finder;
|
struct GsweAspectFinder antiscion_finder;
|
||||||
|
GsweAntiscionData *antiscion_data;
|
||||||
|
GList *antiscion_data_element;
|
||||||
|
|
||||||
if (outer_planet->planet_info->planet == inner_planet->planet_info->planet) {
|
if (outer_planet->planet_info->planet == inner_planet->planet_info->planet) {
|
||||||
continue;
|
continue;
|
||||||
@ -1190,24 +1157,14 @@ gswe_moment_calculate_antiscia(GsweMoment *moment)
|
|||||||
antiscion_finder.planet1 = outer_planet->planet_info->planet;
|
antiscion_finder.planet1 = outer_planet->planet_info->planet;
|
||||||
antiscion_finder.planet2 = inner_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) {
|
if ((antiscion_data_element = g_list_find_custom(moment->priv->antiscia_list, &antiscion_finder, (GCompareFunc)find_antiscion_by_both_planets)) != NULL) {
|
||||||
continue;
|
gswe_antiscion_data_calculate(antiscion_data_element->data);
|
||||||
}
|
} else {
|
||||||
|
antiscion_data = gswe_antiscion_data_new_with_planets(inner_planet, outer_planet);
|
||||||
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);
|
moment->priv->antiscia_list = g_list_prepend(moment->priv->antiscia_list, antiscion_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
moment->priv->antiscia_revision = moment->priv->revision;
|
moment->priv->antiscia_revision = moment->priv->revision;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user