Skip to content

Commit 4dd9e76

Browse files
committed
make mesh[i] return a Polytope again
1 parent 122b2ba commit 4dd9e76

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/basic_types.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,12 @@ Mutating these will change the mesh.
589589
"""
590590
vertex_attributes(mesh::Mesh) = getfield(mesh, :vertex_attributes)
591591

592-
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+
593598
Base.length(mesh::Mesh) = length(mesh.faces)
594599

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

test/meshes.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ end
1111
f = [TriangleFace(1, 2, 3), QuadFace(1, 2, 3, 4)]
1212
p = Point2f[(0, 1), (1, 2), (3, 4), (4, 5)]
1313
m = Mesh(p, f)
14-
@test collect(m) == [GeometryBasics.SVector(p[1], p[2], p[3]), GeometryBasics.SVector(p[1], p[2], p[3], p[4])]
14+
@test collect(m) == [Triangle(p[1], p[2], p[3]), GeometryBasics.Quadrilateral(p[1], p[2], p[3], p[4])]
1515
end
1616

1717
@testset "Heterogenous faces" begin
1818
# https://github.com/JuliaGeometry/GeometryBasics.jl/issues/142
1919
f = [TriangleFace(1, 2, 3), QuadFace(1, 2, 3, 4)]
2020
p = Point2f[(0, 1), (1, 2), (3, 4), (4, 5)]
2121
m = Mesh(p, f)
22-
@test collect(m) == [GeometryBasics.SVector(p[1], p[2], p[3]), GeometryBasics.SVector(p[1], p[2], p[3], p[4])]
22+
@test collect(m) == [Triangle(p[1], p[2], p[3]), GeometryBasics.Quadrilateral(p[1], p[2], p[3], p[4])]
2323
end
2424

2525
@testset "Ambiguous NgonFace constructors" begin

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ end
136136
points = connect([1, 2, 3, 4, 5, 6, 7, 8], Point{2})
137137
f = connect([1, 2, 3, 4], SimplexFace{4})
138138
mesh = Mesh(points, f)
139-
@test collect(mesh) == [GeometryBasics.SVector(points...)]
139+
@test collect(mesh) == [Tetrahedron(points...)]
140140
@test faces(mesh) == [TetrahedronFace{Int64}(1,2,3,4)]
141141
@test decompose(LineFace{Int64}, mesh) == LineFace{Int64}[(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
142142
@test decompose(GLTriangleFace, mesh) == GLTriangleFace[(2, 3, 4), (1, 3, 4), (1, 2, 4), (1, 2, 3)]

0 commit comments

Comments
 (0)