Skip to content

Commit

Permalink
Fix intersecting linestrings
Browse files Browse the repository at this point in the history
This commit fixes an issue where fully contained linestrings are
not intersecting.

Fixes #3
  • Loading branch information
tidwall committed Sep 25, 2023
1 parent 57ed66b commit b0af7c4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
60 changes: 60 additions & 0 deletions tests/relations/line.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -378,5 +378,65 @@
"overlaps": ["F", "F"],
"touches": ["F", "F"]
}
},
{
"geoms": [
"LINESTRING(1 0, 2 0)",
"LINESTRING(0 0,3 0)"
],
"dims": [ 1, 1 ],
"relate": [ "1FF0FF102", "101FF0FF2" ],
"predicates": {
"equals": ["F", "F"],
"intersects": ["T", "T"],
"disjoint": ["F", "F"],
"contains": ["F", "T"],
"within": ["T", "F"],
"covers": ["F", "T"],
"coveredby": ["T", "F"],
"crosses": ["F", "F"],
"overlaps": ["F", "F"],
"touches": ["F", "F"]
}
},
{
"geoms": [
"LINESTRING(1 1,2 2)",
"LINESTRING(0 0,3 3)"
],
"dims": [ 1, 1 ],
"relate": [ "1FF0FF102", "101FF0FF2" ],
"predicates": {
"equals": ["F", "F"],
"intersects": ["T", "T"],
"disjoint": ["F", "F"],
"contains": ["F", "T"],
"within": ["T", "F"],
"covers": ["F", "T"],
"coveredby": ["T", "F"],
"crosses": ["F", "F"],
"overlaps": ["F", "F"],
"touches": ["F", "F"]
}
},
{
"geoms": [
"LINESTRING(-0.5 0.5,-0.1 0.1)",
"LINESTRING(-1 1,1 -1)"
],
"dims": [ 1, 1 ],
"relate": [ "1FF0FF102", "101FF0FF2" ],
"predicates": {
"equals": ["F", "F"],
"intersects": ["T", "T"],
"disjoint": ["F", "F"],
"contains": ["F", "T"],
"within": ["T", "F"],
"covers": ["F", "T"],
"coveredby": ["T", "F"],
"crosses": ["F", "F"],
"overlaps": ["F", "F"],
"touches": ["F", "F"]
}
}
]
6 changes: 4 additions & 2 deletions tg.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,10 @@ bool tg_segment_intersects_segment(struct tg_segment seg_a,
if (!(((c.x-a.x <= 0) != (c.x-b.x <= 0))) ||
((c.y-a.y <= 0) != (c.y-b.y <= 0)))
{
return (tg_segment_covers_point(seg_a, seg_b.a) ||
tg_segment_covers_point(seg_a, seg_b.b));
return tg_segment_covers_point(seg_a, seg_b.a) ||
tg_segment_covers_point(seg_a, seg_b.b) ||
tg_segment_covers_point(seg_b, seg_a.a) ||
tg_segment_covers_point(seg_b, seg_a.b);
}
return true;
}
Expand Down

0 comments on commit b0af7c4

Please sign in to comment.