add test for render_with_detector + fix scale rendering tests - refs #2075

This commit is contained in:
Dane Springmeyer 2013-11-13 10:45:23 -08:00
parent 6844863a89
commit dc3fad51a3
13 changed files with 46 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 B

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View file

@ -173,6 +173,49 @@ def test_render_with_scale_factor_zero_throws():
im = mapnik.Image(256, 256)
mapnik.render(m,im,0.0)
def test_render_with_detector():
ds = mapnik.MemoryDatasource()
context = mapnik.Context()
geojson = '{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [ 0, 0 ] } }'
ds.add_feature(mapnik.Feature.from_geojson(geojson,context))
s = mapnik.Style()
r = mapnik.Rule()
lyr = mapnik.Layer('point')
lyr.datasource = ds
lyr.styles.append('point')
symb = mapnik.MarkersSymbolizer()
symb.allow_overlap = False
r.symbols.append(symb)
s.rules.append(r)
m = mapnik.Map(256,256)
m.append_style('point',s)
m.layers.append(lyr)
m.zoom_to_box(mapnik.Box2d(-180,-85,180,85))
im = mapnik.Image(256, 256)
mapnik.render(m,im)
expected_file = './images/support/marker-in-center.png'
actual_file = '/tmp/' + os.path.basename(expected_file)
#im.save(expected_file,'png8')
im.save(actual_file,'png8')
actual = mapnik.Image.open(expected_file)
expected = mapnik.Image.open(expected_file)
eq_(actual.tostring(),expected.tostring(), 'failed comparing actual (%s) and expected (%s)' % (actual_file,expected_file))
# now render will a collision detector that should
# block out the placement of this point
detector = mapnik.LabelCollisionDetector(m)
eq_(detector.extent(),mapnik.Box2d(-0.0,-0.0,m.width,m.height))
eq_(detector.extent(),mapnik.Box2d(-0.0,-0.0,256.0,256.0))
eq_(detector.boxes(),[])
detector.insert(detector.extent())
eq_(detector.boxes(),[detector.extent()])
im2 = mapnik.Image(256, 256)
mapnik.render_with_detector(m, im2, detector)
expected_file_collision = './images/support/marker-in-center-not-placed.png'
#im2.save(expected_file_collision,'png8')
actual_file = '/tmp/' + os.path.basename(expected_file_collision)
im2.save(actual_file,'png8')
if 'shape' in mapnik.DatasourceCache.plugin_names():
def test_render_with_scale_factor():
@ -185,10 +228,10 @@ if 'shape' in mapnik.DatasourceCache.plugin_names():
mapnik.render(m,im,size)
expected_file = './images/support/marker-text-line-scale-factor-%s.png' % size
actual_file = '/tmp/' + os.path.basename(expected_file)
im.save(actual_file,'png8')
#im.save(expected_file,'png8')
im.save(actual_file,'png32')
#im.save(expected_file,'png32')
# we save and re-open here so both png8 images are ready as full color png
actual = mapnik.Image.open(expected_file)
actual = mapnik.Image.open(actual_file)
expected = mapnik.Image.open(expected_file)
eq_(actual.tostring(),expected.tostring(), 'failed comparing actual (%s) and expected (%s)' % (actual_file,expected_file))