Skip to content

Commit ce1f5a1

Browse files
authored
grdmask: fix region '-Rg' not recognising longitudes more than 180 (#9001)
Fix #8430 Assisted-by: Claude Sonnet 4.6
1 parent 106f952 commit ce1f5a1

1 file changed

Lines changed: 15 additions & 21 deletions

File tree

src/gmt_support.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12313,21 +12313,21 @@ int gmt_get_format (struct GMT_CTRL *GMT, double interval, char *unit, char *pre
1231312313
return (ndec);
1231412314
}
1231512315

12316-
void gmt_set_inside_mode (struct GMT_CTRL *GMT, struct GMT_DATASET *D, unsigned int mode) {
12316+
void gmt_set_inside_mode(struct GMT_CTRL *GMT, struct GMT_DATASET *D, unsigned int mode) {
1231712317
/* Determine if we use spherical or Cartesian function for in--on-out polygon tests */
1231812318
static char *method[2] = {"Cartesian", "spherical"};
1231912319
if (mode == GMT_IOO_SPHERICAL) /* Force spherical */
1232012320
GMT->current.proj.sph_inside = true;
1232112321
else if (mode == GMT_IOO_CARTESIAN) /* Force Cartesian */
1232212322
GMT->current.proj.sph_inside = false;
12323-
else if (gmt_M_is_cartesian (GMT, GMT_IN)) /* If data is Cartesian then we do that */
12323+
else if (gmt_M_is_cartesian(GMT, GMT_IN)) /* If data is Cartesian then we do that */
1232412324
GMT->current.proj.sph_inside = false;
1232512325
else if (GMT->current.map.is_world) /* Here we are dealing with geographic data that has 360 degree range */
1232612326
GMT->current.proj.sph_inside = true;
1232712327
else if (D) { /* Geographic data less than 360 degree range in longitudes */
1232812328
double lat[2];
1232912329
lat[0] = D->min[GMT_Y]; lat[1] = D->max[GMT_Y];
12330-
if (doubleAlmostEqual (lat[0], -90.0) || doubleAlmostEqual (lat[1], +90.0)) /* Goes to a pole, must do spherical */
12330+
if (doubleAlmostEqual(lat[0], -90.0) || doubleAlmostEqual(lat[1], +90.0)) /* Goes to a pole, must do spherical */
1233112331
GMT->current.proj.sph_inside = true;
1233212332
else { /* Limited in lon and lat, can do Cartesian but must ensure polygons do not jump within range */
1233312333
uint64_t tbl, seg, row;
@@ -12347,13 +12347,22 @@ void gmt_set_inside_mode (struct GMT_CTRL *GMT, struct GMT_DATASET *D, unsigned
1234712347
S = D->table[tbl]->segment[seg]; /* Shorthand */
1234812348
for (row = 0; row < S->n_rows; row++)
1234912349
gmt_lon_range_adjust (range, &S->data[GMT_X][row]);
12350+
/* Recompute segment x-range from adjusted vertices; S->min/max may be in a
12351+
* different longitude convention (e.g. 0-360 from quad_finalize) than the
12352+
* vertices just adjusted above, causing gmt_non_zero_winding to receive x
12353+
* and polygon vertices in mismatched ranges. */
12354+
S->min[GMT_X] = S->max[GMT_X] = S->data[GMT_X][0];
12355+
for (row = 1; row < S->n_rows; row++) {
12356+
if (S->data[GMT_X][row] < S->min[GMT_X]) S->min[GMT_X] = S->data[GMT_X][row];
12357+
if (S->data[GMT_X][row] > S->max[GMT_X]) S->max[GMT_X] = S->data[GMT_X][row];
12358+
}
1235012359
}
1235112360
}
1235212361
}
1235312362
}
1235412363
else
12355-
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Not enough information given to gmt_set_inside_mode.\n");
12356-
GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "A point's inside/outside status w.r.t. polygon(s) will be determined using a %s algorithm.\n", method[GMT->current.proj.sph_inside]);
12364+
GMT_Report(GMT->parent, GMT_MSG_ERROR, "Not enough information given to gmt_set_inside_mode.\n");
12365+
GMT_Report(GMT->parent, GMT_MSG_INFORMATION, "A point's inside/outside status w.r.t. polygon(s) will be determined using a %s algorithm.\n", method[GMT->current.proj.sph_inside]);
1235712366
}
1235812367

1235912368
/*! . */
@@ -13238,22 +13247,7 @@ int gmt_grd_BC_set (struct GMT_CTRL *GMT, struct GMT_GRID *G, unsigned int direc
1323813247
}
1323913248

1324013249
/* Clipper to ensure a byte stays in 0-255 range */
13241-
#if 1
13242-
GMT_LOCAL inline unsigned char gmtsupport_clip_to_byte (int byte) { if (byte < 0) return (0); else if (byte > 255) return (255); else return ((unsigned char)byte);}
13243-
#else
13244-
/* For debugging BC actions for images when the result is outside byte range */
13245-
GMT_LOCAL unsigned char gmtsupport_clip_to_byte (int byte) {
13246-
if (byte < 0) {
13247-
fprintf (stderr, "byte = %d\n", byte);
13248-
return (0);
13249-
}
13250-
if (byte > 255) {
13251-
fprintf (stderr, "byte = %d\n", byte);
13252-
return (255);
13253-
}
13254-
return ((unsigned char)byte);
13255-
}
13256-
#endif
13250+
GMT_LOCAL inline unsigned char gmtsupport_clip_to_byte(int byte) { if (byte < 0) return (0); else if (byte > 255) return (255); else return ((unsigned char)byte);}
1325713251

1325813252
/*! . */
1325913253
int gmtlib_image_BC_set (struct GMT_CTRL *GMT, struct GMT_IMAGE *I) {

0 commit comments

Comments
 (0)