Skip to content

Commit 418d7a1

Browse files
committed
figure saving should be an option
1 parent 42e8c39 commit 418d7a1

File tree

11 files changed

+37
-24
lines changed

11 files changed

+37
-24
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DelaunayTriangulation"
22
uuid = "927a84f5-c5f4-47a5-9785-b46e178433df"
33
authors = ["Daniel VandenHeuvel <[email protected]>"]
4-
version = "0.4.1"
4+
version = "0.4.2"
55

66
[deps]
77
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"

test/data_structures/convex_hull.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ using ..DelaunayTriangulation
22
const DT = DelaunayTriangulation
33
using CairoMakie
44

5+
include("../test_setup.jl")
6+
57
save_path = basename(pwd()) == "test" ? "figures" : "test/figures"
68

79
ch = ConvexHull(rand(2, 500), [1, 2, 4, 5, 6, 10, 29, 45, 71, 1])
@@ -35,4 +37,4 @@ fig = Figure()
3537
ax = Axis(fig[1, 1])
3638
scatter!(ax, pts)
3739
lines!(ax, pts[ch.indices])
38-
save("$save_path/convex_hull_1.png", fig)
40+
SAVE_FIGURE && save("$save_path/convex_hull_1.png", fig)

test/operations/add_ghost_triangles.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using ..DelaunayTriangulation
22
const DT = DelaunayTriangulation
33
using CairoMakie
44

5+
include("../test_setup.jl")
56
include("../helper_functions.jl")
67

78
save_path = basename(pwd()) == "test" ? "figures" : "test/figures"
@@ -52,4 +53,4 @@ ax = Axis(fig[1, 2])
5253
triplot!(ax, tri; show_ghost_edges=true, ghost_edge_extension_factor=2.0)
5354
xlims!(ax, -2, 22)
5455
ylims!(ax, -2, 22)
55-
save("$save_path/test_add_ghost_triangles.png", fig)
56+
SAVE_FIGURE && save("$save_path/test_add_ghost_triangles.png", fig)

test/operations/delete_triangle.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using ..DelaunayTriangulation
22
const DT = DelaunayTriangulation
33
using CairoMakie
44

5+
include("../test_setup.jl")
56
save_path = basename(pwd()) == "test" ? "figures" : "test/figures"
67

78
include("../helper_functions.jl")
@@ -55,4 +56,4 @@ triplot!(ax, tri; show_ghost_edges=true, ghost_edge_extension_factor=2.0)
5556
xlims!(ax, -2, 22)
5657
ylims!(ax, -2, 22)
5758

58-
save("$save_path/test_delete_triangles.png", fig)
59+
SAVE_FIGURE && save("$save_path/test_delete_triangles.png", fig)

test/plotting.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using DataStructures
55

66
save_path = basename(pwd()) == "test" ? "figures" : "test/figures"
77

8+
include("./test_setup.jl")
89
include("./helper_functions.jl")
910

1011
x, y = complicated_geometry()
@@ -13,7 +14,7 @@ tri = generate_mesh(x, y, 0.1; convert_result=true, add_ghost_triangles=true)
1314
fig1 = Figure()
1415
ax = Axis(fig1[1, 1])
1516
triplot!(ax, tri)
16-
save("$save_path/test_figure_1.png", fig1)
17+
SAVE_FIGURE && save("$save_path/test_figure_1.png", fig1)
1718

1819
fig2 = Figure()
1920
ax = Axis(fig2[1, 1])
@@ -23,7 +24,7 @@ triplot!(ax, tri;
2324
markersize=6)
2425
xlims!(ax, -0.4, 2.4)
2526
ylims!(ax, -0.4, 6.4)
26-
save("$save_path/test_figure_2.png", fig2)
27+
SAVE_FIGURE && save("$save_path/test_figure_2.png", fig2)
2728

2829
fig3 = Figure()
2930
ax = Axis(fig3[1, 1])
@@ -36,7 +37,7 @@ triplot!(ax, tri;
3637
ghost_edge_color=:darkgreen)
3738
xlims!(ax, -0.4, 2.4)
3839
ylims!(ax, -0.4, 6.4)
39-
save("$save_path/test_figure_3.png", fig3)
40+
SAVE_FIGURE && save("$save_path/test_figure_3.png", fig3)
4041

4142
fig4 = Figure()
4243
ax = Axis(fig4[1, 1])
@@ -49,7 +50,7 @@ triplot!(ax, tri;
4950
ghost_edge_color=:darkgreen)
5051
xlims!(ax, -0.4, 2.4)
5152
ylims!(ax, -0.4, 6.4)
52-
save("$save_path/test_figure_4.png", fig4)
53+
SAVE_FIGURE && save("$save_path/test_figure_4.png", fig4)
5354

5455
fig5 = Figure()
5556
ax = Axis(fig5[1, 1])
@@ -65,7 +66,7 @@ triplot!(ax, tri;
6566
strokewidth=0.0)
6667
xlims!(ax, -0.4, 2.4)
6768
ylims!(ax, -0.4, 6.4)
68-
save("$save_path/test_figure_5.png", fig5)
69+
SAVE_FIGURE && save("$save_path/test_figure_5.png", fig5)
6970

7071
pts = get_points(tri)
7172
T = get_triangles(tri)
@@ -84,7 +85,7 @@ triplot!(ax, pts, T, bn, get_convex_hull(tri);
8485
strokewidth=0.0)
8586
xlims!(ax, -0.4, 2.4)
8687
ylims!(ax, -0.4, 6.4)
87-
save("$save_path/test_figure_6.png", fig6)
88+
SAVE_FIGURE && save("$save_path/test_figure_6.png", fig6)
8889

8990
fig7 = Figure()
9091
ax = Axis(fig7[1, 1])
@@ -104,4 +105,4 @@ triplot!(ax, pts, T, bn, get_convex_hull(tri);
104105
strokewidth=0.0)
105106
xlims!(ax, -0.4, 2.4)
106107
ylims!(ax, -0.4, 6.4)
107-
save("$save_path/test_figure_7.png", fig7)
108+
SAVE_FIGURE && save("$save_path/test_figure_7.png", fig7)

test/polygon_utils.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using CairoMakie
66

77
save_path = basename(pwd()) == "test" ? "figures" : "test/figures"
88

9+
include("./test_setup.jl")
910
include("./helper_functions.jl")
1011

1112
tri, label_map, index_map = simple_geometry()
@@ -392,4 +393,4 @@ lines!(ax, bn1, color=:red, linewidth=4)
392393
lines!(ax, bn2, color=:red, linewidth=4)
393394
lines!(ax, bn3, color=:red, linewidth=4)
394395
scatter!(ax, [x], [y], color=:blue, markersize=23)
395-
save("$save_path/pole_of_inaccessibility.png", fig)
396+
SAVE_FIGURE && save("$save_path/pole_of_inaccessibility.png", fig)

test/test_setup.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const SAVE_FIGURE = false

test/triangulation/bowyer_watson.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using StableRNGs
55
using CairoMakie
66
using DataStructures
77

8+
include("../test_setup.jl")
89
include("../helper_functions.jl")
910

1011
save_path = basename(pwd()) == "test" ? "figures" : "test/figures"
@@ -108,7 +109,7 @@ end
108109
convex_hull_linewidth=7)
109110
xlims!(ax, -6, 12)
110111
ylims!(ax, -6, 12)
111-
save("$save_path/test_bowyer_watson_1.png", fig)
112+
SAVE_FIGURE && save("$save_path/test_bowyer_watson_1.png", fig)
112113
BI = DT.BoundaryIndex
113114
@test get_triangles(tri) == Set{NTuple{3,Int64}}(((3, 2, BI),
114115
(4, BI, 5),
@@ -133,7 +134,7 @@ end
133134
convex_hull_linewidth=7, convex_hull_linestyle=:solid)
134135
xlims!(ax, -5.0, 5.0)
135136
ylims!(ax, -5.0, 5.0)
136-
save("$save_path/test_bowyer_watson_2.png", fig)
137+
SAVE_FIGURE && save("$save_path/test_bowyer_watson_2.png", fig)
137138
validate_triangulation(tri)
138139
end
139140

@@ -336,5 +337,5 @@ end
336337
pts = [a, b, c, d, e, f, g, h, i, j]
337338
tri = DT.triangulate_bowyer_watson(pts; delete_ghosts=false)
338339
fig, ax, sc, = triplot(tri)
339-
save("$save_path/small_example.png", fig)
340+
SAVE_FIGURE && save("$save_path/small_example.png", fig)
340341
end

test/triangulation/gmsh.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using Test
22
using LinearAlgebra
33
using ..DelaunayTriangulation
4-
const DT = DelaunayTriangulation.DT
4+
const DT = DelaunayTriangulation
55
using CairoMakie
66
using DataStructures
77

8+
include("../test_setup.jl")
9+
810
include("../helper_functions.jl")
911

1012
save_path = basename(pwd()) == "test" ? "figures" : "test/figures"
@@ -1055,7 +1057,7 @@ lines!(ax, nodes[:, boundary_nodes[4][4]]; color=:orange, linewidth=6)
10551057

10561058
lines!(ax, nodes[:, boundary_nodes[5][1]]; color=:red, linewidth=6)
10571059

1058-
save("$save_path/sparse_example_triangulation.png", fig)
1060+
SAVE_FIGURE && save("$save_path/sparse_example_triangulation.png", fig)
10591061

10601062
## A square
10611063
x = [0.0, 2.0, 2.0, 0.0, 0.0]
@@ -1082,7 +1084,7 @@ elements4, nodes4, boundary_nodes4 = generate_mesh(0.0, 2.0, 0.0, 2.0, 0.5;
10821084
ax = Axis(fig[2, 2])
10831085
mesh!(ax, nodes4, elements4')
10841086

1085-
save("$save_path/square_triangulation.png", fig)
1087+
SAVE_FIGURE && save("$save_path/square_triangulation.png", fig)
10861088

10871089
@test elements1 == elements3
10881090
@test nodes1 == nodes3
@@ -1596,7 +1598,7 @@ ax = Axis(fig[1, 2], xlabel=L"x", ylabel=L"y", width=300, height=300,
15961598
title=L"(b):$ $ Coarse mesh", titlealign=:left)
15971599
triplot!(ax, tri2)
15981600
resize_to_layout!(fig)
1599-
save("$save_path/gmsh_example_1.png", fig)
1601+
SAVE_FIGURE && save("$save_path/gmsh_example_1.png", fig)
16001602

16011603
### Another specific example with multiple segments
16021604
# The first segment
@@ -1633,7 +1635,7 @@ for (i, segment_index) in enumerate(values(bn_map))
16331635
lines!(ax, get_points(tri)[:, bn_nodes], color=colors[i], linewidth=4)
16341636
end
16351637
resize_to_layout!(fig)
1636-
save("$save_path/gmsh_example_2.png", fig)
1638+
SAVE_FIGURE && save("$save_path/gmsh_example_2.png", fig)
16371639

16381640
### For the docs
16391641
x1 = [collect(LinRange(0, 2, 4)),
@@ -1670,4 +1672,4 @@ tri = generate_mesh(x, y, 0.2)
16701672
fig, ax, sc = triplot(tri; show_ghost_edges=true, convex_hull_linestyle=:solid, convex_hull_linewidth=4)
16711673
xlims!(ax, -0.5, 2.5)
16721674
ylims!(ax, -0.5, 6.5)
1673-
save("$save_path/gmsh_example_3.png", fig)
1675+
SAVE_FIGURE && save("$save_path/gmsh_example_3.png", fig)

test/triangulation/rectangle.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ using ..DelaunayTriangulation
22
const DT = DelaunayTriangulation
33
using CairoMakie
44

5+
include("../test_setup.jl")
6+
57
save_path = basename(pwd()) == "test" ? "figures" : "test/figures"
68

79
a, b, c, d = 2.0, 10.0, -5.0, 7.5
@@ -15,7 +17,7 @@ lines!(ax, tri.points[:, tri.boundary_nodes[1]]; linewidth=4)
1517
lines!(ax, tri.points[:, tri.boundary_nodes[2]]; linewidth=4)
1618
lines!(ax, tri.points[:, tri.boundary_nodes[3]]; linewidth=4)
1719
lines!(ax, tri.points[:, tri.boundary_nodes[4]]; linewidth=4)
18-
save("$save_path/rectangular_triangulation_1.png", fig)
20+
SAVE_FIGURE && save("$save_path/rectangular_triangulation_1.png", fig)
1921
@test tri.boundary_nodes[1] == 1:20
2022
@test tri.boundary_nodes[2] == 20:20:200
2123
@test tri.boundary_nodes[3] == 200:-1:181
@@ -25,7 +27,7 @@ tri = DT.triangulate_rectangle(a, b, c, d, nx, ny; single_boundary=true)
2527
fig, ax, sc = triplot(tri; show_ghost_edges=true)
2628
xlims!(ax, a - 0.5, b + 0.5)
2729
ylims!(ax, c - 0.5, d + 0.5)
28-
save("$save_path/rectangular_triangulation_2.png", fig)
30+
SAVE_FIGURE && save("$save_path/rectangular_triangulation_2.png", fig)
2931
bn = reduce(vcat, [1:20, 20:20:200, 200:-1:181, 181:-20:1])
3032
unique!(bn)
3133
push!(bn, 1)

0 commit comments

Comments
 (0)