* app/makefile.cygwin * app/makefile.msc * plug-ins/makefile.cygwin * plug-ins/makefile.msc * modules/makefile.cygwin * modules/makefile.msc * tools/gcg/makefile.cygwin: Various updates. GCC-compiled DLL name change. * app/context_manager.c: Include paint_options.h for prototype. * app/gimpimage.c (gimp_image_initialize_projection): Break out of loop as soon as possible. * app/menus.c (menus_last_opened_cmd_callback): Check if referring to entry not in list. * app/module_db.c (valid_module_name): (Win32) Require module DLL names to include name of compiler built with. * app/paths_dialog.c (paths_draw_segment_points): No use to draw lines if we have less that two points. * app/qmask.c: Include stdio.h and floating_sel.h. * libgimp/makefile.cygwin: New file. * libgimp/Makefile.am: Distribute above file. * libgimp/gimp.def: Update. * libgimp/gimpenv.c (gimp_directory): Don't warn about missing home directory on Win32, it is perfectly natural. * plug-ins/sel2path/global.h: Bypass unused declarations, some of which clash with functions in MSVCRT. * plug-ins/sel2path/math.c * modules/colorsel_water.c: Define M_PI if necessary. * plug-ins/sel2path/sel2path.c: Include config.h and glib.h. Define rint() if needed. * plug-ins/sel2path/vector.c: Include glib.h (for hypot() renaming on Win32; In the MS C runtime, as hypot() is non-ANSI, it's called _hypot(), sigh). * plug-ins/sinus/sinus_logo.h: Use indexed format, it is easier on some compilers than the huge string.
247 lines
4.1 KiB
C
247 lines
4.1 KiB
C
/* vector.c: vector/point operations.
|
|
|
|
Copyright (C) 1992 Free Software Foundation, Inc.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
|
|
#include <glib.h>
|
|
|
|
#include <math.h>
|
|
#include <assert.h>
|
|
|
|
#include "global.h"
|
|
#include "config.h"
|
|
|
|
#include "vector.h"
|
|
|
|
|
|
/* Given the point COORD, return the corresponding vector. */
|
|
|
|
const vector_type
|
|
make_vector (const real_coordinate_type c)
|
|
{
|
|
vector_type v;
|
|
|
|
v.dx = c.x;
|
|
v.dy = c.y;
|
|
|
|
return v;
|
|
}
|
|
|
|
|
|
/* And the converse: given a vector, return the corresponding point. */
|
|
|
|
const real_coordinate_type
|
|
vector_to_point (const vector_type v)
|
|
{
|
|
real_coordinate_type coord;
|
|
|
|
coord.x = v.dx;
|
|
coord.y = v.dy;
|
|
|
|
return coord;
|
|
}
|
|
|
|
|
|
const real
|
|
magnitude (const vector_type v)
|
|
{
|
|
return hypot (v.dx, v.dy);
|
|
}
|
|
|
|
|
|
const vector_type
|
|
normalize (const vector_type v)
|
|
{
|
|
vector_type new_v;
|
|
real m = magnitude (v);
|
|
|
|
assert (m > 0.0);
|
|
|
|
new_v.dx = v.dx / m;
|
|
new_v.dy = v.dy / m;
|
|
|
|
return new_v;
|
|
}
|
|
|
|
|
|
const vector_type
|
|
Vadd (const vector_type v1, const vector_type v2)
|
|
{
|
|
vector_type new_v;
|
|
|
|
new_v.dx = v1.dx + v2.dx;
|
|
new_v.dy = v1.dy + v2.dy;
|
|
|
|
return new_v;
|
|
}
|
|
|
|
|
|
const real
|
|
Vdot (const vector_type v1, const vector_type v2)
|
|
{
|
|
return v1.dx * v2.dx + v1.dy * v2.dy;
|
|
}
|
|
|
|
|
|
const vector_type
|
|
Vmult_scalar (const vector_type v, const real r)
|
|
{
|
|
vector_type new_v;
|
|
|
|
new_v.dx = v.dx * r;
|
|
new_v.dy = v.dy * r;
|
|
|
|
return new_v;
|
|
}
|
|
|
|
|
|
/* Given the IN_VECTOR and OUT_VECTOR, return the angle between them in
|
|
degrees, in the range zero to 180. */
|
|
|
|
const real
|
|
Vangle (const vector_type in_vector, const vector_type out_vector)
|
|
{
|
|
vector_type v1 = normalize (in_vector);
|
|
vector_type v2 = normalize (out_vector);
|
|
|
|
return acosd (Vdot (v2, v1));
|
|
}
|
|
|
|
|
|
const real_coordinate_type
|
|
Vadd_point (const real_coordinate_type c, const vector_type v)
|
|
{
|
|
real_coordinate_type new_c;
|
|
|
|
new_c.x = c.x + v.dx;
|
|
new_c.y = c.y + v.dy;
|
|
return new_c;
|
|
}
|
|
|
|
|
|
const real_coordinate_type
|
|
Vsubtract_point (const real_coordinate_type c, const vector_type v)
|
|
{
|
|
real_coordinate_type new_c;
|
|
|
|
new_c.x = c.x - v.dx;
|
|
new_c.y = c.y - v.dy;
|
|
return new_c;
|
|
}
|
|
|
|
|
|
const coordinate_type
|
|
Vadd_int_point (const coordinate_type c, const vector_type v)
|
|
{
|
|
coordinate_type a;
|
|
|
|
a.x = ROUND ((real) c.x + v.dx);
|
|
a.y = ROUND ((real) c.y + v.dy);
|
|
return a;
|
|
}
|
|
|
|
|
|
const vector_type
|
|
Vabs (const vector_type v)
|
|
{
|
|
vector_type new_v;
|
|
|
|
new_v.dx = fabs (v.dx);
|
|
new_v.dy = fabs (v.dy);
|
|
return new_v;
|
|
}
|
|
|
|
|
|
/* Operations on points. */
|
|
|
|
const vector_type
|
|
Psubtract (const real_coordinate_type c1, const real_coordinate_type c2)
|
|
{
|
|
vector_type v;
|
|
|
|
v.dx = c1.x - c2.x;
|
|
v.dy = c1.y - c2.y;
|
|
|
|
return v;
|
|
}
|
|
|
|
/* Operations on integer points. */
|
|
|
|
const vector_type
|
|
IPsubtract (const coordinate_type coord1, const coordinate_type coord2)
|
|
{
|
|
vector_type v;
|
|
|
|
v.dx = coord1.x - coord2.x;
|
|
v.dy = coord1.y - coord2.y;
|
|
|
|
return v;
|
|
}
|
|
|
|
|
|
const coordinate_type
|
|
IPsubtractP (const coordinate_type c1, const coordinate_type c2)
|
|
{
|
|
coordinate_type c;
|
|
|
|
c.x = c1.x - c2.x;
|
|
c.y = c1.y - c2.y;
|
|
|
|
return c;
|
|
}
|
|
|
|
|
|
const coordinate_type
|
|
IPadd (const coordinate_type c1, const coordinate_type c2)
|
|
{
|
|
coordinate_type c;
|
|
|
|
c.x = c1.x + c2.x;
|
|
c.y = c1.y + c2.y;
|
|
|
|
return c;
|
|
}
|
|
|
|
|
|
const coordinate_type
|
|
IPmult_scalar (const coordinate_type c, const int i)
|
|
{
|
|
coordinate_type a;
|
|
|
|
a.x = c.x * i;
|
|
a.y = c.y * i;
|
|
|
|
return a;
|
|
}
|
|
|
|
|
|
const real_coordinate_type
|
|
IPmult_real (const coordinate_type c, const real r)
|
|
{
|
|
real_coordinate_type a;
|
|
|
|
a.x = c.x * r;
|
|
a.y = c.y * r;
|
|
|
|
return a;
|
|
}
|
|
|
|
|
|
const boolean
|
|
IPequal (const coordinate_type c1, const coordinate_type c2)
|
|
{
|
|
return c1.x == c2.x && c1.y == c2.y;
|
|
}
|