add dbggen everywhere
This commit is contained in:
parent
cf2a4962e6
commit
86ea42f6cf
9
init.sql
9
init.sql
@ -5,7 +5,14 @@
|
|||||||
-- to preview this somewhat conveniently in QGIS:
|
-- to preview this somewhat conveniently in QGIS:
|
||||||
-- stage || '_' || name || ' gen:' || coalesce(gen, 'Ø') || ' nbend:' || lpad(nbend, 4, '0')
|
-- stage || '_' || name || ' gen:' || coalesce(gen, 'Ø') || ' nbend:' || lpad(nbend, 4, '0')
|
||||||
drop table if exists wm_debug;
|
drop table if exists wm_debug;
|
||||||
create table wm_debug(stage text, name text, gen bigint, nbend bigint, way geometry, props jsonb);
|
create table wm_debug(
|
||||||
|
stage text not null,
|
||||||
|
name text not null,
|
||||||
|
gen bigint not null,
|
||||||
|
nbend bigint,
|
||||||
|
way geometry,
|
||||||
|
props jsonb
|
||||||
|
);
|
||||||
|
|
||||||
-- Run ST_SimplifyWM in debug mode, so `wm_debug` is populated. That table
|
-- Run ST_SimplifyWM in debug mode, so `wm_debug` is populated. That table
|
||||||
-- is used for geometric assertions later in the file.
|
-- is used for geometric assertions later in the file.
|
||||||
|
26
tests.sql
26
tests.sql
@ -53,7 +53,9 @@ insert into wm_figures (name, way) values ('selfcrossing-1-rev',ST_Reverse(ST_Tr
|
|||||||
|
|
||||||
delete from wm_debug where name in (select distinct name from wm_figures);
|
delete from wm_debug where name in (select distinct name from wm_figures);
|
||||||
delete from wm_demo where name in (select distinct name from wm_figures);
|
delete from wm_demo where name in (select distinct name from wm_figures);
|
||||||
insert into wm_demo (name, way) select name, ST_SimplifyWM(way, 100, name) from wm_figures;
|
insert into wm_demo (name, way) select name, ST_SimplifyWM(way, 10000, name) from wm_figures where name != 'fig8';
|
||||||
|
insert into wm_demo (name, way) select name, ST_SimplifyWM(way, 15, name) from wm_figures where name = 'fig8';
|
||||||
|
|
||||||
|
|
||||||
do $$
|
do $$
|
||||||
declare fig6b1 geometry;
|
declare fig6b1 geometry;
|
||||||
@ -76,8 +78,8 @@ begin
|
|||||||
end $$ language plpgsql;
|
end $$ language plpgsql;
|
||||||
|
|
||||||
|
|
||||||
drop function if exists debug_wm_get;
|
drop function if exists wm_debug_get;
|
||||||
create function debug_wm_get(
|
create function wm_debug_get(
|
||||||
_stage text,
|
_stage text,
|
||||||
_name text,
|
_name text,
|
||||||
OUT ways geometry[]
|
OUT ways geometry[]
|
||||||
@ -91,14 +93,14 @@ do $$
|
|||||||
declare
|
declare
|
||||||
vbends geometry[];
|
vbends geometry[];
|
||||||
begin
|
begin
|
||||||
vbends = debug_wm_get('bbends', 'fig3');
|
vbends = wm_debug_get('bbends', 'fig3');
|
||||||
perform assert_equals(5, array_length(vbends, 1));
|
perform assert_equals(5, array_length(vbends, 1));
|
||||||
perform assert_equals('LINESTRING(0 0,12 0,13 4)', st_astext(vbends[1]));
|
perform assert_equals('LINESTRING(0 0,12 0,13 4)', st_astext(vbends[1]));
|
||||||
perform assert_equals('LINESTRING(12 0,13 4,20 2,20 0)', st_astext(vbends[2]));
|
perform assert_equals('LINESTRING(12 0,13 4,20 2,20 0)', st_astext(vbends[2]));
|
||||||
perform assert_equals('LINESTRING(20 2,20 0,32 0,33 10)', st_astext(vbends[3]));
|
perform assert_equals('LINESTRING(20 2,20 0,32 0,33 10)', st_astext(vbends[3]));
|
||||||
perform assert_equals('LINESTRING(32 0,33 10,38 16,43 15,44 10,44 0)', st_astext(vbends[4]));
|
perform assert_equals('LINESTRING(32 0,33 10,38 16,43 15,44 10,44 0)', st_astext(vbends[4]));
|
||||||
perform assert_equals(4, array_length(detect_bends((select way from wm_figures where name='fig3-1')), 1));
|
perform assert_equals(4, array_length(wm_detect_bends((select way from wm_figures where name='fig3-1')), 1));
|
||||||
select detect_bends((select way from wm_figures where name='fig5')) into vbends;
|
select wm_detect_bends((select way from wm_figures where name='fig5')) into vbends;
|
||||||
perform assert_equals(3, array_length(vbends, 1));
|
perform assert_equals(3, array_length(vbends, 1));
|
||||||
end $$ language plpgsql;
|
end $$ language plpgsql;
|
||||||
|
|
||||||
@ -107,7 +109,7 @@ declare
|
|||||||
vbends geometry[];
|
vbends geometry[];
|
||||||
vinflections geometry[];
|
vinflections geometry[];
|
||||||
begin
|
begin
|
||||||
vinflections = debug_wm_get('cinflections', 'fig5');
|
vinflections = wm_debug_get('cinflections', 'fig5');
|
||||||
perform assert_equals('LINESTRING(0 39,19 52,27 77)', st_astext(vinflections[1]));
|
perform assert_equals('LINESTRING(0 39,19 52,27 77)', st_astext(vinflections[1]));
|
||||||
perform assert_equals('LINESTRING(19 52,27 77,26 104,41 115,49 115,65 103,65 75,53 45)', st_astext(vinflections[2]));
|
perform assert_equals('LINESTRING(19 52,27 77,26 104,41 115,49 115,65 103,65 75,53 45)', st_astext(vinflections[2]));
|
||||||
perform assert_equals('LINESTRING(65 75,53 45,63 15,91 0)', st_astext(vinflections[3]));
|
perform assert_equals('LINESTRING(65 75,53 45,63 15,91 0)', st_astext(vinflections[3]));
|
||||||
@ -127,7 +129,7 @@ declare
|
|||||||
vcrossings geometry[];
|
vcrossings geometry[];
|
||||||
mutated boolean;
|
mutated boolean;
|
||||||
begin
|
begin
|
||||||
select * from self_crossing(debug_wm_get('cinflections', 'fig6')) into vcrossings, mutated;
|
select * from wm_self_crossing(wm_debug_get('cinflections', 'fig6')) into vcrossings, mutated;
|
||||||
perform assert_equals(true, mutated);
|
perform assert_equals(true, mutated);
|
||||||
perform assert_equals(
|
perform assert_equals(
|
||||||
fig6,
|
fig6,
|
||||||
@ -136,7 +138,7 @@ begin
|
|||||||
) from (select unnest(vcrossings) way) a)
|
) from (select unnest(vcrossings) way) a)
|
||||||
);
|
);
|
||||||
|
|
||||||
select * from self_crossing(debug_wm_get('cinflections', 'fig6-rev')) into vcrossings, mutated;
|
select * from wm_self_crossing(wm_debug_get('cinflections', 'fig6-rev')) into vcrossings, mutated;
|
||||||
perform assert_equals(true, mutated);
|
perform assert_equals(true, mutated);
|
||||||
perform assert_equals(
|
perform assert_equals(
|
||||||
fig6,
|
fig6,
|
||||||
@ -145,7 +147,7 @@ begin
|
|||||||
) from (select unnest(vcrossings) way) a)
|
) from (select unnest(vcrossings) way) a)
|
||||||
);
|
);
|
||||||
|
|
||||||
select * from self_crossing(debug_wm_get('cinflections', 'fig6-combi')) into vcrossings, mutated;
|
select * from wm_self_crossing(wm_debug_get('cinflections', 'fig6-combi')) into vcrossings, mutated;
|
||||||
perform assert_equals(true, mutated);
|
perform assert_equals(true, mutated);
|
||||||
perform assert_equals(
|
perform assert_equals(
|
||||||
'MULTILINESTRING((84 137,91 149,114 154,120 135,125 129,141 129,147 122),(164 137,171 149,194 154,200 135,205 129,221 129,227 122))',
|
'MULTILINESTRING((84 137,91 149,114 154,120 135,125 129,141 129,147 122),(164 137,171 149,194 154,200 135,205 129,221 129,227 122))',
|
||||||
@ -155,7 +157,7 @@ begin
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
select * from self_crossing(debug_wm_get('cinflections', 'selfcrossing-1')) into vcrossings, mutated;
|
select * from wm_self_crossing(wm_debug_get('cinflections', 'selfcrossing-1')) into vcrossings, mutated;
|
||||||
perform assert_equals(true, mutated);
|
perform assert_equals(true, mutated);
|
||||||
perform assert_equals(
|
perform assert_equals(
|
||||||
selfcrossing1,
|
selfcrossing1,
|
||||||
@ -164,7 +166,7 @@ begin
|
|||||||
) from (select unnest(vcrossings) way) a)
|
) from (select unnest(vcrossings) way) a)
|
||||||
);
|
);
|
||||||
|
|
||||||
select * from self_crossing(debug_wm_get('cinflections', 'selfcrossing-1-rev')) into vcrossings, mutated;
|
select * from wm_self_crossing(wm_debug_get('cinflections', 'selfcrossing-1-rev')) into vcrossings, mutated;
|
||||||
perform assert_equals(true, mutated);
|
perform assert_equals(true, mutated);
|
||||||
perform assert_equals(
|
perform assert_equals(
|
||||||
selfcrossing1,
|
selfcrossing1,
|
||||||
|
22
wm.sql
22
wm.sql
@ -351,7 +351,8 @@ create type wm_t_bend_attrs as (
|
|||||||
);
|
);
|
||||||
create function wm_bend_attrs(
|
create function wm_bend_attrs(
|
||||||
bends geometry[],
|
bends geometry[],
|
||||||
dbgname text default null
|
dbgname text default null,
|
||||||
|
dbggen integer default null
|
||||||
) returns setof wm_t_bend_attrs as $$
|
) returns setof wm_t_bend_attrs as $$
|
||||||
declare
|
declare
|
||||||
fourpi constant real default 4*radians(180);
|
fourpi constant real default 4*radians(180);
|
||||||
@ -388,10 +389,11 @@ begin
|
|||||||
end if;
|
end if;
|
||||||
|
|
||||||
if dbgname is not null then
|
if dbgname is not null then
|
||||||
insert into wm_debug (stage, name, nbend, way, props) values(
|
insert into wm_debug (stage, name, gen, nbend, way, props) values(
|
||||||
'ebendattrs',
|
'ebendattrs',
|
||||||
dbgname,
|
dbgname,
|
||||||
i,
|
i,
|
||||||
|
dbggen,
|
||||||
bend,
|
bend,
|
||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
'area', res.area,
|
'area', res.area,
|
||||||
@ -410,8 +412,8 @@ $$ language plpgsql;
|
|||||||
create function wm_elimination(
|
create function wm_elimination(
|
||||||
INOUT bendattrs wm_t_bend_attrs[],
|
INOUT bendattrs wm_t_bend_attrs[],
|
||||||
dhalfcircle float,
|
dhalfcircle float,
|
||||||
dbgname text,
|
dbgname text default null,
|
||||||
dbggen int4,
|
dbggen integer default null,
|
||||||
OUT mutated boolean
|
OUT mutated boolean
|
||||||
) as $$
|
) as $$
|
||||||
declare
|
declare
|
||||||
@ -461,7 +463,7 @@ begin
|
|||||||
for j in 1..array_length(bendattrs, 1) loop
|
for j in 1..array_length(bendattrs, 1) loop
|
||||||
dbgbends[j] = bendattrs[j].bend;
|
dbgbends[j] = bendattrs[j].bend;
|
||||||
end loop;
|
end loop;
|
||||||
|
|
||||||
insert into wm_debug(stage, name, gen, nbend, way) values(
|
insert into wm_debug(stage, name, gen, nbend, way) values(
|
||||||
'eelimination',
|
'eelimination',
|
||||||
dbgname,
|
dbgname,
|
||||||
@ -475,7 +477,8 @@ $$ language plpgsql;
|
|||||||
|
|
||||||
create function wm_isolated_bends(
|
create function wm_isolated_bends(
|
||||||
INOUT bendattrs wm_t_bend_attrs[],
|
INOUT bendattrs wm_t_bend_attrs[],
|
||||||
dbgname text default null
|
dbgname text default null,
|
||||||
|
dbggen integer default null
|
||||||
) as $$
|
) as $$
|
||||||
declare
|
declare
|
||||||
-- if neighbor's curvatures are within this fraction of the current bend
|
-- if neighbor's curvatures are within this fraction of the current bend
|
||||||
@ -499,9 +502,10 @@ begin
|
|||||||
end if;
|
end if;
|
||||||
|
|
||||||
if dbgname is not null then
|
if dbgname is not null then
|
||||||
insert into wm_debug (stage, name, nbend, way, props) values(
|
insert into wm_debug (stage, name, gen, nbend, way, props) values(
|
||||||
'fisolated_bends',
|
'fisolated_bends',
|
||||||
dbgname,
|
dbgname,
|
||||||
|
dbggen,
|
||||||
i,
|
i,
|
||||||
res.bend,
|
res.bend,
|
||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
@ -615,7 +619,7 @@ begin
|
|||||||
continue;
|
continue;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
bendattrs = array((select wm_bend_attrs(bends, dbgname)));
|
bendattrs = array((select wm_bend_attrs(bends, dbgname, gen)));
|
||||||
|
|
||||||
select * from wm_elimination(
|
select * from wm_elimination(
|
||||||
bendattrs, dhalfcircle, dbgname, gen) into bendattrs, mutated;
|
bendattrs, dhalfcircle, dbgname, gen) into bendattrs, mutated;
|
||||||
@ -629,7 +633,7 @@ begin
|
|||||||
continue;
|
continue;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
perform wm_isolated_bends(bendattrs, dbgname);
|
perform wm_isolated_bends(bendattrs, dbgname, gen);
|
||||||
end loop;
|
end loop;
|
||||||
|
|
||||||
end loop;
|
end loop;
|
||||||
|
Loading…
Reference in New Issue
Block a user