From 58d3068a3b617744b82b8e92981e7c679b111787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Fri, 26 Feb 2021 19:15:39 +0200 Subject: [PATCH] remove array_reverse() --- IV/wm.sql | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/IV/wm.sql b/IV/wm.sql index 5ab7326..2c795db 100644 --- a/IV/wm.sql +++ b/IV/wm.sql @@ -74,22 +74,24 @@ $$ language plpgsql; -- The text does not specify how many vertices can be "adjusted"; it can -- equally be one or many. This function is adjusting many, as long as the -- commulative inflection angle small (see variable below). +-- +-- The implementation could be significantly optimized to avoid `st_reverse` +-- and array reversals, trading for complexity in fix_gentle_inflections1. create or replace function fix_gentle_inflections(INOUT bends geometry[]) as $$ declare len int4; bends1 geometry[]; - bends2 geometry[]; begin len = array_length(bends, 1); - bends1 = fix_gentle_inflections1(bends); + bends = fix_gentle_inflections1(bends); for i in 1..len loop - bends2[i] = st_reverse(bends1[len-i+1]); + bends1[i] = st_reverse(bends[len-i+1]); end loop; - bends2 = fix_gentle_inflections1(bends2); + bends1 = fix_gentle_inflections1(bends1); for i in 1..len loop - bends[i] = st_reverse(bends2[len-i+1]); + bends[i] = st_reverse(bends1[len-i+1]); end loop; end $$ language plpgsql; @@ -166,15 +168,3 @@ begin end loop; end $$ language plpgsql; - --- https://wiki.postgresql.org/wiki/Array_reverse -create or replace function array_reverse(anyarray) returns anyarray as $$ -select array( - select $1[i] - from generate_series( - array_lower($1,1), - array_upper($1,1) - ) as s(i) - order by i desc -); -$$ language 'sql' strict immutable;