| 2078 | } |
| 2079 | |
| 2080 | GMT_LOCAL void gmtplot_map_gridcross (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, double e, double s, double n) { |
| 2081 | unsigned int i, j, k, nx, ny, item[2] = {GMT_GRID_UPPER, GMT_GRID_LOWER}; |
| 2082 | double x0, y0, xa, xb, ya, yb, xi, yj, *x = NULL, *y = NULL; |
| 2083 | double angle, Ca, Sa, L, dx, dy; |
| 2084 | struct GMT_PLOT_AXIS *A[2] = {NULL, NULL}; |
| 2085 | |
| 2086 | for (k = i = 0; k < 2; k++) |
| 2087 | if (GMT->current.setting.map_grid_cross_size[k] > 0.0 && GMT->current.setting.map_grid_cross_type[k] == GMT_CROSS_NORMAL) i++; |
| 2088 | |
| 2089 | if (i == 0) return; /* No grid crosses requested */ |
| 2090 | |
| 2091 | gmt_map_clip_on (GMT, GMT->session.no_rgb, 3); |
| 2092 | |
| 2093 | for (k = 0; k < 2; k++) { |
| 2094 | if (gmt_M_is_zero (GMT->current.setting.map_grid_cross_size[k])) continue; |
| 2095 | |
| 2096 | PSL_comment (PSL, "%s\n", k ? "Map gridcrosses (secondary)" : "Map gridcrosses (primary)"); |
| 2097 | |
| 2098 | gmt_setpen (GMT, &GMT->current.setting.map_grid_pen[k]); |
| 2099 | |
| 2100 | A[GMT_X] = &GMT->current.map.frame.axis[GMT_X]; /* Short-hand for x-axis */ |
| 2101 | A[GMT_Y] = &GMT->current.map.frame.axis[GMT_Y]; /* Short-hand for y-axis */ |
| 2102 | nx = gmtlib_coordinate_array (GMT, w, e, &A[GMT_X]->item[item[k]], &x, NULL); |
| 2103 | ny = gmtlib_coordinate_array (GMT, s, n, &A[GMT_Y]->item[item[k]], &y, NULL); |
| 2104 | dy = (ny > 1) ? y[1] - y[0] : GMT->current.map.dlat; |
| 2105 | dx = (nx > 1) ? x[1] - x[0] : GMT->current.map.dlon; |
| 2106 | |
| 2107 | L = 0.5 * GMT->current.setting.map_grid_cross_size[k]; |
| 2108 | |
| 2109 | for (j = 0; j < ny; j++) { |
| 2110 | yj = y[j]; |
| 2111 | for (i = 0; i < nx; i++) { |
| 2112 | if (gmt_M_pole_is_point(GMT) && doubleAlmostEqual (fabs (yj), 90.0)) { /* Only place one grid cross at the poles for maps where the poles are points */ |
| 2113 | xi = GMT->current.proj.central_meridian; |
| 2114 | i = nx; /* This ends the loop for this particular latitude */ |
| 2115 | } |
| 2116 | else |
| 2117 | xi = x[i]; |
| 2118 | |
| 2119 | if (gmt_map_outside (GMT, xi, yj)) continue; /* Outside map */ |
| 2120 | |
| 2121 | gmt_geo_to_xy (GMT, xi, yj, &x0, &y0); /* Grid crossing center */ |
| 2122 | angle = gmtplot_cross_angle (GMT, xi, yj, dx, dy, GMT_X); |
| 2123 | sincos (angle, &Sa, &Ca); |
| 2124 | xa = x0 - L * Ca; |
| 2125 | xb = x0 + L * Ca; |
| 2126 | ya = y0 - L * Sa; |
| 2127 | yb = y0 + L * Sa; |
| 2128 | PSL_plotsegment (PSL, xa, ya, xb, yb); |
| 2129 | |
| 2130 | angle += M_PI_2; /* Since crosses are orthogonal */ |
| 2131 | sincos (angle, &Sa, &Ca); |
| 2132 | xa = x0 - L * Ca; |
| 2133 | xb = x0 + L * Ca; |
| 2134 | ya = y0 - L * Sa; |
| 2135 | yb = y0 + L * Sa; |
| 2136 | PSL_plotsegment (PSL, xa, ya, xb, yb); |
| 2137 | } |
no test coverage detected