GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
icon.c
Go to the documentation of this file.
1 /*!
2  \file lib/display/icon.c
3 
4  \brief Display Library - Plot icon
5 
6  (C) 2001-2008, 2012 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 USA-CERL
12 */
13 
14 #include <stdlib.h>
15 #include <math.h>
16 #include <grass/gis.h>
17 #include <grass/display.h>
18 #include <grass/glocale.h>
19 
20 static void line(double m[2][3], double x0, double y0, double x1, double y1)
21 {
22  double tx0 = m[0][0] * x0 + m[0][1] * y0 + m[0][2];
23  double ty0 = m[1][0] * x0 + m[1][1] * y0 + m[1][2];
24  double tx1 = m[0][0] * x1 + m[0][1] * y1 + m[0][2];
25  double ty1 = m[1][0] * x1 + m[1][1] * y1 + m[1][2];
26 
27  D_line_abs(tx0, ty0, tx1, ty1);
28 }
29 
30 /*!
31  \brief Plot icon
32 
33  Supported types:
34  - G_ICON_CROSS
35  - G_ICON_BOX
36  - G_ICON_ARROW
37 
38  \param xc,yc icon coordinates
39  \param type icon type
40  \param angle rotation angle [rad]
41  \param scale scale factor
42  */
43 void D_plot_icon(double xc, double yc, int type, double angle, double scale)
44 {
45  static double old_a = 1e299, old_s = 0;
46  static double sin_a, cos_a;
47  static double m[2][3];
48 
49  G_debug(2, "D_plot_icon(): xc=%g, yc=%g", xc, yc);
50 
51  if (angle != old_a) {
52  sin_a = sin(angle);
53  cos_a = cos(angle);
54  }
55  if (angle != old_a || scale != old_s) {
56  m[0][0] = cos_a * scale;
57  m[0][1] = -sin_a * scale;
58  m[1][0] = sin_a * scale;
59  m[1][1] = cos_a * scale;
60  }
61  m[0][2] = xc;
62  m[1][2] = yc;
63 
64  switch (type) {
65  case G_ICON_CROSS:
66  line(m, -0.5, 0.0, 0.5, 0.0);
67  line(m, 0.0, -0.5, 0.0, 0.5);
68  break;
69  case G_ICON_BOX:
70  line(m, -0.5, -0.5, 0.5, -0.5);
71  line(m, 0.5, -0.5, 0.5, 0.5);
72  line(m, 0.5, 0.5, -0.5, 0.5);
73  line(m, -0.5, 0.5, -0.5, -0.5);
74  break;
75  case G_ICON_ARROW:
76  line(m, -1, 0.5, 0, 0.0);
77  line(m, -1, -0.5, 0, 0.0);
78  break;
79  default:
80  G_warning(_("Unsupported icon %d"), type);
81  break;
82  }
83 }
#define G_ICON_CROSS
Definition: gis.h:376
#define G_ICON_BOX
Definition: gis.h:377
void D_line_abs(double, double, double, double)
Definition: draw2.c:399
void G_warning(const char *,...) __attribute__((format(printf
#define _(str)
Definition: glocale.h:10
void D_plot_icon(double xc, double yc, int type, double angle, double scale)
Plot icon.
Definition: icon.c:43
#define G_ICON_ARROW
Definition: gis.h:378
int G_debug(int, const char *,...) __attribute__((format(printf