Skip to content

Commit 6f590ad

Browse files
authored
Merge pull request #8 from visr/multi
MultiPoint
2 parents 2a36f67 + 846d99a commit 6f590ad

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ authors = ["SimonDanisch <[email protected]>"]
44
version = "0.1.2"
55

66
[deps]
7-
GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb"
87
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
98
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
109
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
@@ -14,7 +13,8 @@ julia = ">= 1.1"
1413

1514
[extras]
1615
Query = "1a8c2f83-1ff3-5112-b086-8aa67b057ba1"
16+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1717
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1818

1919
[targets]
20-
test = ["Test", "Query"]
20+
test = ["Test", "Query", "Random"]

src/basic_types.jl

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,10 @@ struct MultiPolygon{
265265
Element <: AbstractPolygon{Dim, T},
266266
A <: AbstractVector{Element}
267267
} <: AbstractVector{Element}
268+
268269
polygons::A
269270
end
270271

271-
272-
273272
function MultiPolygon(polygons::AbstractVector{P}; kw...) where P <: AbstractPolygon{Dim, T} where {Dim, T}
274273
MultiPolygon(meta(polygons; kw...))
275274
end
@@ -283,9 +282,32 @@ struct MultiLineString{
283282
A <: AbstractVector{Element}
284283
} <: AbstractVector{Element}
285284

286-
polygons::A
285+
linestrings::A
287286
end
288287

288+
function MultiLineString(linestrings::AbstractVector{L}; kw...) where L <: AbstractVector{LineP{Dim, T, P}} where {Dim, T, P}
289+
MultiLineString(meta(linestrings; kw...))
290+
end
291+
292+
Base.getindex(ms::MultiLineString, i) = ms.linestrings[i]
293+
Base.size(ms::MultiLineString) = size(ms.linestrings)
294+
295+
struct MultiPoint{
296+
Dim, T <: Real,
297+
Element <: Point{Dim, T},
298+
A <: AbstractVector{Element}
299+
} <: AbstractVector{Element}
300+
301+
points::A
302+
end
303+
304+
function MultiPoint(points::AbstractVector{P}; kw...) where P <: AbstractPoint{Dim, T} where {Dim, T}
305+
MultiPoint(meta(points; kw...))
306+
end
307+
308+
Base.getindex(mpt::MultiPoint, i) = mpt.points[i]
309+
Base.size(mpt::MultiPoint) = size(mpt.points)
310+
289311
struct Mesh{
290312
Dim, T <: Real,
291313
Element <: Polytope{Dim, T},

test/runtests.jl

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using GeometryBasics
2-
using GeometryBasics: Polygon, MultiPolygon, Point, LineFace, Polytope, Line
2+
using GeometryBasics: LineFace, Polytope, Line
3+
using GeometryBasics: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon
34
using GeometryBasics: Simplex, connect, Triangle, NSimplex, Tetrahedron
45
using GeometryBasics: QuadFace, hascolumn, getcolumn, metafree, coordinates, TetrahedronFace
5-
using GeometryBasics: TupleView, TriangleFace, SimplexFace, LineString, Mesh, meta, column_names
6+
using GeometryBasics: TupleView, TriangleFace, SimplexFace, Mesh, meta, column_names
67
using Test, Random, Query, StructArrays, Tables
78
using StaticArrays
89

@@ -235,5 +236,35 @@ end
235236

236237
end
237238

239+
@testset "Multi geometries" begin
240+
# coordinates from https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Geometric_objects
241+
points = Point{2, Int}[(10, 40), (40, 30), (20, 20), (30, 10)]
242+
multipoint = MultiPoint(points)
243+
@test size(multipoint) === size(points)
244+
@test multipoint[3] === points[3]
245+
246+
linestring1 = LineString(Point{2, Int}[(10, 10), (20, 20), (10, 40)])
247+
linestring2 = LineString(Point{2, Int}[(40, 40), (30, 30), (40, 20), (30, 10)])
248+
multilinestring = MultiLineString([linestring1, linestring2])
249+
@test size(multilinestring) === (2,)
250+
@test multilinestring[1] === linestring1
251+
@test multilinestring[2] === linestring2
252+
253+
polygon11 = Polygon(Point{2, Int}[(30, 20), (45, 40), (10, 40), (30, 20)])
254+
polygon12 = Polygon(Point{2, Int}[(15, 5), (40, 10), (10, 20), (5, 10), (15, 5)])
255+
multipolygon1 = MultiPolygon([polygon11, polygon12])
256+
@test size(multipolygon1) === (2,)
257+
@test multipolygon1[1] === polygon11
258+
@test multipolygon1[2] === polygon12
259+
260+
polygon21 = Polygon(Point{2, Int}[(40, 40), (20, 45), (45, 30), (40, 40)])
261+
polygon22 = Polygon(LineString(Point{2, Int}[(20, 35), (10, 30), (10, 10), (30, 5), (45, 20), (20, 35)]),
262+
[LineString(Point{2, Int}[(30, 20), (20, 15), (20, 25), (30, 20)])])
263+
multipolygon2 = MultiPolygon([polygon21, polygon22])
264+
@test size(multipolygon2) === (2,)
265+
@test multipolygon2[1] === polygon21
266+
@test multipolygon2[2] === polygon22
267+
end
268+
238269
end
239270
end

0 commit comments

Comments
 (0)