From aeb270925e9ec97dd8d0fc7f50fae69212e5b0fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Wed, 10 Mar 2021 17:30:17 +0200 Subject: [PATCH] unit tests for self-crossings --- IV/tests.sql | 23 +++++++++++++++++++++-- IV/wm.sql | 6 ++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/IV/tests.sql b/IV/tests.sql index 4a1967a..5d761f1 100644 --- a/IV/tests.sql +++ b/IV/tests.sql @@ -46,8 +46,6 @@ create table demo_selfcrossing3 (name text, i bigint, way geometry); insert into demo_selfcrossing3 select name, generate_subscripts(ways, 1), unnest(ways) from selfcrossing; -\q - do $$ declare vbends geometry[]; @@ -81,3 +79,24 @@ begin 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])); end $$ language plpgsql; + +do $$ +declare + vcrossings geometry[]; +begin + select self_crossing((select ways from inflections where name='fig6')) into vcrossings; + perform assert_equals( + 'LINESTRING(84 47,91 59,114 64,120 45,125 39,141 39,147 32)', + (select st_astext( + st_linemerge(st_union(way)) + ) from (select unnest(vcrossings) way) a) + ); + + select self_crossing((select ways from inflections where name='fig6-rev')) into vcrossings; + perform assert_equals( + 'LINESTRING(84 47,91 59,114 64,120 45,125 39,141 39,147 32)', + (select st_astext( + st_translate(st_reverse(st_linemerge(st_union(way))), -80, 0) + ) from (select unnest(vcrossings) way) a) + ); +end $$ language plpgsql; diff --git a/IV/wm.sql b/IV/wm.sql index edd2dce..ab16593 100644 --- a/IV/wm.sql +++ b/IV/wm.sql @@ -234,8 +234,10 @@ begin -- segment is always duplicated with the i-th bend. bends[i+1] = st_removepoint(bends[i+1], 0); bends[j] = st_geometryn(multi, 1); - bends[j] = st_setpoint(bends[j], st_npoints(bends[j])-1, - st_pointn(bends[i], st_npoints(bends[i]))); + bends[j] = st_setpoint( + bends[j], st_npoints(bends[j])-1, + st_pointn(bends[i], st_npoints(bends[i])) + ); bends = bends[1:j] || bends[i+1:prev_length]; j = i; else