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

Function gmt_rectangle_dimension

src/gmt_support.c:19341–19391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19339 * If +w<arg> was not given then if the def_percent_w/h are set we pass that out via R->scl. */
19340
19341unsigned int gmt_rectangle_dimension (struct GMT_CTRL *GMT, struct GMT_SCALED_RECT_DIM *R, double def_percent_w, double def_percent_h, char *string) {
19342 int n;
19343 unsigned int n_percent;
19344
19345 if (string == NULL || string[0] == '\0') { /* Set default scales if given */
19346 R->scl[GMT_X] = 0.01 * def_percent_w;
19347 R->scl[GMT_Y] = 0.01 * def_percent_h;
19348 return (GMT_NOERROR);
19349 }
19350 if ((n = gmt_get_pair (GMT, string, GMT_PAIR_DIM_NODUP, R->dim)) == 0)
19351 return (GMT_RUNTIME_ERROR);
19352 n_percent = gmt_count_char (GMT, string, '%');
19353
19354 if (n_percent) { /* Gave at least one dimension as percent of plot dimension */
19355 char *p = strchr (string, '%'), *slash = strchr (string, '/'); /* Find position of % and / */
19356 gmt_strrepc (string, '%', ' '); /* Replace any % with spaces */
19357 if (n == 2) { /* Got width/height: Check if we got 1 or 2 percentage(s) */
19358 slash[0] = ' '; /* Replace / with space as well */
19359 if (n_percent == 2) { /* Both length and width given as percentages of plot dimensions */
19360 R->fraction[GMT_X] = R->fraction[GMT_Y] = true;
19361 sscanf (string, "%lf %lf", &R->scl[GMT_X], &R->scl[GMT_Y]);
19362 R->scl[GMT_X] *= 0.01; R->scl[GMT_Y] *= 0.01; /* Convert percent to fraction */
19363 gmt_M_memset (R->dim, 2U, double); /* Wipe back to zero sine still unknown */
19364 }
19365 else { /* Got one percent and one fixed dimension */
19366 if (p < slash) { /* Gave width as percentage of plot width */
19367 R->fraction[GMT_X] = true;
19368 sscanf (string, "%lf %*s", &R->scl[GMT_X]);
19369 R->scl[GMT_X] *= 0.01; /* Convert to fraction */
19370 R->dim[GMT_X] = 0.0; /* Wipe back to zero (height was set by gmt_get_pair) */
19371 }
19372 else { /* Gave height as percentage of plot height */
19373 R->fraction[GMT_Y] = true;
19374 sscanf (string, "%*s %lf", &R->scl[GMT_Y]);
19375 R->scl[GMT_Y] *= 0.01; /* Convert to fraction */
19376 R->dim[GMT_Y] = R->dim[GMT_X] * R->scl[GMT_Y]; /* Wipe back to zero (width was set by gmt_get_pair) */
19377 }
19378 }
19379 }
19380 else { /* Only gave width in percentage */
19381 R->fraction[GMT_X] = true;
19382 R->scl[GMT_X] = atof (string) * 0.01; /* Convert to fraction */
19383 R->dim[GMT_X] = 0.0; /* Wipe back to zero */
19384 }
19385 } /* No percentages, got 1 or 2 dimensions */
19386 else { /* If n == 2 then we got both fixed dimensions */
19387 if (n == 1 && fabs (R->dim[GMT_X]) > 0.0) /* Set height as <def_percent_h>% of width */
19388 R->dim[GMT_Y] = R->scl[GMT_Y] * fabs (R->dim[GMT_X]);
19389 }
19390 return (GMT_NOERROR);
19391}
19392
19393/* Helper functions to handle the parsing of option and modifier arguments that are required.
19394 * If argument is missing then that is an error, otherwise we parse and return */

Callers 2

parseFunction · 0.85
parseFunction · 0.85

Calls 3

gmt_get_pairFunction · 0.85
gmt_count_charFunction · 0.85
gmt_strrepcFunction · 0.85

Tested by

no test coverage detected