remove incorrect direction approximation rules

This commit is contained in:
Motiejus Jakštys 2021-03-10 16:33:56 +02:00
parent 59ab1822b5
commit 97ce2e6a7f
3 changed files with 2 additions and 19 deletions

View File

@ -40,11 +40,6 @@ inflection angles (AB in our examples) must be crossed with all the other bends
to detect a possible line-crossing. This is O(N*M), where N is the total number to detect a possible line-crossing. This is O(N*M), where N is the total number
of line segments, and M is the number of qualifying bends. It is expensive. of line segments, and M is the number of qualifying bends. It is expensive.
This may be simplified: if other bend's endpoints (A' and B') are in the same
sub-plane as divided by AB, then the bend can be skipped from checking if it
intersects with AB. Some intersections may be missed (see the last example),
but they will be eliminated by joining A and B anyway.
Also, there is another way to remove self-crossing, without removing most of Also, there is another way to remove self-crossing, without removing most of
the bend. E.g. from: the bend. E.g. from:
@ -69,4 +64,4 @@ 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. article to do the right thing here and remove the bend altogether.

View File

@ -18,7 +18,7 @@ create table figures (name text, way geometry);
--insert into figures (name, way) values ('fig3-1',ST_GeomFromText('LINESTRING(0 0,12 0,13 4,20 2,20 0,32 0,33 10,38 16,43 15,44 10,44 0)')); --insert into figures (name, way) values ('fig3-1',ST_GeomFromText('LINESTRING(0 0,12 0,13 4,20 2,20 0,32 0,33 10,38 16,43 15,44 10,44 0)'));
--insert into figures (name, way) values ('fig5',ST_GeomFromText('LINESTRING(0 39,19 52,27 77,26 104,41 115,49 115,65 103,65 75,53 45,63 15,91 0)')); --insert into figures (name, way) values ('fig5',ST_GeomFromText('LINESTRING(0 39,19 52,27 77,26 104,41 115,49 115,65 103,65 75,53 45,63 15,91 0)'));
insert into figures (name, way) values ('fig6',ST_GeomFromText('LINESTRING(84 47,91 59,114 64,122 80,116 92,110 93,106 106,117 118,136 107,135 76,120 45,125 39,141 39,147 32)')); insert into figures (name, way) values ('fig6',ST_GeomFromText('LINESTRING(84 47,91 59,114 64,122 80,116 92,110 93,106 106,117 118,136 107,135 76,120 45,125 39,141 39,147 32)'));
--insert into figures (name, way) values ('fig6-rev',ST_Reverse(ST_Translate((select way from figures where name='fig6'), 80, 0))); insert into figures (name, way) values ('fig6-rev',ST_Reverse(ST_Translate((select way from figures where name='fig6'), 80, 0)));
--insert into figures (name, way) values ('inflection-1',ST_GeomFromText('LINESTRING(110 24,114 20,133 20,145 15,145 0,136 5,123 7,114 7,111 2)')); --insert into figures (name, way) values ('inflection-1',ST_GeomFromText('LINESTRING(110 24,114 20,133 20,145 15,145 0,136 5,123 7,114 7,111 2)'));
drop table if exists debug; drop table if exists debug;

View File

@ -178,8 +178,6 @@ declare
p3 geometry; p3 geometry;
a geometry; a geometry;
b geometry; b geometry;
s2 real;
s3 real;
bend geometry; bend geometry;
this geometry; this geometry;
multi geometry; multi geometry;
@ -224,20 +222,10 @@ begin
raise notice 'j: %, i: %', j, i; raise notice 'j: %, i: %', j, i;
-- are p2 and p3 on the different sides of line(p0,p1)? vector
-- multiplication; 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)));
raise notice 'sign(s2): %, sign(s3): %', sign(s2), sign(s3);
continue when sign(s2) = sign(s3);
-- do end vertices of bend[i] cross bend[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));
insert into debug (i, way) values (0, st_geometryn(multi, 1));
raise notice 'bends[i]: %', st_astext(bends[i]); raise notice 'bends[i]: %', st_astext(bends[i]);
raise notice 'bends[j]: %', st_astext(bends[j]); raise notice 'bends[j]: %', st_astext(bends[j]);
raise notice 'a: %, b: %', st_astext(a), st_astext(b); raise notice 'a: %, b: %', st_astext(a), st_astext(b);