diff --git a/src/geometries/polytopes.jl b/src/geometries/polytopes.jl index e8c030610..3785a6d39 100644 --- a/src/geometries/polytopes.jl +++ b/src/geometries/polytopes.jl @@ -32,13 +32,13 @@ macro polytope(type, K, N) structexpr = if K == 3 quote struct $type{C<:CRS,Mₚ<:Manifold} <: Polytope{$K,𝔼{3},C} - vertices::NTuple{$N,Point{Mₚ,C}} + vertices::SVector{$N,Point{Mₚ,C}} end end else quote struct $type{M<:Manifold,C<:CRS} <: Polytope{$K,M,C} - vertices::NTuple{$N,Point{M,C}} + vertices::SVector{$N,Point{M,C}} end end end @@ -46,6 +46,7 @@ macro polytope(type, K, N) expr = quote $Base.@__doc__ $structexpr + $type(vertices::NTuple{$N,P}) where {P<:Point} = $type(SVector(vertices)) $type(vertices::Vararg{Tuple,$N}) = $type(Point.(vertices)) $type(vertices::Vararg{P,$N}) where {P<:Point} = $type(vertices) end diff --git a/src/geometries/polytopes/ngon.jl b/src/geometries/polytopes/ngon.jl index 9d0012a6b..604750d80 100644 --- a/src/geometries/polytopes/ngon.jl +++ b/src/geometries/polytopes/ngon.jl @@ -21,7 +21,7 @@ are `Triangle` (N=3), `Quadrangle` (N=4), `Pentagon` (N=5), etc. `Heptagon`, `Octagon`, `Nonagon`, `Decagon`. """ struct Ngon{N,M<:Manifold,C<:CRS} <: Polygon{M,C} - vertices::NTuple{N,Point{M,C}} + vertices::SVector{N,Point{M,C}} function Ngon{N,M,C}(vertices) where {N,M<:Manifold,C<:CRS} if N < 3 throw(ArgumentError("the number of vertices must be greater than or equal to 3")) @@ -30,11 +30,13 @@ struct Ngon{N,M<:Manifold,C<:CRS} <: Polygon{M,C} end end -Ngon{N}(vertices::NTuple{N,Point{M,C}}) where {N,M<:Manifold,C<:CRS} = Ngon{N,M,C}(vertices) +Ngon{N}(vertices::SVector{N,Point{M,C}}) where {N,M<:Manifold,C<:CRS} = Ngon{N,M,C}(vertices) +Ngon{N}(vertices::NTuple{N,P}) where {N,P<:Point} = Ngon{N}(SVector(vertices)) Ngon{N}(vertices::Vararg{P,N}) where {N,P<:Point} = Ngon{N}(vertices) Ngon{N}(vertices::Vararg{Tuple,N}) where {N} = Ngon{N}(Point.(vertices)) -Ngon(vertices::NTuple{N,Point{M,C}}) where {N,M<:Manifold,C<:CRS} = Ngon{N,M,C}(vertices) +Ngon(vertices::SVector{N,Point{M,C}}) where {N,M<:Manifold,C<:CRS} = Ngon{N,M,C}(vertices) +Ngon(vertices::NTuple{N,P}) where {N,P<:Point} = Ngon(SVector(vertices)) Ngon(vertices::P...) where {P<:Point} = Ngon(vertices) Ngon(vertices::Tuple...) = Ngon(Point.(vertices)) diff --git a/src/transforms.jl b/src/transforms.jl index dfc64048a..be49b250a 100644 --- a/src/transforms.jl +++ b/src/transforms.jl @@ -79,7 +79,7 @@ applycoord(t::CoordinateTransform, g::TransformedGeometry) = TransformedGeometry applycoord(t::CoordinateTransform, m::TransformedMesh) = TransformedMesh(m, t) # special treatment for lists of geometries -applycoord(t::CoordinateTransform, g::NTuple{<:Any,<:Geometry}) = map(gᵢ -> applycoord(t, gᵢ), g) +applycoord(t::CoordinateTransform, g::StaticVector{<:Any,<:Geometry}) = map(gᵢ -> applycoord(t, gᵢ), g) applycoord(t::CoordinateTransform, g::AbstractVector{<:Geometry}) = [applycoord(t, gᵢ) for gᵢ in g] applycoord(t::CoordinateTransform, g::CircularVector{<:Geometry}) = CircularVector([applycoord(t, gᵢ) for gᵢ in g]) diff --git a/test/hulls.jl b/test/hulls.jl index 968c499e8..dfa4476cc 100644 --- a/test/hulls.jl +++ b/test/hulls.jl @@ -90,11 +90,11 @@ # degenerate cases points = [cart(0, 0), cart(1, 0), cart(2, 0)] chull = hull(points, method) - @test vertices(chull) == (cart(0, 0), cart(2, 0)) + @test vertices(chull) == SVector(cart(0, 0), cart(2, 0)) points = [cart(0, 0), cart(1, 0), cart(2, 0), cart(10, 0), cart(100, 0)] chull = hull(points, method) - @test vertices(chull) == (cart(0, 0), cart(100, 0)) + @test vertices(chull) == SVector(cart(0, 0), cart(100, 0)) # partially collinear points = [ diff --git a/test/meshes.jl b/test/meshes.jl index 49f6fcca7..ce1070f8b 100644 --- a/test/meshes.jl +++ b/test/meshes.jl @@ -244,7 +244,7 @@ end @test spacing(grid) == (T(5) * u"m", T(5) * u"m", T(5) * u"m") @test nelements(grid) == 20 * 10 * 5 @test eltype(grid) <: Hexahedron - @test vertices(grid[1]) == ( + @test vertices(grid[1]) == SVector( cart(0, 0, 0), cart(5, 0, 0), cart(5, 5, 0), diff --git a/test/polytopes.jl b/test/polytopes.jl index 6b710f047..8f6a43b26 100644 --- a/test/polytopes.jl +++ b/test/polytopes.jl @@ -293,13 +293,14 @@ end @testitem "Ngons" setup = [Setup] begin pts = (cart(0, 0), cart(1, 0), cart(0, 1)) tups = (T.((0, 0)), T.((1, 0)), T.((0, 1))) + verts = SVector(pts) @test paramdim(Ngon) == 2 - @test vertices(Ngon(pts)) == pts - @test vertices(Ngon(pts...)) == pts - @test vertices(Ngon(tups...)) == pts - @test vertices(Ngon{3}(pts)) == pts - @test vertices(Ngon{3}(pts...)) == pts - @test vertices(Ngon{3}(tups...)) == pts + @test vertices(Ngon(pts)) == verts + @test vertices(Ngon(pts...)) == verts + @test vertices(Ngon(tups...)) == verts + @test vertices(Ngon{3}(pts)) == verts + @test vertices(Ngon{3}(pts...)) == verts + @test vertices(Ngon{3}(tups...)) == verts NGONS = [Triangle, Quadrangle, Pentagon, Hexagon, Heptagon, Octagon, Nonagon, Decagon] NVERT = 3:10 diff --git a/test/testutils.jl b/test/testutils.jl index d1f2f3530..d12c2f374 100644 --- a/test/testutils.jl +++ b/test/testutils.jl @@ -114,7 +114,7 @@ withprecision(T, v::Vec) = numconvert.(T, v) withprecision(T, p::Point) = Meshes.withcrs(p, withprecision(T, to(p))) withprecision(T, len::Meshes.Len) = numconvert(T, len) withprecision(T, lens::NTuple{Dim,Meshes.Len}) where {Dim} = numconvert.(T, lens) -withprecision(T, geoms::NTuple{Dim,<:Geometry}) where {Dim} = withprecision.(T, geoms) +withprecision(T, geoms::StaticVector{Dim,<:Geometry}) where {Dim} = withprecision.(T, geoms) withprecision(T, geoms::AbstractVector{<:Geometry}) = [withprecision(T, g) for g in geoms] withprecision(T, geoms::CircularVector{<:Geometry}) = CircularVector([withprecision(T, g) for g in geoms]) @generated function withprecision(T, g::G) where {G<:Meshes.GeometryOrDomain}