home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / sel2path / vector.h < prev   
Encoding:
C/C++ Source or Header  |  2000-07-30  |  3.5 KB  |  96 lines

  1. /* vector.h: operations on vectors and points.
  2.  
  3. Copyright (C) 1992 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #ifndef VECTOR_H
  20. #define VECTOR_H
  21.  
  22. #include "types.h"
  23.  
  24. /* Our vectors are represented as displacements along the x and y axes.  */
  25.  
  26. typedef struct
  27. {
  28.   real dx, dy;
  29. } vector_type;
  30.  
  31.  
  32. /* Consider a point as a vector from the origin.  */
  33. extern vector_type make_vector (const real_coordinate_type);
  34.  
  35. /* And a vector as a point, i.e., a displacement from the origin.  */
  36. extern real_coordinate_type vector_to_point (const vector_type);
  37.  
  38.  
  39. /* Definitions for these common operations can be found in any decent
  40.    linear algebra book, and most calculus books.  */
  41.  
  42. extern real magnitude (const vector_type);
  43. extern vector_type normalize (const vector_type);
  44.  
  45. extern vector_type Vadd (const vector_type, const vector_type);
  46. extern real Vdot (const vector_type, const vector_type);
  47. extern vector_type Vmult_scalar (const vector_type, const real);
  48. extern real Vangle (const vector_type in, const vector_type out);
  49.  
  50. /* These operations could have been named `P..._vector' just as well as
  51.    V..._point, so we may as well allow both names.  */
  52. #define Padd_vector Vadd_point
  53. extern real_coordinate_type Vadd_point
  54.   (const real_coordinate_type, const vector_type);
  55.  
  56. #define Psubtract_vector Vsubtract_point
  57. extern real_coordinate_type Vsubtract_point
  58.   (const real_coordinate_type, const vector_type);
  59.  
  60. /* This returns the rounded sum.  */
  61. #define IPadd_vector Vadd_int_point
  62. extern coordinate_type Vadd_int_point
  63.   (const coordinate_type, const vector_type);
  64.  
  65. /* Take the absolute value of both components.  */
  66. extern vector_type Vabs (const vector_type);
  67.  
  68.  
  69. /* Operations on points with real coordinates.  It is not orthogonal,
  70.    but more convenient, to have the subtraction operator return a
  71.    vector, and the addition operator return a point.  */
  72. extern vector_type Psubtract
  73.   (const real_coordinate_type, const real_coordinate_type);
  74.  
  75. /* These are heavily used in spline fitting, so we define them as macros
  76.    instead of functions.  */
  77. #define Padd(rc1, rc2)                            \
  78.   ((real_coordinate_type) { (rc1).x + (rc2).x, (rc1).y + (rc2).y })
  79. #define Pmult_scalar(rc, r)                        \
  80.   ((real_coordinate_type) { (rc).x * (r), (rc).y * (r) })
  81.  
  82. /* Similarly, for points with integer coordinates; here, a subtraction
  83.    operator that does return another point is useful.  */
  84. extern vector_type IPsubtract
  85.   (const coordinate_type, const coordinate_type);
  86. extern coordinate_type IPsubtractP
  87.   (const coordinate_type, const coordinate_type);
  88. extern coordinate_type IPadd
  89.   (const coordinate_type, const coordinate_type);
  90. extern coordinate_type IPmult_scalar (const coordinate_type, const int);
  91. extern real_coordinate_type IPmult_real
  92.   (const coordinate_type, const real);
  93. extern boolean IPequal (const coordinate_type, const coordinate_type);
  94.  
  95. #endif /* not VECTOR_H */
  96.