Skip to content

Commit 8e72103

Browse files
authored
Merge pull request #73 from Sov-trotter/geom_points
Give out points of geometries
2 parents 52f478b + feabfde commit 8e72103

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/interfaces.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,19 @@ function decompose(::Type{T}, primitive) where {T}
112112
return collect_with_eltype(T, primitive)
113113
end
114114

115+
function decompose(::Type{P}, pol::Polygon) where {P<:AbstractPoint}
116+
if isempty(pol.interiors)
117+
return decompose(P, pol.exterior)
118+
else
119+
arr = copy(decompose(P, pol.exterior))
120+
for i in pol.interiors
121+
append!(arr, decompose(P, i))
122+
end
123+
return arr
124+
end
125+
end
126+
127+
decompose(::Type{P}, ls::LineString) where {P<:AbstractPoint} = ls.points.parent.data
115128
decompose_uv(primitive) = decompose(UV(), primitive)
116129
decompose_uvw(primitive) = decompose(UVW(), primitive)
117130
decompose_normals(primitive) = decompose(Normal(), primitive)

test/runtests.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,23 @@ end
470470
points = decompose(Point2f0, Circle(Point2f0(0), 1))
471471
m = GeometryBasics.mesh(points)
472472
@test coordinates(m) === points
473+
474+
linestring = LineString(Point{2, Int}[(10, 10), (20, 20), (10, 40)])
475+
pts = Point{2, Int}[(10, 10), (20, 20), (10, 40)]
476+
linestring = LineString(pts)
477+
pts_decomp = decompose(Point{2, Int}, linestring)
478+
@test pts === pts_decomp
479+
480+
pts_ext = Point{2, Int}[(5, 1), (3, 3), (4, 8), (1, 2), (5, 1)]
481+
ls_ext = LineString(pts_ext)
482+
pts_int1 = Point{2, Int}[(2, 2), (3, 8),(5, 6), (3, 4), (2, 2)]
483+
ls_int1 = LineString(pts_int1)
484+
pts_int2 = Point{2, Int}[(3, 2), (4, 5),(6, 1), (1, 4), (3, 2)]
485+
ls_int2 = LineString(pts_int2)
486+
poly_ext = Polygon(ls_ext)
487+
poly_ext_int = Polygon(ls_ext, [ls_int1, ls_int2])
488+
@test decompose(Point{2, Int}, poly_ext) == pts_ext
489+
@test decompose(Point{2, Int}, poly_ext_int) == [pts_ext..., pts_int1..., pts_int2...]
473490
end
474491

475492
@testset "convert mesh + meta" begin

0 commit comments

Comments
 (0)