Skip to content

Commit 744c51b

Browse files
committed
improve meshes.jl coverage
1 parent 73aedef commit 744c51b

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

src/GeometryBasics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export AbstractFace, TriangleFace, QuadFace, GLTriangleFace
4141
export OffsetInteger, ZeroIndex, OneIndex, GLIndex
4242
export decompose, coordinates, faces, normals, decompose_uv, decompose_normals,
4343
texturecoordinates, vertex_attributes
44-
export expand_faceviews
44+
export expand_faceviews, split_mesh, remove_duplicates
4545
export face_normals
4646
export Tessellation, Normal, UV, UVW
4747
export AbstractMesh, Mesh, MetaMesh, FaceView

src/meshes.jl

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,6 @@ function expand_faceviews(mesh::Mesh)
390390
end
391391
end
392392

393-
function merge_vertex_indices(
394-
faces::AbstractVector{FT}, args...
395-
) where {N, T, FT <: AbstractFace{N, T}}
396-
if args[end] isa Integer
397-
fs = tuple(faces, args[1:end-1]...)
398-
return merge_vertex_indices(fs, args[end])
399-
else
400-
return merge_vertex_indices(tuple(faces, args...))
401-
end
402-
end
403-
404393
function merge_vertex_indices(
405394
faces::NTuple{N_Attrib, <: AbstractVector{FT}},
406395
vertex_index_counter::Integer = T(1)
@@ -486,13 +475,13 @@ end
486475

487476

488477
function map_coordinates(f, mesh::Mesh)
489-
result = copy(mesh)
478+
result = deepcopy(mesh)
490479
map_coordinates!(f, result)
491480
return result
492481
end
493482

494483
function map_coordinates(f, mesh::MetaMesh)
495-
result = copy(Mesh(mesh))
484+
result = deepcopy(Mesh(mesh))
496485
map_coordinates!(f, result)
497486
return MetaMesh(result, meta(mesh))
498487
end

test/meshes.jl

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,18 @@ end
5454
@test isempty(m2.views)
5555
end
5656

57-
@testset "complex merge" begin
57+
@testset "Duplicate face removal" begin
58+
fs = GLTriangleFace[(1,2,3), (2,3,4), (3,4,5), (1,2,3), (1,4,5)]
59+
fs = [fs; fs]
60+
new_fs = remove_duplicates(fs)
61+
@test all(f -> f in GLTriangleFace[(1,2,3), (2,3,4), (3,4,5), (1,4,5)], new_fs)
62+
63+
fs = rand(QuadFace{Int32}, 4)
64+
new_fs = remove_duplicates([fs; fs])
65+
@test all(in(fs), new_fs)
66+
end
67+
68+
@testset "complex merge + split" begin
5869
rects = [Rect3f(Point3f(x, y, z), Vec3f(0.5)) for x in -1:1 for y in -1:1 for z in -1:1]
5970
direct_meshes = map(rects) do r
6071
GeometryBasics.Mesh(coordinates(r), faces(r), normal = normals(r))
@@ -264,6 +275,8 @@ end
264275
@test faces(m) isa Vector{GLTriangleFace}
265276
@test length(faces(m)) == 12
266277
@test GeometryBasics.facetype(m) == GLTriangleFace
278+
279+
@test normal_mesh(coordinates(m), faces(m)) == m
267280
end
268281

269282
@testset "normal_uv_mesh()" begin
@@ -372,4 +385,21 @@ end
372385
@test length(faces(m2)) == 12
373386

374387
end
388+
end
389+
390+
@testset "map_coordinates" begin
391+
m = GeometryBasics.mesh(Rect3f(0,0,0,1,1,1))
392+
m2 = GeometryBasics.map_coordinates(p -> 2 * p, m)
393+
@test m !== m2
394+
@test 2 * coordinates(m) == coordinates(m2)
395+
396+
m3 = GeometryBasics.map_coordinates!(p -> 0.5 * p, m2)
397+
@test m3 === m2
398+
@test coordinates(m) == coordinates(m3)
399+
400+
m = MetaMesh(GeometryBasics.mesh(Rect3f(0,0,0,1,1,1)), meta = "test")
401+
m2 = GeometryBasics.map_coordinates(p -> 2 * p, m)
402+
@test m !== m2
403+
@test 2 * coordinates(m) == coordinates(m2)
404+
@test GeometryBasics.meta(m) == GeometryBasics.meta(m2)
375405
end

0 commit comments

Comments
 (0)