gegl r2651 - in trunk: . bin gegl/property-types
- From: ok svn gnome org
- To: svn-commits-list gnome org
- Subject: gegl r2651 - in trunk: . bin gegl/property-types
- Date: Mon, 20 Oct 2008 19:03:31 +0000 (UTC)
Author: ok
Date: Mon Oct 20 19:03:30 2008
New Revision: 2651
URL: http://svn.gnome.org/viewvc/gegl?rev=2651&view=rev
Log:
* gegl/property-types/gegl-vector.[ch]:
(gegl_vector_path_add): new API call replacing move_to, line_to etc.
(gegl_vector_add): new API call replacing move_to, curve_to etc.
* bin/gegl-spiro.c: (moveto), (lineto), (curveto),
(points_to_bezier_path): use the new var_args powered internal path
list API.
Modified:
trunk/ChangeLog
trunk/bin/gegl-spiro.c
trunk/gegl/property-types/gegl-vector.c
trunk/gegl/property-types/gegl-vector.h
Modified: trunk/bin/gegl-spiro.c
==============================================================================
--- trunk/bin/gegl-spiro.c (original)
+++ trunk/bin/gegl-spiro.c Mon Oct 20 19:03:30 2008
@@ -46,11 +46,11 @@
static void moveto (bezctx *bc, double x, double y, int is_open)
{
- bezcontext.path = gegl_vector_path_add1 (bezcontext.path, 'M', x, y);
+ bezcontext.path = gegl_vector_path_add (bezcontext.path, 'M', x, y);
}
static void lineto (bezctx *bc, double x, double y)
{
- bezcontext.path = gegl_vector_path_add1 (bezcontext.path, 'L', x, y);
+ bezcontext.path = gegl_vector_path_add (bezcontext.path, 'L', x, y);
}
static void quadto (bezctx *bc, double x1, double y1, double x2, double y2)
{
@@ -61,7 +61,7 @@
double x2, double y2,
double x3, double y3)
{
- bezcontext.path = gegl_vector_path_add3 (bezcontext.path, 'C', x1, y1, x2, y2, x3, y3);
+ bezcontext.path = gegl_vector_path_add (bezcontext.path, 'C', x1, y1, x2, y2, x3, y3);
}
static GeglVectorPath *gegl_vector_spiro_flatten (GeglVectorPath *original)
@@ -169,7 +169,7 @@
if (!n_coords)
return NULL;
- ret = gegl_vector_path_add1 (ret, 'M', coord_x[0], coord_y[0]);
+ ret = gegl_vector_path_add (ret, 'M', coord_x[0], coord_y[0]);
for (i=1;i<n_coords;i++)
{
@@ -231,9 +231,9 @@
ctrl2_y = y2;
}
- ret = gegl_vector_path_add3 (ret, 'C', ctrl1_x, ctrl1_y,
- ctrl2_x, ctrl2_y,
- x2, y2);
+ ret = gegl_vector_path_add (ret, 'C', ctrl1_x, ctrl1_y,
+ ctrl2_x, ctrl2_y,
+ x2, y2);
}
}
return ret;
Modified: trunk/gegl/property-types/gegl-vector.c
==============================================================================
--- trunk/gegl/property-types/gegl-vector.c (original)
+++ trunk/gegl/property-types/gegl-vector.c Mon Oct 20 19:03:30 2008
@@ -31,6 +31,7 @@
#include "gegl-utils.h"
#include <glib/gprintf.h>
+#include <stdarg.h>
/* ###################################################################### */
@@ -79,9 +80,11 @@
/* FIXME: handling of relative commands should be moved to the flattening stage */
-/* this table should be possible to replace at runtime */
+/* This table can be extended at runtime and extends the type of knots understood by the
+ * "SVG path" parser/serializer.
+ */
-static KnotInfo knot_types[256]=
+static KnotInfo knot_types[64]= /* reserve space for a total of up to 64 types of instructions. */
{
{'M', 1, "move to", flatten_copy},
{'L', 1, "line to", flatten_copy},
@@ -93,7 +96,7 @@
{'s', 0, "sentinel", flatten_nop},
{'z', 0, "sentinel", flatten_nop},
- {'\0', 0, "marker for end of", flatten_copy},
+ {'\0', 0, "end of instructions", flatten_copy},
};
void
@@ -209,11 +212,7 @@
lerp (dest, &abbc, &bccd, t);
}
-GeglVectorPath *
-gegl_vector_path_add1 (GeglVectorPath *head,
- gchar type,
- gfloat x,
- gfloat y);
+
static GeglVectorPath *flatten_curve (GeglVectorPath *head, GeglVectorPath *prev, GeglVectorPath *self)
{ /* create piecevise linear approximation of bezier curve */
@@ -225,9 +224,9 @@
bezier2 (prev, self, &res, f);
- head = gegl_vector_path_add1 (head, 'L', res.x, res.y);
+ head = gegl_vector_path_add (head, 'L', res.x, res.y);
}
- head = gegl_vector_path_add1 (head, 'L', self->d.point[2].x, self->d.point[2].y);
+ head = gegl_vector_path_add (head, 'L', self->d.point[2].x, self->d.point[2].y);
return head;
}
@@ -290,121 +289,34 @@
return NULL;
}
-
-GeglVectorPath *
-gegl_vector_path_add4 (GeglVectorPath *head,
- gchar type,
- gfloat x0, gfloat y0,
- gfloat x1, gfloat y1,
- gfloat x2, gfloat y2,
- gfloat x3, gfloat y3)
+GeglVectorPath * gegl_vector_path_add (GeglVectorPath *head,
+ ...)
{
+ KnotInfo *info;
GeglVectorPath *iter;
+ gchar type;
+ gint pair_no;
+
+ va_list var_args;
+ va_start (var_args, head);
+ type = va_arg (var_args, int); /* we pass in a char, but it is promoted to int by varargs*/
+
+ info = find_knot_type(type);
+ if (!info)
+ g_error ("didn't find [%c]", type);
head = path_append (head, &iter);
+
iter->d.type = type;
- iter->d.point[0].x = x0;
- iter->d.point[0].y = y0;
- iter->d.point[1].x = x1;
- iter->d.point[1].y = y1;
- iter->d.point[2].x = x2;
- iter->d.point[2].y = y2;
- iter->d.point[3].x = x3;
- iter->d.point[3].y = y3;
+ for (pair_no=0;pair_no<info->pairs;pair_no++)
+ {
+ iter->d.point[pair_no].x = va_arg (var_args, gdouble);
+ iter->d.point[pair_no].y = va_arg (var_args, gdouble);
+ }
+ va_end (var_args);
return head;
}
-
-GeglVectorPath *
-gegl_vector_path_add1 (GeglVectorPath *head,
- gchar type,
- gfloat x, gfloat y)
-{
- return gegl_vector_path_add4 (head, type, x, y, 0, 0, 0, 0, 0, 0);
-}
-
-GeglVectorPath *
-gegl_vector_path_add2 (GeglVectorPath *head,
- gchar type,
- gfloat x,
- gfloat y,
- gfloat x1,
- gfloat y1)
-{
- return gegl_vector_path_add4 (head, type, x, y, x1, y1, 0, 0, 0, 0);
-}
-
-GeglVectorPath *
-gegl_vector_path_add3 (GeglVectorPath *head,
- gchar type,
- gfloat x,
- gfloat y,
- gfloat x1,
- gfloat y1,
- gfloat x2,
- gfloat y2)
-{
- return gegl_vector_path_add4 (head, type, x, y, x1, y1, x2, y2, 0, 0);
-}
-
-static GeglVectorPath *
-path_move_to (GeglVectorPath *path,
- gfloat x,
- gfloat y)
-{
- return gegl_vector_path_add1 (path, 'M', x, y);
-}
-
-static GeglVectorPath *
-path_line_to (GeglVectorPath *path,
- gfloat x,
- gfloat y)
-{
- return gegl_vector_path_add1 (path, 'L', x, y);
-}
-
-static GeglVectorPath *
-path_curve_to (GeglVectorPath *path,
- gfloat x1,
- gfloat y1,
- gfloat x2,
- gfloat y2,
- gfloat x3,
- gfloat y3)
-{
- return gegl_vector_path_add3 (path, 'C', x1, y1, x2, y2, x3, y3);
-}
-
-static GeglVectorPath *
-path_rel_move_to (GeglVectorPath *path,
- gfloat x,
- gfloat y)
-{
- return gegl_vector_path_add1 (path, 'm', x, y);
-}
-
-static GeglVectorPath *
-path_rel_line_to (GeglVectorPath *path,
- gfloat x,
- gfloat y)
-{
- return gegl_vector_path_add1 (path, 'l', x, y);
-}
-
-static GeglVectorPath *
-path_rel_curve_to (GeglVectorPath *path,
- gfloat x1,
- gfloat y1,
- gfloat x2,
- gfloat y2,
- gfloat x3,
- gfloat y3)
-{
- return gegl_vector_path_add3 (path, 'c', x1, y1, x2, y2, x3, y3);
-}
-
-
-
static void
path_calc (GeglVectorPath *path,
gdouble pos,
@@ -1166,119 +1078,6 @@
return self;
}
-static void gen_rect (GeglRectangle *r,
- gdouble x1, gdouble y1, gdouble x2, gdouble y2)
-{
- if (x1>x2)
- {
- gint t;
- t=x1;
- x1=x2;
- x2=x1;
- }
- if (y1>y2)
- {
- gint t;
- t=y1;
- y1=y2;
- y2=y1;
- }
- x1=floor (x1);
- y1=floor (y1);
- x2=ceil (x2);
- y2=ceil (y2);
- r->x=x1;
- r->y=y1;
- r->width=x2-x1;
- r->height=y2-y1;
-}
-
-void
-gegl_vector_line_to (GeglVector *self,
- gdouble x,
- gdouble y)
-{
- GeglVectorPrivate *priv;
- priv = GEGL_VECTOR_GET_PRIVATE (self);
-
- if (priv->path)
- gen_rect (&priv->dirtied, x, y, priv->path->d.point[0].x,
- priv->path->d.point[0].y);
- priv->path = path_line_to (priv->path, x, y);
-
- if (priv->path)
- gegl_vector_emit_changed (self, &priv->dirtied);
- priv->flat_path_clean = FALSE;
-}
-
-void
-gegl_vector_move_to (GeglVector *self,
- gdouble x,
- gdouble y)
-{
- GeglVectorPrivate *priv;
- priv = GEGL_VECTOR_GET_PRIVATE (self);
- priv->path = path_move_to (priv->path, x, y);
- /*gegl_vector_emit_changed (self);*/
- priv->flat_path_clean = FALSE;
-}
-
-void
-gegl_vector_curve_to (GeglVector *self,
- gdouble x1,
- gdouble y1,
- gdouble x2,
- gdouble y2,
- gdouble x3,
- gdouble y3)
-{
- GeglVectorPrivate *priv;
- priv = GEGL_VECTOR_GET_PRIVATE (self);
- priv->path = path_curve_to (priv->path, x1, y1, x2, y2, x3, y3);
- priv->flat_path_clean = FALSE;
- gegl_vector_emit_changed (self, NULL);
-}
-
-
-void
-gegl_vector_rel_line_to (GeglVector *self,
- gdouble x,
- gdouble y)
-{
- GeglVectorPrivate *priv;
- priv = GEGL_VECTOR_GET_PRIVATE (self);
- priv->path = path_rel_line_to (priv->path, x, y);
- priv->flat_path_clean = FALSE;
- gegl_vector_emit_changed (self, NULL);
-}
-
-void
-gegl_vector_rel_move_to (GeglVector *self,
- gdouble x,
- gdouble y)
-{
- GeglVectorPrivate *priv;
- priv = GEGL_VECTOR_GET_PRIVATE (self);
- priv->path = path_rel_move_to (priv->path, x, y);
- priv->flat_path_clean = FALSE;
- gegl_vector_emit_changed (self, NULL);
-}
-
-void
-gegl_vector_rel_curve_to (GeglVector *self,
- gdouble x1,
- gdouble y1,
- gdouble x2,
- gdouble y2,
- gdouble x3,
- gdouble y3)
-{
- GeglVectorPrivate *priv;
- priv = GEGL_VECTOR_GET_PRIVATE (self);
- priv->path = path_rel_curve_to (priv->path, x1, y1, x2, y2, x3, y3);
- priv->flat_path_clean = FALSE;
- gegl_vector_emit_changed (self, NULL);
-}
gdouble
gegl_vector_get_length (GeglVector *self)
@@ -1606,23 +1405,23 @@
switch (info->pairs)
{
case 0:
- priv->path = gegl_vector_path_add1 (priv->path, type, x0, y0);
+ priv->path = gegl_vector_path_add (priv->path, type, x0, y0);
/* coordinates are ignored, all of these could have used add3)*/
break;
case 1:
p = parse_float_pair (p, &x0, &y0);
- priv->path = gegl_vector_path_add1 (priv->path, type, x0, y0);
+ priv->path = gegl_vector_path_add (priv->path, type, x0, y0);
break;
case 2:
p = parse_float_pair (p, &x0, &y0);
p = parse_float_pair (p, &x1, &y1);
- priv->path = gegl_vector_path_add2 (priv->path, type, x0, y0, x1, y1);
+ priv->path = gegl_vector_path_add (priv->path, type, x0, y0, x1, y1);
break;
case 3:
p = parse_float_pair (p, &x0, &y0);
p = parse_float_pair (p, &x1, &y1);
p = parse_float_pair (p, &x2, &y2);
- priv->path = gegl_vector_path_add3 (priv->path, type, x0, y0, x1, y1, x2, y2);
+ priv->path = gegl_vector_path_add (priv->path, type, x0, y0, x1, y1, x2, y2);
break;
}
previnfo = info;
@@ -1835,6 +1634,39 @@
}
}
+
+void
+gegl_vector_add (GeglVector *self,
+ ...)
+{
+ GeglVectorPrivate *priv;
+ KnotInfo *info;
+ GeglVectorPath *iter;
+ gchar type;
+ gint pair_no;
+ va_list var_args;
+
+ priv = GEGL_VECTOR_GET_PRIVATE (self);
+ va_start (var_args, self);
+ type = va_arg (var_args, int); /* we pass in a char, but it is promoted to int by varargs*/
+
+ info = find_knot_type(type);
+ if (!info)
+ g_error ("didn't find [%c]", type);
+
+ priv->path = path_append (priv->path, &iter);
+
+ iter->d.type = type;
+ for (pair_no=0;pair_no<info->pairs;pair_no++)
+ {
+ iter->d.point[pair_no].x = va_arg (var_args, gdouble);
+ iter->d.point[pair_no].y = va_arg (var_args, gdouble);
+ }
+ va_end (var_args);
+ priv->flat_path_clean = FALSE;
+ gegl_vector_emit_changed (self, NULL);
+}
+
#if 0
const GeglMatrix *gegl_vector_get_matrix (GeglVector *vector)
{
@@ -1844,3 +1676,33 @@
{
}
#endif
+
+
+#if 0
+static void gen_rect (GeglRectangle *r,
+ gdouble x1, gdouble y1, gdouble x2, gdouble y2)
+{
+ if (x1>x2)
+ {
+ gint t;
+ t=x1;
+ x1=x2;
+ x2=x1;
+ }
+ if (y1>y2)
+ {
+ gint t;
+ t=y1;
+ y1=y2;
+ y2=y1;
+ }
+ x1=floor (x1);
+ y1=floor (y1);
+ x2=ceil (x2);
+ y2=ceil (y2);
+ r->x=x1;
+ r->y=y1;
+ r->width=x2-x1;
+ r->height=y2-y1;
+}
+#endif
Modified: trunk/gegl/property-types/gegl-vector.h
==============================================================================
--- trunk/gegl/property-types/gegl-vector.h (original)
+++ trunk/gegl/property-types/gegl-vector.h Mon Oct 20 19:03:30 2008
@@ -73,38 +73,15 @@
GeglVector * gegl_vector_new (void);
-
-void gegl_vector_line_to (GeglVector *self,
- gdouble x,
- gdouble y);
-
-void gegl_vector_move_to (GeglVector *self,
- gdouble x,
- gdouble y);
-
-void gegl_vector_curve_to (GeglVector *self,
- gdouble x1,
- gdouble y1,
- gdouble x2,
- gdouble y2,
- gdouble x3,
- gdouble y3);
-
-void gegl_vector_rel_line_to (GeglVector *self,
- gdouble x,
- gdouble y);
-
-void gegl_vector_rel_move_to (GeglVector *self,
- gdouble x,
- gdouble y);
-
-void gegl_vector_rel_curve_to (GeglVector *self,
- gdouble x1,
- gdouble y1,
- gdouble x2,
- gdouble y2,
- gdouble x3,
- gdouble y3);
+/* Adds a path knot/instuction,. e.g:
+ *
+ * gegl_vector_add ('m', 10.0, 10.0); for a relative move_to 10, 10
+ * the number of arguments are determined automatically through the
+ * command used, for language bindings append knots at position -1
+ * with gegl_vector_add_knot
+ *
+ */
+void gegl_vector_add (GeglVector *self, ...);
void gegl_vector_get_bounds (GeglVector *self,
gdouble *min_x,
@@ -114,60 +91,46 @@
gdouble gegl_vector_get_length (GeglVector *self);
-
+/*
+ * compute x,y coordinates at pos along the path (0.0 to gegl_vector_length() is valid positions
+ */
void gegl_vector_calc (GeglVector *self,
gdouble pos,
gdouble *x,
gdouble *y);
+/*
+ * compute a set of samples for the entire path
+ */
void gegl_vector_calc_values (GeglVector *self,
guint num_samples,
gdouble *xs,
gdouble *ys);
-#define GEGL_TYPE_PARAM_VECTOR (gegl_param_vector_get_type ())
-#define GEGL_IS_PARAM_VECTOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEGL_TYPE_PARAM_VECTOR))
-
-GType gegl_param_vector_get_type (void) G_GNUC_CONST;
-
GParamSpec * gegl_param_spec_vector (const gchar *name,
const gchar *nick,
const gchar *blurb,
GeglVector *default_vector,
GParamFlags flags);
-#include <gegl-buffer.h>
-
-void gegl_vector_fill (GeglBuffer *buffer,
- GeglVector *vector,
- GeglColor *color,
- gboolean winding);
-
-void gegl_vector_stroke (GeglBuffer *buffer,
- GeglVector *vector,
- GeglColor *color,
- gdouble linewidth,
- gdouble hardness);
-
+/* parse an SVG path (or any other path with additional valid path instructions */
void gegl_vector_parse_svg_path (GeglVector *vector,
const gchar *path);
-void gegl_vector_clear (GeglVector *vector);
-
+/* serialie the path in an SVG manner (not yet flattened to any specified level) */
gchar * gegl_vector_to_svg_path (GeglVector *vector);
+/* clear path for all knots */
+void gegl_vector_clear (GeglVector *vector);
+
+
+/* for pos parameters -1 can be used to indicate the end of the path */
gint gegl_vector_get_knot_count (GeglVector *vector);
const GeglVectorKnot *gegl_vector_get_knot (GeglVector *vector,
gint pos);
-
-/* -1 means last */
-/* pos = 0, pushes the existing 0 if any to 1,
- * passing -1 means add at end
- */
-
void gegl_vector_remove_knot (GeglVector *vector,
gint pos);
void gegl_vector_add_knot (GeglVector *vector,
@@ -184,38 +147,46 @@
void (*func) (const GeglVectorKnot *knot,
gpointer data),
gpointer data);
+
+
+#define GEGL_TYPE_PARAM_VECTOR (gegl_param_vector_get_type ())
+#define GEGL_IS_PARAM_VECTOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEGL_TYPE_PARAM_VECTOR))
+
+GType gegl_param_vector_get_type (void) G_GNUC_CONST;
+
+
+/* the following API is for hooking in additional path types, that can be flattened by
+ * external flatterners, it allows acces to a linked list version of the paths, which
+ * is what is used internally
+ */
+
+
+void gegl_vector_add_flattener (GeglVectorPath *(*func) (GeglVectorPath *original));
+void gegl_vector_add_knot_type (gchar type, gint pairs, const gchar *description);
+
+GeglVectorPath * gegl_vector_path_add (GeglVectorPath *head, ...);
+GeglVectorPath * gegl_vector_path_destroy (GeglVectorPath *path);
+GeglVectorPath * gegl_vector_path_flatten (GeglVectorPath *original);
#if 0
const GeglMatrix *gegl_vector_get_matrix (GeglVector *vector);
GeglMatrix gegl_vector_set_matrix (GeglVector *vector,
const GeglMatrix *matrix);
-
#endif
+/* this can and should be the responsiblity of cairo */
+#include <gegl-buffer.h>
-GeglVectorPath *gegl_vector_path_flatten (GeglVectorPath *original);
-
-void gegl_vector_add_flattener (GeglVectorPath *(*func) (GeglVectorPath *original));
-void gegl_vector_add_knot_type (gchar type, gint pairs, const gchar *description);
+void gegl_vector_fill (GeglBuffer *buffer,
+ GeglVector *vector,
+ GeglColor *color,
+ gboolean winding);
-GeglVectorPath * gegl_vector_path_add1 (GeglVectorPath *head,
- gchar type,
- gfloat x, gfloat y);
-GeglVectorPath * gegl_vector_path_add2 (GeglVectorPath *head,
- gchar type,
- gfloat x, gfloat y,
- gfloat x1, gfloat y1);
-GeglVectorPath * gegl_vector_path_add3 (GeglVectorPath *head,
- gchar type,
- gfloat x, gfloat y,
- gfloat x1, gfloat y1,
- gfloat x2, gfloat y2);
-GeglVectorPath * gegl_vector_path_add4 (GeglVectorPath *head,
- gchar type,
- gfloat x0, gfloat y0,
- gfloat x1, gfloat y1,
- gfloat x2, gfloat y2,
- gfloat x3, gfloat y3);
-GeglVectorPath *gegl_vector_path_destroy (GeglVectorPath *path);
+/* this will go away, it is the stroke routines */
+void gegl_vector_stroke (GeglBuffer *buffer,
+ GeglVector *vector,
+ GeglColor *color,
+ gdouble linewidth,
+ gdouble hardness);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]