From 8e64f969a2cefa5effd34513c0339253cbe5ff7f Mon Sep 17 00:00:00 2001 From: Simon Budig Date: Mon, 30 Sep 2002 00:06:30 +0000 Subject: [PATCH] fixed the default spacing, so that lines actually look like 1 pixel 2002-09-30 Simon Budig * data/brushes/1circle.gbr: fixed the default spacing, so that lines actually look like 1 pixel lines... * themes/Default/images/tools/.cvsignore: Added some files. * app/vectors/gimpanchor.h * app/vectors/gimpbezierstroke.[ch] * app/vectors/gimpstroke.h * app/vectors/gimpvectors.h: Added some stuff, mostly unused code that otherwise would just rot on my harddisk. Mitch: I need to discuss the data structures with you... --- ChangeLog | 14 +++ app/vectors/gimpanchor.h | 2 +- app/vectors/gimpbezierstroke.c | 139 ++++++++++++++++++++++++- app/vectors/gimpbezierstroke.h | 4 +- app/vectors/gimpstroke.h | 38 ++++--- app/vectors/gimpvectors.h | 1 + data/brushes/1circle.gbr | Bin 33 -> 41 bytes themes/Default/images/tools/.cvsignore | 2 + 8 files changed, 180 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index ebb37372a6..9f73de3875 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2002-09-30 Simon Budig + + * data/brushes/1circle.gbr: fixed the default spacing, so that + lines actually look like 1 pixel lines... + + * themes/Default/images/tools/.cvsignore: Added some files. + + * app/vectors/gimpanchor.h + * app/vectors/gimpbezierstroke.[ch] + * app/vectors/gimpstroke.h + * app/vectors/gimpvectors.h: Added some stuff, mostly unused + code that otherwise would just rot on my harddisk. Mitch: I + need to discuss the data structures with you... + 2002-09-27 Michael Natterer * app/display/gimpdisplayshell.[ch]: added new signal "reconnect" diff --git a/app/vectors/gimpanchor.h b/app/vectors/gimpanchor.h index 92ce2c1c37..4392403c8a 100644 --- a/app/vectors/gimpanchor.h +++ b/app/vectors/gimpanchor.h @@ -27,7 +27,7 @@ struct _GimpAnchor { GimpCoords position; - gint type; + gint type; /* Interpretation dependant on GimpStroke type */ }; #endif /* __GIMP_ANCHOR_H__ */ diff --git a/app/vectors/gimpbezierstroke.c b/app/vectors/gimpbezierstroke.c index 551fed1d3c..b4a2766634 100644 --- a/app/vectors/gimpbezierstroke.c +++ b/app/vectors/gimpbezierstroke.c @@ -42,6 +42,14 @@ static void gimp_bezier_stroke_init (GimpBezierStroke *bezier_stroke) static void gimp_bezier_stroke_finalize (GObject *object); +static void gimp_bezier_coords_average (GimpCoords *a, + GimpCoords *b, + GimpCoords *ret_average); + +static void gimp_bezier_coords_subdivide (GimpCoords *beziercoords, + const gdouble precision, + gint *ret_ncoords, + GimpCoords *ret_coords); GType gimp_bezier_stroke_get_type (void) @@ -128,9 +136,39 @@ gimp_bezier_stroke_new (const GimpCoords *start) } +GimpStroke * +gimp_bezier_stroke_new_from_coords (const GimpCoords *coords, + const gint ncoords) +{ + GimpBezierStroke *bezier_stroke; + GimpStroke *stroke = NULL; + GimpAnchor *last_anchor; + + gint count; + + if (ncoords >= 1) + { + stroke = gimp_bezier_stroke_new (coords); + bezier_stroke = GIMP_BEZIER_STROKE (stroke); + last_anchor = (GimpAnchor *) (stroke->anchors->data); + + count = 1; + while (count < ncoords) + { + last_anchor = gimp_bezier_stroke_extend (bezier_stroke, + &(coords[count]), + last_anchor); + } + + } + + return stroke; +} + + GimpAnchor * gimp_bezier_stroke_extend (GimpBezierStroke *bezier_stroke, - GimpCoords *coords, + const GimpCoords *coords, GimpAnchor *neighbor) { GimpAnchor *anchor; @@ -191,6 +229,7 @@ gimp_bezier_stroke_extend (GimpBezierStroke *bezier_stroke, return anchor; } + GimpCoords * gimp_bezier_stroke_interpolate (const GimpStroke *stroke, gdouble precision, @@ -233,3 +272,101 @@ gimp_bezier_stroke_interpolate (const GimpStroke *stroke, } +/* local helper functions for bezier subdivision */ + +static void +gimp_bezier_coords_average (GimpCoords *a, + GimpCoords *b, + GimpCoords *ret_average) +{ + ret_average->x = (a->x + b->x ) / 2.0; + ret_average->y = (a->y + b->y ) / 2.0; + ret_average->pressure = (a->pressure + b->pressure) / 2.0; + ret_average->xtilt = (a->xtilt + b->xtilt ) / 2.0; + ret_average->ytilt = (a->ytilt + b->ytilt ) / 2.0; + ret_average->wheel = (a->wheel + b->wheel ) / 2.0; +} + + +static void +gimp_bezier_coords_subdivide (GimpCoords *beziercoords, + const gdouble precision, + gint *ret_ncoords, + GimpCoords *ret_coords) +{ + /* + * beziercoords has to contain four GimpCoords with the four control points + * of the bezier segment. We subdivide it at the parameter 0.5. + */ + + GimpCoords subdivided[8]; + gint i, good_enough = 1; + + subdivided[0] = beziercoords[0]; + subdivided[6] = beziercoords[3]; + + gimp_bezier_coords_average (&(beziercoords[0]), &(beziercoords[1]), + &(subdivided[1])); + + gimp_bezier_coords_average (&(beziercoords[1]), &(beziercoords[2]), + &(subdivided[7])); + + gimp_bezier_coords_average (&(beziercoords[2]), &(beziercoords[3]), + &(subdivided[5])); + + gimp_bezier_coords_average (&(subdivided[1]), &(subdivided[7]), + &(subdivided[2])); + + gimp_bezier_coords_average (&(subdivided[7]), &(subdivided[5]), + &(subdivided[4])); + + gimp_bezier_coords_average (&(subdivided[2]), &(subdivided[4]), + &(subdivided[3])); + + /* + * We now have the coordinates of the two bezier segments in + * subdivided [0-3] and subdivided [3-6] + */ + + /* + * Here we need to check, if we have sufficiently subdivided, i.e. + * if the stroke is sufficiently close to a straight line. + */ + + if ( good_enough /* stroke 1 */ ) + { + for (i=0; i < 3; i++) + { + /* if necessary, allocate new memory for return coords */ + ret_coords[*ret_ncoords] = subdivided[i]; + (*ret_ncoords)++; + } + } + else + { + gimp_bezier_coords_subdivide (&(subdivided[0]), precision, + ret_ncoords, ret_coords); + } + + if ( good_enough /* stroke 2 */ ) + { + for (i=0; i < 3; i++) + { + /* if necessary, allocate new memory for return coords */ + ret_coords[*ret_ncoords] = subdivided[i+3]; + (*ret_ncoords)++; + } + } + else + { + gimp_bezier_coords_subdivide (&(subdivided[3]), precision, + ret_ncoords, ret_coords); + } + + if ( /* last iteration */ 0) + { + /* if necessary, allocate new memory for return coords */ + ret_coords[*ret_ncoords] = subdivided[6]; + (*ret_ncoords)++; + } +} diff --git a/app/vectors/gimpbezierstroke.h b/app/vectors/gimpbezierstroke.h index 7caea18664..7641d41891 100644 --- a/app/vectors/gimpbezierstroke.h +++ b/app/vectors/gimpbezierstroke.h @@ -58,9 +58,11 @@ GType gimp_bezier_stroke_get_type (void) G_GNUC_CONST; GimpStroke * gimp_bezier_stroke_new (const GimpCoords *start); +GimpStroke * gimp_bezier_stroke_new_from_coords (const GimpCoords *coords, + const gint ncoords); GimpAnchor * gimp_bezier_stroke_extend (GimpBezierStroke *bezier_stroke, - GimpCoords *coords, + const GimpCoords *coords, GimpAnchor *neighbor); GimpCoords * gimp_bezier_stroke_interpolate (const GimpStroke *stroke, diff --git a/app/vectors/gimpstroke.h b/app/vectors/gimpstroke.h index 4b4ca79ab0..660199f394 100644 --- a/app/vectors/gimpstroke.h +++ b/app/vectors/gimpstroke.h @@ -38,7 +38,10 @@ struct _GimpStroke GList *anchors; GimpStroke *next; - /* Stuff missing */ + + GimpAnchor *temp_anchor; + + /* Stuff missing? */ }; @@ -87,6 +90,7 @@ struct _GimpStrokeClass const GimpCoords *coord); gboolean (* temp_anchor_fix) (GimpStroke *stroke); + GimpStroke * (* make_bezier) (const GimpStroke *stroke); }; @@ -111,49 +115,49 @@ GimpAnchor * gimp_stroke_anchor_get_next (const GimpStroke *stroke, * VECTORS_NONE, VECTORS_FIX_ANGLE, VECTORS_FIX_RATIO, VECTORS_RESTRICT_ANGLE * or so. */ -void gimp_stroke_anchor_move_relative (GimpStroke *stroke, +void gimp_stroke_anchor_move_relative (GimpStroke *stroke, GimpAnchor *anchor, const GimpCoords *deltacoord, const gint type); -void gimp_stroke_anchor_move_absolute (GimpStroke *stroke, +void gimp_stroke_anchor_move_absolute (GimpStroke *stroke, GimpAnchor *anchor, const GimpCoords *coord, const gint type); -void gimp_stroke_anchor_delete (GimpStroke *stroke, - GimpAnchor *anchor); +void gimp_stroke_anchor_delete (GimpStroke *stroke, + GimpAnchor *anchor); /* accessing the shape of the curve */ -gdouble gimp_stroke_get_length (const GimpStroke *stroke); +gdouble gimp_stroke_get_length (const GimpStroke *stroke); -gdouble gimp_stroke_get_distance (const GimpStroke *stroke, - const GimpCoords *coord); +gdouble gimp_stroke_get_distance (const GimpStroke *stroke, + const GimpCoords *coord); /* returns the number of valid coordinates */ -GimpCoords * gimp_stroke_interpolate (const GimpStroke *stroke, - gdouble precision, - gint *ret_numcoords, - gboolean *ret_closed); +GimpCoords * gimp_stroke_interpolate (const GimpStroke *stroke, + gdouble precision, + gint *ret_numcoords, + gboolean *ret_closed); /* Allow a singular temorary anchor (marking the "working point")? */ -GimpAnchor * gimp_stroke_temp_anchor_get (const GimpStroke *stroke); +GimpAnchor * gimp_stroke_temp_anchor_get (const GimpStroke *stroke); -GimpAnchor * gimp_stroke_temp_anchor_set (GimpStroke *stroke, - const GimpCoords *coord); +GimpAnchor * gimp_stroke_temp_anchor_set (GimpStroke *stroke, + const GimpCoords *coord); -gboolean gimp_stroke_temp_anchor_fix (GimpStroke *stroke); +gboolean gimp_stroke_temp_anchor_fix (GimpStroke *stroke); /* usually overloaded */ /* creates a bezier approximation. */ -GimpStroke * gimp_stroke_make_bezier (const GimpStroke *stroke); +GimpStroke * gimp_stroke_make_bezier (const GimpStroke *stroke); #endif /* __GIMP_STROKE_H__ */ diff --git a/app/vectors/gimpvectors.h b/app/vectors/gimpvectors.h index 91429bd582..1bb939e65b 100644 --- a/app/vectors/gimpvectors.h +++ b/app/vectors/gimpvectors.h @@ -40,6 +40,7 @@ struct _GimpVectors gboolean visible; /* controls visibility */ gboolean locked; /* transformation locking */ + /* Should the following be a GList of GimpStrokes? */ GimpStroke * strokes; /* The first stroke */ /* Stuff missing */ diff --git a/data/brushes/1circle.gbr b/data/brushes/1circle.gbr index ccfdcdc8874d3802ef7c0df6521b03437b63813c..8c81f6bf2f45ba3d32f8ffb636b96884c5c5f8cf 100644 GIT binary patch literal 41 mcmZQzV9;P-U|<4bMi_SY^bG*AxtueLl5YX&Y4BYIjIU728Nmp{{bO71V{h? diff --git a/themes/Default/images/tools/.cvsignore b/themes/Default/images/tools/.cvsignore index 4155185e15..bfc4dea1f0 100644 --- a/themes/Default/images/tools/.cvsignore +++ b/themes/Default/images/tools/.cvsignore @@ -1,2 +1,4 @@ +Makefile +Makefile.in .xvpics .thumbnails