Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runic #166

Merged
merged 3 commits into from
Jul 28, 2024
Merged

Runic #166

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DelaunayTriangulation = "927a84f5-c5f4-47a5-9785-b46e178433df"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterTools = "35a29f4d-8980-5a13-9543-d66fff28ecb8"
ElasticArrays = "fdbdab4c-e67f-52f5-8c3f-e7b388dad3d4"
Expand Down
11 changes: 6 additions & 5 deletions docs/liveserver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ Pkg.instantiate()
import LiveServer
withenv("LIVESERVER_ACTIVE" => "true") do
LiveServer.servedocs(;
launch_browser=true,
foldername=joinpath(repo_root, "docs"),
include_dirs=[joinpath(repo_root, "src")],
skip_dirs=[joinpath(repo_root, "docs/src/tutorials"),
launch_browser = true,
foldername = joinpath(repo_root, "docs"),
include_dirs = [joinpath(repo_root, "src")],
skip_dirs = [
joinpath(repo_root, "docs/src/tutorials"),
joinpath(repo_root, "docs/src/applications"),
joinpath(repo_root, "docs/src/figures"),
],
)
end
end
86 changes: 46 additions & 40 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ using Literate
using Test
using Dates

DocMeta.setdocmeta!(DelaunayTriangulation, :DocTestSetup, :(using DelaunayTriangulation, Test);
recursive=true)
DocMeta.setdocmeta!(
DelaunayTriangulation, :DocTestSetup, :(using DelaunayTriangulation, Test);
recursive = true,
)

const IS_LIVESERVER = false && get(ENV, "LIVESERVER_ACTIVE", "false") == "true"
if IS_LIVESERVER
Expand Down Expand Up @@ -41,7 +43,7 @@ function add_just_the_code_section(dir, file)
file_name, file_ext = splitext(file)
file_path = joinpath(dir, file)
new_file_path = joinpath(session_tmp, file_name * "_just_the_code" * file_ext)
cp(file_path, new_file_path, force=true)
cp(file_path, new_file_path, force = true)
folder = splitpath(dir)[end] # literate_tutorials or literate_applications
open(new_file_path, "a") do io
write(io, "\n")
Expand Down Expand Up @@ -74,7 +76,7 @@ for folder in ("tutorials", "applications")
# end
#end
new_file_path = add_just_the_code_section(dir, file)
script = Literate.script(file_path, session_tmp, name=splitext(file)[1] * "_just_the_code_cleaned")
script = Literate.script(file_path, session_tmp, name = splitext(file)[1] * "_just_the_code_cleaned")
code = strip(read(script, String))
@info "[$(ct())] Processing $file: Converting markdown script"
line_ending_symbol = occursin(code, "\r\n") ? "\r\n" : "\n"
Expand All @@ -86,12 +88,12 @@ for folder in ("tutorials", "applications")
Literate.markdown(
new_file_path,
outputdir;
documenter=true,
postprocess=editurl_update ∘ post_strip,
credit=true,
name=splitext(file)[1],
execute=false,
flavor=Literate.DocumenterFlavor(),
documenter = true,
postprocess = editurl_update ∘ post_strip,
credit = true,
name = splitext(file)[1],
execute = false,
flavor = Literate.DocumenterFlavor(),
)
end
end
Expand Down Expand Up @@ -127,15 +129,15 @@ const _PAGES = [
"Voronoi Tessellations" => "tutorials/voronoi.md",
"Clipped Voronoi Tessellations" => [
"Clipping to the Convex Hull" => "tutorials/clipped.md",
"Clipping to a Rectangle" => "tutorials/clipped_rectangle.md"
"Clipping to a Rectangle" => "tutorials/clipped_rectangle.md",
],
"Centroidal Voronoi Tessellations" => "tutorials/centroidal.md",
"Point Location" => "tutorials/point_location.md",
"Nearest Neighbour Queries" => "tutorials/nearest.md",
"Convex Hulls" => "tutorials/convex_hull.md",
"Pole of Inaccessibility" => "tutorials/pole_of_inaccessibility.md",
"Point-in-Polygon Testing" => "tutorials/point_in_polygon.md",
"Using Custom Structs for Primitives and Boundaries" => "tutorials/custom_primitive.md"
"Using Custom Structs for Primitives and Boundaries" => "tutorials/custom_primitive.md",
],
"Manual" => [
"Overview" => "manual/overview.md",
Expand Down Expand Up @@ -168,7 +170,7 @@ const _PAGES = [
"Data Structures" => "extended/data_structures.md",
"Algorithm Internals" => "extended/algorithms.md",
"Utility Functions" => "extended/utils.md",
],
],
"Mathematical Details" => [
"Overview" => "math/overview.md",
"Delaunay Triangulations" => "math/delaunay.md",
Expand Down Expand Up @@ -221,34 +223,38 @@ end

# Make and deploy
makedocs(;
modules=[DelaunayTriangulation],
authors="Daniel VandenHeuvel <danj.vandenheuvel@gmail.com>",
sitename="DelaunayTriangulation.jl",
format=Documenter.HTML(;
prettyurls=IS_CI,
canonical="https://JuliaGeometry.github.io/DelaunayTriangulation.jl",
edit_link="main",
size_threshold=8000 * 2^10,
size_threshold_warn=1000 * 2^10,
size_threshold_ignore=["api/triangulation.md", "extended/data_structures.md"],
collapselevel=1,
assets=String[],
mathengine=MathJax3(Dict(
:loader => Dict("load" => ["[tex]/physics"]),
:tex => Dict(
"inlineMath" => [["\$", "\$"], ["\\(", "\\)"]],
"tags" => "ams",
"packages" => ["base", "ams", "autoload", "physics"],
modules = [DelaunayTriangulation],
authors = "Daniel VandenHeuvel <danj.vandenheuvel@gmail.com>",
sitename = "DelaunayTriangulation.jl",
format = Documenter.HTML(;
prettyurls = IS_CI,
canonical = "https://JuliaGeometry.github.io/DelaunayTriangulation.jl",
edit_link = "main",
size_threshold = 8000 * 2^10,
size_threshold_warn = 1000 * 2^10,
size_threshold_ignore = ["api/triangulation.md", "extended/data_structures.md"],
collapselevel = 1,
assets = String[],
mathengine = MathJax3(
Dict(
:loader => Dict("load" => ["[tex]/physics"]),
:tex => Dict(
"inlineMath" => [["\$", "\$"], ["\\(", "\\)"]],
"tags" => "ams",
"packages" => ["base", "ams", "autoload", "physics"],
),
),
))),
linkcheck=false,
warnonly=true,
draft=IS_LIVESERVER,
pages=_PAGES,
pagesonly=true,
),
),
linkcheck = false,
warnonly = true,
draft = IS_LIVESERVER,
pages = _PAGES,
pagesonly = true,
)

deploydocs(;
repo="github.com/JuliaGeometry/DelaunayTriangulation.jl",
devbranch="main",
push_preview=true)
repo = "github.com/JuliaGeometry/DelaunayTriangulation.jl",
devbranch = "main",
push_preview = true,
)
1 change: 0 additions & 1 deletion docs/src/api/triangulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ get_section_index
map_ghost_vertex
get_ghost_vertex_range
all_ghost_vertices
get_point
num_points
get_representative_point_coordinates
compute_representative_points!
Expand Down
60 changes: 34 additions & 26 deletions docs/src/applications/cell_simulations.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ using StatsBase
using CairoMakie
Base.@kwdef mutable struct CellModel{P}
tri::Triangulation{P}
new_r_cache::Vector{NTuple{2,Float64}} # for r(t + Δt)
new_r_cache::Vector{NTuple{2, Float64}} # for r(t + Δt)
α::Float64
s::Float64
Δt::Float64
Expand Down Expand Up @@ -103,7 +103,7 @@ function polygon_area(points) # this is the same function from the Interpolation
rx, ry = getxy(r)
sx, sy = getxy(s)
area = px * (qy - ry) + rx * (py - sy)
for i in 2:(n-1)
for i in 2:(n - 1)
p, q, r = get_point(points, i, i + 1, i - 1)
px, py = getxy(p)
qx, qy = getxy(q)
Expand All @@ -113,7 +113,7 @@ function polygon_area(points) # this is the same function from the Interpolation
return area / 2
end
function get_voronoi_area(tri::Triangulation, i)
points = NTuple{2,Float64}[]
points = NTuple{2, Float64}[]
!DelaunayTriangulation.has_vertex(tri, i) && return (0.0, points) # might not be included anymore due to retriangulation
DelaunayTriangulation.is_boundary_node(tri, i)[1] && return (0.0, points) # to prevent boundary cells from proliferating
N = get_neighbours(tri, i)
Expand Down Expand Up @@ -157,7 +157,7 @@ function proliferate_cells!(cells::CellModel)
δ = DelaunayTriangulation.distance_to_polygon(p, get_points(tri), poly)
s, c = sincos(θ)
q = p .+ (δ * cells.ϵ) .* (c, s)
add_point!(tri, q; rng=cells.rng)
add_point!(tri, q; rng = cells.rng)
push!(cells.new_r_cache, q)
end
return nothing
Expand All @@ -174,7 +174,7 @@ function perform_step!(cells::CellModel)
end
function simulate_cells(cells::CellModel)
t = 0.0
all_points = Vector{Vector{NTuple{2,Float64}}}()
all_points = Vector{Vector{NTuple{2, Float64}}}()
push!(all_points, deepcopy(get_points(cells.tri)))
while t < cells.final_time
perform_step!(cells)
Expand All @@ -194,23 +194,27 @@ $\beta = 0.25$, $K = 100^2$, and $\epsilon = 0.5$.
rng = StableRNG(123444)
a, b, c, d = -2.0, 2.0, -5.0, 5.0
points = [(a + (b - a) * rand(rng), c + (d - c) * rand(rng)) for _ in 1:10]
tri = triangulate(points; rng=rng)
cells = CellModel(; tri=tri, new_r_cache=similar(points), α=5.0, s=2.0, Δt=1e-3,
β=0.25, K=100.0^2, rng, final_time=25.0, ϵ=0.5)
tri = triangulate(points; rng = rng)
cells = CellModel(;
tri = tri, new_r_cache = similar(points), α = 5.0, s = 2.0, Δt = 1.0e-3,
β = 0.25, K = 100.0^2, rng, final_time = 25.0, ϵ = 0.5,
)
results = simulate_cells(cells);

fig = Figure(fontsize=26)
fig = Figure(fontsize = 26)
title_obs = Observable(L"t = %$(0.0)")
ax1 = Axis(fig[1, 1], width=1200, height=400, title=title_obs, titlealign=:left)
ax1 = Axis(fig[1, 1], width = 1200, height = 400, title = title_obs, titlealign = :left)
Δt = cells.Δt
i = Observable(1)
voronoiplot!(ax1, @lift(voronoi(triangulate(results[$i]; rng), clip=true, rng=rng)),
color=:darkgreen, strokecolor=:black, strokewidth=2, show_generators=false)
voronoiplot!(
ax1, @lift(voronoi(triangulate(results[$i]; rng), clip = true, rng = rng)),
color = :darkgreen, strokecolor = :black, strokewidth = 2, show_generators = false,
)
xlims!(ax1, -12, 12)
ylims!(ax1, -12, 12)
resize_to_layout!(fig)
t = 0:Δt:cells.final_time
record(fig, "cell_simulation.mp4", 1:10:length(t); framerate=60) do ii
record(fig, "cell_simulation.mp4", 1:10:length(t); framerate = 60) do ii
i[] = ii
title_obs[] = L"t = %$(((ii-1) * Δt))"
end;
Expand All @@ -231,7 +235,7 @@ using StatsBase
using CairoMakie
Base.@kwdef mutable struct CellModel{P}
tri::Triangulation{P}
new_r_cache::Vector{NTuple{2,Float64}} # for r(t + Δt)
new_r_cache::Vector{NTuple{2, Float64}} # for r(t + Δt)
α::Float64
s::Float64
Δt::Float64
Expand Down Expand Up @@ -270,7 +274,7 @@ function polygon_area(points) # this is the same function from the Interpolation
rx, ry = getxy(r)
sx, sy = getxy(s)
area = px * (qy - ry) + rx * (py - sy)
for i in 2:(n-1)
for i in 2:(n - 1)
p, q, r = get_point(points, i, i + 1, i - 1)
px, py = getxy(p)
qx, qy = getxy(q)
Expand All @@ -280,7 +284,7 @@ function polygon_area(points) # this is the same function from the Interpolation
return area / 2
end
function get_voronoi_area(tri::Triangulation, i)
points = NTuple{2,Float64}[]
points = NTuple{2, Float64}[]
!DelaunayTriangulation.has_vertex(tri, i) && return (0.0, points) # might not be included anymore due to retriangulation
DelaunayTriangulation.is_boundary_node(tri, i)[1] && return (0.0, points) # to prevent boundary cells from proliferating
N = get_neighbours(tri, i)
Expand Down Expand Up @@ -319,7 +323,7 @@ function proliferate_cells!(cells::CellModel)
δ = DelaunayTriangulation.distance_to_polygon(p, get_points(tri), poly)
s, c = sincos(θ)
q = p .+ (δ * cells.ϵ) .* (c, s)
add_point!(tri, q; rng=cells.rng)
add_point!(tri, q; rng = cells.rng)
push!(cells.new_r_cache, q)
end
return nothing
Expand All @@ -332,7 +336,7 @@ function perform_step!(cells::CellModel)
end
function simulate_cells(cells::CellModel)
t = 0.0
all_points = Vector{Vector{NTuple{2,Float64}}}()
all_points = Vector{Vector{NTuple{2, Float64}}}()
push!(all_points, deepcopy(get_points(cells.tri)))
while t < cells.final_time
perform_step!(cells)
Expand All @@ -345,23 +349,27 @@ end
rng = StableRNG(123444)
a, b, c, d = -2.0, 2.0, -5.0, 5.0
points = [(a + (b - a) * rand(rng), c + (d - c) * rand(rng)) for _ in 1:10]
tri = triangulate(points; rng=rng)
cells = CellModel(; tri=tri, new_r_cache=similar(points), α=5.0, s=2.0, Δt=1e-3,
β=0.25, K=100.0^2, rng, final_time=25.0, ϵ=0.5)
tri = triangulate(points; rng = rng)
cells = CellModel(;
tri = tri, new_r_cache = similar(points), α = 5.0, s = 2.0, Δt = 1.0e-3,
β = 0.25, K = 100.0^2, rng, final_time = 25.0, ϵ = 0.5,
)
results = simulate_cells(cells);

fig = Figure(fontsize=26)
fig = Figure(fontsize = 26)
title_obs = Observable(L"t = %$(0.0)")
ax1 = Axis(fig[1, 1], width=1200, height=400, title=title_obs, titlealign=:left)
ax1 = Axis(fig[1, 1], width = 1200, height = 400, title = title_obs, titlealign = :left)
Δt = cells.Δt
i = Observable(1)
voronoiplot!(ax1, @lift(voronoi(triangulate(results[$i]; rng), clip=true, rng=rng)),
color=:darkgreen, strokecolor=:black, strokewidth=2, show_generators=false)
voronoiplot!(
ax1, @lift(voronoi(triangulate(results[$i]; rng), clip = true, rng = rng)),
color = :darkgreen, strokecolor = :black, strokewidth = 2, show_generators = false,
)
xlims!(ax1, -12, 12)
ylims!(ax1, -12, 12)
resize_to_layout!(fig)
t = 0:Δt:cells.final_time
record(fig, "cell_simulation.mp4", 1:10:length(t); framerate=60) do ii
record(fig, "cell_simulation.mp4", 1:10:length(t); framerate = 60) do ii
i[] = ii
title_obs[] = L"t = %$(((ii-1) * Δt))"
end;
Expand Down
Loading
Loading