MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / gmtplot_draw_dir_rose

Function gmtplot_draw_dir_rose

src/gmt_plot.c:3584–3755  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3582#define ROSE_OFFSET_SCL 0.4 /* Set label offset to 40% of font size */
3583
3584GMT_LOCAL void gmtplot_draw_dir_rose (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, struct GMT_MAP_ROSE *mr) {
3585 bool adjust = (GMT->current.setting.map_embellishment_mode); /* A bit shorter to use */
3586 unsigned int i, kind, form, just[4] = {PSL_TC, PSL_ML, PSL_BC, PSL_MR};
3587 int k;
3588 double angle, title_size, txt_offset, L[4], R[4], x[PSL_MAX_DIMS], y[PSL_MAX_DIMS], xp[PSL_MAX_DIMS], yp[PSL_MAX_DIMS], tx[3], ty[3];
3589 double lon, lat, s, c, rot[4] = {0.0, 45.0, 22.5, -22.5};
3590 struct GMT_FILL f;
3591
3592 /* Set default font size in modern mode based on rose size - or honor setting in classic mode */
3593 title_size = (adjust) ? ROSE_LABEL_SCL * mr->size * 72.0 : GMT->current.setting.font_title.size;
3594
3595 /* Initialize fill structure */
3596 gmt_init_fill (GMT, &f, GMT->current.setting.color_patch[GMT_BGD][0], GMT->current.setting.color_patch[GMT_BGD][1], GMT->current.setting.color_patch[GMT_BGD][2]);
3597
3598 gmt_xy_to_geo (GMT, &lon, &lat, mr->refpoint->x, mr->refpoint->y);
3599 angle = gmt_azim_to_angle (GMT, lon, lat, DIST_TO_2ND_POINT, 90.0); /* Get angle of E-W direction at this location */
3600
3601#if 0
3602 /* This section can be activated if we need to test for angles of directional roses.
3603 * Then, use export GMT_FAKE_ANGLE=value to change the orientation of the rose. */
3604#ifdef DEBUG
3605 {
3606 char *this_c = NULL;
3607 if ((this_c = getenv ("GMT_FAKE_ANGLE")) != NULL)
3608 angle = atof (this_c);
3609 }
3610#endif
3611#endif
3612
3613 if (angle < 0.0) angle += 360.0; if (angle >= 360.0) angle -= 360.0;
3614 gmt_setpen (GMT, &GMT->current.setting.map_tick_pen[GMT_PRIMARY]);
3615
3616 PSL_command (PSL, "V\n"); /* Place the rose under gsave/grestore */
3617
3618 if (mr->type == GMT_ROSE_DIR_FANCY) { /* Fancy scale */
3619 PSL_comment (PSL, "Draw fancy directional rose of level %d\n", mr->kind);
3620 /* Set default offset size in modern mode based on rose size - or honor setting in classic mode */
3621 txt_offset = (adjust) ? ROSE_OFFSET_SCL * title_size / 72.0 : GMT->current.setting.map_title_offset;
3622 if (mr->do_label) { /* Need to determine the shift in (x,y) due to the dimensions of label and offset */
3623 int hh = mr->justify % 4 - 2, vv = mr->justify / 4 - 1; /* Horizontal and vertical shift indicators */
3624 char *T_label = NULL;
3625 if (hh) { /* We need horizontal adjustments. Do label offset here and adjust for text size in PSL */
3626 T_label = (hh == -1) ? mr->label[3] : mr->label[1]; /* Get the W or E text label */
3627 if (T_label[0]) { /* Get width of label and use it to shift origin left or right */
3628 mr->refpoint->x -= hh * txt_offset; /* Any horizontal shifts we know exactly */
3629 PSL_deftextdim (PSL, "-w", title_size, T_label); /* Get label width and place on PSL stack */
3630 PSL_command (PSL, "%d mul 0 T\n", -hh); /* Multiply by +1 or -1 and transform x-origin by that amount */
3631 }
3632 }
3633 if (vv) { /* We need vertical adjustments. Do label offset here and adjust for text size in PSL */
3634 T_label = (vv == -1) ? mr->label[0] : mr->label[2]; /* Get the S or N text label */
3635 if (T_label[0]) { /* Get height of string and use it to shift origin up or down */
3636 mr->refpoint->y -= vv * txt_offset; /* Any horizontal shifts we know exactly */
3637 PSL_deftextdim (PSL, "-H", title_size, T_label); /* Get label height and place on PSL stack */
3638 PSL_command (PSL, "%d mul 0 exch T\n", -vv); /* Multiply by +1 or -1 and transform y-origin by that amount */
3639 }
3640 }
3641 }

Callers 1

gmt_draw_map_roseFunction · 0.85

Calls 15

gmt_init_fillFunction · 0.85
gmt_xy_to_geoFunction · 0.85
gmt_azim_to_angleFunction · 0.85
gmt_setpenFunction · 0.85
PSL_commandFunction · 0.85
PSL_commentFunction · 0.85
PSL_deftextdimFunction · 0.85
gmtlib_rotate2DFunction · 0.85
PSL_setfillFunction · 0.85
PSL_plotpolygonFunction · 0.85
gmt_setfontFunction · 0.85
PSL_plottextFunction · 0.85

Tested by

no test coverage detected