parent
3a06d4bcee
commit
f92caa4e1a
@ -42,9 +42,10 @@ gswe_moment_get_type
|
|||||||
|
|
||||||
<SECTION>
|
<SECTION>
|
||||||
<FILE>gswe-moon-phase-data</FILE>
|
<FILE>gswe-moon-phase-data</FILE>
|
||||||
gswe_moon_phase_data_set_phase
|
gswe_moon_phase_data_new
|
||||||
|
gswe_moon_phase_data_ref
|
||||||
|
gswe_moon_phase_data_unref
|
||||||
gswe_moon_phase_data_get_phase
|
gswe_moon_phase_data_get_phase
|
||||||
gswe_moon_phase_data_set_illumination
|
|
||||||
gswe_moon_phase_data_get_illumination
|
gswe_moon_phase_data_get_illumination
|
||||||
GsweMoonPhaseData
|
GsweMoonPhaseData
|
||||||
<SUBSECTION Standard>
|
<SUBSECTION Standard>
|
||||||
|
@ -75,7 +75,7 @@ struct _GsweMomentPrivate {
|
|||||||
GHashTable *element_points;
|
GHashTable *element_points;
|
||||||
GHashTable *quality_points;
|
GHashTable *quality_points;
|
||||||
guint moon_phase_revision;
|
guint moon_phase_revision;
|
||||||
GsweMoonPhaseData moon_phase;
|
GsweMoonPhaseData *moon_phase;
|
||||||
GList *aspect_list;
|
GList *aspect_list;
|
||||||
guint aspect_revision;
|
guint aspect_revision;
|
||||||
GList *antiscia_list;
|
GList *antiscia_list;
|
||||||
@ -166,6 +166,7 @@ gswe_moment_init(GsweMoment *moment)
|
|||||||
moment->priv->planet_list = NULL;
|
moment->priv->planet_list = NULL;
|
||||||
moment->priv->aspect_list = NULL;
|
moment->priv->aspect_list = NULL;
|
||||||
moment->priv->antiscia_list = NULL;
|
moment->priv->antiscia_list = NULL;
|
||||||
|
moment->priv->moon_phase = gswe_moon_phase_data_new();
|
||||||
moment->priv->element_points = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL);
|
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);
|
moment->priv->quality_points = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL);
|
||||||
moment->priv->house_revision = 0;
|
moment->priv->house_revision = 0;
|
||||||
@ -203,6 +204,7 @@ gswe_moment_finalize(GObject *gobject)
|
|||||||
g_list_free_full(moment->priv->house_list, g_free);
|
g_list_free_full(moment->priv->house_list, g_free);
|
||||||
g_list_free_full(moment->priv->planet_list, (GDestroyNotify)gswe_planet_data_unref);
|
g_list_free_full(moment->priv->planet_list, (GDestroyNotify)gswe_planet_data_unref);
|
||||||
g_list_free_full(moment->priv->aspect_list, (GDestroyNotify)gswe_aspect_data_unref);
|
g_list_free_full(moment->priv->aspect_list, (GDestroyNotify)gswe_aspect_data_unref);
|
||||||
|
gswe_moon_phase_data_unref(moment->priv->moon_phase);
|
||||||
|
|
||||||
G_OBJECT_CLASS(gswe_moment_parent_class)->finalize(gobject);
|
G_OBJECT_CLASS(gswe_moment_parent_class)->finalize(gobject);
|
||||||
}
|
}
|
||||||
@ -964,7 +966,7 @@ gswe_moment_get_moon_phase(GsweMoment *moment, GError **err)
|
|||||||
jdb;
|
jdb;
|
||||||
|
|
||||||
if (moment->priv->moon_phase_revision == moment->priv->revision) {
|
if (moment->priv->moon_phase_revision == moment->priv->revision) {
|
||||||
return &(moment->priv->moon_phase);
|
return moment->priv->moon_phase;
|
||||||
}
|
}
|
||||||
|
|
||||||
jd = gswe_timestamp_get_julian_day(moment->priv->timestamp, err);
|
jd = gswe_timestamp_get_julian_day(moment->priv->timestamp, err);
|
||||||
@ -990,31 +992,31 @@ gswe_moment_get_moon_phase(GsweMoment *moment, GError **err)
|
|||||||
g_error("Error during Moon phase calculation!");
|
g_error("Error during Moon phase calculation!");
|
||||||
}
|
}
|
||||||
|
|
||||||
moment->priv->moon_phase.illumination = (50.0 - fabs(phase_percent - 50.0)) * 2;
|
moment->priv->moon_phase->illumination = (50.0 - fabs(phase_percent - 50.0)) * 2;
|
||||||
|
|
||||||
if (phase_percent == 0) {
|
if (phase_percent == 0) {
|
||||||
moment->priv->moon_phase.phase = GSWE_MOON_PHASE_NEW;
|
moment->priv->moon_phase->phase = GSWE_MOON_PHASE_NEW;
|
||||||
} else if (phase_percent < 25) {
|
} else if (phase_percent < 25) {
|
||||||
moment->priv->moon_phase.phase = GSWE_MOON_PHASE_WAXING_CRESCENT;
|
moment->priv->moon_phase->phase = GSWE_MOON_PHASE_WAXING_CRESCENT;
|
||||||
} else if (phase_percent == 25) {
|
} else if (phase_percent == 25) {
|
||||||
moment->priv->moon_phase.phase = GSWE_MOON_PHASE_WAXING_HALF;
|
moment->priv->moon_phase->phase = GSWE_MOON_PHASE_WAXING_HALF;
|
||||||
} else if (phase_percent < 50) {
|
} else if (phase_percent < 50) {
|
||||||
moment->priv->moon_phase.phase = GSWE_MOON_PHASE_WAXING_GIBBOUS;
|
moment->priv->moon_phase->phase = GSWE_MOON_PHASE_WAXING_GIBBOUS;
|
||||||
} else if (phase_percent == 50) {
|
} else if (phase_percent == 50) {
|
||||||
moment->priv->moon_phase.phase = GSWE_MOON_PHASE_FULL;
|
moment->priv->moon_phase->phase = GSWE_MOON_PHASE_FULL;
|
||||||
} else if (phase_percent < 75) {
|
} else if (phase_percent < 75) {
|
||||||
moment->priv->moon_phase.phase = GSWE_MOON_PHASE_WANING_GIBBOUS;
|
moment->priv->moon_phase->phase = GSWE_MOON_PHASE_WANING_GIBBOUS;
|
||||||
} else if (phase_percent == 75) {
|
} else if (phase_percent == 75) {
|
||||||
moment->priv->moon_phase.phase = GSWE_MOON_PHASE_WANING_HALF;
|
moment->priv->moon_phase->phase = GSWE_MOON_PHASE_WANING_HALF;
|
||||||
} else if (phase_percent < 100) {
|
} else if (phase_percent < 100) {
|
||||||
moment->priv->moon_phase.phase = GSWE_MOON_PHASE_WANING_CRESCENT;
|
moment->priv->moon_phase->phase = GSWE_MOON_PHASE_WANING_CRESCENT;
|
||||||
} else {
|
} else {
|
||||||
moment->priv->moon_phase.phase = GSWE_MOON_PHASE_DARK;
|
moment->priv->moon_phase->phase = GSWE_MOON_PHASE_DARK;
|
||||||
}
|
}
|
||||||
|
|
||||||
moment->priv->moon_phase_revision = moment->priv->revision;
|
moment->priv->moon_phase_revision = moment->priv->revision;
|
||||||
|
|
||||||
return &(moment->priv->moon_phase);
|
return moment->priv->moon_phase;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
|
@ -28,9 +28,10 @@ struct _GsweMoonPhaseData {
|
|||||||
|
|
||||||
/* the illumination percentage of the Moon */
|
/* the illumination percentage of the Moon */
|
||||||
gdouble illumination;
|
gdouble illumination;
|
||||||
};
|
|
||||||
|
|
||||||
GsweMoonPhaseData *gswe_moon_phase_data_copy(GsweMoonPhaseData *moon_phase_data);
|
/* reference count */
|
||||||
|
guint refcount;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* __SWE_GLIB_GSWE_MOON_PHASE_DATA_PRIVATE_H__ */
|
#endif /* __SWE_GLIB_GSWE_MOON_PHASE_DATA_PRIVATE_H__ */
|
||||||
#else /* not defined __SWE_GLIB_BUILDING__ */
|
#else /* not defined __SWE_GLIB_BUILDING__ */
|
||||||
|
@ -32,37 +32,59 @@
|
|||||||
* Moon, including its illumination percentage.
|
* Moon, including its illumination percentage.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
G_DEFINE_BOXED_TYPE(GsweMoonPhaseData, gswe_moon_phase_data, (GBoxedCopyFunc)gswe_moon_phase_data_copy, (GBoxedFreeFunc)g_free);
|
G_DEFINE_BOXED_TYPE(GsweMoonPhaseData, gswe_moon_phase_data, (GBoxedCopyFunc)gswe_moon_phase_data_ref, (GBoxedFreeFunc)gswe_moon_phase_data_unref);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gswe_moon_phase_data_new:
|
||||||
|
*
|
||||||
|
* Creates a new #GsweMoonPhaseData object with reference count set to 1.
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): a new #GsweMoonPhaseData object
|
||||||
|
*/
|
||||||
GsweMoonPhaseData *
|
GsweMoonPhaseData *
|
||||||
gswe_moon_phase_data_copy(GsweMoonPhaseData *moon_phase_data)
|
gswe_moon_phase_data_new(void)
|
||||||
{
|
{
|
||||||
GsweMoonPhaseData *ret = g_new0(struct _GsweMoonPhaseData, 1);
|
GsweMoonPhaseData *ret;
|
||||||
|
|
||||||
ret->phase = moon_phase_data->phase;
|
ret = g_new0(GsweMoonPhaseData, 1);
|
||||||
ret->illumination = moon_phase_data->illumination;
|
ret->refcount = 1;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gswe_moon_phase_data_set_phase:
|
* gswe_moon_phase_data_ref:
|
||||||
* @moon_phase_data: a GsweMoonPhaseData
|
* @moon_phase_data: (in): a #GsweMoonPhaseData
|
||||||
* @phase: the phase to set
|
|
||||||
*
|
*
|
||||||
* Sets the phase of the Moon in the given GsweMoonPhaseData.
|
* Increases reference count on @moon_phase_data by one.
|
||||||
|
*
|
||||||
|
* Returns: (transfer none): the same #GsweMoonPhaseData
|
||||||
|
*/
|
||||||
|
GsweMoonPhaseData *
|
||||||
|
gswe_moon_phase_data_ref(GsweMoonPhaseData *moon_phase_data)
|
||||||
|
{
|
||||||
|
moon_phase_data->refcount++;
|
||||||
|
|
||||||
|
return moon_phase_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gswe_moon_phase_data_unref:
|
||||||
|
* @moon_phase_data: (in): a #GsweMoonPhaseData
|
||||||
|
*
|
||||||
|
* Decreases reference count on @moon_phase_data by one. If reference count drops to zero, @moon_phase_data is freed.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
gswe_moon_phase_data_set_phase(GsweMoonPhaseData *moon_phase_data, GsweMoonPhase phase)
|
gswe_moon_phase_data_unref(GsweMoonPhaseData *moon_phase_data)
|
||||||
{
|
{
|
||||||
if (moon_phase_data) {
|
if (--moon_phase_data->refcount == 0) {
|
||||||
moon_phase_data->phase = phase;
|
g_free(moon_phase_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gswe_moon_phase_data_get_phase:
|
* gswe_moon_phase_data_get_phase:
|
||||||
* @moon_phase_data: a GsweMoonPhaseData
|
* @moon_phase_data: (in): a GsweMoonPhaseData
|
||||||
*
|
*
|
||||||
* Gets the phase of the Moon in the given GsweMoonPhaseData.
|
* Gets the phase of the Moon in the given GsweMoonPhaseData.
|
||||||
*
|
*
|
||||||
@ -78,24 +100,9 @@ gswe_moon_phase_data_get_phase(GsweMoonPhaseData *moon_phase_data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* gswe_moon_phase_data_set_illumination:
|
|
||||||
* @moon_phase_data: a GsweMoonPhaseData
|
|
||||||
* @illumination: the illumination to set
|
|
||||||
*
|
|
||||||
* Sets the illumination percentage in the given GsweMoonPhaseData.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
gswe_moon_phase_data_set_illumination(GsweMoonPhaseData *moon_phase_data, gdouble illumination)
|
|
||||||
{
|
|
||||||
if (moon_phase_data) {
|
|
||||||
moon_phase_data->illumination = illumination;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gswe_moon_phase_data_get_illumination:
|
* gswe_moon_phase_data_get_illumination:
|
||||||
* @moon_phase_data: a GsweMoonPhaseData
|
* @moon_phase_data: (in): a GsweMoonPhaseData
|
||||||
*
|
*
|
||||||
* Gets the illumination percentage from the given GsweMoonPhaseData.
|
* Gets the illumination percentage from the given GsweMoonPhaseData.
|
||||||
*
|
*
|
||||||
|
@ -34,9 +34,12 @@ G_BEGIN_DECLS
|
|||||||
*/
|
*/
|
||||||
typedef struct _GsweMoonPhaseData GsweMoonPhaseData;
|
typedef struct _GsweMoonPhaseData GsweMoonPhaseData;
|
||||||
|
|
||||||
void gswe_moon_phase_data_set_phase(GsweMoonPhaseData *moon_phase_data, GsweMoonPhase phase);
|
GsweMoonPhaseData *gswe_moon_phase_data_new(void);
|
||||||
|
|
||||||
|
GsweMoonPhaseData *gswe_moon_phase_data_ref(GsweMoonPhaseData *moon_phase_data);
|
||||||
|
void gswe_moon_phase_data_unref(GsweMoonPhaseData *moon_phase_data);
|
||||||
|
|
||||||
GsweMoonPhase gswe_moon_phase_data_get_phase(GsweMoonPhaseData *moon_phase_data);
|
GsweMoonPhase gswe_moon_phase_data_get_phase(GsweMoonPhaseData *moon_phase_data);
|
||||||
void gswe_moon_phase_data_set_illumination(GsweMoonPhaseData *moon_phase_data, gdouble illumination);
|
|
||||||
gdouble gswe_moon_phase_data_get_illumination(GsweMoonPhaseData *moon_phase_data);
|
gdouble gswe_moon_phase_data_get_illumination(GsweMoonPhaseData *moon_phase_data);
|
||||||
|
|
||||||
GType gswe_moon_phase_data_get_type(void);
|
GType gswe_moon_phase_data_get_type(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user