Skip to content

Commit 41ad8d4

Browse files
authored
Merge branch 'JuliaGeometry:master' into JRC_addGreinerHormann
2 parents e391960 + 54c872f commit 41ad8d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+372
-111
lines changed

.github/workflows/CI.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
env:
5555
FLOAT_TYPE: ${{ matrix.float }}
5656
- uses: julia-actions/julia-processcoverage@v1
57-
- uses: codecov/codecov-action@v4
57+
- uses: codecov/codecov-action@v5
5858
with:
5959
file: lcov.info
6060
token: ${{ secrets.CODECOV_TOKEN }}

Project.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Meshes"
22
uuid = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
33
authors = ["Júlio Hoffimann and contributors"]
4-
version = "0.52.0"
4+
version = "0.52.6"
55

66
[deps]
77
Bessels = "0e736298-9ec6-45e8-9647-e4fc86a2fe38"
@@ -18,6 +18,7 @@ ScopedValues = "7e506255-f358-4e82-b7e4-beb19740aa63"
1818
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1919
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2020
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
21+
TiledIteration = "06e1c1a7-607b-532d-9fad-de7d9aa2abac"
2122
TransformsBase = "28dd2a49-a57a-4bfb-84ca-1a49db9b96b8"
2223
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
2324

@@ -37,6 +38,7 @@ ScopedValues = "1.2"
3738
SparseArrays = "1.9"
3839
StaticArrays = "1.0"
3940
StatsBase = "0.33, 0.34"
41+
TiledIteration = "0.5"
4042
TransformsBase = "1.6"
4143
Unitful = "1.17"
4244
julia = "1.9"

docs/src/algorithms/neighborsearch.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ point of reference. This can be performed with search methods:
1010

1111
```@docs
1212
NeighborSearchMethod
13+
BoundedNeighborSearchMethod
1314
search
1415
search!
1516
searchdists

ext/grid.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function vizgridfallback!(plot, M, pdim, edim)
6363
# decide whether or not to reverse connectivity list
6464
rfunc = Makie.@lift _reverse($grid)
6565

66-
verts = Makie.@lift map(asmakie, vertices($grid))
66+
verts = Makie.@lift map(asmakie, eachvertex($grid))
6767
quads = Makie.@lift [GB.QuadFace($rfunc(indices(e))) for e in elements(topology($grid))]
6868

6969
dims = Makie.@lift size($grid)

ext/mesh.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function vizmesh!(plot, ::Type{<:𝔼}, ::Val{2}, ::Val)
6464
dim = embeddim($mesh)
6565
nvert = nvertices($mesh)
6666
nelem = nelements($mesh)
67-
verts = vertices($mesh)
67+
verts = eachvertex($mesh)
6868
topo = topology($mesh)
6969
elems = elements(topo)
7070

ext/utils.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ asmakie(multis::AbstractVector{<:Multi}) = mapreduce(m -> asmakie.(parent(m)), v
3434

3535
function asmakie(poly::Polygon)
3636
rs = rings(poly)
37-
outer = [asmakie(p) for p in vertices(first(rs))]
37+
outer = map(asmakie, eachvertex(rs[1]))
3838
if hasholes(poly)
39-
inners = map(i -> [asmakie(p) for p in vertices(rs[i])], 2:length(rs))
39+
inners = map(i -> map(asmakie, eachvertex(rs[i])), 2:length(rs))
4040
Makie.Polygon(outer, inners)
4141
else
4242
Makie.Polygon(outer)

src/Meshes.jl

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ using Distances: Haversine, SphericalAngle
2020
using Distances: evaluate, result_type
2121
using Rotations: Rotation, QuatRotation, Angle2d
2222
using Rotations: rotation_between
23+
using TiledIteration: TileIterator
2324
using CoordRefSystems: Basic, Projected, Geographic
2425
using NearestNeighbors: KDTree, BallTree
2526
using NearestNeighbors: knn, inrange
@@ -220,6 +221,7 @@ export
220221
vertex,
221222
vertices,
222223
nvertices,
224+
eachvertex,
223225
rings,
224226
segments,
225227
angles,
@@ -312,6 +314,7 @@ export
312314
vertex,
313315
vertices,
314316
nvertices,
317+
eachvertex,
315318
element,
316319
elements,
317320
nelements,

src/boundingboxes.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function boundingbox end
1313
# FALLBACKS
1414
# ----------
1515

16-
boundingbox(p::Polytope) = _pboxes(vertices(p))
16+
boundingbox(p::Polytope) = _pboxes(eachvertex(p))
1717

1818
boundingbox(p::Primitive) = boundingbox(boundary(p))
1919

@@ -78,7 +78,7 @@ boundingbox(g::TransformedGrid{<:Any,<:Any,<:OrthoRegularGrid}) = boundingbox(pa
7878
boundingbox(g::TransformedGrid{<:Any,<:Any,<:OrthoRectilinearGrid}) =
7979
boundingbox(parent(g)) |> transform(g) |> boundingbox
8080

81-
boundingbox(m::Mesh) = _pboxes(vertices(m))
81+
boundingbox(m::Mesh) = _pboxes(eachvertex(m))
8282

8383
# ----------------
8484
# IMPLEMENTATIONS

src/coarsening/regular.jl

+24-7
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,43 @@ RegularCoarsening(factors::Vararg{Int,N}) where {N} = RegularCoarsening(factors)
2222

2323
function coarsen(grid::OrthoRegularGrid, method::RegularCoarsening)
2424
factors = fitdims(method.factors, paramdim(grid))
25-
RegularGrid(minimum(grid), maximum(grid), dims=size(grid) factors)
25+
dims = _coarsesize(grid, factors)
26+
RegularGrid(minimum(grid), maximum(grid), dims=dims)
2627
end
2728

2829
function coarsen(grid::RectilinearGrid, method::RegularCoarsening)
2930
factors = fitdims(method.factors, paramdim(grid))
30-
dims = vsize(grid)
31-
rngs = ntuple(i -> 1:factors[i]:dims[i], paramdim(grid))
31+
inds = _coarseinds(grid, factors)
3232
xyzₛ = xyz(grid)
33-
xyzₜ = ntuple(i -> xyzₛ[i][rngs[i]], paramdim(grid))
33+
xyzₜ = ntuple(i -> xyzₛ[i][inds[i]], paramdim(grid))
3434
RectilinearGrid{manifold(grid),crs(grid)}(xyzₜ)
3535
end
3636

3737
function coarsen(grid::StructuredGrid, method::RegularCoarsening)
3838
factors = fitdims(method.factors, paramdim(grid))
39-
dims = vsize(grid)
40-
rngs = ntuple(i -> 1:factors[i]:dims[i], paramdim(grid))
39+
inds = _coarseinds(grid, factors)
4140
XYZₛ = XYZ(grid)
42-
XYZₜ = ntuple(i -> XYZₛ[i][rngs...], paramdim(grid))
41+
XYZₜ = ntuple(i -> XYZₛ[i][inds...], paramdim(grid))
4342
StructuredGrid{manifold(grid),crs(grid)}(XYZₜ)
4443
end
4544

4645
coarsen(grid::TransformedGrid, method::RegularCoarsening) =
4746
TransformedGrid(coarsen(parent(grid), method), transform(grid))
47+
48+
# -----------------
49+
# HELPER FUNCTIONS
50+
# -----------------
51+
52+
function _coarsesize(grid, factors)
53+
dims = size(grid)
54+
axes = ntuple(i -> 1:dims[i], paramdim(grid))
55+
size(TileIterator(axes, factors))
56+
end
57+
58+
_coarsevsize(grid, factors) = _coarsesize(grid, factors) .+ .!isperiodic(grid)
59+
60+
function _coarseinds(grid, factors)
61+
dims = vsize(grid)
62+
tdims = _coarsevsize(grid, factors)
63+
ntuple(i -> floor.(Int, range(start=1, stop=dims[i], length=tdims[i])), paramdim(grid))
64+
end

src/discretization.jl

+4-5
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ function discretize(polygon::Polygon, method::BoundaryTriangulationMethod)
105105

106106
# handle degenerate polygons
107107
if nvertices(cpoly) == 1
108-
v = first(vertices(cpoly))
109-
points = [v, v, v]
108+
points = fill(vertex(cpoly, 1), 3)
110109
connec = [connect((1, 2, 3))]
111110
return SimpleMesh(points, connec)
112111
end
@@ -153,8 +152,8 @@ function discretize(polygon::Polygon, method::BoundaryTriangulationMethod)
153152
end
154153

155154
function discretizewithin(ring::Ring, method::BoundaryTriangulationMethod)
156-
# collect vertices to get rid of static containers
157-
points = collect(vertices(ring))
155+
# retrieve vertices of ring
156+
points = collect(eachvertex(ring))
158157

159158
# discretize within 2D ring with given method
160159
ring2D = Ring(_proj2D(manifold(ring), points))
@@ -198,7 +197,7 @@ function simplexify(chain::Chain)
198197
np = nvertices(chain) + isclosed(chain)
199198
ip = isperiodic(chain)
200199

201-
points = collect(vertices(chain))
200+
points = collect(eachvertex(chain))
202201
topo = GridTopology((np - 1,), ip)
203202

204203
SimpleMesh(points, topo)

src/discretization/dehn.jl

+1-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ with small number of vertices.
2222
struct DehnTriangulation <: BoundaryTriangulationMethod end
2323

2424
function discretizewithin(ring::Ring{𝔼{2}}, ::DehnTriangulation)
25-
# points on resulting mesh
26-
points = collect(vertices(ring))
27-
28-
# Dehn's recursion
25+
points = collect(eachvertex(ring))
2926
connec = dehn1899(points, 1:length(points))
30-
3127
SimpleMesh(points, connec)
3228
end
3329

src/discretization/delaunay.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ end
2525
DelaunayTriangulation(rng=Random.default_rng()) = DelaunayTriangulation(rng)
2626

2727
function discretizewithin(ring::Ring{𝔼{2}}, method::DelaunayTriangulation)
28-
points = vertices(ring)
28+
points = collect(eachvertex(ring))
2929
coords = map(p -> ustrip.(to(p)), points)
3030
bnodes = [1:nvertices(ring); 1]
3131
triang = triangulate(coords, boundary_nodes=bnodes, rng=method.rng)

src/discretization/fan.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ See [https://en.wikipedia.org/wiki/Fan_triangulation]
1212
struct FanTriangulation <: BoundaryTriangulationMethod end
1313

1414
function discretizewithin(ring::Ring, ::FanTriangulation)
15-
points = collect(vertices(ring))
15+
points = collect(eachvertex(ring))
1616
connec = [connect((1, i, i + 1)) for i in 2:(nvertices(ring) - 1)]
1717
SimpleMesh(points, connec)
1818
end

src/discretization/held.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ function discretizewithin(ring::Ring{𝔼{2}}, method::HeldTriangulation)
4545
𝒫 =|> StdCoords()
4646

4747
# points of resulting mesh
48-
points = collect(vertices(ℛ))
48+
points = collect(eachvertex(ℛ))
4949

5050
# standardized points for algorithm
51-
stdpts = collect(vertices(𝒫))
51+
stdpts = collect(eachvertex(𝒫))
5252

5353
# keep track of global indices
5454
I = CircularVector(1:nvertices(𝒫))

src/domains.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Base.isapprox(d1::Domain, d2::Domain; kwargs...) =
3636

3737
Base.getindex(d::Domain, ind::Int) = element(d, ind)
3838

39-
Base.getindex(d::Domain, inds::AbstractVector) = [element(d, ind) for ind in inds]
39+
Base.getindex(d::Domain, inds::AbstractVector) = [d[ind] for ind in inds]
4040

4141
Base.firstindex(d::Domain) = 1
4242

src/domains/meshes.jl

+10-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function vertex end
2323
2424
Return the vertices of the `mesh`.
2525
"""
26-
vertices(m::Mesh) = [vertex(m, ind) for ind in 1:nvertices(m)]
26+
vertices(m::Mesh) = collect(eachvertex(m))
2727

2828
"""
2929
nvertices(mesh)
@@ -32,6 +32,13 @@ Return the number of vertices of the `mesh`.
3232
"""
3333
nvertices(m::Mesh) = nvertices(topology(m))
3434

35+
"""
36+
eachvertex(mesh)
37+
38+
Return an iterator for the vertices of the `mesh`.
39+
"""
40+
eachvertex(m::Mesh) = (vertex(m, i) for i in 1:nvertices(m))
41+
3542
"""
3643
faces(mesh, rank)
3744
@@ -220,8 +227,9 @@ function Base.getindex(g::Grid, I::CartesianIndices)
220227
odims = size(g)
221228
cinds = first(I):CartesianIndex(Tuple(last(I)) .+ 1)
222229
inds = vec(LinearIndices(odims .+ 1)[cinds])
230+
points = [vertex(g, ind) for ind in inds]
223231
periodic = isperiodic(topology(g)) .&& dims .== odims
224-
SimpleMesh(vertices(g)[inds], GridTopology(dims, periodic))
232+
SimpleMesh(points, GridTopology(dims, periodic))
225233
end
226234

227235
_asrange(::Int, r::UnitRange{Int}) = r

src/domains/meshes/transformedmesh.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct TransformedMesh{M<:Manifold,C<:CRS,TP<:Topology,MS<:Mesh,TR<:Transform} <
1818
end
1919

2020
function TransformedMesh(m::Mesh, t::Transform)
21-
p = t(first(vertices(m)))
21+
p = t(vertex(m, 1))
2222
TransformedMesh{manifold(p),crs(p)}(m, t)
2323
end
2424

src/geometries/multigeom.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ Base.isapprox(m₁::Multi, m₂::Multi; atol=atol(lentype(m₁)), kwargs...) =
4848
# POLYTOPE
4949
# ---------
5050

51-
vertex(m::MultiPolytope, ind) = vertices(m)[ind]
51+
vertex(m::MultiPolytope, ind) = first(Iterators.drop(eachvertex(m), ind - 1))
5252

53-
vertices(m::MultiPolytope) = [vertex for geom in m.geoms for vertex in vertices(geom)]
53+
vertices(m::MultiPolytope) = collect(eachvertex(m))
5454

5555
nvertices(m::MultiPolytope) = sum(nvertices, m.geoms)
5656

57+
eachvertex(m::MultiPolytope) = (v for g in m.geoms for v in eachvertex(g))
58+
5759
Base.unique(m::MultiPolytope) = unique!(deepcopy(m))
5860

5961
function Base.unique!(m::MultiPolytope)

src/geometries/polytopes.jl

+11-3
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,21 @@ macro polytope(type, K, N)
3232
structexpr = if K == 3
3333
quote
3434
struct $type{C<:CRS,Mₚ<:Manifold} <: Polytope{$K,𝔼{3},C}
35-
vertices::NTuple{$N,Point{Mₚ,C}}
35+
vertices::SVector{$N,Point{Mₚ,C}}
3636
end
3737
end
3838
else
3939
quote
4040
struct $type{M<:Manifold,C<:CRS} <: Polytope{$K,M,C}
41-
vertices::NTuple{$N,Point{M,C}}
41+
vertices::SVector{$N,Point{M,C}}
4242
end
4343
end
4444
end
4545

4646
expr = quote
4747
$Base.@__doc__ $structexpr
4848

49+
$type(vertices::NTuple{$N,P}) where {P<:Point} = $type(SVector(vertices))
4950
$type(vertices::Vararg{Tuple,$N}) = $type(Point.(vertices))
5051
$type(vertices::Vararg{P,$N}) where {P<:Point} = $type(vertices)
5152
end
@@ -246,10 +247,17 @@ vertices(p::Polytope) = p.vertices
246247
"""
247248
nvertices(polytope)
248249
249-
Return the number of vertices in the `polytope`.
250+
Return the number of vertices of the `polytope`.
250251
"""
251252
nvertices(p::Polytope) = nvertices(typeof(p))
252253

254+
"""
255+
eachvertex(polytope)
256+
257+
Return an iterator for the vertices of the `polytope`.
258+
"""
259+
eachvertex(p::Polytope) = (vertex(p, i) for i in 1:nvertices(p))
260+
253261
"""
254262
unique(polytope)
255263

src/geometries/polytopes/ngon.jl

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ are `Triangle` (N=3), `Quadrangle` (N=4), `Pentagon` (N=5), etc.
2121
`Heptagon`, `Octagon`, `Nonagon`, `Decagon`.
2222
"""
2323
struct Ngon{N,M<:Manifold,C<:CRS} <: Polygon{M,C}
24-
vertices::NTuple{N,Point{M,C}}
24+
vertices::SVector{N,Point{M,C}}
2525
function Ngon{N,M,C}(vertices) where {N,M<:Manifold,C<:CRS}
2626
if N < 3
2727
throw(ArgumentError("the number of vertices must be greater than or equal to 3"))
@@ -30,11 +30,13 @@ struct Ngon{N,M<:Manifold,C<:CRS} <: Polygon{M,C}
3030
end
3131
end
3232

33-
Ngon{N}(vertices::NTuple{N,Point{M,C}}) where {N,M<:Manifold,C<:CRS} = Ngon{N,M,C}(vertices)
33+
Ngon{N}(vertices::SVector{N,Point{M,C}}) where {N,M<:Manifold,C<:CRS} = Ngon{N,M,C}(vertices)
34+
Ngon{N}(vertices::NTuple{N,P}) where {N,P<:Point} = Ngon{N}(SVector(vertices))
3435
Ngon{N}(vertices::Vararg{P,N}) where {N,P<:Point} = Ngon{N}(vertices)
3536
Ngon{N}(vertices::Vararg{Tuple,N}) where {N} = Ngon{N}(Point.(vertices))
3637

37-
Ngon(vertices::NTuple{N,Point{M,C}}) where {N,M<:Manifold,C<:CRS} = Ngon{N,M,C}(vertices)
38+
Ngon(vertices::SVector{N,Point{M,C}}) where {N,M<:Manifold,C<:CRS} = Ngon{N,M,C}(vertices)
39+
Ngon(vertices::NTuple{N,P}) where {N,P<:Point} = Ngon(SVector(vertices))
3840
Ngon(vertices::P...) where {P<:Point} = Ngon(vertices)
3941
Ngon(vertices::Tuple...) = Ngon(Point.(vertices))
4042

src/geometries/polytopes/polyarea.jl

+13-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,19 @@ PolyArea(outer...) = PolyArea(collect(outer))
3131
Base.isapprox(p₁::PolyArea, p₂::PolyArea; atol=atol(lentype(p₁)), kwargs...) =
3232
length(p₁.rings) == length(p₂.rings) && all(isapprox(r₁, r₂; atol, kwargs...) for (r₁, r₂) in zip(p₁.rings, p₂.rings))
3333

34-
vertices(p::PolyArea) = mapreduce(vertices, vcat, p.rings)
34+
function vertex(p::PolyArea, ind)
35+
offset = 0
36+
for r in p.rings
37+
nverts = nvertices(r)
38+
if ind offset + nverts
39+
return vertex(r, ind - offset)
40+
end
41+
offset += nverts
42+
end
43+
throw(BoundsError(p, ind))
44+
end
45+
46+
vertices(p::PolyArea) = collect(eachvertex(p))
3547

3648
nvertices(p::PolyArea) = mapreduce(nvertices, +, p.rings)
3749

0 commit comments

Comments
 (0)