wip self-crossing
This commit is contained in:
parent
545aff111f
commit
72f89360f7
50
IV/wm.sql
50
IV/wm.sql
@ -41,9 +41,8 @@ begin
|
|||||||
p3 = p2;
|
p3 = p2;
|
||||||
p2 = p1;
|
p2 = p1;
|
||||||
p1 = p;
|
p1 = p;
|
||||||
if p3 is null then
|
continue when p3 is null;
|
||||||
continue;
|
|
||||||
end if;
|
|
||||||
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
|
||||||
@ -169,10 +168,12 @@ declare
|
|||||||
j int4;
|
j int4;
|
||||||
pi real;
|
pi real;
|
||||||
angle real;
|
angle real;
|
||||||
p geometry;
|
p0 geometry;
|
||||||
p1 geometry;
|
p1 geometry;
|
||||||
p2 geometry;
|
p2 geometry;
|
||||||
p3 geometry;
|
p3 geometry;
|
||||||
|
s2 real;
|
||||||
|
s3 real;
|
||||||
bend geometry;
|
bend geometry;
|
||||||
begin
|
begin
|
||||||
pi = radians(180);
|
pi = radians(180);
|
||||||
@ -183,28 +184,43 @@ begin
|
|||||||
p1 = null;
|
p1 = null;
|
||||||
p2 = null;
|
p2 = null;
|
||||||
p3 = null;
|
p3 = null;
|
||||||
for p in (select geom from st_dumppoints(bends[i]) order by path[1] asc) loop
|
for p0 in (select geom from st_dumppoints(bends[i]) order by path[1] asc) loop
|
||||||
p3 = p2;
|
p3 = p2;
|
||||||
p2 = p1;
|
p2 = p1;
|
||||||
p1 = p;
|
p1 = p0;
|
||||||
if p3 is null then
|
continue when p3 is null;
|
||||||
continue;
|
|
||||||
end if;
|
|
||||||
angle = angle + abs(pi - st_angle(p1, p2, p3));
|
angle = angle + abs(pi - st_angle(p1, p2, p3));
|
||||||
end loop;
|
end loop;
|
||||||
|
|
||||||
if abs(angle) > pi then
|
continue when abs(angle) <= pi;
|
||||||
raise notice 'maybe self-crossing bend %: %', st_astext(bends[i]), round(degrees(abs(angle)));
|
|
||||||
-- 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 crosses this one.
|
|
||||||
for j in 1..array_length(bends, 1) loop
|
|
||||||
continue when i = j;
|
|
||||||
|
|
||||||
|
-- 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 crosses this one.
|
||||||
|
p0 = st_pointn(bends[i], 1);
|
||||||
|
p1 = st_pointn(bends[i], -1);
|
||||||
|
--this = st_makeline(st_pointn(bends[i], 1), st_pointn(bends[i], -1));
|
||||||
|
|
||||||
|
-- go through each bend in this line, and see if has a potential to cross bends[i].
|
||||||
|
-- optimization: we care only about bends which beginning and end start at different
|
||||||
|
-- sides of the plane, separated by endpoints p0 and p1.
|
||||||
|
for j in 1..array_length(bends, 1) loop
|
||||||
|
continue when i = j;
|
||||||
|
|
||||||
end loop;
|
p2 = st_pointn(bends[j], 1);
|
||||||
|
p3 = st_pointn(bends[j], -1);
|
||||||
|
|
||||||
|
-- https://stackoverflow.com/questions/1560492
|
||||||
|
s2 = (st_x(p0)-st_x(p1)*(st_y(p2)-st_y(p1))-(st_y(p0)-st_y(p1))*(st_x(p2)-st_x(p1)));
|
||||||
|
s3 = (st_x(p0)-st_x(p1)*(st_y(p3)-st_y(p1))-(st_y(p0)-st_y(p1))*(st_x(p3)-st_x(p1)));
|
||||||
|
continue when sign(s2) = sign(s3);
|
||||||
|
|
||||||
|
-- bend j may be crossing bend i, and it has a chance to be "important" --
|
||||||
|
-- p2 and p3 are in different sides of the plane as delimited by p0 and p1.
|
||||||
|
-- now does it really cross the line (p0, p1)?
|
||||||
|
|
||||||
|
end loop;
|
||||||
|
|
||||||
end if;
|
|
||||||
end loop;
|
end loop;
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user