Commit f09f3657 authored by Simon Budig's avatar Simon Budig Committed by Simon Budig

Introduced function to compare two gimpcoords

2003-09-01  Simon Budig  <simon@gimp.org>

	* app/vectors/gimpcoordmath.[ch]: Introduced function to compare
	two gimpcoords

	* app/vectors/gimpstroke.[ch]: virtualized gimp_stroke_close.

	* app/vectors/gimpbezierstroke.c: made the _close function check,
	if there is an unneeded segment (CCA-Sequence with all the same
	coordinates) at the gap to be closed. If so, remove it.
parent cd31cdd7
2003-09-01 Simon Budig <simon@gimp.org>
* app/vectors/gimpcoordmath.[ch]: Introduced function to compare
two gimpcoords
* app/vectors/gimpstroke.[ch]: virtualized gimp_stroke_close.
* app/vectors/gimpbezierstroke.c: made the _close function check,
if there is an unneeded segment (CCA-Sequence with all the same
coordinates) at the gap to be closed. If so, remove it.
2003-09-01 Tor Lillqvist <tml@iki.fi>
* README.win32: Update.
......@@ -145,3 +145,16 @@ gimp_bezier_coords_length (const GimpCoords *a)
{
return sqrt (gimp_bezier_coords_length2 (a));
}
gboolean
gimp_bezier_coords_equal (const GimpCoords *a,
const GimpCoords *b)
{
return ( a->x == b->x &&
a->y == b->y &&
a->pressure == b->pressure &&
a->xtilt == b->xtilt &&
a->ytilt == b->ytilt &&
a->wheel == b->wheel);
}
......@@ -42,3 +42,5 @@ gdouble gimp_bezier_coords_scalarprod (const GimpCoords *a,
gdouble gimp_bezier_coords_length (const GimpCoords *a);
gdouble gimp_bezier_coords_length2 (const GimpCoords *a);
gboolean gimp_bezier_coords_equal (const GimpCoords *a,
const GimpCoords *b);
......@@ -78,6 +78,7 @@ static void gimp_bezier_stroke_point_move_absolute
const GimpCoords *coord,
GimpAnchorFeatureType feature);
static void gimp_bezier_stroke_close (GimpStroke *stroke);
static GimpStroke * gimp_bezier_stroke_open (GimpStroke *stroke,
GimpAnchor *end_anchor);
......@@ -169,6 +170,7 @@ gimp_bezier_stroke_class_init (GimpBezierStrokeClass *klass)
stroke_class->point_is_movable = gimp_bezier_stroke_point_is_movable;
stroke_class->point_move_relative = gimp_bezier_stroke_point_move_relative;
stroke_class->point_move_absolute = gimp_bezier_stroke_point_move_absolute;
stroke_class->close = gimp_bezier_stroke_close;
stroke_class->open = gimp_bezier_stroke_open;
stroke_class->anchor_is_insertable = gimp_bezier_stroke_anchor_is_insertable;
stroke_class->anchor_insert = gimp_bezier_stroke_anchor_insert;
......@@ -517,6 +519,53 @@ gimp_bezier_stroke_point_move_absolute (GimpStroke *stroke,
&deltacoord, feature);
}
static void
gimp_bezier_stroke_close (GimpStroke *stroke)
{
GList *start, *end;
GimpAnchor *anchor;
g_return_if_fail (stroke->anchors != NULL);
stroke->closed = TRUE;
start = g_list_first (stroke->anchors);
end = g_list_last (stroke->anchors);
g_return_if_fail (start->next != NULL && end->prev != NULL);
if (start->next != end->prev)
{
if (gimp_bezier_coords_equal (&(GIMP_ANCHOR (start->next->data)->position),
&(GIMP_ANCHOR (start->data)->position)) &&
gimp_bezier_coords_equal (&(GIMP_ANCHOR (start->data)->position),
&(GIMP_ANCHOR (end->data)->position)) &&
gimp_bezier_coords_equal (&(GIMP_ANCHOR (end->data)->position),
&(GIMP_ANCHOR (end->prev->data)->position)))
{
/* redundant segment */
anchor = GIMP_ANCHOR (stroke->anchors->data);
stroke->anchors = g_list_delete_link (stroke->anchors,
stroke->anchors);
gimp_anchor_free (anchor);
anchor = GIMP_ANCHOR (stroke->anchors->data);
stroke->anchors = g_list_delete_link (stroke->anchors,
stroke->anchors);
gimp_anchor_free (anchor);
anchor = GIMP_ANCHOR (stroke->anchors->data);
stroke->anchors = g_list_delete_link (stroke->anchors,
stroke->anchors);
end = g_list_last (stroke->anchors);
gimp_anchor_free (GIMP_ANCHOR (end->data));
end->data = anchor;
}
}
}
static gdouble
gimp_bezier_stroke_nearest_point_get (const GimpStroke *stroke,
const GimpCoords *coord,
......
......@@ -145,3 +145,16 @@ gimp_bezier_coords_length (const GimpCoords *a)
{
return sqrt (gimp_bezier_coords_length2 (a));
}
gboolean
gimp_bezier_coords_equal (const GimpCoords *a,
const GimpCoords *b)
{
return ( a->x == b->x &&
a->y == b->y &&
a->pressure == b->pressure &&
a->xtilt == b->xtilt &&
a->ytilt == b->ytilt &&
a->wheel == b->wheel);
}
......@@ -42,3 +42,5 @@ gdouble gimp_bezier_coords_scalarprod (const GimpCoords *a,
gdouble gimp_bezier_coords_length (const GimpCoords *a);
gdouble gimp_bezier_coords_length2 (const GimpCoords *a);
gboolean gimp_bezier_coords_equal (const GimpCoords *a,
const GimpCoords *b);
......@@ -84,6 +84,7 @@ static void gimp_stroke_real_point_move_absolute
const GimpCoords *coord,
GimpAnchorFeatureType feature);
static void gimp_stroke_real_close (GimpStroke *stroke);
static GimpStroke * gimp_stroke_real_open (GimpStroke *stroke,
GimpAnchor *end_anchor);
static gboolean gimp_stroke_real_anchor_is_insertable
......@@ -211,6 +212,7 @@ gimp_stroke_class_init (GimpStrokeClass *klass)
klass->point_move_absolute = gimp_stroke_real_point_move_absolute;
klass->nearest_point_get = gimp_stroke_real_nearest_point_get;
klass->close = gimp_stroke_real_close;
klass->open = gimp_stroke_real_open;
klass->anchor_is_insertable = gimp_stroke_real_anchor_is_insertable;
klass->anchor_insert = gimp_stroke_real_anchor_insert;
......@@ -561,6 +563,14 @@ gimp_stroke_real_point_move_absolute (GimpStroke *stroke,
void
gimp_stroke_close (GimpStroke *stroke)
{
g_return_if_fail (GIMP_IS_STROKE (stroke));
GIMP_STROKE_GET_CLASS (stroke)->close (stroke);
}
static void
gimp_stroke_real_close (GimpStroke *stroke)
{
stroke->closed = TRUE;
}
......
......@@ -92,6 +92,7 @@ struct _GimpStrokeClass
const GimpCoords *coord,
GimpAnchorFeatureType feature);
void (* close) (GimpStroke *stroke);
GimpStroke * (* open) (GimpStroke *stroke,
GimpAnchor *end_anchor);
gboolean (* anchor_is_insertable) (GimpStroke *stroke,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment