remove array_reverse()

main
Motiejus Jakštys 2021-05-19 22:57:45 +03:00 committed by Motiejus Jakštys
parent 395d8a87f6
commit 8cde484775
1 changed files with 7 additions and 17 deletions

24
wm.sql
View File

@ -74,22 +74,24 @@ $$ language plpgsql;
-- The text does not specify how many vertices can be "adjusted"; it can -- 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 -- equally be one or many. This function is adjusting many, as long as the
-- commulative inflection angle small (see variable below). -- 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 $$ create or replace function fix_gentle_inflections(INOUT bends geometry[]) as $$
declare declare
len int4; len int4;
bends1 geometry[]; bends1 geometry[];
bends2 geometry[];
begin begin
len = array_length(bends, 1); len = array_length(bends, 1);
bends1 = fix_gentle_inflections1(bends); bends = fix_gentle_inflections1(bends);
for i in 1..len loop for i in 1..len loop
bends2[i] = st_reverse(bends1[len-i+1]); bends1[i] = st_reverse(bends[len-i+1]);
end loop; end loop;
bends2 = fix_gentle_inflections1(bends2); bends1 = fix_gentle_inflections1(bends1);
for i in 1..len loop 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 loop;
end end
$$ language plpgsql; $$ language plpgsql;
@ -166,15 +168,3 @@ begin
end loop; end loop;
end end
$$ language plpgsql; $$ 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;