Skip to content
This repository was archived by the owner on Nov 22, 2023. It is now read-only.

Allow arbitrary vectors of points to be passed to polygon #201

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/polygon.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function Polygon(
points::AbstractVector;
boundingbox = Rect2D(points),
boundingbox = boundingbox(points),
isconvex = isconvex(points),
ishole = false
)
Expand All @@ -17,6 +17,19 @@ boundingbox(poly::Polygon) = poly.boundingbox
ishole(poly::Polygon) = poly.ishole
isconvex(poly::Polygon) = poly.isconvex

function boundingbox(poly::AbstractVector{Point{N, T}}) where {N, T}
origins = Vector{T}(undef, N)
widths = Vector{T}(undef, N)

for i in 1:N
values = getindex.(poly, i)
min, max = extrema(values)
origins[i] = min
widths[i] = max - min
end

return HyperRectangle{N, T}(origins, widths)
end

"""
in(point::AbstractPoint, poly::Polygon)
Expand Down