Skip to content

Commit ea4a1a0

Browse files
committed
improvements to access meshes etc
1 parent ee3aec5 commit ea4a1a0

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

src/basic_types.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,17 @@ end
297297

298298
Tables.schema(fw::Mesh) = Tables.schema(getfield(fw, :simplices))
299299

300-
column_names(fw::Mesh) = column_names(getfield(fw, :simplices))
301-
column_types(fw::Mesh) = column_types(getfield(fw, :simplices))
300+
function Base.getproperty(x::Mesh, name::Symbol)
301+
getproperty(getfield(x, :simplices), name)
302+
end
302303

303304
function Base.summary(io::IO, x::Mesh{Dim, T, Element}) where {Dim, T, Element}
304305
print(io, "Mesh{$Dim, $T, ")
305306
summary(io, Element)
306307
print(io, "}")
307308
end
308-
Base.size(x::Mesh) = size(x.simplices)
309-
Base.getindex(x::Mesh, i::Integer) = x.simplices[i]
309+
Base.size(x::Mesh) = size(getfield(x, :simplices))
310+
Base.getindex(x::Mesh, i::Integer) = getfield(x, :simplices)[i]
310311

311312

312313
function Mesh(elements::AbstractVector{<: Polytope{Dim, T}}) where {Dim, T}

src/metadata.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ macro meta_type(name, mainfield, supertype, params...)
130130
return esc(expr)
131131
end
132132

133-
@meta_type(Point, point, AbstractPoint, Dim, T)
133+
@meta_type(Point, position, AbstractPoint, Dim, T)
134134
Base.getindex(x::PointMeta, idx::Int) = getindex(metafree(x), idx)
135135

136136

src/viewtypes.jl

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,29 +115,29 @@ struct FaceView{
115115
F <: AbstractVector{Face}
116116
} <: AbstractVector{Element}
117117

118-
points::P
118+
elements::P
119119
faces::F
120120
end
121+
function Base.getproperty(x::FaceView, name::Symbol)
122+
getproperty(getfield(x, :elements), name)
123+
end
121124

122-
Tables.schema(fw::FaceView) = Tables.schema(getfield(fw, :points))
123-
124-
column_names(fw::FaceView) = column_names(getfield(fw, :points))
125-
column_types(fw::FaceView) = column_types(getfield(fw, :points))
125+
Tables.schema(fw::FaceView) = Tables.schema(getfield(fw, :elements))
126126

127127

128-
Base.size(x::FaceView) = size(x.faces)
128+
Base.size(x::FaceView) = size(getfield(x, :faces))
129129

130130
Base.show(io::IO, x::Type{<: FaceView{Element}}) where Element = print(io, "FaceView{", Element, "}")
131131

132132

133133
@propagate_inbounds function Base.getindex(x::FaceView{Element}, i) where Element
134-
Element(map(idx-> x.points[idx], x.faces[i]))
134+
Element(map(idx-> coordinates(x)[idx], faces(x)[i]))
135135
end
136136

137137
@propagate_inbounds function Base.setindex!(x::FaceView{Element}, element::Element, i) where Element
138-
face = x.faces[i]
138+
face = faces(x)[i]
139139
for (i, f) in enumerate(face) # TODO unroll!?
140-
x.points[face[i]] = element[i]
140+
coordinates(x)[face[i]] = element[i]
141141
end
142142
return element
143143
end
@@ -146,13 +146,10 @@ function connect(points::AbstractVector{P}, faces::AbstractVector{F}) where {P <
146146
FaceView{Polytope(P, F), P, F, typeof(points), typeof(faces)}(points, faces)
147147
end
148148

149-
150-
151149
const FaceMesh{Dim, T, Element} = Mesh{Dim, T, Element, <: FaceView{Element}}
152150

153-
function coordinates(mesh::FaceMesh)
154-
mesh.simplices.points
155-
end
156-
function faces(mesh::FaceMesh)
157-
mesh.simplices.faces
158-
end
151+
coordinates(mesh::FaceView) = getfield(mesh, :elements)
152+
faces(mesh::FaceView) = getfield(mesh, :faces)
153+
154+
coordinates(mesh::FaceMesh) = coordinates(getfield(mesh, :simplices))
155+
faces(mesh::FaceMesh) = faces(getfield(mesh, :simplices))

0 commit comments

Comments
 (0)