Skip to content

Commit dc103e8

Browse files
authored
Use default getindex for vector[face] when no Polytope is generated (#246)
* use default getindex when not generating Polytopes * revert Polytope return type for getindex * fix tests * make mesh[i] return a Polytope again * test Bool operations on faces * revert changes to volume
1 parent bab7f91 commit dc103e8

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/basic_types.jl

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ abstract type AbstractNgonFace{N,T} <: AbstractFace{N,T} end
3131

3232
abstract type AbstractSimplex{Dim,T} <: Polytope{Dim,T} end
3333

34-
@propagate_inbounds function Base.getindex(points::AbstractVector{P}, face::F) where {P<: Point, F <: AbstractFace}
35-
return Polytope(P, F)(map(i-> points[i], face.data))
36-
end
37-
38-
@propagate_inbounds function Base.getindex(elements::AbstractVector, face::F) where {F <: AbstractFace}
39-
return map(i-> elements[i], face.data)
40-
end
41-
4234
@fixed_vector SimplexFace = AbstractSimplexFace
4335

4436
const TetrahedronFace{T} = SimplexFace{4,T}
@@ -597,7 +589,12 @@ Mutating these will change the mesh.
597589
"""
598590
vertex_attributes(mesh::Mesh) = getfield(mesh, :vertex_attributes)
599591

600-
Base.getindex(mesh::Mesh, i::Integer) = mesh.position[mesh.faces[i]]
592+
function Base.getindex(mesh::Mesh, i::Integer)
593+
f = mesh.faces[i]
594+
P = Polytope(eltype(mesh.position), typeof(f))
595+
return P(map(j -> mesh.position[j], f.data))
596+
end
597+
601598
Base.length(mesh::Mesh) = length(mesh.faces)
602599

603600
function Base.:(==)(a::Mesh, b::Mesh)

test/geometrytypes.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,15 @@ end
298298

299299
ps = rand(Point2f, 10)
300300
f = GLTriangleFace(1, 2, 3)
301-
@test ps[f] == Triangle(ps[[1,2,3]]...)
301+
@test ps[f] == GeometryBasics.@SVector [ps[1], ps[2], ps[3]]
302+
302303
data = [string(i) for i in 1:10]
303304
f = QuadFace(3, 4, 7, 8)
304-
@test data[f] == ("3", "4", "7", "8")
305+
@test data[f] == ["3", "4", "7", "8"]
306+
307+
@test (f .== 4) == QuadFace(false, true, false, false)
308+
@test f[f .== 4] isa Vector{Int}
309+
@test f[f .== 4] == [4]
305310

306311
@test GeometryBasics.cyclic_hash(f) != GeometryBasics.cyclic_hash(QuadFace(1,2,3,4))
307312
@test GeometryBasics.cyclic_hash(f) == GeometryBasics.cyclic_hash(QuadFace(3,4,7,8))

0 commit comments

Comments
 (0)