JuliaGeometry / GeometryBasics.jl

Basic Geometry Types
MIT License
165 stars 54 forks source link

Polygon constructor adds an interior by default, rather than an exterior as the docs say. #183

Closed rafaqz closed 1 year ago

rafaqz commented 1 year ago
julia> Polygon([Point2(1,2), Point2(3, 4), Point(5, 6), Point(1,2)])
Polygon{2, Int64, Point2{Int64}, LineString{2, Int64, Point2{Int64}, Base.ReinterpretArray{Line{2, Int64}, 1, Tuple{Point2{Int64}, Point2{Int64}}, TupleView{Tuple{Point2{Int64}, Po
int2{Int64}}, 2, 1, Vector{Point2{Int64}}}, false}}, Vector{LineString{2, Int64, Point2{Int64}, Base.ReinterpretArray{Line{2, Int64}, 1, Tuple{Point2{Int64}, Point2{Int64}}, TupleV
iew{Tuple{Point2{Int64}, Point2{Int64}}, 2, 1, Vector{Point2{Int64}}}, false}}}}(Line{2, Int64}[Line([1, 2] => [3, 4]), Line([3, 4] => [5, 6]), Line([5, 6] => [1, 2])], LineString{
2, Int64, Point2{Int64}, Base.ReinterpretArray{Line{2, Int64}, 1, Tuple{Point2{Int64}, Point2{Int64}}, TupleView{Tuple{Point2{Int64}, Point2{Int64}}, 2, 1, Vector{Point2{Int64}}},
false}}[])

julia> p.interiors
LineString{2, Int64, Point2{Int64}, Base.ReinterpretArray{Line{2, Int64}, 1, Tuple{Point2{Int64}, Point2{Int64}}, TupleView{Tuple{Point2{Int64}, Point2{Int64}}, 2, 1, Vector{Point2
{Int64}}}, false}}[]

julia> p.exterior
0-element LineString{2, Int64, Point2{Int64}, Base.ReinterpretArray{Line{2, Int64}, 1, Tuple{Point2{Int64}, Point2{Int64}}, TupleView{Tuple{Point2{Int64}, Point2{Int64}}, 2, 1, Vec
tor{Point2{Int64}}}, false}}

help?> Polygon
search: Polygon PolygonMeta MultiPolygon MultiPolygonMeta AbstractPolygon

  Polygon(exterior::AbstractVector{<:Point})
  Polygon(exterior::AbstractVector{<:Point}, interiors::Vector{<:AbstractVector{<:AbstractPoint}})
SimonDanisch commented 1 year ago

Hm, I can't reproduce this:

image

Would have also surprised me, not much should have worked with such a bug. I see that you don't assign the polygon to p in your example, so maybe it's some other polygon?

rafaqz commented 1 year ago

Haha weird, I tried to make the example "better" and forgot to add the p =

It turns out it was the original dumb example that was causing the problem:

julia> p = Makie.Polygon([Point2(1,2)])
Polygon{2, Int64, Point2{Int64}, LineString{2, Int64, Point2{Int64}, Base.ReinterpretArray{Line{2, Int64}, 1, Tuple{Point2{Int64}, Point2{Int64}}, TupleView{Tuple{Point2{Int64}, Po
int2{Int64}}, 2, 1, Vector{Point2{Int64}}}, false}}, Vector{LineString{2, Int64, Point2{Int64}, Base.ReinterpretArray{Line{2, Int64}, 1, Tuple{Point2{Int64}, Point2{Int64}}, TupleV
iew{Tuple{Point2{Int64}, Point2{Int64}}, 2, 1, Vector{Point2{Int64}}}, false}}}}(Line{2, Int64}[], LineString{2, Int64, Point2{Int64}, Base.ReinterpretArray{Line{2, Int64}, 1, Tupl
e{Point2{Int64}, Point2{Int64}}, TupleView{Tuple{Point2{Int64}, Point2{Int64}}, 2, 1, Vector{Point2{Int64}}}, false}}[])

julia> p.exterior
0-element LineString{2, Int64, Point2{Int64}, Base.ReinterpretArray{Line{2, Int64}, 1, Tuple{Point2{Int64}, Point2{Int64}}, TupleView{Tuple{Point2{Int64}, Point2{Int64}}, 2, 1, Vec
tor{Point2{Int64}}}, false}}

julia> p.interiors
LineString{2, Int64, Point2{Int64}, Base.ReinterpretArray{Line{2, Int64}, 1, Tuple{Point2{Int64}, Point2{Int64}}, TupleView{Tuple{Point2{Int64}, Point2{Int64}}, 2, 1, Vector{Point2
{Int64}}}, false}}[]

And yes my example above works fine:

julia> p = Polygon([Point2(1,2), Point2(3, 4), Point(5, 6), Point(1,2)])
Polygon{2, Int64, Point2{Int64}, LineString{2, Int64, Point2{Int64}, Base.ReinterpretArray{Line{2, Int64}, 1, Tuple{Point2{Int64}, Point2{Int64}}, TupleView{Tuple{Point2{Int64}, Po
int2{Int64}}, 2, 1, Vector{Point2{Int64}}}, false}}, Vector{LineString{2, Int64, Point2{Int64}, Base.ReinterpretArray{Line{2, Int64}, 1, Tuple{Point2{Int64}, Point2{Int64}}, TupleV
iew{Tuple{Point2{Int64}, Point2{Int64}}, 2, 1, Vector{Point2{Int64}}}, false}}}}(Line{2, Int64}[Line([1, 2] => [3, 4]), Line([3, 4] => [5, 6]), Line([5, 6] => [1, 2])], LineString{
2, Int64, Point2{Int64}, Base.ReinterpretArray{Line{2, Int64}, 1, Tuple{Point2{Int64}, Point2{Int64}}, TupleView{Tuple{Point2{Int64}, Point2{Int64}}, 2, 1, Vector{Point2{Int64}}},
false}}[])

julia> p.exterior
3-element LineString{2, Int64, Point2{Int64}, Base.ReinterpretArray{Line{2, Int64}, 1, Tuple{Point2{Int64}, Point2{Int64}}, TupleView{Tuple{Point2{Int64}, Point2{Int64}}, 2, 1, Vec
tor{Point2{Int64}}}, false}}:
 Line([1, 2] => [3, 4])
 Line([3, 4] => [5, 6])
 Line([5, 6] => [1, 2])

julia> p.interiors
LineString{2, Int64, Point2{Int64}, Base.ReinterpretArray{Line{2, Int64}, 1, Tuple{Point2{Int64}, Point2{Int64}}, TupleView{Tuple{Point2{Int64}, Point2{Int64}}, 2, 1, Vector{Point2
{Int64}}}, false}}[]

So its just the case of having only a single point and I was being dumb. Sorry for the noise!!

SimonDanisch commented 1 year ago

Ah yeah, I guess for a single point both will be empty