Skip to content

Commit fcdbe93

Browse files
committed
more tests, more fixes
1 parent b364326 commit fcdbe93

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

src/GeometryBasics.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ module GeometryBasics
2929
export OffsetInteger, ZeroIndex, OneIndex, GLIndex
3030
export FaceView, SimpleFaceView
3131
export AbstractPoint, PointMeta, PointWithUV
32-
export decompose, coordinates, faces, normals, decompose_uv, decompose_normals
33-
export Tesselation
32+
export decompose, coordinates, faces, normals, decompose_uv, decompose_normals, texturecoordinates
33+
export Tesselation, pointmeta, Normal, UV, UVW
3434
export GLTriangleFace, GLNormalMesh3D, GLPlainTriangleMesh, GLUVMesh3D, GLUVNormalMesh3D
3535
export AbstractMesh, Mesh, TriangleMesh
3636
export GLNormalMesh2D, PlainTriangleMesh

src/interfaces.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ decompose_normals(primitive) = decompose(Normal(), primitive)
117117
function decompose(NT::Normal{T}, primitive) where T
118118
n = normals(primitive)
119119
if n === nothing
120-
return decompose(NT, normals(coordinates(primitive), faces(primitive)))
120+
return collect_with_eltype(T, normals(coordinates(primitive), faces(primitive)))
121121
end
122122
return collect_with_eltype(T, n)
123123
end

src/meshes.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ function mesh(polygon::AbstractVector{P}; pointtype=P, facetype=GLTriangleFace,
150150
return Mesh(positions, faces)
151151
end
152152

153-
function triangle_mesh(primitive::Meshable{N}) where {N}
153+
function triangle_mesh(primitive::Meshable{N}; nvertices=nothing) where {N}
154+
if nvertices !== nothing
155+
@warn("nvertices argument deprecated. Wrap primitive in `Tesselation(primitive, nvertices)`")
156+
primitive = Tesselation(primitive, nvertices)
157+
end
154158
return mesh(primitive; pointtype=Point{N, Float32}, facetype=GLTriangleFace)
155159
end
156160

@@ -172,20 +176,15 @@ function normal_mesh(points::AbstractVector{<:AbstractPoint},
172176
return Mesh(meta(_points; normals=normals(_points, _faces)), _faces)
173177
end
174178

175-
function normal_mesh(primitive::Meshable{N}) where {N}
179+
function normal_mesh(primitive::Meshable{N}; nvertices=nothing) where {N}
180+
if nvertices !== nothing
181+
@warn("nvertices argument deprecated. Wrap primitive in `Tesselation(primitive, nvertices)`")
182+
primitive = Tesselation(primitive, nvertices)
183+
end
176184
return mesh(primitive; pointtype=Point{N, Float32}, normaltype=Vec3f0,
177185
facetype=GLTriangleFace)
178186
end
179187

180-
## Backward compatibility
181-
function normal_mesh(primitive::GeometryPrimitive; nvertices=30)
182-
return normal_mesh(Tesselation(primitive, nvertices))
183-
end
184-
185-
function triangle_mesh(primitive::GeometryPrimitive; nvertices=30)
186-
return triangle_mesh(Tesselation(primitive, nvertices))
187-
end
188-
189188
"""
190189
volume(triangle)
191190
@@ -244,7 +243,7 @@ function pointmeta(mesh::Mesh, uv::UV)
244243
end
245244

246245
function pointmeta(mesh::Mesh, normal::Normal)
247-
return pointmeta(mesh; normal=decompose(normal, mesh))
246+
return pointmeta(mesh; normals=decompose(normal, mesh))
248247
end
249248

250249
"""

test/runtests.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ end
284284
mesh = triangle_mesh(primitive)
285285
@test decompose(Point, mesh) isa Vector{Point3f0}
286286
@test decompose(Point, primitive) isa Vector{Point3f0}
287+
287288
primitive = Rect2D(0, 0, 1, 1)
288289
mesh = triangle_mesh(primitive)
289290

@@ -294,19 +295,22 @@ end
294295
triangle_mesh(primitive)
295296

296297
primitive = Sphere(Point3f0(0), 1)
297-
normal_mesh(primitive)
298+
m_normal = normal_mesh(primitive)
299+
@test normals(m_normal) isa Vector{Vec3f0}
298300
primitive = Rect2D(0, 0, 1, 1)
299-
normal_mesh(primitive)
301+
m_normal = normal_mesh(primitive)
302+
@test normals(m_normal) isa Vector{Vec3f0}
300303
primitive = Rect3D(0, 0, 0, 1, 1, 1)
301-
normal_mesh(primitive)
304+
m_normal = normal_mesh(primitive)
305+
@test normals(m_normal) isa Vector{Vec3f0}
302306

303307
points = decompose(Point2f0, Circle(Point2f0(0), 1))
304-
triangle_mesh(points)
305-
@test true # yay no errors so far!
308+
tmesh = triangle_mesh(points)
309+
@test normals(tmesh) == nothing
306310

307311
m = GeometryBasics.mesh(Sphere(Point3f0(0), 1))
308312
@test normals(m) == nothing
309-
m_normals = pointmeta(m, Normal(Vec3f0))
313+
m_normals = pointmeta(m, Normal())
310314
@test normals(m_normals) isa Vector{Vec3f0}
311315

312316
@test texturecoordinates(m) == nothing
@@ -327,7 +331,7 @@ end
327331
points = rand(Point3f0, 10)
328332
m = GeometryBasics.Mesh(meta(points, xx=xx), GLTriangleFace[(1,2,3), (3,4,5)])
329333
color = rand(10)
330-
m = GeometryBasics.pointmeta(m; color=color)
334+
m = pointmeta(m; color=color)
331335

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

0 commit comments

Comments
 (0)