11"""
22Abstract Geometry in R{Dim} with Number type T
33"""
4- abstract type AbstractGeometry{Dim, T <: Real } end
4+ abstract type AbstractGeometry{Dim, T <: Number } end
5+ abstract type GeometryPrimitive{Dim, T} <: AbstractGeometry{Dim, T} end
6+ Base. ndims (x:: AbstractGeometry{Dim} ) where Dim = Dim
57
68"""
79Geometry made of N connected points. Connected as one flat geometry, it makes a Ngon / Polygon.
@@ -18,32 +20,47 @@ abstract type AbstractNgonFace{N, T} <: AbstractFace{N, T} end
1820
1921abstract type AbstractSimplex{Dim, N, T} <: StaticVector{Dim, T} end
2022
21- @fixed_vector Point AbstractPoint
22-
23-
23+ """
24+ coordinates(geometry)
25+ Returns the edges/vertices/coordinates of a geometry. Is allowed to return lazy iterators!
26+ Use `decompose(ConcretePointType, geometry)` to get `Vector{ConcretePointType}` with
27+ `ConcretePointType` to be something like `Point{3, Float32}`.
28+ """
29+ function coordinates (points:: AbstractVector{<:AbstractPoint} )
30+ return points
31+ end
2432
33+ """
34+ faces(geometry)
35+ Returns the face connections of a geometry. Is allowed to return lazy iterators!
36+ Use `decompose(ConcreteFaceType, geometry)` to get `Vector{ConcreteFaceType}` with
37+ `ConcreteFaceType` to be something like `TriangleFace{Int}`.
38+ """
39+ function faces (f:: AbstractVector{<:AbstractFace} )
40+ return f
41+ end
2542
2643"""
2744Face index, connecting points to form a simplex
2845"""
2946
3047@fixed_vector SimplexFace AbstractSimplexFace
31- const LineFace{T} = SimplexFace{2 , T}
3248const TetrahedronFace{T} = SimplexFace{4 , T}
3349Face (:: Type{<: SimplexFace{N}} , :: Type{T} ) where {N, T} = SimplexFace{N, T}
3450
35-
3651"""
3752Face index, connecting points to form an Ngon
3853"""
3954
4055@fixed_vector NgonFace AbstractNgonFace
56+ const LineFace{T} = NgonFace{2 , T}
4157const TriangleFace{T} = NgonFace{3 , T}
4258const QuadFace{T} = NgonFace{4 , T}
4359
4460Base. show (io:: IO , x:: TriangleFace{T} ) where T = print (io, " TriangleFace(" , join (x, " , " ), " )" )
4561
4662Face (:: Type{<: NgonFace{N}} , :: Type{T} ) where {N, T} = NgonFace{N, T}
63+ Face (F:: Type{NgonFace{N, FT}} , :: Type{T} ) where {FT, N, T} = F
4764
4865@propagate_inbounds Base. getindex (x:: Polytope , i:: Integer ) = coordinates (x)[i]
4966@propagate_inbounds Base. iterate (x:: Polytope ) = iterate (coordinates (x))
@@ -65,10 +82,11 @@ struct Ngon{
6582
6683 points:: SVector{N, Point}
6784end
85+
6886const NNgon{N} = Ngon{Dim, T, N, P} where {Dim, T, P}
6987
7088function (:: Type{<: NNgon{N}} )(points:: Vararg{P, N} ) where {P <: AbstractPoint{Dim, T} , N} where {Dim, T}
71- Ngon {Dim, T, N, P} (SVector (points))
89+ return Ngon {Dim, T, N, P} (SVector (points))
7290end
7391Base. show (io:: IO , x:: NNgon{N} ) where N = print (io, " Ngon{$N }(" , join (x, " , " ), " )" )
7492
@@ -92,6 +110,10 @@ function Polytope(::Type{<: NNgon{N}}, P::Type{<: AbstractPoint{NDim, T}}) where
92110 Ngon{NDim, T, N, P}
93111end
94112
113+
114+ const LineP{Dim, T, P <: AbstractPoint{Dim, T} } = Ngon{Dim, T, 2 , P}
115+ const Line{Dim, T} = LineP{Dim, T, Point{Dim, T}}
116+
95117# Simplex{D, T, 3} & Ngon{D, T, 3} are both representing a triangle.
96118# Since Ngon is supposed to be flat and a triangle is flat, lets prefer Ngon
97119# for triangle:
@@ -130,8 +152,6 @@ struct Simplex{
130152end
131153
132154const NSimplex{N} = Simplex{Dim, T, N, P} where {Dim, T, P}
133- const LineP{Dim, T, P <: AbstractPoint{Dim, T} } = Simplex{Dim, T, 2 , P}
134- const Line{Dim, T} = LineP{Dim, T, Point{Dim, T}}
135155const TetrahedronP{T, P <: AbstractPoint{3, T} } = Simplex{3 , T, 4 , P}
136156const Tetrahedron{T} = TetrahedronP{T, Point{3 , T}}
137157
@@ -293,56 +313,72 @@ Base.getindex(ms::MultiLineString, i) = ms.linestrings[i]
293313Base. size (ms:: MultiLineString ) = size (ms. linestrings)
294314
295315struct MultiPoint{
296- Dim, T <: Real ,
297- Element <: AbstractPoint{Dim, T} ,
298- A <: AbstractVector{Element}
299- } <: AbstractVector{Element}
316+ Dim, T <: Real ,
317+ Element <: AbstractPoint{Dim, T} ,
318+ A <: AbstractVector{Element}
319+ } <: AbstractVector{Element}
300320
301321 points:: A
302322end
303323
304324function MultiPoint (points:: AbstractVector{P} ; kw... ) where P <: AbstractPoint{Dim, T} where {Dim, T}
305- MultiPoint (meta (points; kw... ))
325+ return MultiPoint (meta (points; kw... ))
306326end
307327
308328Base. getindex (mpt:: MultiPoint , i) = mpt. points[i]
309329Base. size (mpt:: MultiPoint ) = size (mpt. points)
310330
331+ """
332+ AbstractMesh
333+
334+ An abstract mesh is a collection of Polytope elements (Simplices / Ngons).
335+ The connections are defined via faces(mesh), the coordinates of the elements are returned by
336+ coordinates(mesh). Arbitrary meta information can be attached per point or per face
337+ """
338+ const AbstractMesh{Element} = AbstractVector{Element}
339+
340+ """
341+ Mesh <: AbstractVector{Element}
342+ The conrecte AbstractMesh implementation
343+ """
311344struct Mesh{
312345 Dim, T <: Real ,
313346 Element <: Polytope{Dim, T} ,
314347 V <: AbstractVector{Element}
315- } <: AbstractVector{Element}
316-
317- simplices:: V
348+ } <: AbstractMesh{Element}
349+ simplices:: V # usually a FaceView, to connect a set of points via a set of faces.
318350end
319351
320- Tables. schema (fw:: Mesh ) = Tables. schema (getfield (fw, :simplices ))
352+ Tables. schema (mesh:: Mesh ) = Tables. schema (getfield (mesh, :simplices ))
353+
354+ function Base. getproperty (mesh:: Mesh , name:: Symbol )
355+ return getproperty (getfield (mesh, :simplices ), name)
356+ end
321357
322- function Base. getproperty (x :: Mesh , name :: Symbol )
323- getproperty (getfield (x , :simplices ), name )
358+ function Base. propertynames (mesh :: Mesh )
359+ return propertynames (getfield (mesh , :simplices ))
324360end
325361
326- function Base. summary (io:: IO , x :: Mesh{Dim, T, Element} ) where {Dim, T, Element}
362+ function Base. summary (io:: IO , :: Mesh{Dim, T, Element} ) where {Dim, T, Element}
327363 print (io, " Mesh{$Dim , $T , " )
328364 summary (io, Element)
329365 print (io, " }" )
330366end
331- Base. size (x:: Mesh ) = size (getfield (x, :simplices ))
332- Base. getindex (x:: Mesh , i:: Integer ) = getfield (x, :simplices )[i]
333367
368+ Base. size (mesh:: Mesh ) = size (getfield (mesh, :simplices ))
369+ Base. getindex (mesh:: Mesh , i:: Integer ) = getfield (mesh, :simplices )[i]
334370
335371function Mesh (elements:: AbstractVector{<: Polytope{Dim, T}} ) where {Dim, T}
336- Mesh {Dim, T, eltype(elements), typeof(elements)} (elements)
372+ return Mesh {Dim, T, eltype(elements), typeof(elements)} (elements)
337373end
338374
339375function Mesh (points:: AbstractVector{<: AbstractPoint} , faces:: AbstractVector{<: AbstractFace} )
340- Mesh (connect (points, faces))
376+ return Mesh (connect (points, faces))
341377end
342378
343379function Mesh (
344380 points:: AbstractVector{<: AbstractPoint} , faces:: AbstractVector{<: Integer} ,
345381 facetype = TriangleFace, skip = 1
346382 )
347- Mesh (connect (points, connect (faces, facetype, skip)))
383+ return Mesh (connect (points, connect (faces, facetype, skip)))
348384end
0 commit comments