wip start wm_exaggeration

This commit is contained in:
Motiejus Jakštys 2021-05-04 17:16:01 +03:00
parent edf2989857
commit 534a9b9814

View File

@ -10,7 +10,6 @@ create function wm_detect_bends(
OUT bends geometry[] OUT bends geometry[]
) as $$ ) as $$
declare declare
pi constant real default radians(180);
p geometry; p geometry;
p1 geometry; p1 geometry;
p2 geometry; p2 geometry;
@ -52,7 +51,7 @@ begin
p1 = p; p1 = p;
continue when p3 is null; continue when p3 is null;
cur_sign = sign(pi - st_angle(p1, p2, p2, p3)); cur_sign = sign(pi() - st_angle(p1, p2, p2, p3));
if bend is null then if bend is null then
bend = st_makeline(p3, p2); bend = st_makeline(p3, p2);
@ -170,7 +169,6 @@ $$ language plpgsql;
drop function if exists wm_fix_gentle_inflections1; drop function if exists wm_fix_gentle_inflections1;
create function wm_fix_gentle_inflections1(INOUT bends geometry[]) as $$ create function wm_fix_gentle_inflections1(INOUT bends geometry[]) as $$
declare declare
pi constant real default 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 constant real default radians(45); small_angle constant real default radians(45);
@ -214,7 +212,7 @@ begin
exit when array_length(phead, 1) < 3; exit when array_length(phead, 1) < 3;
-- inflection angle between ptail[1:3] is "large", stop processing -- inflection angle between ptail[1:3] is "large", stop processing
exit when abs(st_angle(phead[1], phead[2], phead[3]) - pi) > small_angle; exit when abs(st_angle(phead[1], phead[2], phead[3]) - pi()) > small_angle;
-- distance from head's 1st vertex should be larger than from 2nd vertex -- distance from head's 1st vertex should be larger than from 2nd vertex
exit when st_distance(ptail, phead[2]) < st_distance(ptail, phead[3]); exit when st_distance(ptail, phead[2]) < st_distance(ptail, phead[3]);
@ -271,7 +269,6 @@ create function wm_self_crossing(
OUT mutated boolean OUT mutated boolean
) as $$ ) as $$
declare declare
pi constant real default radians(180);
i int4; i int4;
j int4; j int4;
multi geometry; multi geometry;
@ -279,7 +276,7 @@ begin
mutated = false; mutated = false;
<<bendloop>> <<bendloop>>
for i in 1..array_length(bends, 1) loop for i in 1..array_length(bends, 1) loop
continue when abs(wm_inflection_angle(bends[i])) <= pi; continue when abs(wm_inflection_angle(bends[i])) <= pi();
-- sum of inflection angles for this bend is >180, so it may be -- sum of inflection angles for this bend is >180, so it may be
-- self-crossing. Now try to find another bend in this line that -- self-crossing. Now try to find another bend in this line that
-- crosses an imaginary line of end-vertices -- crosses an imaginary line of end-vertices
@ -337,7 +334,6 @@ $$ language plpgsql;
drop function if exists wm_inflection_angle; drop function if exists wm_inflection_angle;
create function wm_inflection_angle (IN bend geometry, OUT angle real) as $$ create function wm_inflection_angle (IN bend geometry, OUT angle real) as $$
declare declare
pi constant real default radians(180);
p0 geometry; p0 geometry;
p1 geometry; p1 geometry;
p2 geometry; p2 geometry;
@ -349,7 +345,7 @@ begin
p2 = p1; p2 = p1;
p1 = p0; p1 = p0;
continue when p3 is null; continue when p3 is null;
angle = angle + abs(pi - st_angle(p1, p2, p3)); angle = angle + abs(pi() - st_angle(p1, p2, p3));
end loop; end loop;
end end
$$ language plpgsql; $$ language plpgsql;
@ -357,6 +353,7 @@ $$ language plpgsql;
drop function if exists wm_bend_attrs; drop function if exists wm_bend_attrs;
drop function if exists wm_isolated_bends; drop function if exists wm_isolated_bends;
drop function if exists wm_elimination; drop function if exists wm_elimination;
drop function if exists wm_exaggeration;
drop type if exists wm_t_bend_attrs; drop type if exists wm_t_bend_attrs;
create type wm_t_bend_attrs as ( create type wm_t_bend_attrs as (
bend geometry, bend geometry,
@ -427,6 +424,20 @@ begin
end; end;
$$ language plpgsql; $$ language plpgsql;
create function wm_exaggeration(
INOUT bendattrs wm_t_bend_attrs[],
dhalfcircle float,
dbgname text default null,
dbggen integer default null,
OUT mutated boolean
) as $$
declare
area_threshold float;
begin
end
$$ language plpgsql;
create function wm_elimination( create function wm_elimination(
INOUT bendattrs wm_t_bend_attrs[], INOUT bendattrs wm_t_bend_attrs[],
dhalfcircle float, dhalfcircle float,
@ -637,6 +648,13 @@ begin
bendattrs = array((select wm_bend_attrs(bends, dbgname, gen))); bendattrs = array((select wm_bend_attrs(bends, dbgname, gen)));
-- code to detect isolated bends is there, but bend exaggeration
-- is not implemented.
perform wm_isolated_bends(bendattrs, dbgname, gen);
select * from wm_exaggeration(
bendattrs, dhalfcircle, dbgname, gen) into bendattrs, mutated;
select * from wm_elimination( select * from wm_elimination(
bendattrs, dhalfcircle, dbgname, gen) into bendattrs, mutated; bendattrs, dhalfcircle, dbgname, gen) into bendattrs, mutated;
if mutated then if mutated then
@ -647,10 +665,6 @@ begin
gen = gen + 1; gen = gen + 1;
continue; continue;
end if; end if;
-- code to detect isolated bends is there, but bend exaggeration
-- is not implemented.
--perform wm_isolated_bends(bendattrs, dbgname, gen);
end loop; end loop;
end loop; end loop;