Skip to content

Commit

Permalink
Update exports (#1015)
Browse files Browse the repository at this point in the history
* Update exports

* Update test/meshes.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Export TransformedGeometry

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
juliohm and github-actions[bot] committed Aug 21, 2024
1 parent 3d403c0 commit 45d86ce
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 41 deletions.
2 changes: 1 addition & 1 deletion ext/grid/transformed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

function vizgrid!(plot::Viz{<:Tuple{Meshes.TransformedGrid}}, M::Type{<:𝔼}, pdim::Val, edim::Val)
function vizgrid!(plot::Viz{<:Tuple{TransformedGrid}}, M::Type{<:𝔼}, pdim::Val, edim::Val)
tgrid = plot[:object]
color = plot[:color]
alpha = plot[:alpha]
Expand Down
8 changes: 6 additions & 2 deletions src/Meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ export
MultiPolygon,
MultiPolyhedron,

# transformed geometry
TransformedGeometry,

# connectivities
Connectivity,
paramdim,
Expand Down Expand Up @@ -297,11 +300,12 @@ export
# meshes
Mesh,
Grid,
SubGrid,
SimpleMesh,
TransformedMesh,
CartesianGrid,
RectilinearGrid,
StructuredGrid,
SimpleMesh,
TransformedGrid,
vertex,
vertices,
nvertices,
Expand Down
2 changes: 1 addition & 1 deletion src/domains/meshes/transformedmesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
TransformedMesh(mesh, transform)
Lazy representation of a geometric `transform` applied to a `mesh`.
Lazy representation of a coordinate `transform` applied to a `mesh`.
"""
struct TransformedMesh{M<:Manifold,C<:CRS,TP<:Topology,MS<:Mesh,TR<:Transform} <: Mesh{M,C,TP}
mesh::MS
Expand Down
2 changes: 1 addition & 1 deletion src/geometries/transformedgeom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
TransformedGeometry(geometry, transform)
Lazy representation of a geometric `transform` applied to a `geometry`.
Lazy representation of a coordinate `transform` applied to a `geometry`.
"""
struct TransformedGeometry{M<:Manifold,C<:CRS,G<:Geometry,T<:Transform} <: Geometry{M,C}
geometry::G
Expand Down
4 changes: 2 additions & 2 deletions test/boundingboxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@
@test @allocated(boundingbox(d)) < 50

g = cartgrid(10, 10)
d = Meshes.TransformedGrid(g, Rotate(T/ 2)))
d = TransformedGrid(g, Rotate(T/ 2)))
@test boundingbox(d) Box(cart(-10, 0), cart(0, 10))
@test @allocated(boundingbox(d)) < 3000

g = cartgrid(10, 10)
rg = convert(RectilinearGrid, g)
d = Meshes.TransformedGrid(rg, Rotate(T/ 2)))
d = TransformedGrid(rg, Rotate(T/ 2)))
@test boundingbox(d) Box(cart(-10, 0), cart(0, 10))
@test @allocated(boundingbox(d)) < 3000

Expand Down
4 changes: 2 additions & 2 deletions test/coarsening.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
sgrid = convert(StructuredGrid, grid)
tsgrid = convert(StructuredGrid, tgrid)
@test coarsen(sgrid, RegularCoarsening(2)) == tsgrid
tfgrid = Meshes.TransformedGrid(grid, Identity())
tfgrid = TransformedGrid(grid, Identity())
@test coarsen(tfgrid, RegularCoarsening(2)) == coarsen(grid, RegularCoarsening(2))

grid = CartesianGrid(cart(0.0, 0.0), cart(10.0, 10.0), dims=(20, 20))
Expand All @@ -27,7 +27,7 @@
sgrid = convert(StructuredGrid, grid)
tsgrid = convert(StructuredGrid, tgrid)
@test coarsen(sgrid, RegularCoarsening(2, 4, 5)) == tsgrid
tfgrid = Meshes.TransformedGrid(grid, Identity())
tfgrid = TransformedGrid(grid, Identity())
@test coarsen(tfgrid, RegularCoarsening(2, 4, 5)) == coarsen(grid, RegularCoarsening(2, 4, 5))
end
end
2 changes: 1 addition & 1 deletion test/discretization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@

poly = PolyArea(cart.([(0, 0), (0, 1), (1, 2), (2, 1), (2, 0)]))
mesh = discretize(poly, RegularDiscretization(50))
@test mesh isa SubGrid
@test mesh isa Meshes.SubGrid
grid = parent(mesh)
@test grid isa CartesianGrid
@test eltype(mesh) <: Quadrangle
Expand Down
35 changes: 17 additions & 18 deletions test/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -701,43 +701,42 @@
sgrid = convert(StructuredGrid, grid)
mesh = convert(SimpleMesh, grid)
trans = Identity()
tmesh = Meshes.TransformedMesh(mesh, trans)
tmesh = TransformedMesh(mesh, trans)
@test crs(tmesh) <: Cartesian{NoDatum}
@test Meshes.lentype(tmesh) ==
@test parent(tmesh) === mesh
@test Meshes.transform(tmesh) === trans
@test Meshes.TransformedMesh(grid, trans) == grid
@test Meshes.TransformedMesh(rgrid, trans) == rgrid
@test Meshes.TransformedMesh(sgrid, trans) == sgrid
@test Meshes.TransformedMesh(mesh, trans) == mesh
@test TransformedMesh(grid, trans) == grid
@test TransformedMesh(rgrid, trans) == rgrid
@test TransformedMesh(sgrid, trans) == sgrid
@test TransformedMesh(mesh, trans) == mesh
trans = Translate(T(10), T(10)) Translate(T(-10), T(-10))
@test Meshes.TransformedMesh(grid, trans) == grid
@test Meshes.TransformedMesh(rgrid, trans) == rgrid
@test Meshes.TransformedMesh(sgrid, trans) == sgrid
@test Meshes.TransformedMesh(mesh, trans) == mesh
@test TransformedMesh(grid, trans) == grid
@test TransformedMesh(rgrid, trans) == rgrid
@test TransformedMesh(sgrid, trans) == sgrid
@test TransformedMesh(mesh, trans) == mesh
trans1 = Translate(T(10), T(10))
trans2 = Translate(T(-10), T(-10))
@test Meshes.TransformedMesh(Meshes.TransformedMesh(grid, trans1), trans2) ==
Meshes.TransformedMesh(grid, trans1 trans2)
@test TransformedMesh(TransformedMesh(grid, trans1), trans2) == TransformedMesh(grid, trans1 trans2)

# transforms that change the Manifold and/or CRS
points = latlon.([(0, 0), (0, 1), (1, 0), (1, 1), (0.5, 0.5)])
connec = connect.([(1, 2, 5), (2, 4, 5), (4, 3, 5), (3, 1, 5)], Triangle)
mesh = SimpleMesh(points, connec)
trans = Proj(Cartesian)
tmesh = Meshes.TransformedMesh(mesh, trans)
tmesh = TransformedMesh(mesh, trans)
@test manifold(tmesh) === 🌐
@test crs(tmesh) <: Cartesian
trans = Proj(Polar)
tgrid = Meshes.TransformedMesh(grid, trans)
@test tgrid isa Meshes.TransformedGrid
tgrid = TransformedMesh(grid, trans)
@test tgrid isa TransformedGrid
@test manifold(tgrid) === 𝔼{2}
@test crs(tgrid) <: Polar

# grid interface
trans = Identity()
tgrid = Meshes.TransformedMesh(grid, trans)
@test tgrid isa Meshes.TransformedGrid
tgrid = TransformedMesh(grid, trans)
@test tgrid isa TransformedGrid
@test size(tgrid) == (10, 10)
@test minimum(tgrid) == cart(0, 0)
@test maximum(tgrid) == cart(10, 10)
Expand All @@ -762,14 +761,14 @@
# optimization of centroid
trans = Rotate(T/ 4))
cgrid = cartgrid(10, 10)
tmesh = Meshes.TransformedMesh(cgrid, trans)
tmesh = TransformedMesh(cgrid, trans)
centr = centroid(tmesh, 1)
@test @allocated(centroid(tmesh, 1)) < 50

# optimization of ==
trans = Rotate(T/ 4))
cgrid = cartgrid(1000, 1000)
tmesh = Meshes.TransformedMesh(cgrid, trans)
tmesh = TransformedMesh(cgrid, trans)
@test tmesh == tmesh

@test sprint(show, tgrid) == "10×10 TransformedGrid"
Expand Down
4 changes: 2 additions & 2 deletions test/refinement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
sgrid = convert(StructuredGrid, grid)
tsgrid = convert(StructuredGrid, tgrid)
@test refine(sgrid, RegularRefinement(2)) == tsgrid
tfgrid = Meshes.TransformedGrid(grid, Identity())
tfgrid = TransformedGrid(grid, Identity())
@test refine(tfgrid, RegularRefinement(2)) == refine(grid, RegularRefinement(2))

# 3D grids
Expand All @@ -66,7 +66,7 @@
sgrid = convert(StructuredGrid, grid)
tsgrid = convert(StructuredGrid, tgrid)
@test refine(sgrid, RegularRefinement(2)) == tsgrid
tfgrid = Meshes.TransformedGrid(grid, Identity())
tfgrid = TransformedGrid(grid, Identity())
@test refine(tfgrid, RegularRefinement(2)) == refine(grid, RegularRefinement(2))
end

Expand Down
4 changes: 2 additions & 2 deletions test/subdomains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# view of view stores the correct domain
g = cartgrid(10, 10)
v = view(view(g, 11:20), 1:3)
@test v isa SubGrid
@test v isa Meshes.SubGrid
@test v[1] == g[11]
@test v[2] == g[12]
@test v[3] == g[13]
Expand All @@ -58,7 +58,7 @@
# concatenation with same parent
g = cartgrid(10, 10)
vg = vcat(view(g, 50:70), view(g, 10:30))
@test vg isa SubGrid
@test vg isa Meshes.SubGrid
@test vg == view(g, [50:70; 10:30])
# concatenation with different parents
g1 = cartgrid(10, 10)
Expand Down
18 changes: 9 additions & 9 deletions test/transformedgeoms.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@testset "TransformedGeometry" begin
b = Box(cart(0, 0), cart(1, 1))
t = Translate(T(1), T(2))
tb = Meshes.TransformedGeometry(b, t)
tb = TransformedGeometry(b, t)
@test parent(tb) == b
@test Meshes.transform(tb) == t
t2 = Scale(T(2), T(3))
tb2 = Meshes.TransformedGeometry(tb, t2)
tb2 = TransformedGeometry(tb, t2)
@test Meshes.transform(tb2) == (t t2)
@test paramdim(tb) == paramdim(b)
@test tb == tb
Expand All @@ -14,26 +14,26 @@
@test centroid(tb) == t(centroid(b))
@test discretize(tb) == t(discretize(b))
t3 = Scale(T(2), T(2))
tb3 = Meshes.TransformedGeometry(b, t3)
tb3 = TransformedGeometry(b, t3)
@test measure(tb3) == 4 * measure(b)
equaltest(tb)
isapproxtest(tb)

b = Ball(latlon(0, 0), T(1))
t = Proj(Cartesian)
tb = Meshes.TransformedGeometry(b, t)
tb = TransformedGeometry(b, t)
@test paramdim(tb) == paramdim(b)
@test centroid(tb) == t(centroid(b))

s = Sphere(latlon(0, 0), T(1))
t = Proj(Cartesian)
ts = Meshes.TransformedGeometry(s, t)
ts = TransformedGeometry(s, t)
@test paramdim(ts) == paramdim(s)
@test centroid(ts) == t(centroid(s))

s = Segment(cart(0, 0), cart(1, 1))
t = Translate(T(1), T(2))
ts = Meshes.TransformedGeometry(s, t)
ts = TransformedGeometry(s, t)
@test vertex(ts, 1) == t(vertex(s, 1))
@test vertices(ts) == t.(vertices(s))
@test nvertices(ts) == nvertices(s)
Expand All @@ -42,20 +42,20 @@

p = PolyArea(cart(0, 0), cart(1, 0), cart(1, 1), cart(0, 1))
t = Translate(T(1), T(2))
tp = Meshes.TransformedGeometry(p, t)
tp = TransformedGeometry(p, t)
@test vertex(tp, 1) == t(vertex(p, 1))
@test vertices(tp) == t.(vertices(p))
@test nvertices(tp) == nvertices(p)
@test rings(tp) == t.(rings(p))
p2 = PolyArea(cart(0, 0), cart(0, 0), cart(1, 0), cart(1, 1), cart(0, 1))
tp2 = Meshes.TransformedGeometry(p2, t)
tp2 = TransformedGeometry(p2, t)
@test unique(tp2) == tp
equaltest(tp)
isapproxtest(tp)

b = Box(cart(0, 0), cart(1, 1))
t = Translate(T(1), T(2))
tb = Meshes.TransformedGeometry(b, t)
tb = TransformedGeometry(b, t)
@test sprint(show, tb) ==
"TransformedBox(geometry: Box(min: (x: 0.0 m, y: 0.0 m), max: (x: 1.0 m, y: 1.0 m)), transform: Translate(offsets: (1.0 m, 2.0 m)))"
@test sprint(show, MIME"text/plain"(), tb) == """
Expand Down

0 comments on commit 45d86ce

Please sign in to comment.