From 0e23fc0f7b9904d62a8d67d1a2023713830985d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Wed, 19 May 2021 22:57:45 +0300 Subject: [PATCH] tests for bends vs inflections --- tests.sql | 18 +++++++++++++----- wm.sql | 6 ++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/tests.sql b/tests.sql index 0592fa6..b981d09 100644 --- a/tests.sql +++ b/tests.sql @@ -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; diff --git a/wm.sql b/wm.sql index 5ddb216..39b3e32 100644 --- a/wm.sql +++ b/wm.sql @@ -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(