Skip to content

Commit

Permalink
remove add_meta, pop_meta
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Aug 31, 2024
1 parent 6ffd173 commit 9758bed
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 74 deletions.
1 change: 0 additions & 1 deletion src/GeometryBasics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export decompose, coordinates, faces, normals, decompose_uv, decompose_normals,
texturecoordinates
export Tesselation, Normal, UV, UVW
export AbstractMesh, Mesh, MetaMesh
export add_meta, pop_meta


# all the different predefined mesh types
Expand Down
32 changes: 1 addition & 31 deletions src/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function mesh(polygon::AbstractVector{P}; pointtype=P, facetype=GLTriangleFace)
return mesh(Polygon(polygon); pointtype=pointtype, facetype=facetype)
end

function triangle_mesh(primitive::Union{AbstractGeometry{N}, AbstractVector{<: Point{N}}})::TriangleMesh{N} where {N}
function triangle_mesh(primitive::Union{AbstractGeometry{N}, AbstractVector{<: Point{N}}})::SimpleTriangleMesh{N} where {N}
return mesh(primitive; pointtype=Point{N, Float32})
end

Expand Down Expand Up @@ -278,36 +278,6 @@ function map_coordinates!(f, mesh::AbstractMesh)
return mesh
end

# TODO:
add_meta(m, kw...) = error("TODO")
pop_meta(m, kw...) = error("TODO")
# function add_meta(mesh::MetaMesh; kw...)
# return MetaMesh(Mesh(mesh), (; meta(mesh)..., kw...))
# end

# function add_meta(mesh::Mesh; kw...)
# return MetaMesh(mesh, (; meta(mesh)..., kw...))
# end

# # I didn't find a simple way to remove a field from a namedtuple in a type stable way without
# # a generated function..
# @generated function pop(nt::NamedTuple{Names, Values}, ::Val{name}) where {Names, Values, name}
# if !(name in Names)
# return :(throw(Base.KeyError($(QuoteNode(name)))))
# else
# names = filter(x-> x !== name, Names)
# nt = map(names) do name
# :($name = nt.$(name))
# end
# return :((; $(nt...)), nt.$(name))
# end
# end

# function pop_meta(mesh::MetaMesh, name::Symbol)
# new_meta, value = pop(meta(mesh), Val(name))
# return MetaMesh(mesh, new_meta), value
# end

function Base.show(io::IO, ::MIME"text/plain", mesh::Mesh{N, T, FT}) where {N, T, FT}
println(io, "Mesh{$N, $T, $FT}")
println(io, " faces: ", length(faces(mesh)))
Expand Down
2 changes: 1 addition & 1 deletion test/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ end
m2 = GeometryBasics.merge_vertex_indices(m)

@test faces(m) isa AbstractVector{<: GeometryBasics.MultiFace}
@test names(eltype(faces(m))) == keys(GeometryBasics.vertex_attributes(m))
@test propertynames(eltype(faces(m))) == keys(GeometryBasics.vertex_attributes(m))
@test isempty(m.views)

@test faces(m2) isa AbstractVector{<: QuadFace}
Expand Down
42 changes: 1 addition & 41 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Test, Random, OffsetArrays
using GeometryBasics
using LinearAlgebra
using GeometryBasics: MetaMesh, add_meta, pop_meta
using GeometryBasics: MetaMesh
using GeoInterface
using GeoJSON
using Extents
Expand Down Expand Up @@ -203,46 +203,6 @@ end
@test m.normals == [Vec3f(0, 0, 1) for p in coordinates(m)]
end

@testset "convert mesh + meta" begin
m = uv_normal_mesh(Rect3f(Vec3f(-1), Vec3f(1, 2, 3)))
m_normal = add_meta(m; normals = decompose_normals(m))
# make sure we don't loose the uv
@test hasproperty(m_normal, :uv)
# Make sure we don't create any copies
@test coordinates(m) === coordinates(m_normal)
@test m.normals == m_normal.normals
@test m.uv === m_normal.uv

m = uv_mesh(Rect3f(Vec3f(-1), Vec3f(1, 2, 3)))
m_normal = add_meta(m, normals = decompose_normals(m))
@test hasproperty(m_normal, :uv)
@test coordinates(m) === coordinates(m_normal)
@test decompose_normals(m) == GeometryBasics.normals(m_normal)
# uv stays untouched, since we don't specify the element type in normalmesh
@test m.uv === m_normal.uv
end

@testset "modifying meta" begin
xx = rand(10)
points = rand(Point3f, 10)
m = MetaMesh(points, GLTriangleFace[(1,2,3), (3,4,5)]; xx=xx)
color = rand(10)
m = add_meta(m; color=color)

@test hasproperty(m, :xx)
@test hasproperty(m, :color)

@test m.xx === xx
@test m.color === color

m, colpopt = GeometryBasics.pop_meta(m, :color)
m, xxpopt = GeometryBasics.pop_meta(m, :xx)

@test propertynames(m) == ()
@test colpopt === color
@test xxpopt === xx
end

@testset "mesh conversion" begin
s = Sphere(Point3(0.0), 1.0)
m = GeometryBasics.mesh(s)
Expand Down

0 comments on commit 9758bed

Please sign in to comment.