Skip to content

Commit 243d3f0

Browse files
authored
Use SVector in Polytope instead of NTuple (#1130)
* Use 'SVector' in 'Polytope' instead of 'NTuple' * Update constructors * Fix constructors * Fix tests
1 parent cbd8f42 commit 243d3f0

File tree

7 files changed

+20
-16
lines changed

7 files changed

+20
-16
lines changed

src/geometries/polytopes.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,21 @@ macro polytope(type, K, N)
3232
structexpr = if K == 3
3333
quote
3434
struct $type{C<:CRS,Mₚ<:Manifold} <: Polytope{$K,𝔼{3},C}
35-
vertices::NTuple{$N,Point{Mₚ,C}}
35+
vertices::SVector{$N,Point{Mₚ,C}}
3636
end
3737
end
3838
else
3939
quote
4040
struct $type{M<:Manifold,C<:CRS} <: Polytope{$K,M,C}
41-
vertices::NTuple{$N,Point{M,C}}
41+
vertices::SVector{$N,Point{M,C}}
4242
end
4343
end
4444
end
4545

4646
expr = quote
4747
$Base.@__doc__ $structexpr
4848

49+
$type(vertices::NTuple{$N,P}) where {P<:Point} = $type(SVector(vertices))
4950
$type(vertices::Vararg{Tuple,$N}) = $type(Point.(vertices))
5051
$type(vertices::Vararg{P,$N}) where {P<:Point} = $type(vertices)
5152
end

src/geometries/polytopes/ngon.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ are `Triangle` (N=3), `Quadrangle` (N=4), `Pentagon` (N=5), etc.
2121
`Heptagon`, `Octagon`, `Nonagon`, `Decagon`.
2222
"""
2323
struct Ngon{N,M<:Manifold,C<:CRS} <: Polygon{M,C}
24-
vertices::NTuple{N,Point{M,C}}
24+
vertices::SVector{N,Point{M,C}}
2525
function Ngon{N,M,C}(vertices) where {N,M<:Manifold,C<:CRS}
2626
if N < 3
2727
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}
3030
end
3131
end
3232

33-
Ngon{N}(vertices::NTuple{N,Point{M,C}}) where {N,M<:Manifold,C<:CRS} = Ngon{N,M,C}(vertices)
33+
Ngon{N}(vertices::SVector{N,Point{M,C}}) where {N,M<:Manifold,C<:CRS} = Ngon{N,M,C}(vertices)
34+
Ngon{N}(vertices::NTuple{N,P}) where {N,P<:Point} = Ngon{N}(SVector(vertices))
3435
Ngon{N}(vertices::Vararg{P,N}) where {N,P<:Point} = Ngon{N}(vertices)
3536
Ngon{N}(vertices::Vararg{Tuple,N}) where {N} = Ngon{N}(Point.(vertices))
3637

37-
Ngon(vertices::NTuple{N,Point{M,C}}) where {N,M<:Manifold,C<:CRS} = Ngon{N,M,C}(vertices)
38+
Ngon(vertices::SVector{N,Point{M,C}}) where {N,M<:Manifold,C<:CRS} = Ngon{N,M,C}(vertices)
39+
Ngon(vertices::NTuple{N,P}) where {N,P<:Point} = Ngon(SVector(vertices))
3840
Ngon(vertices::P...) where {P<:Point} = Ngon(vertices)
3941
Ngon(vertices::Tuple...) = Ngon(Point.(vertices))
4042

src/transforms.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ applycoord(t::CoordinateTransform, g::TransformedGeometry) = TransformedGeometry
7979
applycoord(t::CoordinateTransform, m::TransformedMesh) = TransformedMesh(m, t)
8080

8181
# special treatment for lists of geometries
82-
applycoord(t::CoordinateTransform, g::NTuple{<:Any,<:Geometry}) = map(gᵢ -> applycoord(t, gᵢ), g)
82+
applycoord(t::CoordinateTransform, g::StaticVector{<:Any,<:Geometry}) = map(gᵢ -> applycoord(t, gᵢ), g)
8383
applycoord(t::CoordinateTransform, g::AbstractVector{<:Geometry}) = [applycoord(t, gᵢ) for gᵢ in g]
8484
applycoord(t::CoordinateTransform, g::CircularVector{<:Geometry}) = CircularVector([applycoord(t, gᵢ) for gᵢ in g])
8585

test/hulls.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@
9090
# degenerate cases
9191
points = [cart(0, 0), cart(1, 0), cart(2, 0)]
9292
chull = hull(points, method)
93-
@test vertices(chull) == (cart(0, 0), cart(2, 0))
93+
@test vertices(chull) == SVector(cart(0, 0), cart(2, 0))
9494

9595
points = [cart(0, 0), cart(1, 0), cart(2, 0), cart(10, 0), cart(100, 0)]
9696
chull = hull(points, method)
97-
@test vertices(chull) == (cart(0, 0), cart(100, 0))
97+
@test vertices(chull) == SVector(cart(0, 0), cart(100, 0))
9898

9999
# partially collinear
100100
points = [

test/meshes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ end
244244
@test spacing(grid) == (T(5) * u"m", T(5) * u"m", T(5) * u"m")
245245
@test nelements(grid) == 20 * 10 * 5
246246
@test eltype(grid) <: Hexahedron
247-
@test vertices(grid[1]) == (
247+
@test vertices(grid[1]) == SVector(
248248
cart(0, 0, 0),
249249
cart(5, 0, 0),
250250
cart(5, 5, 0),

test/polytopes.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,14 @@ end
293293
@testitem "Ngons" setup = [Setup] begin
294294
pts = (cart(0, 0), cart(1, 0), cart(0, 1))
295295
tups = (T.((0, 0)), T.((1, 0)), T.((0, 1)))
296+
verts = SVector(pts)
296297
@test paramdim(Ngon) == 2
297-
@test vertices(Ngon(pts)) == pts
298-
@test vertices(Ngon(pts...)) == pts
299-
@test vertices(Ngon(tups...)) == pts
300-
@test vertices(Ngon{3}(pts)) == pts
301-
@test vertices(Ngon{3}(pts...)) == pts
302-
@test vertices(Ngon{3}(tups...)) == pts
298+
@test vertices(Ngon(pts)) == verts
299+
@test vertices(Ngon(pts...)) == verts
300+
@test vertices(Ngon(tups...)) == verts
301+
@test vertices(Ngon{3}(pts)) == verts
302+
@test vertices(Ngon{3}(pts...)) == verts
303+
@test vertices(Ngon{3}(tups...)) == verts
303304

304305
NGONS = [Triangle, Quadrangle, Pentagon, Hexagon, Heptagon, Octagon, Nonagon, Decagon]
305306
NVERT = 3:10

test/testutils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ withprecision(T, v::Vec) = numconvert.(T, v)
114114
withprecision(T, p::Point) = Meshes.withcrs(p, withprecision(T, to(p)))
115115
withprecision(T, len::Meshes.Len) = numconvert(T, len)
116116
withprecision(T, lens::NTuple{Dim,Meshes.Len}) where {Dim} = numconvert.(T, lens)
117-
withprecision(T, geoms::NTuple{Dim,<:Geometry}) where {Dim} = withprecision.(T, geoms)
117+
withprecision(T, geoms::StaticVector{Dim,<:Geometry}) where {Dim} = withprecision.(T, geoms)
118118
withprecision(T, geoms::AbstractVector{<:Geometry}) = [withprecision(T, g) for g in geoms]
119119
withprecision(T, geoms::CircularVector{<:Geometry}) = CircularVector([withprecision(T, g) for g in geoms])
120120
@generated function withprecision(T, g::G) where {G<:Meshes.GeometryOrDomain}

0 commit comments

Comments
 (0)