GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
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 SPDX-FileCopyrightText: 2001-2008, 2012 GRASS Development Team
7 SPDX-License-Identifier: GPL-2.0-or-later
8
9 \author USA-CERL
10*/
11
12#include <stdlib.h>
13#include <math.h>
14#include <grass/gis.h>
15#include <grass/display.h>
16#include <grass/glocale.h>
17
18static void line(double m[2][3], double x0, double y0, double x1, double y1)
19{
20 double tx0 = m[0][0] * x0 + m[0][1] * y0 + m[0][2];
21 double ty0 = m[1][0] * x0 + m[1][1] * y0 + m[1][2];
22 double tx1 = m[0][0] * x1 + m[0][1] * y1 + m[0][2];
23 double ty1 = m[1][0] * x1 + m[1][1] * y1 + m[1][2];
24
26}
27
28/*!
29 \brief Plot icon
30
31 Supported types:
32 - G_ICON_CROSS
33 - G_ICON_BOX
34 - G_ICON_ARROW
35
36 \param xc,yc icon coordinates
37 \param type icon type
38 \param angle rotation angle [rad]
39 \param scale scale factor
40 */
41void D_plot_icon(double xc, double yc, int type, double angle, double scale)
42{
43 static double old_a = 1e299, old_s = 0;
44 static double sin_a, cos_a;
45 static double m[2][3];
46
47 G_debug(2, "D_plot_icon(): xc=%g, yc=%g", xc, yc);
48
49 if (angle != old_a) {
50 sin_a = sin(angle);
51 cos_a = cos(angle);
52 }
53 if (angle != old_a || scale != old_s) {
54 m[0][0] = cos_a * scale;
55 m[0][1] = -sin_a * scale;
56 m[1][0] = sin_a * scale;
57 m[1][1] = cos_a * scale;
58 }
59 m[0][2] = xc;
60 m[1][2] = yc;
61
62 switch (type) {
63 case G_ICON_CROSS:
64 line(m, -0.5, 0.0, 0.5, 0.0);
65 line(m, 0.0, -0.5, 0.0, 0.5);
66 break;
67 case G_ICON_BOX:
68 line(m, -0.5, -0.5, 0.5, -0.5);
69 line(m, 0.5, -0.5, 0.5, 0.5);
70 line(m, 0.5, 0.5, -0.5, 0.5);
71 line(m, -0.5, 0.5, -0.5, -0.5);
72 break;
73 case G_ICON_ARROW:
74 line(m, -1, 0.5, 0, 0.0);
75 line(m, -1, -0.5, 0, 0.0);
76 break;
77 default:
78 G_warning(_("Unsupported icon %d"), type);
79 break;
80 }
81}
void D_line_abs(double, double, double, double)
Definition draw2.c:400
void G_warning(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
#define G_ICON_CROSS
Definition gis.h:397
#define G_ICON_BOX
Definition gis.h:398
#define G_ICON_ARROW
Definition gis.h:399
#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:41