Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow zero length geometries #2911

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 41 additions & 10 deletions src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,16 @@ end
Takes an input `Array{LineString}` or a `MultiLineString` and decomposes it to points.
"""
function convert_arguments(PB::PointBased, linestring::Union{Array{<:LineString}, MultiLineString})
arr = copy(convert_arguments(PB, linestring[1])[1])
if length(linestring) > 0
converted = convert_arguments(PB, linestring[1])
if length(converted) > 0
arr = copy(converted[1])
else
arr = Point2f[]
end
else
arr = Point2f[]
end
for ls in 2:length(linestring)
push!(arr, Point2f(NaN))
append!(arr, convert_arguments(PB, linestring[ls])[1])
Expand All @@ -226,15 +235,25 @@ end
Takes an input `Polygon` and decomposes it to points.
"""
function convert_arguments(PB::PointBased, pol::Polygon)
arr = copy(convert_arguments(PB, pol.exterior)[1])
push!(arr, arr[1]) # close exterior
converted = convert_arguments(PB, pol.exterior)
if length(converted) > 0
arr = copy(converted[1])
if length(arr) > 0
push!(arr, arr[1]) # close exterior
end
else
arr = Point2f[]
end
if !isempty(pol.interiors)
push!(arr, Point2f(NaN))
for interior in pol.interiors
inter = convert_arguments(PB, interior)[1]
append!(arr, inter)
# close interior + separate!
push!(arr, inter[1], Point2f(NaN))
converted = convert_arguments(PB, interior)
if length(converted) > 0
inter = converted[1]
append!(arr, inter)
# close interior + separate!
push!(arr, inter[1], Point2f(NaN))
end
end
end
return (arr,)
Expand All @@ -247,10 +266,22 @@ end
Takes an input `Array{Polygon}` or a `MultiPolygon` and decomposes it to points.
"""
function convert_arguments(PB::PointBased, mp::Union{Array{<:Polygon}, MultiPolygon})
arr = copy(convert_arguments(PB, mp[1])[1])
if length(mp) > 0
converted = convert_arguments(PB, mp[1])
if length(converted) > 0
arr = copy(converted[1])
else
arr = Point2f[]
end
else
arr = Point2f[]
end
for p in 2:length(mp)
push!(arr, Point2f(NaN))
append!(arr, convert_arguments(PB, mp[p])[1])
converted = convert_arguments(PB, mp[p])
if length(converted) > 0
push!(arr, Point2f(NaN))
append!(arr, converted[1])
end
end
return (arr,)
end
Expand Down
17 changes: 17 additions & 0 deletions test/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ end
p = convert_arguments(Makie.PointBased(), ls)
@test p[1] == pts

pts_empty = Point2f[]
ls_empty = LineString(pts_empty)
p_empty = convert_arguments(Makie.PointBased(), ls_empty)
@test p_empty[1] == pts_empty

pts1 = [Point(5, 2), Point(4,8), Point(2, 8), Point(5, 2)]
ls1 = LineString(pts1)
lsa = [ls, ls1]
Expand All @@ -90,6 +95,10 @@ end
@test p2[1][1:4] == pts
@test p2[1][6:9] == pts1

mls_emtpy = MultiLineString([LineString(pts_empty)])
p_empty = convert_arguments(Makie.PointBased(), mls_emtpy)
@test p_empty[1] == pts_empty

pol_e = Polygon(ls)
p3_e = convert_arguments(Makie.PointBased(), pol_e)
@test p3_e[1][1:end-1] == pts # for poly we repeat last point
Expand All @@ -99,6 +108,10 @@ end
@test p3[1][1:4] == pts
@test p3[1][7:10] == pts1

pol_emtpy = Polygon(pts_empty)
p_empty = convert_arguments(Makie.PointBased(), pol_emtpy)
@test p_empty[1] == pts_empty

pts2 = Point{2, Int}[(5, 1), (3, 3), (4, 8), (1, 2), (5, 1)]
pts3 = Point{2, Int}[(2, 2), (2, 3),(3, 4), (2, 2)]
pts4 = Point{2, Int}[(2, 2), (3, 8),(5, 6), (3, 4), (2, 2)]
Expand All @@ -114,6 +127,10 @@ end
@test p4[1][14:18] == pts2
@test p4[1][21:24] == pts3
@test p4[1][27:31] == pts4

mpol_emtpy = MultiPolygon(typeof(pol_emtpy)[])
p_empty = convert_arguments(Makie.PointBased(), mpol_emtpy)
@test p_empty[1] == pts_empty
end

using Makie: check_line_pattern, line_diff_pattern
Expand Down