~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/vectors/gimpvectors-warp.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * gimpvectors-warp.c
 
5
 * Copyright (C) 2005 Bill Skaggs  <weskaggs@primate.ucdavis.edu>
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <glib-object.h>
 
25
 
 
26
#include "vectors-types.h"
 
27
 
 
28
#include "libgimpmath/gimpmath.h"
 
29
 
 
30
#include "core/gimp-utils.h"
 
31
#include "core/gimpcoords.h"
 
32
 
 
33
#include "gimpanchor.h"
 
34
#include "gimpstroke.h"
 
35
#include "gimpvectors.h"
 
36
#include "gimpvectors-warp.h"
 
37
 
 
38
 
 
39
#define EPSILON 0.2
 
40
#define DX      2.0
 
41
 
 
42
 
 
43
static void gimp_stroke_warp_point   (const GimpStroke  *stroke,
 
44
                                      gdouble            x,
 
45
                                      gdouble            y,
 
46
                                      GimpCoords        *point_warped,
 
47
                                      gdouble            y_offset);
 
48
 
 
49
static void gimp_vectors_warp_stroke (const GimpVectors *vectors,
 
50
                                      GimpStroke        *stroke,
 
51
                                      gdouble            y_offset);
 
52
 
 
53
 
 
54
void
 
55
gimp_vectors_warp_point (const GimpVectors *vectors,
 
56
                         GimpCoords        *point,
 
57
                         GimpCoords        *point_warped,
 
58
                         gdouble            y_offset)
 
59
{
 
60
  gdouble     x      = point->x;
 
61
  gdouble     y      = point->y;
 
62
  gdouble     len;
 
63
  GList      *list;
 
64
  GimpStroke *stroke;
 
65
 
 
66
  for (list = vectors->strokes; list; list = g_list_next (list))
 
67
    {
 
68
      stroke = list->data;
 
69
 
 
70
      len = gimp_vectors_stroke_get_length (vectors, stroke);
 
71
 
 
72
      if (x < len)
 
73
        break;
 
74
 
 
75
      x -= len;
 
76
    }
 
77
 
 
78
  if (! list)
 
79
    {
 
80
      point_warped->x = 0;
 
81
      point_warped->y = 0;
 
82
      return;
 
83
    }
 
84
 
 
85
  gimp_stroke_warp_point (stroke, x, y, point_warped, y_offset);
 
86
}
 
87
 
 
88
static void
 
89
gimp_stroke_warp_point (const GimpStroke *stroke,
 
90
                        gdouble           x,
 
91
                        gdouble           y,
 
92
                        GimpCoords       *point_warped,
 
93
                        gdouble           y_offset)
 
94
{
 
95
  GimpCoords *point_zero;
 
96
  GimpCoords *point_minus;
 
97
  GimpCoords *point_plus;
 
98
  gdouble     slope;
 
99
  gdouble     dx, dy, nx, ny, len;
 
100
 
 
101
  point_zero  = (GimpCoords*) g_new0 (GimpCoords, 1);
 
102
  point_minus = (GimpCoords*) g_new0 (GimpCoords, 1);
 
103
  point_plus  = (GimpCoords*) g_new0 (GimpCoords, 1);
 
104
 
 
105
  if (! gimp_stroke_get_point_at_dist (stroke, x, EPSILON, point_zero,  &slope))
 
106
    {
 
107
      point_warped->x = 0;
 
108
      point_warped->y = 0;
 
109
      return;
 
110
    }
 
111
 
 
112
  point_warped->x = point_zero->x;
 
113
  point_warped->y = point_zero->y;
 
114
 
 
115
  if (!  gimp_stroke_get_point_at_dist (stroke, x - DX, EPSILON, point_minus, &slope))
 
116
    return;
 
117
 
 
118
  if (! gimp_stroke_get_point_at_dist (stroke, x + DX, EPSILON, point_plus,  &slope))
 
119
    return;
 
120
 
 
121
  dx = point_plus->x - point_minus->x;
 
122
  dy = point_plus->y - point_minus->y;
 
123
 
 
124
  len = hypot (dx, dy);
 
125
 
 
126
  if (len < 0.01)
 
127
    return;
 
128
 
 
129
  nx = - dy / len;
 
130
  ny =   dx / len;
 
131
 
 
132
  point_warped->x = point_zero->x + nx * (y - y_offset);
 
133
  point_warped->y = point_zero->y + ny * (y - y_offset);
 
134
}
 
135
 
 
136
static void
 
137
gimp_vectors_warp_stroke (const GimpVectors *vectors,
 
138
                          GimpStroke        *stroke,
 
139
                          gdouble            y_offset)
 
140
{
 
141
  GList *list;
 
142
 
 
143
  for (list = stroke->anchors; list; list = g_list_next (list))
 
144
    {
 
145
      GimpAnchor *anchor = list->data;
 
146
 
 
147
      gimp_vectors_warp_point (vectors,
 
148
                               &anchor->position, &anchor->position,
 
149
                               y_offset);
 
150
    }
 
151
}
 
152
 
 
153
void
 
154
gimp_vectors_warp_vectors (const GimpVectors *vectors,
 
155
                           GimpVectors       *vectors_in,
 
156
                           gdouble            y_offset)
 
157
{
 
158
  GList *list;
 
159
 
 
160
  for (list = vectors_in->strokes; list; list = g_list_next (list))
 
161
    {
 
162
      GimpStroke *stroke = list->data;
 
163
 
 
164
      gimp_vectors_warp_stroke (vectors, stroke, y_offset);
 
165
    }
 
166
}