pi is a constant

This commit is contained in:
Motiejus Jakštys 2021-04-03 09:45:35 +03:00
parent 7475df5394
commit 0403100d11

View File

@ -5,7 +5,7 @@ SET plpgsql.extra_errors TO 'all';
drop function if exists detect_bends; drop function if exists detect_bends;
create function detect_bends(line geometry, OUT bends geometry[]) as $$ create function detect_bends(line geometry, OUT bends geometry[]) as $$
declare declare
pi real; pi constant real default radians(180);
p geometry; p geometry;
p1 geometry; p1 geometry;
p2 geometry; p2 geometry;
@ -14,7 +14,6 @@ declare
prev_sign int4; prev_sign int4;
cur_sign int4; cur_sign int4;
begin begin
pi = radians(180);
-- the last vertex is iterated over twice, because the algorithm uses 3 -- the last vertex is iterated over twice, because the algorithm uses 3
-- vertices to calculate the angle between them. -- vertices to calculate the angle between them.
@ -100,13 +99,12 @@ $$ language plpgsql;
drop function if exists fix_gentle_inflections1; drop function if exists fix_gentle_inflections1;
create function fix_gentle_inflections1(INOUT bends geometry[]) as $$ create function fix_gentle_inflections1(INOUT bends geometry[]) as $$
declare declare
pi real; pi constant real default radians(180);
small_angle real; small_angle real;
ptail geometry; -- tail point of tail bend ptail geometry; -- tail point of tail bend
phead geometry[]; -- 3 tail points of head bend phead geometry[]; -- 3 tail points of head bend
i int4; -- bends[i] is the current head i int4; -- bends[i] is the current head
begin begin
pi = radians(180);
-- the threshold when the angle is still "small", so gentle inflections can -- the threshold when the angle is still "small", so gentle inflections can
-- be joined -- be joined
small_angle := radians(30); small_angle := radians(30);
@ -170,7 +168,7 @@ create function self_crossing(
OUT mutated boolean OUT mutated boolean
) as $$ ) as $$
declare declare
pi real; pi constant real default radians(180);
i int4; i int4;
j int4; j int4;
prev_length int4; prev_length int4;
@ -178,7 +176,6 @@ declare
b geometry; b geometry;
multi geometry; multi geometry;
begin begin
pi = radians(180);
mutated = false; mutated = false;
-- go through the bends and find one where sum of inflection angle is >180 -- go through the bends and find one where sum of inflection angle is >180
@ -244,17 +241,13 @@ $$ language plpgsql;
drop function if exists inflection_angle; drop function if exists inflection_angle;
create function inflection_angle (IN bend geometry, OUT angle real) as $$ create function inflection_angle (IN bend geometry, OUT angle real) as $$
declare declare
pi real; pi constant real default radians(180);
p0 geometry; p0 geometry;
p1 geometry; p1 geometry;
p2 geometry; p2 geometry;
p3 geometry; p3 geometry;
begin begin
pi = radians(180);
angle = 0; angle = 0;
p1 = null;
p2 = null;
p3 = null;
for p0 in ( for p0 in (
select geom from st_dumppoints(bend) order by path[1] asc select geom from st_dumppoints(bend) order by path[1] asc
) loop ) loop