icon.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * \file icon.c
  3. *
  4. * \brief GIS Library - Plot icon
  5. *
  6. * (C) 2001-2008 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public License
  9. * (>=v2). Read the file COPYING that comes with GRASS for details.
  10. *
  11. * \author GRASS GIS Development Team
  12. *
  13. * \date 1999-2008
  14. */
  15. #include <stdlib.h>
  16. #include <math.h>
  17. #include <grass/gis.h>
  18. static void trans(double *x, double *y, int n_points,
  19. double angle, double scale, double xc, double yc)
  20. {
  21. double m[2][2];
  22. double sin_a = sin(angle);
  23. double cos_a = cos(angle);
  24. int i;
  25. m[0][0] = cos_a * scale;
  26. m[0][1] = -sin_a * scale;
  27. m[1][0] = sin_a * scale;
  28. m[1][1] = cos_a * scale;
  29. for (i = 0; i < n_points; i++) {
  30. double xi = x[i];
  31. double yi = y[i];
  32. x[i] = m[0][0] * xi + m[0][1] * yi + xc;
  33. y[i] = m[1][0] * xi + m[1][1] * yi + yc;
  34. }
  35. }
  36. /**
  37. * \brief Plot icon
  38. *
  39. * \param[in] xc,yc icon coordinates
  40. * \param[in] type icon type
  41. * \param[in] angle rotation angle [rad]
  42. * \param[in] scale scale factor
  43. *
  44. * \return 1
  45. */
  46. int G_plot_icon(double xc, double yc, int type, double angle, double scale)
  47. {
  48. int i, np = 0;
  49. double x[10], y[10];
  50. G_debug(2, "G_plot_icon(): xc=%g, yc=%g", xc, yc);
  51. /* diamond, box */
  52. switch (type) {
  53. case G_ICON_CROSS:
  54. x[0] = -0.5;
  55. y[0] = 0.0;
  56. x[1] = 0.5;
  57. y[1] = 0.0;
  58. x[2] = 0.0;
  59. y[2] = -0.5;
  60. x[3] = 0.0;
  61. y[3] = 0.5;
  62. np = 4;
  63. break;
  64. case G_ICON_BOX:
  65. G_debug(1, "box");
  66. x[0] = -0.5;
  67. y[0] = -0.5;
  68. x[1] = 0.5;
  69. y[1] = -0.5;
  70. x[2] = 0.5;
  71. y[2] = -0.5;
  72. x[3] = 0.5;
  73. y[3] = 0.5;
  74. x[4] = 0.5;
  75. y[4] = 0.5;
  76. x[5] = -0.5;
  77. y[5] = 0.5;
  78. x[6] = -0.5;
  79. y[6] = 0.5;
  80. x[7] = -0.5;
  81. y[7] = -0.5;
  82. np = 8;
  83. break;
  84. case G_ICON_ARROW:
  85. x[0] = -1;
  86. y[0] = 0.5;
  87. x[1] = 0;
  88. y[1] = 0.0;
  89. x[2] = -1;
  90. y[2] = -0.5;
  91. x[3] = 0;
  92. y[3] = 0.0;
  93. np = 4;
  94. break;
  95. }
  96. trans(x, y, np, angle, scale, xc, yc);
  97. for (i = 0; i < np; i += 2)
  98. G_plot_line(x[i], y[i], x[i + 1], y[i + 1]);
  99. return (1);
  100. }