icon.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #include <grass/display.h>
  19. static void line(double m[2][3], double x0, double y0, double x1, double y1)
  20. {
  21. double tx0 = m[0][0] * x0 + m[0][1] * y0 + m[0][2];
  22. double ty0 = m[1][0] * x0 + m[1][1] * y0 + m[1][2];
  23. double tx1 = m[0][0] * x1 + m[0][1] * y1 + m[0][2];
  24. double ty1 = m[1][0] * x1 + m[1][1] * y1 + m[1][2];
  25. D_line_abs(tx0, ty0, tx1, ty1);
  26. }
  27. /**
  28. * \brief Plot icon
  29. *
  30. * \param[in] xc,yc icon coordinates
  31. * \param[in] type icon type
  32. * \param[in] angle rotation angle [rad]
  33. * \param[in] scale scale factor
  34. *
  35. * \return 1
  36. */
  37. void D_plot_icon(double xc, double yc, int type, double angle, double scale)
  38. {
  39. static double old_a = 1e299, old_s = 0;
  40. static double sin_a, cos_a;
  41. static double m[2][3];
  42. G_debug(2, "D_plot_icon(): xc=%g, yc=%g", xc, yc);
  43. if (angle != old_a) {
  44. sin_a = sin(angle);
  45. cos_a = cos(angle);
  46. }
  47. if (angle != old_a || scale != old_s) {
  48. m[0][0] = cos_a * scale;
  49. m[0][1] = -sin_a * scale;
  50. m[1][0] = sin_a * scale;
  51. m[1][1] = cos_a * scale;
  52. }
  53. m[0][2] = xc;
  54. m[1][2] = yc;
  55. switch (type) {
  56. case G_ICON_CROSS:
  57. line(m, -0.5, 0.0, 0.5, 0.0);
  58. line(m, 0.0, -0.5, 0.0, 0.5);
  59. break;
  60. case G_ICON_BOX:
  61. line(m, -0.5, -0.5, 0.5, -0.5);
  62. line(m, 0.5, -0.5, 0.5, 0.5);
  63. line(m, 0.5, 0.5, -0.5, 0.5);
  64. line(m, -0.5, 0.5, -0.5, -0.5);
  65. break;
  66. case G_ICON_ARROW:
  67. line(m, -1, 0.5, 0, 0.0);
  68. line(m, -1, -0.5, 0, 0.0);
  69. break;
  70. }
  71. }