Skip to content

Commit

Permalink
Update constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
eliascarv committed Nov 12, 2024
1 parent f4ca9ed commit 753ec1a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/geometries/polytopes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ macro polytope(type, K, N)
expr = quote
$Base.@__doc__ $structexpr

$type(vertices::Vararg{Tuple,$N}) = $type(SVector(Point.(vertices)))
$type(vertices::Vararg{P,$N}) where {P<:Point} = $type(SVector(vertices))
$type(vertices::NTuple{$N,Point{M,C}}) 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

esc(expr)
Expand Down
12 changes: 6 additions & 6 deletions src/geometries/polytopes/ngon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ struct Ngon{N,M<:Manifold,C<:CRS} <: Polygon{M,C}
end
end

Ngon{N}(vertices::SVector{N,Point{M,C}}) where {N,M<:Manifold,C<:CRS} = Ngon{N,M,C}(vertices)
Ngon{N}(vertices::Vararg{P,N}) where {N,P<:Point} = Ngon{N}(SVector(vertices))
Ngon{N}(vertices::Vararg{Tuple,N}) where {N} = Ngon{N}(SVector(Point.(vertices)))
Ngon{N}(vertices::NTuple{N,Point{M,C}}) where {N,M<:Manifold,C<:CRS} = Ngon{N,M,C}(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::SVector{N,Point{M,C}}) where {N,M<:Manifold,C<:CRS} = Ngon{N,M,C}(vertices)
Ngon(vertices::P...) where {P<:Point} = Ngon(SVector(vertices))
Ngon(vertices::Tuple...) = Ngon(SVector(Point.(vertices)))
Ngon(vertices::NTuple{N,Point{M,C}}) where {N,M<:Manifold,C<:CRS} = Ngon{N,M,C}(SVector(vertices))
Ngon(vertices::P...) where {P<:Point} = Ngon(vertices)
Ngon(vertices::Tuple...) = Ngon(Point.(vertices))

# type aliases for convenience
const Triangle = Ngon{3}
Expand Down
15 changes: 8 additions & 7 deletions test/polytopes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,16 @@ end
end

@testitem "Ngons" setup = [Setup] begin
pts = SVector(cart(0, 0), cart(1, 0), cart(0, 1))
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
Expand Down

0 comments on commit 753ec1a

Please sign in to comment.