Skip to content

Commit 74d670e

Browse files
authored
Refactor collect(vertices(...)) (#1139)
1 parent d1d8ebe commit 74d670e

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

src/discretization.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ function discretize(polygon::Polygon, method::BoundaryTriangulationMethod)
152152
end
153153

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

158158
# discretize within 2D ring with given method
159159
ring2D = Ring(_proj2D(manifold(ring), points))
@@ -197,7 +197,7 @@ function simplexify(chain::Chain)
197197
np = nvertices(chain) + isclosed(chain)
198198
ip = isperiodic(chain)
199199

200-
points = collect(vertices(chain))
200+
points = collect(eachvertex(chain))
201201
topo = GridTopology((np - 1,), ip)
202202

203203
SimpleMesh(points, topo)

src/discretization/dehn.jl

Lines changed: 1 addition & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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(𝒫))

test/discretization.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
@test eltype(mesh) <: Triangle
99
@test vertices(mesh) == pts
1010
@test collect(elements(mesh)) == tris
11+
12+
# type stability tests
13+
poly = PolyArea(cart(0, 0), cart(1, 0), cart(1, 1), cart(0, 1))
14+
@inferred discretize(poly, FanTriangulation())
1115
end
1216

1317
@testitem "DehnTriangulation" setup = [Setup] begin
@@ -26,10 +30,6 @@ end
2630
@test nelements(mesh) == 6
2731
@test eltype(mesh) <: Triangle
2832

29-
# type stability tests
30-
poly = PolyArea(cart(0, 0), cart(1, 0), cart(1, 1), cart(0, 1))
31-
@inferred discretize(poly, DehnTriangulation())
32-
3333
octa = Octagon(
3434
cart(0.2, 0.2, 0.0),
3535
cart(0.5, -0.5, 0.0),
@@ -44,6 +44,10 @@ end
4444
@test nvertices(mesh) == 8
4545
@test nelements(mesh) == 6
4646
@test eltype(mesh) <: Triangle
47+
48+
# type stability tests
49+
poly = PolyArea(cart(0, 0), cart(1, 0), cart(1, 1), cart(0, 1))
50+
@inferred discretize(poly, DehnTriangulation())
4751
end
4852

4953
@testitem "HeldTriangulation" setup = [Setup] begin
@@ -128,6 +132,10 @@ end
128132
mesh = discretize(poly, HeldTriangulation(rng))
129133
@test nvertices(mesh) == 5
130134
@test nelements(mesh) == 3
135+
136+
# type stability tests
137+
poly = PolyArea(cart(0, 0), cart(1, 0), cart(1, 1), cart(0, 1))
138+
@inferred discretize(poly, HeldTriangulation())
131139
end
132140

133141
@testitem "DelaunayTriangulation" setup = [Setup] begin

0 commit comments

Comments
 (0)