diff --git a/src/basic_types.jl b/src/basic_types.jl index 996b0800..48e776d8 100644 --- a/src/basic_types.jl +++ b/src/basic_types.jl @@ -31,14 +31,6 @@ abstract type AbstractNgonFace{N,T} <: AbstractFace{N,T} end abstract type AbstractSimplex{Dim,T} <: Polytope{Dim,T} end -@propagate_inbounds function Base.getindex(points::AbstractVector{P}, face::F) where {P<: Point, F <: AbstractFace} - return Polytope(P, F)(map(i-> points[i], face.data)) -end - -@propagate_inbounds function Base.getindex(elements::AbstractVector, face::F) where {F <: AbstractFace} - return map(i-> elements[i], face.data) -end - @fixed_vector SimplexFace = AbstractSimplexFace const TetrahedronFace{T} = SimplexFace{4,T} @@ -597,7 +589,12 @@ Mutating these will change the mesh. """ vertex_attributes(mesh::Mesh) = getfield(mesh, :vertex_attributes) -Base.getindex(mesh::Mesh, i::Integer) = mesh.position[mesh.faces[i]] +function Base.getindex(mesh::Mesh, i::Integer) + f = mesh.faces[i] + P = Polytope(eltype(mesh.position), typeof(f)) + return P(map(j -> mesh.position[j], f.data)) +end + Base.length(mesh::Mesh) = length(mesh.faces) function Base.:(==)(a::Mesh, b::Mesh) diff --git a/test/geometrytypes.jl b/test/geometrytypes.jl index f35236ca..51746602 100644 --- a/test/geometrytypes.jl +++ b/test/geometrytypes.jl @@ -298,10 +298,15 @@ end ps = rand(Point2f, 10) f = GLTriangleFace(1, 2, 3) - @test ps[f] == Triangle(ps[[1,2,3]]...) + @test ps[f] == GeometryBasics.@SVector [ps[1], ps[2], ps[3]] + data = [string(i) for i in 1:10] f = QuadFace(3, 4, 7, 8) - @test data[f] == ("3", "4", "7", "8") + @test data[f] == ["3", "4", "7", "8"] + + @test (f .== 4) == QuadFace(false, true, false, false) + @test f[f .== 4] isa Vector{Int} + @test f[f .== 4] == [4] @test GeometryBasics.cyclic_hash(f) != GeometryBasics.cyclic_hash(QuadFace(1,2,3,4)) @test GeometryBasics.cyclic_hash(f) == GeometryBasics.cyclic_hash(QuadFace(3,4,7,8))