mapnik 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +35 -0
- data/.yardopts +1 -0
- data/Gemfile +14 -0
- data/LICENSE +19 -0
- data/Manifest.txt +172 -0
- data/README.rdoc +107 -0
- data/Rakefile +43 -0
- data/demo/data/COPYRIGHT.txt +3 -0
- data/demo/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.dbf +0 -0
- data/demo/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.prj +1 -0
- data/demo/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.shp +0 -0
- data/demo/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.shx +0 -0
- data/demo/data/boundaries.dbf +0 -0
- data/demo/data/boundaries.prj +1 -0
- data/demo/data/boundaries.sbx +0 -0
- data/demo/data/boundaries.shp +0 -0
- data/demo/data/boundaries.shx +0 -0
- data/demo/data/boundaries_l.dbf +0 -0
- data/demo/data/boundaries_l.prj +1 -0
- data/demo/data/boundaries_l.sbx +0 -0
- data/demo/data/boundaries_l.shp +0 -0
- data/demo/data/boundaries_l.shx +0 -0
- data/demo/data/ontdrainage.dbf +0 -0
- data/demo/data/ontdrainage.prj +1 -0
- data/demo/data/ontdrainage.sbx +0 -0
- data/demo/data/ontdrainage.shp +0 -0
- data/demo/data/ontdrainage.shx +0 -0
- data/demo/data/popplaces.dbf +0 -0
- data/demo/data/popplaces.prj +1 -0
- data/demo/data/popplaces.sbx +0 -0
- data/demo/data/popplaces.shp +0 -0
- data/demo/data/popplaces.shx +0 -0
- data/demo/data/qcdrainage.dbf +0 -0
- data/demo/data/qcdrainage.prj +1 -0
- data/demo/data/qcdrainage.sbx +0 -0
- data/demo/data/qcdrainage.shp +0 -0
- data/demo/data/qcdrainage.shx +0 -0
- data/demo/data/roads.dbf +0 -0
- data/demo/data/roads.prj +1 -0
- data/demo/data/roads.sbx +0 -0
- data/demo/data/roads.shp +0 -0
- data/demo/data/roads.shx +0 -0
- data/demo/data/test/charplacement.dbf +0 -0
- data/demo/data/test/charplacement.shp +0 -0
- data/demo/data/test/charplacement.shx +0 -0
- data/demo/data/test/displacement.dbf +0 -0
- data/demo/data/test/displacement.shp +0 -0
- data/demo/data/test/displacement.shx +0 -0
- data/demo/data/test/overlap.dbf +0 -0
- data/demo/data/test/overlap.shp +0 -0
- data/demo/data/test/overlap.shx +0 -0
- data/demo/data/test/raw/charplacement.gfs +25 -0
- data/demo/data/test/raw/charplacement.gml +99 -0
- data/demo/data/test/raw/charplacement.xsd +36 -0
- data/demo/data/test/raw/displacement.gfs +25 -0
- data/demo/data/test/raw/displacement.gml +173 -0
- data/demo/data/test/raw/displacement.xsd +36 -0
- data/demo/data/test/raw/overlap.gfs +25 -0
- data/demo/data/test/raw/overlap.gml +127 -0
- data/demo/data/test/raw/overlap.xsd +36 -0
- data/demo/data/test/raw/textspacing.gfs +25 -0
- data/demo/data/test/raw/textspacing.gml +117 -0
- data/demo/data/test/raw/textspacing.xsd +36 -0
- data/demo/data/test/readme.txt +3 -0
- data/demo/data/test/regenerate.sh +20 -0
- data/demo/data/test/textspacing.dbf +0 -0
- data/demo/data/test/textspacing.shp +0 -0
- data/demo/data/test/textspacing.shx +0 -0
- data/demo/rundemo.rb +145 -0
- data/demo/sinatra/demo.rb +31 -0
- data/demo/sinatra/public/css/demo_map.css +7 -0
- data/demo/sinatra/public/index.html +13 -0
- data/demo/sinatra/public/javascripts/demo_map.js +42 -0
- data/ext/ruby_mapnik/_mapnik.cpp +52 -0
- data/ext/ruby_mapnik/_mapnik.h +65 -0
- data/ext/ruby_mapnik/_mapnik_color.rb.cpp +179 -0
- data/ext/ruby_mapnik/_mapnik_color.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_coord.rb.cpp +145 -0
- data/ext/ruby_mapnik/_mapnik_coord.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_datasource.rb.cpp +170 -0
- data/ext/ruby_mapnik/_mapnik_datasource.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_datasource_cache.rb.cpp +87 -0
- data/ext/ruby_mapnik/_mapnik_datasource_cache.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_envelope.rb.cpp +220 -0
- data/ext/ruby_mapnik/_mapnik_envelope.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_expression.rb.cpp +91 -0
- data/ext/ruby_mapnik/_mapnik_expression.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_feature.rb.cpp +93 -0
- data/ext/ruby_mapnik/_mapnik_feature.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_font_engine.rb.cpp +71 -0
- data/ext/ruby_mapnik/_mapnik_font_engine.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_layer.rb.cpp +208 -0
- data/ext/ruby_mapnik/_mapnik_layer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_line_pattern_symbolizer.rb.cpp +71 -0
- data/ext/ruby_mapnik/_mapnik_line_pattern_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_line_symbolizer.rb.cpp +43 -0
- data/ext/ruby_mapnik/_mapnik_line_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_map.rb.cpp +489 -0
- data/ext/ruby_mapnik/_mapnik_map.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_markers_symbolizer.rb.cpp +140 -0
- data/ext/ruby_mapnik/_mapnik_markers_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_point_symbolizer.rb.cpp +150 -0
- data/ext/ruby_mapnik/_mapnik_point_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_polygon_pattern_symbolizer.rb.cpp +93 -0
- data/ext/ruby_mapnik/_mapnik_polygon_pattern_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_polygon_symbolizer.rb.cpp +89 -0
- data/ext/ruby_mapnik/_mapnik_polygon_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_projection.rb.cpp +100 -0
- data/ext/ruby_mapnik/_mapnik_projection.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_raster_colorizer.rb.cpp +162 -0
- data/ext/ruby_mapnik/_mapnik_raster_colorizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_raster_symbolizer.rb.cpp +87 -0
- data/ext/ruby_mapnik/_mapnik_raster_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_rule.rb.cpp +69 -0
- data/ext/ruby_mapnik/_mapnik_rule.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_shield_symbolizer.rb.cpp +86 -0
- data/ext/ruby_mapnik/_mapnik_shield_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_stroke.rb.cpp +188 -0
- data/ext/ruby_mapnik/_mapnik_stroke.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_style.rb.cpp +76 -0
- data/ext/ruby_mapnik/_mapnik_style.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_symbolizer.rb.cpp +75 -0
- data/ext/ruby_mapnik/_mapnik_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/_mapnik_text_symbolizer.rb.cpp +471 -0
- data/ext/ruby_mapnik/_mapnik_text_symbolizer.rb.h +32 -0
- data/ext/ruby_mapnik/extconf.rb +80 -0
- data/ext/ruby_mapnik/ruby_mapnik.cpp +32 -0
- data/lib/mapnik.rb +1 -0
- data/lib/ruby_mapnik.rb +48 -0
- data/lib/ruby_mapnik/mapnik/font_engine.rb +35 -0
- data/lib/ruby_mapnik/mapnik/layer.rb +68 -0
- data/lib/ruby_mapnik/mapnik/map.rb +166 -0
- data/lib/ruby_mapnik/mapnik/projection.rb +44 -0
- data/lib/ruby_mapnik/mapnik/raster_colorizer.rb +55 -0
- data/lib/ruby_mapnik/mapnik/rule.rb +104 -0
- data/lib/ruby_mapnik/mapnik/stroke.rb +56 -0
- data/lib/ruby_mapnik/mapnik/style.rb +64 -0
- data/lib/ruby_mapnik/mapnik/tile.rb +93 -0
- data/script/console +2 -0
- data/test/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.dbf +0 -0
- data/test/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.prj +1 -0
- data/test/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.shp +0 -0
- data/test/data/TM_WORLD_BORDERS_SIMPL_0.3_MOD.shx +0 -0
- data/test/data/test_map.xml +15 -0
- data/test/test_helper.rb +29 -0
- data/test/test_line_pattern_symbolizer.rb +26 -0
- data/test/test_mapnik_color.rb +66 -0
- data/test/test_mapnik_coord.rb +92 -0
- data/test/test_mapnik_datasource.rb +49 -0
- data/test/test_mapnik_envelope.rb +232 -0
- data/test/test_mapnik_expression.rb +19 -0
- data/test/test_mapnik_feature.rb +29 -0
- data/test/test_mapnik_font_engine.rb +13 -0
- data/test/test_mapnik_layer.rb +121 -0
- data/test/test_mapnik_line_symbolizer.rb +25 -0
- data/test/test_mapnik_map.rb +211 -0
- data/test/test_mapnik_markers_symbolizer.rb +46 -0
- data/test/test_mapnik_point_symbolizer.rb +53 -0
- data/test/test_mapnik_polygon_symbolizer.rb +44 -0
- data/test/test_mapnik_projection.rb +46 -0
- data/test/test_mapnik_raster_colorizer.rb +56 -0
- data/test/test_mapnik_raster_symbolizer.rb +45 -0
- data/test/test_mapnik_rule.rb +45 -0
- data/test/test_mapnik_shield_symbolizer.rb +156 -0
- data/test/test_mapnik_stroke.rb +94 -0
- data/test/test_mapnik_style.rb +28 -0
- data/test/test_mapnik_symbolizer.rb +9 -0
- data/test/test_mapnik_text_symbolizer.rb +208 -0
- data/test/test_polygon_pattern_symbolizer.rb +34 -0
- data/test/test_ruby_mapnik.rb +34 -0
- data/yard/lib/yard/parser/generic_parser.rb +72 -0
- data/yard/lib/yard_generic.rb +18 -0
- metadata +333 -0
data/test/test_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
=begin
|
2
|
+
******************************************************************************
|
3
|
+
*
|
4
|
+
* Copyright (C) 2011 Elliot Laster
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*
|
20
|
+
******************************************************************************
|
21
|
+
=end
|
22
|
+
require "test/unit"
|
23
|
+
|
24
|
+
CURRENT_PATH = File.expand_path(File.dirname(__FILE__))
|
25
|
+
require File.join(CURRENT_PATH, '..', 'lib', 'ruby_mapnik')
|
26
|
+
|
27
|
+
unless defined?(SHAPEFILE)
|
28
|
+
SHAPEFILE = File.join(CURRENT_PATH, 'data', 'TM_WORLD_BORDERS_SIMPL_0.3_MOD')
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestLinePatternSymbolizer < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@filename = "/my/file.png"
|
7
|
+
path_expression = Mapnik::PathExpression.parse("/my/file.png")
|
8
|
+
@sym = Mapnik::LinePatternSymbolizer.new(path_expression)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_presence
|
12
|
+
assert Mapnik::LinePatternSymbolizer
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_instantiate
|
16
|
+
assert @sym
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_should_get_and_set_filename
|
20
|
+
assert_equal @filename, @sym.filename
|
21
|
+
new_filename = "/something/else.png"
|
22
|
+
@sym.filename = new_filename
|
23
|
+
assert_equal new_filename, @sym.filename
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
=begin
|
2
|
+
******************************************************************************
|
3
|
+
*
|
4
|
+
* Copyright (C) 2011 Elliot Laster
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*
|
20
|
+
******************************************************************************
|
21
|
+
=end
|
22
|
+
require 'test_helper'
|
23
|
+
class TestMapnikColor < Test::Unit::TestCase
|
24
|
+
|
25
|
+
def test_should_instantiate_and_update_values
|
26
|
+
values = {:red => 0, :green => 0, :blue => 0, :alpha => 0}
|
27
|
+
color = Mapnik::Color.new("#000")
|
28
|
+
color.alpha = 0
|
29
|
+
values.each do |key, value|
|
30
|
+
assert_equal(value, color.send("#{key}"))
|
31
|
+
color.send("#{key}=", value + 1)
|
32
|
+
assert_equal(value + 1, color.send("#{key}"))
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_should_instantiate_with_a_css_hex_value
|
38
|
+
color = Mapnik::Color.new("#ff0000")
|
39
|
+
assert_equal 255, color.red
|
40
|
+
assert_equal 0, color.green
|
41
|
+
assert_equal 0, color.blue
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_should_instantiate_with_a_rgb_value
|
45
|
+
red = 34
|
46
|
+
green = 120
|
47
|
+
blue = 134
|
48
|
+
color = Mapnik::Color.new(red, green, blue)
|
49
|
+
assert_equal red, color.red
|
50
|
+
assert_equal green, color.green
|
51
|
+
assert_equal blue, color.blue
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_should_instantiate_with_a_rgba_value
|
55
|
+
red = 34
|
56
|
+
green = 120
|
57
|
+
blue = 134
|
58
|
+
alpha = 0
|
59
|
+
color = Mapnik::Color.new(red, green, blue, alpha)
|
60
|
+
assert_equal red, color.red
|
61
|
+
assert_equal green, color.green
|
62
|
+
assert_equal blue, color.blue
|
63
|
+
assert_equal alpha, color.alpha
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
=begin
|
2
|
+
******************************************************************************
|
3
|
+
*
|
4
|
+
* Copyright (C) 2011 Elliot Laster
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*
|
20
|
+
******************************************************************************
|
21
|
+
=end
|
22
|
+
require 'test_helper'
|
23
|
+
class TestMapnikCoord < Test::Unit::TestCase
|
24
|
+
|
25
|
+
def test_should_hang_onto_and_update_values
|
26
|
+
coord2d = Mapnik::Coord2d.new(1, 2)
|
27
|
+
assert_equal(1, coord2d.x)
|
28
|
+
assert_equal(2, coord2d.y)
|
29
|
+
|
30
|
+
coord2d.x = 2
|
31
|
+
coord2d.y = 4
|
32
|
+
assert_equal(2, coord2d.x)
|
33
|
+
assert_equal(4, coord2d.y)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_should_be_equal_to_another_coord_if_the_x_and_ys_match
|
37
|
+
coord2d = Mapnik::Coord2d.new(1,2)
|
38
|
+
other_coord = Mapnik::Coord2d.new(coord2d.x, coord2d.y)
|
39
|
+
assert other_coord.object_id != coord2d.object_id
|
40
|
+
assert_equal(other_coord.x, coord2d.x)
|
41
|
+
assert_equal(other_coord.y, coord2d.y)
|
42
|
+
assert_equal(other_coord, coord2d)
|
43
|
+
|
44
|
+
other_coord.x += 3
|
45
|
+
assert_not_equal(other_coord, coord2d)
|
46
|
+
other_coord.x = coord2d.x
|
47
|
+
assert_equal(other_coord, coord2d)
|
48
|
+
|
49
|
+
other_coord.y += 3
|
50
|
+
assert_not_equal(other_coord, coord2d)
|
51
|
+
other_coord.y = coord2d.y
|
52
|
+
assert_equal(other_coord, coord2d)
|
53
|
+
|
54
|
+
other_coord.x += 3
|
55
|
+
other_coord.y += 3
|
56
|
+
assert_not_equal(other_coord, coord2d)
|
57
|
+
end
|
58
|
+
|
59
|
+
# These could be refactored, I suppose...
|
60
|
+
def test_should_return_a_new_coord_when_multiplied_by_a_number
|
61
|
+
coord_check_with_operator(:*)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_should_return_a_new_coord_when_added_to_by_a_number
|
65
|
+
coord_check_with_operator(:+)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_should_return_a_new_coord_when_subtracted_from_by_a_number
|
69
|
+
coord_check_with_operator(:-)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_should_return_a_new_coord_when_divided_by_a_number
|
73
|
+
coord_check_with_operator(:/)
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def coord_check_with_operator(operator)
|
79
|
+
start_x = 1
|
80
|
+
start_y = 2
|
81
|
+
factor = 3
|
82
|
+
coord2d = Mapnik::Coord2d.new(start_x, start_y)
|
83
|
+
updated_coord = coord2d.send(operator, factor)
|
84
|
+
|
85
|
+
assert_not_equal(coord2d.object_id, updated_coord.object_id)
|
86
|
+
assert_equal(coord2d.x.send(operator, factor), updated_coord.x)
|
87
|
+
assert_equal(coord2d.y.send(operator, factor), updated_coord.y)
|
88
|
+
assert_equal(coord2d.x, start_x)
|
89
|
+
assert_equal(coord2d.y, start_y)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
=begin
|
2
|
+
******************************************************************************
|
3
|
+
*
|
4
|
+
* Copyright (C) 2011 Elliot Laster
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*
|
20
|
+
******************************************************************************
|
21
|
+
=end
|
22
|
+
require 'test_helper'
|
23
|
+
class TestMapnikDatasource < Test::Unit::TestCase
|
24
|
+
|
25
|
+
def setup
|
26
|
+
@datasource_params = {
|
27
|
+
:type => 'shape',
|
28
|
+
:file => SHAPEFILE
|
29
|
+
}
|
30
|
+
@datasource = Mapnik::Datasource.create(@datasource_params)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_create_a_new_datasource
|
34
|
+
assert @datasource
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_should_have_an_envelope
|
38
|
+
assert @datasource.envelope.kind_of?(Mapnik::Envelope)
|
39
|
+
end
|
40
|
+
|
41
|
+
# def test_should_have_a_descriptor
|
42
|
+
# raise @datasource.descriptor.inspect
|
43
|
+
# end
|
44
|
+
|
45
|
+
def test_should_get_params
|
46
|
+
assert_equal @datasource_params, @datasource.params
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,232 @@
|
|
1
|
+
=begin
|
2
|
+
******************************************************************************
|
3
|
+
*
|
4
|
+
* Copyright (C) 2011 Elliot Laster
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*
|
20
|
+
******************************************************************************
|
21
|
+
=end
|
22
|
+
require "test_helper"
|
23
|
+
|
24
|
+
class TestMapnikEnvelope < Test::Unit::TestCase
|
25
|
+
|
26
|
+
def test_presence
|
27
|
+
assert Mapnik::Envelope
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_should_instantiate
|
31
|
+
assert Mapnik::Envelope.new(1,1,5,5)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_should_set_attributes_correctly
|
35
|
+
min_x = 1
|
36
|
+
min_y = 2
|
37
|
+
max_x = 3
|
38
|
+
max_y = 4
|
39
|
+
envelope = Mapnik::Envelope.new(min_x, min_y, max_x, max_y)
|
40
|
+
assert_equal(min_x, envelope.min_x)
|
41
|
+
assert_equal(min_y, envelope.min_y)
|
42
|
+
assert_equal(max_x, envelope.max_x)
|
43
|
+
assert_equal(max_y, envelope.max_y)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_equality
|
47
|
+
envelope1 = Mapnik::Envelope.new(0, 0, 10, 10)
|
48
|
+
envelope2 = Mapnik::Envelope.new(0, 0, 10, 10)
|
49
|
+
assert_equal(envelope1, envelope2)
|
50
|
+
envelope1.re_center_to_xy!(7, 7)
|
51
|
+
assert_not_equal(envelope1, envelope2)
|
52
|
+
envelope1.re_center_to_coord!(envelope2.center)
|
53
|
+
assert_equal(envelope1, envelope2)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_should_return_center
|
57
|
+
envelope = Mapnik::Envelope.new(0, 0, 100, 50)
|
58
|
+
assert center = envelope.center
|
59
|
+
assert_equal 50, center.x
|
60
|
+
assert_equal 25, center.y
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_should_return_height
|
64
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
65
|
+
assert_equal(10, envelope.height)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_should_update_height
|
69
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
70
|
+
assert_equal(10, envelope.height)
|
71
|
+
envelope.height = 20
|
72
|
+
assert_equal 20, envelope.height
|
73
|
+
assert_equal 15, envelope.max_y
|
74
|
+
assert_equal(-5, envelope.min_y)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_should_return_width
|
78
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
79
|
+
assert_equal(10, envelope.width)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_should_update_width
|
83
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
84
|
+
assert_equal(10, envelope.width)
|
85
|
+
envelope.width = 20
|
86
|
+
assert_equal 20, envelope.width
|
87
|
+
assert_equal 15, envelope.max_x
|
88
|
+
assert_equal(-5, envelope.min_x)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_should_recenter_to_xy
|
92
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
93
|
+
assert_equal 5, envelope.center.x
|
94
|
+
assert_equal 5, envelope.center.y
|
95
|
+
height_before = envelope.height
|
96
|
+
width_before = envelope.width
|
97
|
+
|
98
|
+
envelope.re_center_to_xy!(7,6)
|
99
|
+
|
100
|
+
assert_equal 7, envelope.center.x
|
101
|
+
assert_equal 6, envelope.center.y
|
102
|
+
assert_equal height_before, envelope.height
|
103
|
+
assert_equal width_before, envelope.width
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_should_recenter_to_coord
|
107
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
108
|
+
assert_equal 5, envelope.center.x
|
109
|
+
assert_equal 5, envelope.center.y
|
110
|
+
height_before = envelope.height
|
111
|
+
width_before = envelope.width
|
112
|
+
|
113
|
+
envelope.re_center_to_coord!(Mapnik::Coord2d.new(7,6))
|
114
|
+
|
115
|
+
assert_equal 7, envelope.center.x
|
116
|
+
assert_equal 6, envelope.center.y
|
117
|
+
assert_equal height_before, envelope.height
|
118
|
+
assert_equal width_before, envelope.width
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_should_know_if_it_contains_an_xy
|
122
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
123
|
+
assert !envelope.contains_xy?(11, 11)
|
124
|
+
assert envelope.contains_xy?(5, 5)
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_should_know_if_it_contains_a_coord
|
128
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
129
|
+
assert !envelope.contains_coord?(Mapnik::Coord2d.new(11, 11))
|
130
|
+
assert envelope.contains_coord?(Mapnik::Coord2d.new(5, 5))
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_should_know_if_it_contains_another_envelope
|
134
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
135
|
+
assert !envelope.contains_envelope?(Mapnik::Envelope.new(20,20,30,30))
|
136
|
+
assert !envelope.contains_envelope?(Mapnik::Envelope.new(9,9,12,12))
|
137
|
+
assert envelope.contains_envelope?(Mapnik::Envelope.new(5,5,6,6))
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_should_know_if_it_intersects_an_xy
|
141
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
142
|
+
assert !envelope.intersects_xy?(11, 11)
|
143
|
+
assert envelope.intersects_xy?(5, 5)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_should_know_if_it_intersects_a_coord
|
147
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
148
|
+
assert !envelope.intersects_coord?(Mapnik::Coord2d.new(11, 11))
|
149
|
+
assert envelope.intersects_coord?(Mapnik::Coord2d.new(5, 5))
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_should_know_if_it_intersects_another_envelope
|
153
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
154
|
+
assert !envelope.intersects_envelope?(Mapnik::Envelope.new(20,20,30,30))
|
155
|
+
assert envelope.intersects_envelope?(Mapnik::Envelope.new(9,9,12,12))
|
156
|
+
assert envelope.intersects_envelope?(Mapnik::Envelope.new(5,5,6,6))
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_should_expand_to_include_an_xy
|
160
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
161
|
+
assert !envelope.contains_xy?(11, 11)
|
162
|
+
height_before = envelope.height
|
163
|
+
width_before = envelope.width
|
164
|
+
|
165
|
+
envelope.expand_to_include_xy!(11, 11)
|
166
|
+
|
167
|
+
assert envelope.contains_xy?(11, 11)
|
168
|
+
assert_equal height_before + 1, envelope.height
|
169
|
+
assert_equal width_before + 1, envelope.width
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_should_expand_to_include_a_coord
|
173
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
174
|
+
coord = Mapnik::Coord2d.new(11, 11)
|
175
|
+
assert !envelope.contains_coord?(coord)
|
176
|
+
height_before = envelope.height
|
177
|
+
width_before = envelope.width
|
178
|
+
|
179
|
+
envelope.expand_to_include_coord!(coord)
|
180
|
+
|
181
|
+
assert envelope.contains_coord?(coord)
|
182
|
+
assert_equal height_before + 1, envelope.height
|
183
|
+
assert_equal width_before + 1, envelope.width
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_should_expand_to_include_an_envelope
|
187
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
188
|
+
other_envelope = Mapnik::Envelope.new(11, 11, 12, 12)
|
189
|
+
assert !envelope.contains_envelope?(other_envelope)
|
190
|
+
height_before = envelope.height
|
191
|
+
width_before = envelope.width
|
192
|
+
|
193
|
+
envelope.expand_to_include_envelope!(other_envelope)
|
194
|
+
|
195
|
+
assert envelope.contains_envelope?(other_envelope)
|
196
|
+
assert_equal height_before + 2, envelope.height
|
197
|
+
assert_equal width_before + 2, envelope.width
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_should_provide_an_intersection
|
201
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
202
|
+
other_envelope = Mapnik::Envelope.new(9,9,12,12)
|
203
|
+
assert envelope.intersects_envelope?(other_envelope)
|
204
|
+
|
205
|
+
intersection = envelope.intersection(other_envelope)
|
206
|
+
|
207
|
+
assert_not_equal(intersection, envelope)
|
208
|
+
assert_not_equal(other_envelope, intersection)
|
209
|
+
assert envelope.contains_envelope?(intersection)
|
210
|
+
assert other_envelope.contains_envelope?(intersection)
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_should_clip
|
214
|
+
envelope = Mapnik::Envelope.new(0,0,10,10)
|
215
|
+
width_before = envelope.width
|
216
|
+
other_envelope = Mapnik::Envelope.new(9,9,12,12)
|
217
|
+
assert envelope.intersects_envelope?(other_envelope)
|
218
|
+
|
219
|
+
envelope.clip!(other_envelope)
|
220
|
+
|
221
|
+
assert envelope.intersects_envelope?(other_envelope)
|
222
|
+
assert_not_equal(width_before, envelope.width)
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_validity
|
226
|
+
envelope = Mapnik::Envelope.new(0,0,-1,-1)
|
227
|
+
assert envelope.min_x <= envelope.max_x
|
228
|
+
assert envelope.min_y <= envelope.max_y
|
229
|
+
assert envelope.valid?
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|