@@ -171,13 +171,12 @@ Base.show(io::IO, x::Line) = print(io, "Line(", x[1], " => ", x[2], ")")
171171 Polygon(exterior::AbstractVector{<:Point}, interiors::Vector{<:AbstractVector{<:Point}})
172172
173173"""
174- struct Polygon{Dim,T<: Real ,L<: AbstractVector{Point{Dim,T}} ,
175- V<: AbstractVector{L} } <: AbstractPolygon{Dim,T}
176- exterior:: L
177- interiors:: V
174+ struct Polygon{Dim,T<: Real } <: AbstractPolygon{Dim,T}
175+ exterior:: Vector{Point{Dim, T}}
176+ interiors:: Vector{Vector{Point{Dim, T}}}
178177end
179178
180- Base. copy (x:: Polygon ) = Polygon (copy (x. exterior), copy (x. interiors))
179+ Base. copy (x:: Polygon ) = Polygon (copy (x. exterior), deepcopy (x. interiors))
181180
182181function Base.:(== )(a:: Polygon , b:: Polygon )
183182 return (a. exterior == b. exterior) && (a. interiors == b. interiors)
@@ -186,27 +185,24 @@ end
186185function Polygon (
187186 exterior:: AbstractVector{Point{Dim,T}} ,
188187 interiors:: AbstractVector{AbstractVector{Point{Dim,T}}} ) where {Dim, T}
189- return Polygon {Dim,T,typeof(exterior),typeof(interiors)} (exterior, interiors)
188+ tov (v) = convert (Vector{Point{Dim, T}}, v)
189+ return Polygon {Dim,T} (tov (exterior), map (tov, interiors))
190190end
191191
192192Polygon (exterior:: AbstractVector{Point{N, T}} ) where {N, T} = Polygon (exterior, Vector{Point{N, T}}[])
193193
194- function Polygon (exterior:: AbstractVector{Point{Dim, T}} , faces:: AbstractVector{<:Integer} ,
195- skip:: Int = 1 ) where {Dim,T}
196- return Polygon (LineString (exterior, faces, skip))
197- end
198-
199194function Polygon (exterior:: AbstractVector{Point{Dim,T}} ,
200195 faces:: AbstractVector{<:LineFace} ) where {Dim, T}
201196 return Polygon (LineString (exterior, faces))
202197end
203198
204- function Polygon (exterior:: AbstractVector{Point{Dim, T}} ,
205- interior:: AbstractVector{<:AbstractVector{Point{Dim, T}}} ) where {Dim,T}
206- # if we just map over it, it won't infer the element type correctly!
207- int = typeof (exterior)[]
208- foreach (x -> push! (int, x), interior)
209- return Polygon (exterior, int)
199+ function Polygon (exterior:: AbstractGeometry{Dim, T} , interior:: AbstractVector = []) where {Dim, T}
200+ to_p (v) = decompose (Point{Dim, T}, v)
201+ int = Vector{Point{Dim, T}}[]
202+ for i in interior
203+ push! (int, to_p (i))
204+ end
205+ return Polygon (to_p (exterior), int)
210206end
211207
212208function coordinates (polygon:: Polygon{N,T} ) where {N,T}
@@ -224,49 +220,56 @@ end
224220"""
225221 MultiPolygon(polygons::AbstractPolygon)
226222"""
227- struct MultiPolygon{Dim,T<: Real ,Element<: AbstractPolygon{Dim,T} ,
228- A<: AbstractVector{Element} } <: AbstractVector{Element}
229- polygons:: A
223+ struct MultiPolygon{Dim, T<: Real } <: AbstractGeometry{Dim, T}
224+ polygons:: Vector{<:AbstractPolygon{Dim,T}}
230225end
231226
232- function MultiPolygon (polygons:: AbstractVector{P} ;
233- kw... ) where {P<: AbstractPolygon{Dim,T} } where {Dim,T}
234- return MultiPolygon (meta (polygons; kw... ))
227+ function MultiPolygon (polygons:: AbstractVector{<:AbstractPolygon{Dim,T}} ) where {Dim,T}
228+ return MultiPolygon (convert (Vector{eltype (polygons)}, polygons))
235229end
236230
237231Base. getindex (mp:: MultiPolygon , i) = mp. polygons[i]
238232Base. size (mp:: MultiPolygon ) = size (mp. polygons)
233+ Base. length (mp:: MultiPolygon ) = length (mp. polygons)
234+
235+ """
236+ LineString(points::AbstractVector{<:Point})
237+ A LineString is a geometry of connected line segments
238+ """
239+ struct LineString{Dim, T<: Real } <: AbstractGeometry{Dim, T}
240+ points:: Vector{Point{Dim, T}}
241+ end
242+ Base. length (ls:: LineString ) = length (coordinates (ls))
243+ coordinates (ls:: LineString ) = ls. points
239244
240- struct MultiLineString{Dim,T<: Real ,Element<: LineString{Dim,T} ,A<: AbstractVector{Element} } < :
241- AbstractVector{Element}
242- linestrings:: A
245+ struct MultiLineString{Dim, T<: Real } <: AbstractGeometry{Dim, T}
246+ linestrings:: Vector{LineString{Dim, T}}
243247end
244248
245- function MultiLineString (linestrings:: AbstractVector{L} ;
246- kw... ) where {L<: AbstractVector{LineP{Dim,T,P}} } where {Dim,T,P}
247- return MultiLineString (meta (linestrings; kw... ))
249+ function MultiLineString (linestrings:: AbstractVector{L} ) where {L<: LineString }
250+ return MultiLineString (convert (Vector{L}, linestrings))
248251end
249252
250253Base. getindex (ms:: MultiLineString , i) = ms. linestrings[i]
251254Base. size (ms:: MultiLineString ) = size (ms. linestrings)
255+ Base. length (mpt:: MultiLineString ) = length (mpt. linestrings)
252256
253257"""
254258 MultiPoint(points::AbstractVector{AbstractPoint})
255259
256260A collection of points
257261"""
258- struct MultiPoint{Dim,T<: Real ,P<: AbstractPoint{Dim,T} ,A<: AbstractVector{P} } < :
259- AbstractVector{P}
260- points:: A
262+ struct MultiPoint{Dim,T<: Real } <: AbstractGeometry{Dim, T}
263+ points:: Vector{Point{Dim, T}}
261264end
262265
263- function MultiPoint (points:: AbstractVector{P} ;
264- kw... ) where {P<: AbstractPoint{Dim,T} } where {Dim,T}
265- return MultiPoint (meta (points; kw... ))
266+ function MultiPoint (points:: AbstractVector{Point{Dim, T}} ) where {Dim,T}
267+ return MultiPoint (convert (Vector{Point{Dim, T}}, points))
266268end
267269
268270Base. getindex (mpt:: MultiPoint , i) = mpt. points[i]
269271Base. size (mpt:: MultiPoint ) = size (mpt. points)
272+ Base. length (mpt:: MultiPoint ) = length (mpt. points)
270273
271274"""
272275 AbstractMesh
@@ -333,3 +336,4 @@ texturecoordinates(mesh::MetaMesh) = hasproperty(mesh, :uv) ? mesh.uv : nothing
333336meta (@nospecialize (m)) = NamedTuple ()
334337meta (mesh:: MetaMesh ) = getfield (mesh, :meta )
335338Mesh (mesh:: MetaMesh ) = getfield (mesh, :mesh )
339+ Mesh (mesh:: Mesh ) = mesh
0 commit comments