Skip to content

Commit 93362a2

Browse files
authored
Merge pull request #198 from JuliaGeometry/sd/triangle_mesh-fastpath
don't convert if already of correct type
2 parents d5435e4 + c3c1147 commit 93362a2

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/meshes.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ function mesh(polygon::AbstractPolygon{Dim,T}; pointtype=Point{Dim,T},
167167
return Mesh(positions, faces)
168168
end
169169

170+
pointtype(x::Mesh) = eltype(decompose(Point, x))
171+
facetype(x::Mesh) = eltype(faces(x))
172+
173+
function triangle_mesh(primitive::Mesh{N}) where {N}
174+
# already target type:
175+
if pointtype(primitive) === Point{N,Float32} && GLTriangleFace === facetype(primitive)
176+
return primitive
177+
else
178+
return mesh(primitive; pointtype=Point{N,Float32}, facetype=GLTriangleFace)
179+
end
180+
end
181+
170182
function triangle_mesh(primitive::Meshable{N}; nvertices=nothing) where {N}
171183
if nvertices !== nothing
172184
@warn("nvertices argument deprecated. Wrap primitive in `Tesselation(primitive, nvertices)`")

test/geometrytypes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ using Test, GeometryBasics
7373
@test faces == decompose(TriangleFace{Int}, Tesselation(s, 8))
7474

7575
m = triangle_mesh(Tesselation(s, 8))
76-
76+
@test m === triangle_mesh(m)
7777
@test GeometryBasics.faces(m) == faces
7878
@test GeometryBasics.coordinates(m) positions
7979
m = normal_mesh(s)# just test that it works without explicit resolution parameter

0 commit comments

Comments
 (0)