Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/basic_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions test/geometrytypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading