Skip to content

Commit 407e0c4

Browse files
Optimize centroid of TransformedMesh (#995)
* Optimize centroid of TransformedMesh * Update test/mesh.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 89c7088 commit 407e0c4

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/mesh/transformedmesh.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ topology(m::TransformedMesh) = topology(m.mesh)
3333

3434
vertex(m::TransformedMesh, ind::Int) = m.transform(vertex(m.mesh, ind))
3535

36+
centroid(m::TransformedMesh, ind::Int) = m.transform(centroid(m.mesh, ind))
37+
3638
# alias to improve readability in IO methods
3739
const TransformedGrid{M<:Manifold,C<:CRS,Dim,G<:Grid,TR<:Transform} = TransformedMesh{M,C,GridTopology{Dim},G,TR}
3840

test/mesh.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,13 @@
759759
@test minimum(sub) == cart(0, 2)
760760
@test maximum(sub) == cart(10, 7)
761761

762+
# optimization of centroid
763+
trans = Rotate(T/ 4))
764+
cgrid = cartgrid(10, 10)
765+
tmesh = Meshes.TransformedMesh(cgrid, trans)
766+
centr = centroid(tmesh, 1)
767+
@test @allocated(centroid(tmesh, 1)) < 50
768+
762769
@test sprint(show, tgrid) == "10×10 TransformedGrid"
763770
if T == Float32
764771
@test sprint(show, MIME"text/plain"(), tgrid) == """

0 commit comments

Comments
 (0)