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.
This commit is contained in:
Simon Budig 2003-09-01 00:39:47 +00:00 committed by Simon Budig
parent cd31cdd7eb
commit f09f3657d4
8 changed files with 101 additions and 0 deletions

View File

@ -1,3 +1,14 @@
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.

View File

@ -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);
}

View File

@ -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);

View File

@ -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,

View File

@ -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);
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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,