Skip to content

Commit 1915d31

Browse files
committed
fix type targeting in connect
1 parent b1ae5f5 commit 1915d31

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/viewtypes.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,25 @@ function connect(points::AbstractVector{Point},
7373
end
7474

7575
function connect(points::AbstractVector{T}, ::Type{<:Point{N}}, skip::Int=N) where {T <: Real,N}
76+
return connect(points, Point{N, T}, skip)
77+
end
78+
function connect(points::AbstractVector{_T}, ::Type{<:Point{N, T}}, skip::Int=N) where {T <: Real, N, _T <: Real}
7679
return map(Point{N,T}, TupleView{N,skip}(points))
7780
end
7881

7982
function connect(indices::AbstractVector{T}, P::Type{<:AbstractFace{N}},
8083
skip::Int=N) where {T <: Integer, N}
84+
return connect(indices, Face(P, T), skip)
85+
end
86+
function connect(indices::AbstractVector{_T}, P::Type{<:AbstractFace{N, T}},
87+
skip::Int=N) where {T <: Integer, N, _T <: Integer}
8188
return collect(reinterpret(Face(P, T), TupleView{N, skip}(indices)))
8289
end
8390

84-
function connect(points::AbstractMatrix{T}, P::Type{<:Point{N}}) where {T <: Real, N}
91+
function connect(points::AbstractMatrix{T}, ::Type{<:Point{N}}) where {T <: Real, N}
92+
return connect(points, Point{N, T})
93+
end
94+
function connect(points::AbstractMatrix{_T}, P::Type{Point{N, T}}) where {T <: Real, N, _T <: Real}
8595
return if size(points, 1) === N
8696
return reinterpret(Point{N,T}, points)
8797
elseif size(points, 2) === N

test/polygons.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
@testset "Polygon" begin
22
@testset "Constructors" begin
33
points = connect([1, 2, 3, 4, 5, 6], Point2f)
4+
@test points isa Vector{Point2f}
5+
points = connect([1, 2, 3, 4, 5, 6], Point2)
6+
@test points isa Vector{Point2i}
47
polygon = Polygon(points)
58
@test polygon == Polygon(points)
69
@test polygon == copy(polygon)
@@ -23,8 +26,7 @@
2326
@test size(mp) == (3,) # TODO: What does size even mean here?
2427
@test length(mp) == 3
2528
@test MultiPolygon(OffsetArray([polygon, p1, p2], 0)) == mp
26-
mp = MultiPolygon([Polygon(Point2f.()), p1, p2])
27-
29+
@test MultiPolygon([Polygon(Point2f.(points)), p1, p2]) == mp
2830
end
2931

3032
rect = Rect2f(0, 0, 1, 1)

0 commit comments

Comments
 (0)