self-crossing bugfix
This commit is contained in:
parent
9f717f1e3a
commit
d390d373a9
14
notes.txt
14
notes.txt
@ -52,6 +52,20 @@ To:
|
|||||||
But perhaps it doesn't look quite as natural. I will trust the original
|
But perhaps it doesn't look quite as natural. I will trust the original
|
||||||
article to do the right thing here and remove the bend altogether.
|
article to do the right thing here and remove the bend altogether.
|
||||||
|
|
||||||
|
ALSO: the bends should be iterated from different directions:
|
||||||
|
|
||||||
|
for i := 0; i < len(bends); i++ {
|
||||||
|
for j := 0; j < i; j++ {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
for j := len(bends); j > i; j-- {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
So if there are multiple bends between the baseline, they will be cut
|
||||||
|
correctly.
|
||||||
|
|
||||||
The Context of a Bend
|
The Context of a Bend
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
@ -53,7 +53,9 @@ insert into wm_figures (name, way) values ('inflection-1',ST_GeomFromText('LINES
|
|||||||
insert into wm_figures (name, way) values ('multi-island',ST_GeomFromText('MULTILINESTRING((-15 10,-10 10,-5 11,0 11,5 11,10 10,11 9,13 10,15 9),(-5 11,-2 15,0 16,2 15,5 11))'));
|
insert into wm_figures (name, way) values ('multi-island',ST_GeomFromText('MULTILINESTRING((-15 10,-10 10,-5 11,0 11,5 11,10 10,11 9,13 10,15 9),(-5 11,-2 15,0 16,2 15,5 11))'));
|
||||||
|
|
||||||
-- TODO: there is a bug and it does not go through `self_crossing` function.
|
-- TODO: there is a bug and it does not go through `self_crossing` function.
|
||||||
--insert into wm_figures (name, way) values ('selfcrossing-1',ST_GeomFromText('LINESTRING(-27 180,-20 166,-21 142,-18 136,55 136,55 136,71 145,44 165,37 146,22 145,14 164,11 164,3 146,-12 146,-13 176,-18 184)'));
|
insert into wm_figures (name, way) values ('selfcrossing-1',ST_GeomFromText('LINESTRING(-27 180,-20 166,-21 142,-18 136,55 136,55 136,71 145,44 165,37 146,22 145,14 164,11 164,3 146,-12 146,-13 176,-18 184)'));
|
||||||
|
insert into wm_figures (name, way) values ('selfcrossing-1-rev',ST_Reverse(ST_Translate((select way from wm_figures where name='selfcrossing-1'), 60, 0)));
|
||||||
|
|
||||||
|
|
||||||
-- Run ST_SimplifyWM in debug mode, so `wm_debug` is populated. That table
|
-- Run ST_SimplifyWM in debug mode, so `wm_debug` is populated. That table
|
||||||
-- is used for geometric assertions later in the file.
|
-- is used for geometric assertions later in the file.
|
||||||
|
38
wm.sql
38
wm.sql
@ -236,12 +236,7 @@ begin
|
|||||||
|
|
||||||
-- go through each bend in the given line, and see if has a potential to
|
-- go through each bend in the given line, and see if has a potential to
|
||||||
-- cross bends[i].
|
-- cross bends[i].
|
||||||
j = 0;
|
for j in 1..i-1 loop
|
||||||
while j < array_length(bends, 1) loop
|
|
||||||
j = j + 1;
|
|
||||||
continue when i = j;
|
|
||||||
|
|
||||||
-- do end vertices of bend[i] cross bend[j]?
|
|
||||||
a = st_pointn(bends[i], 1);
|
a = st_pointn(bends[i], 1);
|
||||||
b = st_pointn(bends[i], -1);
|
b = st_pointn(bends[i], -1);
|
||||||
multi = st_split(bends[j], st_makeline(a, b));
|
multi = st_split(bends[j], st_makeline(a, b));
|
||||||
@ -257,7 +252,7 @@ begin
|
|||||||
-- figure out what happens here, by hand. I know it's hard to follow.
|
-- figure out what happens here, by hand. I know it's hard to follow.
|
||||||
-- Apologies.
|
-- Apologies.
|
||||||
prev_length = array_length(bends, 1);
|
prev_length = array_length(bends, 1);
|
||||||
if j < i then
|
|
||||||
-- remove first vertex of the following bend, because the last
|
-- remove first vertex of the following bend, because the last
|
||||||
-- segment is always duplicated with the i'th bend.
|
-- segment is always duplicated with the i'th bend.
|
||||||
bends[i+1] = st_removepoint(bends[i+1], 0);
|
bends[i+1] = st_removepoint(bends[i+1], 0);
|
||||||
@ -268,24 +263,35 @@ begin
|
|||||||
st_pointn(bends[i], st_npoints(bends[i]))
|
st_pointn(bends[i], st_npoints(bends[i]))
|
||||||
);
|
);
|
||||||
bends = bends[1:j] || bends[i+1:prev_length];
|
bends = bends[1:j] || bends[i+1:prev_length];
|
||||||
j = i;
|
exit;
|
||||||
else
|
end loop;
|
||||||
|
|
||||||
|
for j in reverse array_length(bends, 1)..i+1 loop
|
||||||
|
a = st_pointn(bends[i], 1);
|
||||||
|
b = st_pointn(bends[i], -1);
|
||||||
|
multi = st_split(bends[j], st_makeline(a, b));
|
||||||
|
continue when st_numgeometries(multi) = 1;
|
||||||
|
continue when st_numgeometries(multi) = 2 and
|
||||||
|
(st_contains(bends[j], a) or st_contains(bends[j], b));
|
||||||
|
|
||||||
|
-- vertices, segments and stars are aligned, we are changing the bend
|
||||||
|
mutated = true;
|
||||||
|
|
||||||
|
-- To understand the block below, I suggest you take a pencil and paper,
|
||||||
|
-- draw a self-crossing bend (fig6 from the article works well), and
|
||||||
|
-- figure out what happens here, by hand. I know it's hard to follow.
|
||||||
|
-- Apologies.
|
||||||
|
prev_length = array_length(bends, 1);
|
||||||
-- remove last vertex of the previous bend, because the last
|
-- remove last vertex of the previous bend, because the last
|
||||||
-- segment is duplicated with the i'th bend.
|
-- segment is duplicated with the i'th bend.
|
||||||
bends[i-1] = st_removepoint(bends[i-1], st_npoints(bends[i-1])-1);
|
bends[i-1] = st_removepoint(bends[i-1], st_npoints(bends[i-1])-1);
|
||||||
-- continue debugging the selfcrossing-1 here.
|
-- continue debugging the selfcrossing-1 here.
|
||||||
--raise notice 'previous bend: %', st_astext(bends[i-1]);
|
|
||||||
--raise notice 'multi: %', st_astext(multi);
|
|
||||||
--raise notice '2: removing first point from %', st_astext(st_geometryn(multi, st_numgeometries(multi)));
|
|
||||||
--mutated = false;
|
|
||||||
--return;
|
|
||||||
bends[i] = st_makeline(
|
bends[i] = st_makeline(
|
||||||
st_pointn(bends[i], 1),
|
st_pointn(bends[i], 1),
|
||||||
st_removepoint(st_geometryn(multi, st_numgeometries(multi)), 0)
|
st_removepoint(st_geometryn(multi, st_numgeometries(multi)), 0)
|
||||||
);
|
);
|
||||||
bends = bends[1:i] || bends[j+1:prev_length];
|
bends = bends[1:i] || bends[j+1:prev_length];
|
||||||
end if;
|
exit;
|
||||||
j = j - prev_length + array_length(bends, 1);
|
|
||||||
end loop;
|
end loop;
|
||||||
end loop;
|
end loop;
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user