1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
5
* Copyright (C) 2005 Bill Skaggs <weskaggs@primate.ucdavis.edu>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
#include <glib-object.h>
26
#include "vectors-types.h"
28
#include "libgimpmath/gimpmath.h"
30
#include "core/gimp-utils.h"
31
#include "core/gimpcoords.h"
33
#include "gimpanchor.h"
34
#include "gimpstroke.h"
35
#include "gimpvectors.h"
36
#include "gimpvectors-warp.h"
43
static void gimp_stroke_warp_point (const GimpStroke *stroke,
46
GimpCoords *point_warped,
49
static void gimp_vectors_warp_stroke (const GimpVectors *vectors,
55
gimp_vectors_warp_point (const GimpVectors *vectors,
57
GimpCoords *point_warped,
66
for (list = vectors->strokes; list; list = g_list_next (list))
70
len = gimp_vectors_stroke_get_length (vectors, stroke);
85
gimp_stroke_warp_point (stroke, x, y, point_warped, y_offset);
89
gimp_stroke_warp_point (const GimpStroke *stroke,
92
GimpCoords *point_warped,
95
GimpCoords *point_zero;
96
GimpCoords *point_minus;
97
GimpCoords *point_plus;
99
gdouble dx, dy, nx, ny, len;
101
point_zero = (GimpCoords*) g_new0 (GimpCoords, 1);
102
point_minus = (GimpCoords*) g_new0 (GimpCoords, 1);
103
point_plus = (GimpCoords*) g_new0 (GimpCoords, 1);
105
if (! gimp_stroke_get_point_at_dist (stroke, x, EPSILON, point_zero, &slope))
112
point_warped->x = point_zero->x;
113
point_warped->y = point_zero->y;
115
if (! gimp_stroke_get_point_at_dist (stroke, x - DX, EPSILON, point_minus, &slope))
118
if (! gimp_stroke_get_point_at_dist (stroke, x + DX, EPSILON, point_plus, &slope))
121
dx = point_plus->x - point_minus->x;
122
dy = point_plus->y - point_minus->y;
124
len = hypot (dx, dy);
132
point_warped->x = point_zero->x + nx * (y - y_offset);
133
point_warped->y = point_zero->y + ny * (y - y_offset);
137
gimp_vectors_warp_stroke (const GimpVectors *vectors,
143
for (list = stroke->anchors; list; list = g_list_next (list))
145
GimpAnchor *anchor = list->data;
147
gimp_vectors_warp_point (vectors,
148
&anchor->position, &anchor->position,
154
gimp_vectors_warp_vectors (const GimpVectors *vectors,
155
GimpVectors *vectors_in,
160
for (list = vectors_in->strokes; list; list = g_list_next (list))
162
GimpStroke *stroke = list->data;
164
gimp_vectors_warp_stroke (vectors, stroke, y_offset);