Skip to content

Commit 2c8f093

Browse files
committed
add some more constructors
1 parent 712691b commit 2c8f093

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/GeometryBasics.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ abstract type AbstractSimplex{Dimension, N, T} <: StaticVector{Dimension, T} end
1717

1818
GeometryTypes.@fixed_vector Point AbstractPoint
1919

20+
"""
21+
Face index, connecting points to form a simplex
22+
"""
23+
GeometryTypes.@fixed_vector SimplexFace AbstractFace
24+
25+
"""
26+
Face index, connecting points to form an Ngon
27+
"""
28+
GeometryTypes.@fixed_vector NgonFace AbstractFace
29+
const TriangleFace{T} = NgonFace{3, T}
30+
function element_type(P::Type{<: AbstractPoint{Dim, T}}, ::Type{<: NgonFace{N}}) where {N, Dim, T}
31+
NGon{Dim, T, N, P}
32+
end
33+
2034
"""
2135
Fixed Size Polygon, e.g.
2236
N 1-2 : Illegal!
@@ -168,6 +182,10 @@ struct Mesh{
168182
simplices::V
169183
end
170184

185+
function Mesh(elements::AbstractVector{<: Polytope{Dim, T}}) where {Dim, T}
186+
Mesh{Dim, T, eltype(elements), typeof(elements)}(elements)
187+
end
188+
171189
"""
172190
FaceView enables to link one array of points via a face array, to generate one
173191
abstract array of elements.
@@ -195,6 +213,13 @@ struct FaceView{
195213
points::P
196214
faces::F
197215
end
216+
function FaceView(points::AbstractVector{P}, faces::AbstractVector{F}) where {P <: AbstractPoint, F <: AbstractFace}
217+
Element = element_type(P, F)
218+
FaceView{Element, P, F, typeof(points), typeof(faces)}(points, faces)
219+
end
198220

221+
function Mesh(points::AbstractVector{<: AbstractPoint}, faces::AbstractVector{<: AbstractFace})
222+
Mesh(FaceView(points, faces))
223+
end
199224

200225
end # module

0 commit comments

Comments
 (0)