Changeset 1686
- Timestamp:
- 03/12/10 08:34:32 (5 months ago)
- Location:
- trunk
- Files:
-
- 2 modified
-
include/mapnik/raster_colorizer.hpp (modified) (2 diffs)
-
tests/python_tests/raster_colorizer_test.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/mapnik/raster_colorizer.hpp
r1685 r1686 154 154 * otherwise: transparent 155 155 * where 0 <= pos < length(bands)-1 156 * Last band is special, its value represents the upper bound and its 157 * color will only be used if the value matches its value exactly. 156 158 */ 157 159 color get_color(float value) const { 158 int pos=-1, l o=0, hi=colors_.size()-1;160 int pos=-1, last=(int)colors_.size()-1, lo=0, hi=last; 159 161 while (lo<=hi) { 160 162 pos = (lo+hi)/2; … … 169 171 } 170 172 lo--; 171 return (0 <= lo && lo < (int)colors_.size()-1)? 172 colors_[lo].color_: 173 color(0,0,0,0); 173 if ((0 <= lo && lo < last) || 174 (lo==last && colors_[last].value_==value)) 175 return colors_[lo].color_; 176 else 177 return color(0,0,0,0); 174 178 } 175 179 -
trunk/tests/python_tests/raster_colorizer_test.py
r1685 r1686 19 19 ( 80, "#990099"), 20 20 ( 90, "#660066"), 21 ( 200, "#00000"), # last band denotes upper limit, values above it will 22 # not return the color 21 ( 200, "#ffffff"), 23 22 ]] 24 23 for value, color in bands: … … 29 28 eq_(colorizer.get_color(5), bands[0][1]) 30 29 eq_(colorizer.get_color(10), bands[1][1]) 31 eq_(colorizer.get_color(200), mapnik2.Color("transparent")) 30 # last value is used if it matches exactly 31 eq_(colorizer.get_color(200), bands[-1][1]) 32 # values greater than the last value are mapped to "transparent" 32 33 eq_(colorizer.get_color(201), mapnik2.Color("transparent"))
