gimpcageconfig: add the scaling factor computation

This commit is contained in:
Michael Muré 2010-07-24 11:27:47 +02:00
parent 973aeee9d4
commit 54ef87a7d3
2 changed files with 52 additions and 14 deletions

View File

@ -56,6 +56,7 @@ static void gimp_cage_config_set_property (GObject *obj
guint property_id, guint property_id,
const GValue *value, const GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
static void gimp_cage_config_compute_scaling_factor (GimpCageConfig *gcc);
/* FIXME: to debug only */ /* FIXME: to debug only */
static void static void
@ -95,6 +96,7 @@ gimp_cage_config_init (GimpCageConfig *self)
self->cage_vertices = g_new(GimpVector2, self->cage_vertices_max); self->cage_vertices = g_new(GimpVector2, self->cage_vertices_max);
self->cage_vertices_d = g_new(GimpVector2, self->cage_vertices_max); self->cage_vertices_d = g_new(GimpVector2, self->cage_vertices_max);
self->scaling_factor = g_malloc (self->cage_vertices_max * sizeof(gfloat));
} }
static void static void
@ -104,6 +106,7 @@ gimp_cage_config_finalize (GObject *object)
g_free(gcc->cage_vertices); g_free(gcc->cage_vertices);
g_free(gcc->cage_vertices_d); g_free(gcc->cage_vertices_d);
g_free(gcc->scaling_factor);
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
@ -170,21 +173,27 @@ gimp_cage_config_add_cage_point (GimpCageConfig *gcc,
gcc->cage_vertices_d[gcc->cage_vertice_number].y = y; gcc->cage_vertices_d[gcc->cage_vertice_number].y = y;
gcc->cage_vertice_number++; gcc->cage_vertice_number++;
gimp_cage_config_compute_scaling_factor (gcc);
} }
void gimp_cage_config_remove_last_cage_point (GimpCageConfig *gcc) void
gimp_cage_config_remove_last_cage_point (GimpCageConfig *gcc)
{ {
g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc)); g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc));
if (gcc->cage_vertice_number >= 1) if (gcc->cage_vertice_number >= 1)
gcc->cage_vertice_number--; gcc->cage_vertice_number--;
gimp_cage_config_compute_scaling_factor (gcc);
} }
gint gimp_cage_config_is_on_handle (GimpCageConfig *gcc, gint
GimpCageMode mode, gimp_cage_config_is_on_handle (GimpCageConfig *gcc,
gdouble x, GimpCageMode mode,
gdouble y, gdouble x,
gint handle_size) gdouble y,
gint handle_size)
{ {
gint i; gint i;
gdouble vert_x, vert_y; gdouble vert_x, vert_y;
@ -217,11 +226,12 @@ gint gimp_cage_config_is_on_handle (GimpCageConfig *gcc,
return -1; return -1;
} }
void gimp_cage_config_move_cage_point (GimpCageConfig *gcc, void
GimpCageMode mode, gimp_cage_config_move_cage_point (GimpCageConfig *gcc,
gint point_number, GimpCageMode mode,
gdouble x, gint point_number,
gdouble y) gdouble x,
gdouble y)
{ {
g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc)); g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc));
g_return_if_fail (point_number < gcc->cage_vertice_number); g_return_if_fail (point_number < gcc->cage_vertice_number);
@ -237,10 +247,13 @@ void gimp_cage_config_move_cage_point (GimpCageConfig *gcc,
gcc->cage_vertices_d[point_number].x = x; gcc->cage_vertices_d[point_number].x = x;
gcc->cage_vertices_d[point_number].y = y; gcc->cage_vertices_d[point_number].y = y;
} }
gimp_cage_config_compute_scaling_factor (gcc);
} }
GimpVector2 gimp_cage_config_get_edge_normal (GimpCageConfig *gcc, GimpVector2
gint edge_index) gimp_cage_config_get_edge_normal (GimpCageConfig *gcc,
gint edge_index)
{ {
GimpVector2 result; GimpVector2 result;
@ -255,7 +268,8 @@ GimpVector2 gimp_cage_config_get_edge_normal (GimpCageConfig *gcc,
return gimp_vector2_normal (&result); return gimp_vector2_normal (&result);
} }
GeglRectangle gimp_cage_config_get_bounding_box (GimpCageConfig *gcc) GeglRectangle
gimp_cage_config_get_bounding_box (GimpCageConfig *gcc)
{ {
gint i; gint i;
GeglRectangle bounding_box = {0, }; GeglRectangle bounding_box = {0, };
@ -319,6 +333,8 @@ gimp_cage_config_reverse_cage (GimpCageConfig *gcc)
gcc->cage_vertices_d[i] = gcc->cage_vertices_d[gcc->cage_vertice_number - i -1]; gcc->cage_vertices_d[i] = gcc->cage_vertices_d[gcc->cage_vertice_number - i -1];
gcc->cage_vertices_d[gcc->cage_vertice_number - i -1] = temp; gcc->cage_vertices_d[gcc->cage_vertice_number - i -1] = temp;
} }
gimp_cage_config_compute_scaling_factor (gcc);
} }
void void
@ -354,3 +370,24 @@ gimp_cage_config_reverse_cage_if_needed (GimpCageConfig *gcc)
printf("reverse the cage !\n"); printf("reverse the cage !\n");
} }
} }
static void
gimp_cage_config_compute_scaling_factor (GimpCageConfig *gcc)
{
gint i;
gdouble length, length_d;
GimpVector2 edge;
g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc));
for (i = 0; i < gcc->cage_vertice_number; i++)
{
gimp_vector2_sub ( &edge, &gcc->cage_vertices[i], &gcc->cage_vertices[(i+1) % gcc->cage_vertice_number]);
length = gimp_vector2_length (&edge);
gimp_vector2_sub ( &edge, &gcc->cage_vertices_d[i], &gcc->cage_vertices_d[(i+1) % gcc->cage_vertice_number]);
length_d = gimp_vector2_length (&edge);
gcc->scaling_factor[i] = length_d / length;
}
}

View File

@ -43,6 +43,7 @@ struct _GimpCageConfig
GimpVector2 *cage_vertices; /* cage before deformation */ GimpVector2 *cage_vertices; /* cage before deformation */
GimpVector2 *cage_vertices_d; /* cage after deformation */ GimpVector2 *cage_vertices_d; /* cage after deformation */
gdouble *scaling_factor;
}; };