icon.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*!
  2. \file lib/display/icon.c
  3. \brief Display Library - Plot icon
  4. (C) 2001-2008, 2012 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author USA-CERL
  8. */
  9. #include <stdlib.h>
  10. #include <math.h>
  11. #include <grass/gis.h>
  12. #include <grass/display.h>
  13. #include <grass/glocale.h>
  14. static void line(double m[2][3], double x0, double y0, double x1, double y1)
  15. {
  16. double tx0 = m[0][0] * x0 + m[0][1] * y0 + m[0][2];
  17. double ty0 = m[1][0] * x0 + m[1][1] * y0 + m[1][2];
  18. double tx1 = m[0][0] * x1 + m[0][1] * y1 + m[0][2];
  19. double ty1 = m[1][0] * x1 + m[1][1] * y1 + m[1][2];
  20. D_line_abs(tx0, ty0, tx1, ty1);
  21. }
  22. /*!
  23. \brief Plot icon
  24. Supported types:
  25. - G_ICON_CROSS
  26. - G_ICON_BOX
  27. - G_ICON_ARROW
  28. \param xc,yc icon coordinates
  29. \param type icon type
  30. \param angle rotation angle [rad]
  31. \param scale scale factor
  32. */
  33. void D_plot_icon(double xc, double yc, int type, double angle, double scale)
  34. {
  35. static double old_a = 1e299, old_s = 0;
  36. static double sin_a, cos_a;
  37. static double m[2][3];
  38. G_debug(2, "D_plot_icon(): xc=%g, yc=%g", xc, yc);
  39. if (angle != old_a) {
  40. sin_a = sin(angle);
  41. cos_a = cos(angle);
  42. }
  43. if (angle != old_a || scale != old_s) {
  44. m[0][0] = cos_a * scale;
  45. m[0][1] = -sin_a * scale;
  46. m[1][0] = sin_a * scale;
  47. m[1][1] = cos_a * scale;
  48. }
  49. m[0][2] = xc;
  50. m[1][2] = yc;
  51. switch (type) {
  52. case G_ICON_CROSS:
  53. line(m, -0.5, 0.0, 0.5, 0.0);
  54. line(m, 0.0, -0.5, 0.0, 0.5);
  55. break;
  56. case G_ICON_BOX:
  57. line(m, -0.5, -0.5, 0.5, -0.5);
  58. line(m, 0.5, -0.5, 0.5, 0.5);
  59. line(m, 0.5, 0.5, -0.5, 0.5);
  60. line(m, -0.5, 0.5, -0.5, -0.5);
  61. break;
  62. case G_ICON_ARROW:
  63. line(m, -1, 0.5, 0, 0.0);
  64. line(m, -1, -0.5, 0, 0.0);
  65. break;
  66. default:
  67. G_warning(_("Unsupported icon %d"), type);
  68. break;
  69. }
  70. }