Skip to content

Commit 3ca17d6

Browse files
juliohmCopilot
andauthored
Widen vector type in GeometrySet (#1256)
* Widen vector type in GeometrySet * Apply Copilot suggestion Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent d28f8a9 commit 3ca17d6

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/domains/sets.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ julia> GeometrySet([Ball((0.0, 0.0)), Ball((1.0, 1.0))])
1919
2020
Geometries with different CRS will be projected to the CRS of the first geometry.
2121
"""
22-
struct GeometrySet{M<:Manifold,C<:CRS,G<:Geometry{M,C}} <: Domain{M,C}
23-
geoms::Vector{G}
22+
struct GeometrySet{M<:Manifold,C<:CRS,G<:Geometry{M,C},V<:AbstractVector{G}} <: Domain{M,C}
23+
geoms::V
2424
end
2525

2626
# constructor with iterator of geometries
@@ -50,7 +50,7 @@ Base.vcat(d1::Domain, d2::GeometrySet) = GeometrySet(vcat(collect(d1), d2.geoms)
5050
# SPECIAL CASE: POINT SET
5151
# ------------------------
5252

53-
const PointSet{M<:Manifold,C<:CRS} = GeometrySet{M,C,Point{M,C}}
53+
const PointSet{M<:Manifold,C<:CRS,V<:AbstractVector{Point{M,C}}} = GeometrySet{M,C,Point{M,C},V}
5454

5555
"""
5656
PointSet(points)
@@ -68,7 +68,7 @@ julia> PointSet([(1,2,3), (4,5,6)])
6868
julia> PointSet((1,2,3), (4,5,6))
6969
```
7070
"""
71-
PointSet(points::AbstractVector{Point{M,C}}) where {M<:Manifold,C<:CRS} = PointSet{M,C}(points)
71+
PointSet(points::AbstractVector{Point{M,C}}) where {M<:Manifold,C<:CRS} = PointSet{M,C,typeof(points)}(points)
7272
PointSet(points::Vararg{P}) where {P<:Point} = PointSet(collect(points))
7373
PointSet(coords::AbstractVector{TP}) where {TP<:Tuple} = PointSet(Point.(coords))
7474
PointSet(coords::Vararg{TP}) where {TP<:Tuple} = PointSet(collect(coords))

test/sets.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
push!(geoms, Segment(cart(1, 1), cart(0, 0)))
2424
gset = GeometrySet(geoms)
2525
@test eltype(gset) <: Segment
26+
@test nelements(gset) == 3
27+
28+
# construction with custom vectors of geometries
29+
# https://github.com/JuliaEarth/GeoStats.jl/issues/551
30+
geoms = @SVector [cart(0, 0), cart(1, 1)]
31+
gset = GeometrySet(geoms)
32+
@test eltype(gset) <: Point
33+
@test nelements(gset) == 2
2634

2735
# different CRS
2836
s = Segment(latlon(0, 0), latlon(1, 1))

0 commit comments

Comments
 (0)