MCPcopy Index your code
hub / github.com/MapServer/MapServer / DefineAxis

Function DefineAxis

mapgraticule.c:1162–1239  ·  view source on GitHub ↗

********************************************************************************************************************** * DefineAxes - Copyright (c) 2000, Michael P.D. Bramley. * * Permission is granted to use this code without restriction as long as * this copyright notice appears in all source files. * * Minor tweaks to incrment calculations - jnovak */

Source from the content-addressed store, hash-verified

1160 * Minor tweaks to incrment calculations - jnovak
1161 */
1162void DefineAxis( int iTickCountTarget, double *Min, double *Max, double *Inc )
1163{
1164 /* define local variables... */
1165
1166 double Test_inc, /* candidate increment value */
1167 Test_min, /* minimum scale value */
1168 Test_max, /* maximum scale value */
1169 Range = *Max - *Min ; /* range of data */
1170
1171 int i = 0 ; /* counter */
1172
1173 /* don't create problems -- solve them */
1174
1175 if( Range < 0 ) {
1176 *Inc = 0 ;
1177 return ;
1178 }
1179
1180 /* handle special case of repeated values */
1181
1182 else if( Range == 0) {
1183 *Min = ceil(*Max) - 1 ;
1184 *Max = *Min + 1 ;
1185 *Inc = 1 ;
1186 return ;
1187 }
1188
1189 /* compute candidate for increment */
1190
1191 Test_inc = pow( 10.0, ceil( log10( Range/10 ) ) ) ;
1192 if(*Inc > 0 && ( Test_inc < *Inc || Test_inc > *Inc ))
1193 Test_inc = *Inc;
1194
1195 /* establish maximum scale value... */
1196 Test_max = ( (long)(*Max / Test_inc)) * Test_inc ;
1197
1198 if( Test_max < *Max )
1199 Test_max += Test_inc ;
1200
1201 /* establish minimum scale value... */
1202 Test_min = Test_max ;
1203 do {
1204 ++i ;
1205 Test_min -= Test_inc ;
1206 } while( Test_min > *Min ) ;
1207
1208 /* subtracting small values can screw up the scale limits, */
1209 /* eg: if DefineAxis is called with (min,max)=(0.01, 0.1), */
1210 /* then the calculated scale is 1.0408E17 TO 0.05 BY 0.01. */
1211 /* the following if statment corrects for this... */
1212
1213 /* if(fabs(Test_min) < 1E-10) */
1214 /* Test_min = 0 ; */
1215
1216 /* adjust for too few tick marks */
1217
1218 if(iTickCountTarget <= 0)
1219 iTickCountTarget = MAPGRATICULE_ARC_MINIMUM;

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected