tests for bends vs inflections

main
Motiejus Jakštys 2021-05-19 22:57:45 +03:00 committed by Motiejus Jakštys
parent 02f2ac3e60
commit 0e23fc0f7b
2 changed files with 17 additions and 7 deletions

View File

@ -25,28 +25,36 @@ insert into bends select unnest(detect_bends((select way from figures where name
insert into bends select unnest(detect_bends((select way from figures where name='fig5')));
insert into bends select unnest(detect_bends((select way from figures where name='inflection-1')));
-- DETECT BENDS
do $$
declare
vbends geometry[];
begin
-- DETECT BENDS
select detect_bends((select way from figures where name='fig3')) into vbends;
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(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(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 figures where name='fig3-1')), 1));
select detect_bends((select way from figures where name='fig5')) into vbends;
perform assert_equals(3, array_length(vbends, 1));
end $$ language plpgsql;
-- FIX BEND INFLECTIONS
-- FIX BEND INFLECTIONS
do $$
declare
vbends geometry[];
vinflections geometry[];
begin
select detect_bends((select way from figures where name='inflection-1')) into vbends;
select fix_gentle_inflections(vbends) into vinflections;
perform assert_equals(vbends[1], vinflections[1]); -- unchanged
perform assert_equals('LINESTRING(114 20,133 20,145 15,145 0,136 5,123 7,114 7)', st_astext(vinflections[2]));
perform assert_equals('LINESTRING(123 7,114 7,111 2)', st_astext(vinflections[3]));
drop table if exists inflections;
create table inflections (way geometry);
insert into inflections select unnest(fix_gentle_inflections(vbends));
end $$ language plpgsql;

6
wm.sql
View File

@ -98,7 +98,7 @@ begin
-- Then edges (A,B) and (E,F) are shared with the neighboring bends.
--
--
-- Assume this curve (figure `inflection-1`):
-- Assume this curve (figure `inflection-1`), going clockwise from A:
--
-- \______B
-- A `-------. C
@ -110,7 +110,9 @@ begin
-- After processing the curve following the definition of a bend, the bend
-- [A-E] would be detected. Assuming inflection point E and F are "small",
-- the bend needs to be extended by two edges to [A,G].
select geom from st_dumppoints(bends[i-1]) order by path[1] asc limit 1 into ptail;
select geom from st_dumppoints(bends[i-1])
order by path[1] asc limit 1 into ptail;
while true loop
-- copy last 3 points of bends[i-1] (tail) to ptail
select array(