Skip to content

Commit b445089

Browse files
authored
Optimize == for TranformedMesh (#998)
1 parent 8e81ec6 commit b445089

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/mesh/cartesiangrid.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ function Base.getindex(g::CartesianGrid, I::CartesianIndices)
162162
CartesianGrid(dims, g.origin, g.spacing, offset)
163163
end
164164

165-
==(g1::CartesianGrid, g2::CartesianGrid) =
166-
g1.topology == g2.topology &&
167-
g1.spacing == g2.spacing &&
168-
Tuple(g1.origin - g2.origin) == (g1.offset .- g2.offset) .* g1.spacing
165+
==(g₁::CartesianGrid, g₂::CartesianGrid) =
166+
g₁.topology == g₂.topology &&
167+
g₁.spacing == g₂.spacing &&
168+
Tuple(g₁.origin - g₂.origin) == (g₁.offset .- g₂.offset) .* g₁.spacing
169169

170170
# -----------
171171
# IO METHODS

src/mesh/transformedmesh.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ vertex(m::TransformedMesh, ind::Int) = m.transform(vertex(m.mesh, ind))
3535

3636
centroid(m::TransformedMesh, ind::Int) = m.transform(centroid(m.mesh, ind))
3737

38+
==(m₁::TransformedMesh, m₂::TransformedMesh) = m₁.mesh == m₂.mesh && m₁.transform == m₂.transform
39+
3840
# alias to improve readability in IO methods
3941
const TransformedGrid{M<:Manifold,C<:CRS,Dim,G<:Grid,TR<:Transform} = TransformedMesh{M,C,GridTopology{Dim},G,TR}
4042

test/mesh.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,12 @@
766766
centr = centroid(tmesh, 1)
767767
@test @allocated(centroid(tmesh, 1)) < 50
768768

769+
# optimization of ==
770+
trans = Rotate(T/ 4))
771+
cgrid = cartgrid(1000, 1000)
772+
tmesh = Meshes.TransformedMesh(cgrid, trans)
773+
@test tmesh == tmesh
774+
769775
@test sprint(show, tgrid) == "10×10 TransformedGrid"
770776
if T == Float32
771777
@test sprint(show, MIME"text/plain"(), tgrid) == """

0 commit comments

Comments
 (0)