gegl r2730 - in trunk: . bin
- From: ok svn gnome org
- To: svn-commits-list gnome org
- Subject: gegl r2730 - in trunk: . bin
- Date: Tue, 11 Nov 2008 10:09:57 +0000 (UTC)
Author: ok
Date: Tue Nov 11 10:09:57 2008
New Revision: 2730
URL: http://svn.gnome.org/viewvc/gegl?rev=2730&view=rev
Log:
* bin/editor.c: (sumdist), (path_smoothen), (stroke_release_event),
(gui_press_event): add a very simple, rather broken, slow, path
smoothener.
Modified:
trunk/ChangeLog
trunk/bin/editor.c
Modified: trunk/bin/editor.c
==============================================================================
--- trunk/bin/editor.c (original)
+++ trunk/bin/editor.c Tue Nov 11 10:09:57 2008
@@ -977,6 +977,83 @@
return 0;
}
+static gdouble sumdist (gint n,
+ gdouble *samples_x,
+ gdouble *samples_y,
+ gdouble *samples_x2,
+ gdouble *samples_y2)
+{
+ gint i;
+ gdouble squaresum =0;
+ for (i=0;i<n;i++)
+ {
+ gdouble dx = samples_x2[i] - samples_x[i];
+ gdouble dy = samples_y2[i] - samples_y[i];
+ squaresum += (dx*dx + dx*dy);
+ }
+ return sqrt (squaresum);
+}
+
+static gint path_smoothen (gint argc, char **argv)
+{
+ GeglPath *path = tools.path;
+ gdouble length = gegl_path_get_length (path);
+ gint i, n;
+ gdouble *samples_x;
+ gdouble *samples_y;
+
+ gdouble *samples_x2;
+ gdouble *samples_y2;
+
+ gboolean *skiplist;
+ gint iter = 0;
+
+ n = length / 5;
+
+ samples_x = g_malloc (sizeof (gdouble)* n);
+ samples_y = g_malloc (sizeof (gdouble)* n);
+ samples_x2 = g_malloc (sizeof (gdouble)* n);
+ samples_y2 = g_malloc (sizeof (gdouble)* n);
+ skiplist = g_malloc0 (sizeof (gboolean)* n);
+
+ gegl_path_calc_values (path, n, samples_x, samples_y);
+ gegl_path_freeze (path);
+
+ for (iter=1; iter < n * 0.9 ;iter++)
+ {
+ gint tryno = -1;
+ tryno = g_random_int_range (0, n-1);
+ while (tryno <0 ||
+ skiplist[tryno])
+ tryno++;
+ if (tryno >= n)
+ continue;
+
+ gegl_path_clear (path);
+ for (i=0;i<n;i++)
+ {
+ if (i != tryno && skiplist[i] == FALSE)
+ gegl_path_append (path, 'O', samples_x[i], samples_y[i]);
+ }
+ gegl_path_calc_values (path, n, samples_x2, samples_y2);
+ if (sumdist (n, samples_x, samples_y, samples_x2, samples_y2) < 25)
+ {
+ skiplist[tryno]=TRUE;
+ g_print ("(%2.1f)x", (iter*100.0/n));
+ }
+ else
+ g_print ("[%2.1f]", (iter*100.0/n));
+ }
+
+ g_free (samples_x);
+ g_free (samples_y);
+ g_free (samples_x2);
+ g_free (samples_y2);
+ gegl_path_thaw (path);
+
+ return 0;
+}
+
static gint set_state (gint argc, char **argv)
{
if (argv[1]==NULL)
@@ -1258,12 +1335,10 @@
GdkEventButton *event,
gpointer dataa)
{
-
tools.in_drag = FALSE;
return FALSE;
}
-
static gboolean
stroke_motion_notify_event (GtkWidget *widget,
GdkEventMotion *event,
@@ -1398,6 +1473,7 @@
menu_add ("+", G_CALLBACK (do_command), "insert-node");
menu_add ("â", G_CALLBACK (do_command), "remove-node");
menu_add ("â", G_CALLBACK (do_command), "set-state edit-width");
+ menu_add ("S", G_CALLBACK (do_command), "path-smoothen");
menu_add ("â", G_CALLBACK (do_command), "set-state move");
break;
case STATE_STROKES:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]