Skip to content

Commit b08c030

Browse files
committed
Round results rather than truncate the in the DOUBLE_TO_FIX macro
As ram nodes go through a double conversion, results differed depending on if they were stored in ram cache in the database. Also adapt the tests, as they the rounding changes changed the sizes of many of the polygons by a tiny amount.
1 parent d1b6c5e commit b08c030

2 files changed

Lines changed: 22 additions & 22 deletions

File tree

node-ram-cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/* Scale is chosen such that 40,000 * SCALE < 2^32 */
1818
#define FIXED_POINT
1919
static int scale = 100;
20-
#define DOUBLE_TO_FIX(x) ((int)((x) * scale))
20+
#define DOUBLE_TO_FIX(x) ((int)((x) * scale + 0.4))
2121
#define FIX_TO_DOUBLE(x) (((double)x) / scale)
2222

2323
#define UNUSED __attribute__ ((unused))

tests/regression-test.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
( 10, 'Absence of nodes table', 'SELECT count(*) FROM pg_tables WHERE tablename = \'planet_osm_nodes\'', 0),
2828
( 11, 'Absence of way table', 'SELECT count(*) FROM pg_tables WHERE tablename = \'planet_osm_ways\'', 0),
2929
( 12, 'Absence of rel line', 'SELECT count(*) FROM pg_tables WHERE tablename = \'planet_osm_rels\'', 0),
30-
( 13, 'Basic polygon area', 'SELECT round(sum(cast(ST_Area(way) as numeric)),0) FROM planet_osm_polygon;', 1223787843),
30+
( 13, 'Basic polygon area', 'SELECT round(sum(cast(ST_Area(way) as numeric)),0) FROM planet_osm_polygon;', 1223787932),
3131
( 14, 'Gazetteer place count', 'SELECT count(*) FROM place', 4709),
3232
( 15, 'Gazetteer place node count', 'SELECT count(*) FROM place WHERE osm_type = \'N\'', 988),
3333
( 16, 'Gazetteer place way count', 'SELECT count(*) FROM place WHERE osm_type = \'W\'', 3699),
@@ -43,25 +43,25 @@
4343
( 26, 'Multipolygon basic case (Tags from outer way)',
4444
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -15 and landuse = \'residential\' and name = \'Name_way\'', 12894),
4545
( 27, 'Multipolygon basic case (Tags from relation)',
46-
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -1 and landuse = \'residential\' and name = \'Name_rel\'', 12894),
46+
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -1 and landuse = \'residential\' and name = \'Name_rel\'', 12895),
4747
( 28, 'Multipolygon named inner - outer (Tags from way)',
48-
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -16 and landuse = \'residential\' and name = \'Name_way2\'', 12893),
48+
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -16 and landuse = \'residential\' and name = \'Name_way2\'', 12895),
4949
( 29, 'Multipolygon named inner - inner way',
5050
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = 4 and landuse = \'farmland\' and name = \'Name_way3\'', 3144),
5151
( 30, 'Multipolygon named inner - outer (Tags from relation)',
52-
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -8 and landuse = \'residential\' and name = \'Name_rel2\'', 12893),
52+
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -8 and landuse = \'residential\' and name = \'Name_rel2\'', 12894),
5353
( 31, 'Multipolygon named inner - inner way',
5454
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = 5 and landuse = \'farmland\' and name = \'Name_way4\'', 3144),
5555
( 32, 'Multipolygon named same inner - outer (Tags from way)',
56-
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -17 and landuse = \'residential\' and name = \'Name_way16\'', 12894),
56+
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -17 and landuse = \'residential\' and name = \'Name_way16\'', 12895),
5757
( 33, 'Multipolygon named same inner - inner way absent',
5858
'SELECT count(*) FROM planet_osm_polygon WHERE osm_id = 15', 0),
5959
( 34, 'Multipolygon non-area inner - outer (Tags from relation)',
60-
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -14 and landuse = \'residential\' and name = \'Name_way5\'', 12894),
60+
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -14 and landuse = \'residential\' and name = \'Name_way5\'', 12893),
6161
( 35, 'Multipolygon non-area inner - inner (Tags from way)',
6262
'SELECT round(ST_Length(way)) FROM planet_osm_line WHERE osm_id = 6 and highway = \'residential\' and name = \'Name_way6\'', 228),
6363
( 36, 'Multipolygon 2 holes (Tags from way)',
64-
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -18 and landuse = \'residential\' and name = \'Name_way7\'', 11822),
64+
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -18 and landuse = \'residential\' and name = \'Name_way7\'', 11823),
6565
( 37, 'Multipolygon 2 holes (Tags from way)',
6666
'SELECT ST_NumInteriorRing(way) FROM planet_osm_polygon WHERE osm_id = -18 and landuse = \'residential\' and name = \'Name_way7\'', 2),
6767
( 38, 'Multipolygon from multiple outer ways 0 holes (Tags from relation)',
@@ -75,15 +75,15 @@
7575
( 42, 'Multipolygon with touching inner ways 1 hole (Tags from way)',
7676
'SELECT ST_NumInteriorRing(way) FROM planet_osm_polygon WHERE osm_id = -19 and landuse = \'residential\' and name = \'Name_way8\'', 1),
7777
( 43, 'Multipolygon with 2 outer ways (Tags from relation)',
78-
'SELECT round(sum(ST_Area(way))) FROM planet_osm_polygon WHERE osm_id = -13 and landuse = \'farmland\' and name = \'Name_rel9\'', 17582),
78+
'SELECT round(sum(ST_Area(way))) FROM planet_osm_polygon WHERE osm_id = -13 and landuse = \'farmland\' and name = \'Name_rel9\'', 17581),
7979
( 44, 'Multipolygon with 2 outer ways (Tags from relation)',
8080
'SELECT count(*) FROM planet_osm_polygon WHERE osm_id = -13 and landuse = \'farmland\' and name = \'Name_rel9\'', 2),
8181
( 45, 'Multipolygon with 2 outer ways (multigeometry)',
8282
'SELECT count(*) FROM planet_osm_polygon WHERE osm_id = -13 and landuse = \'farmland\' and name = \'Name_rel9\'', 1),
8383
( 46, 'Multipolygon with 2 outer ways (multigeometry)',
8484
'SELECT ST_NumGeometries(way) FROM planet_osm_polygon WHERE osm_id = -13 and landuse = \'farmland\' and name = \'Name_rel9\'', 2),
8585
( 47, 'Multipolygon nested outer ways. Both outer and inner ways are from multiple ways (Tags from relation)',
86-
'SELECT round(sum(ST_Area(way))) FROM planet_osm_polygon WHERE osm_id = -7 and landuse = \'farmland\' and name = \'Name_rel15\'', 16168),
86+
'SELECT round(sum(ST_Area(way))) FROM planet_osm_polygon WHERE osm_id = -7 and landuse = \'farmland\' and name = \'Name_rel15\'', 16169),
8787
( 48, 'Multipolygon nested outer ways. Both outer and inner ways are from multiple ways (Tags from relation)',
8888
'SELECT count(*) FROM planet_osm_polygon WHERE osm_id = -7 and landuse = \'farmland\' and name = \'Name_rel15\'', 2),
8989
( 49, 'Multipolygon nested outer ways. Both outer and inner ways are from multiple ways (multigeometry)',
@@ -113,35 +113,35 @@
113113
( 65, 'Multipolygon non copying of tags from outer with polygon tags on relation (presence of way)',
114114
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = 83 and "landuse" = \'farmland\'', 24859),
115115
( 66, 'Multipolygon diff moved point of outer way case (Tags from outer way)',
116-
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -15 and landuse = \'residential\' and name = \'Name_way\'', 24749),
116+
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -15 and landuse = \'residential\' and name = \'Name_way\'', 24751),
117117
( 67, 'Multipolygon diff moved point of inner way case (Tags from relation)',
118-
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -1 and landuse = \'residential\' and name = \'Name_rel\'', 13948),
118+
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -1 and landuse = \'residential\' and name = \'Name_rel\'', 13949),
119119
( 68, 'Multipolygon point of inner way case (Tags from relation)',
120-
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -25 and landuse = \'farmland\' and name = \'my name\'', 23884),
120+
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -25 and landuse = \'farmland\' and name = \'my name\'', 23886),
121121
( 69, 'Multipolygon point of inner way case (Tags from relation)',
122122
'SELECT count(*) FROM planet_osm_polygon WHERE osm_id = 90', 0),
123123
( 70, 'Multipolygon diff remove relation (tagged outer way gets re added)',
124-
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = 90 and landuse = \'farmland\'', 32624),
124+
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = 90 and landuse = \'farmland\'', 32626),
125125
( 71, 'Multipolygon diff remove relation',
126126
'SELECT count(*) FROM planet_osm_polygon WHERE osm_id = -25', 0),
127127
( 72, 'Multipolygon tags on both inner and outer (presence of relation)',
128-
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -34 and "natural" = \'water\'', 15245),
128+
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -34 and "natural" = \'water\'', 15246),
129129
( 73, 'Multipolygon tags on both inner and outer (abscence of outer)',
130130
'SELECT count(*) FROM planet_osm_polygon WHERE osm_id = 113', 0),
131131
( 74, 'Multipolygon tags on both inner and outer (abscence of inner)',
132132
'SELECT count(*) FROM planet_osm_polygon WHERE osm_id = 118', 0),
133133
( 75, 'Multipolygon tags on both inner and outer diff change outer (presence of relation)',
134-
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -34 and "landuse" = \'farmland\'', 15245),
134+
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -34 and "landuse" = \'farmland\'', 15246),
135135
( 76, 'Multipolygon tags on both inner and outer diff change outer (abscence of outer)',
136136
'SELECT count(*) FROM planet_osm_polygon WHERE osm_id = 113', 0),
137137
( 77, 'Multipolygon tags on both inner and outer diff change on outer (creation of inner)',
138138
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = 118 and "natural" = \'water\'', 1234),
139139
( 78, 'Multipolygon tags on outer (presence of relation)',
140-
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -33 and "natural" = \'water\'', 15614),
140+
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -33 and "natural" = \'water\'', 15612),
141141
( 79, 'Multipolygon tags on outer (abscence of outer)',
142142
'SELECT count(*) FROM planet_osm_polygon WHERE osm_id = 114', 0),
143143
( 80, 'Multipolygon tags on outer change of way tags (presence of relation)',
144-
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -33 and "landuse" = \'cemetery\'', 15614),
144+
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -33 and "landuse" = \'cemetery\'', 15612),
145145
( 81, 'Multipolygon tags on outer (abscence of old relation)',
146146
'SELECT count(*) FROM planet_osm_polygon WHERE osm_id = -33 and "natural" = \'water\'', 0),
147147
( 82, 'Multipolygon tags on relation two outer (presence of relation)',
@@ -151,15 +151,15 @@
151151
( 84, 'Multipolygon tags on relation two outer (abscence of outer)',
152152
'SELECT count(*) FROM planet_osm_polygon WHERE osm_id = 104', 0),
153153
( 85, 'Multipolygon tags on relation two outer diff delete way (presence of relation)',
154-
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -29 and "natural" = \'water\'', 29153),
154+
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -29 and "natural" = \'water\'', 29154),
155155
( 86, 'Multipolygon tags on relation two outer (presence of relation)',
156156
'SELECT round(sum(ST_Area(way))) FROM planet_osm_polygon WHERE osm_id = -35 and "natural" = \'water\'', 28730),
157157
( 87, 'Multipolygon tags on relation two outer (abscence of outer)',
158158
'SELECT count(*) FROM planet_osm_polygon WHERE osm_id = 107', 0),
159159
( 88, 'Multipolygon tags on relation two outer (abscence of outer)',
160160
'SELECT count(*) FROM planet_osm_polygon WHERE osm_id = 102', 0),
161161
( 89, 'Multipolygon tags on relation two outer diff remove way from relation (presence of relation)',
162-
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -35 and "natural" = \'water\'', 15737),
162+
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = -35 and "natural" = \'water\'', 15736),
163163
( 90, 'Multipolygon tags on relation two outer diff remove way from relation (presence of single way)',
164164
'SELECT round(ST_Area(way)) FROM planet_osm_polygon WHERE osm_id = 102 and "natural" = \'water\'', 12994),
165165
( 91, 'Basic line length', 'SELECT round(sum(ST_Length(way))) FROM planet_osm_line;', 4269394),
@@ -189,8 +189,8 @@ def __init__(self):
189189
"testTwo")))
190190
self.addTest(BasicSlimTestCase("basic case", [], [0,1,2,3,13, 91, 92],[6,7,8,9]))
191191
self.addTest(BasicSlimTestCase("Parallel processing", ["--number-processes", "8", "-C100"], [0,1,2,3,13,91,92],[6,7,8,9]))
192-
#It looks like --cache-strategy=dense is broken, as it it produces wrong geometries.
193-
#self.addTest(BasicSlimTestCase("Parallel processing with non 100% node-cache", ["--number-processes", "8", "-C1", "--cache-strategy=dense"], [0,1,2,3,13,91,92],[6,7,8,9]))
192+
self.addTest(BasicSlimTestCase("Parallel processing with non 100% node-cache", ["--number-processes", "8", "-C1", "--cache-strategy=dense"], [0,1,2,3,13,91,92],[6,7,8,9]))
193+
self.addTest(BasicSlimTestCase("Parallel processing with disabled node-cache", ["-C0"], [0,1,2,3,13,91,92],[6,7,8,9]))
194194
# Failes to do correct error checking. This needs fixing in osm2pgsql
195195
# self.addTest(BasicSlimTestCase("Parallel processing with failing database conneciton (connection limit exceeded)", ["--number-processes", "32", "-C100"], [0,1,2,3],[6,7,8,9]))
196196
# Counts are expected to be different in hstore, needs adjusted tests

0 commit comments

Comments
 (0)