[mapserver-dev] Scale checking function or macro...

Daniel Morissette dmorissette at mapgears.com
Tue Dec 20 21:18:14 EST 2011


On 11-12-16 11:18 AM, Lime, Steve D (DNR) wrote:
> Hi all: I'm doing some refactoring in mapdraw.c/msDrawShape() for RFC 77
> and see code like
> this frequently:
>
> if(map->scaledenom > 0) {
> if((curStyle->maxscaledenom != -1) && (map->scaledenom >=
> curStyle->maxscaledenom))
> continue;
> if((curStyle->minscaledenom != -1) && (map->scaledenom <
> curStyle->minscaledenom))
> continue;
> }
>
> Seems ripe for a utility function (e.g. msScaleInBounds() or a macro). I
> did a quick scan of the
> headers and didn't find anything similar but thought I check before
> adding. Anyone put something
> like this in place already? What's better a function or a macro?
> Assuming a macro I'm not sure
> what a macro would look like- ideas welcome.
>

Maybe something like this? (untested, so I could be wrong)

#define MS_SCALE_IN_BOUNDS(scaledenom, minscaledenom, maxscaledenom)   \
     (((scaledenom) <= 0) || 	\
      ( ((maxscaledenom) == -1 || (scaledenom) < (maxscaledenom)) &&    \
        ((minscaledenom) == -1 || (scaledenom) >= (minscaledenom))   )  \
     )

and then

if (!MS_SCALE_IN_BOUNDS(map->scaledenom, curStyle->minscaledenom, 
curStyle->maxscaledenom))
   continue;


-- 
Daniel Morissette
http://www.mapgears.com/
Provider of Professional MapServer Support since 2000



More information about the mapserver-dev mailing list