/
issimple.jl
39 lines (32 loc) · 1.01 KB
/
issimple.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# ------------------------------------------------------------------
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------
"""
issimple(polygon)
Tells whether or not the `polygon` is simple.
See [https://en.wikipedia.org/wiki/Simple_polygon]
(https://en.wikipedia.org/wiki/Simple_polygon).
"""
issimple(p::Polygon) = issimple(typeof(p))
issimple(p::PolyArea) = !hasholes(p) && issimple(first(rings(p)))
issimple(::Type{<:Ngon}) = true
"""
issimple(chain)
Tells whether or not the `chain` is simple.
A chain is simple when all its segments only
intersect at end points.
"""
function issimple(c::Chain)
λ(I) = !(type(I) == CornerTouching || type(I) == NotIntersecting)
ss = collect(segments(c))
result = Threads.Atomic{Bool}(true)
Threads.@threads for i in 1:length(ss)
for j in (i + 1):length(ss)
if intersection(λ, ss[i], ss[j])
result[] || break
result[] = false
end
end
end
result[]
end