Skip to content

Commit

Permalink
Merge pull request #15 from jpthiele/runic
Browse files Browse the repository at this point in the history
Apply runic formatting and add to pre-commit
  • Loading branch information
pjaap authored Nov 27, 2024
2 parents f344c27 + 490a452 commit db82290
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 137 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ repos:
rev: v2.2.4
hooks:
- id: codespell
- repo: https://github.com/fredrikekre/runic-pre-commit
rev: v1.0.0
hooks:
- id: runic
22 changes: 12 additions & 10 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ using Documenter, GridVisualizeTools, ColorTypes, Colors

function mkdocs()
DocMeta.setdocmeta!(GridVisualizeTools, :DocTestSetup, :(using GridVisualizeTools, ColorTypes, Colors); recursive = true)
makedocs(; sitename = "GridVisualizeTools.jl",
modules = [GridVisualizeTools],
clean = false,
doctest = true,
authors = "J. Fuhrmann",
repo = "https://github.com/WIAS-PDELib/GridVisualizeTools.jl",
pages = [
"Home" => "index.md",
])
if !isinteractive()
makedocs(;
sitename = "GridVisualizeTools.jl",
modules = [GridVisualizeTools],
clean = false,
doctest = true,
authors = "J. Fuhrmann",
repo = "https://github.com/WIAS-PDELib/GridVisualizeTools.jl",
pages = [
"Home" => "index.md",
]
)
return if !isinteractive()
deploydocs(; repo = "github.com/WIAS-PDELib/GridVisualizeTools.jl.git", devbranch = "main")
end
end
Expand Down
28 changes: 16 additions & 12 deletions src/colors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ RGB{Float64}(0.85, 0.6, 0.6)
"""
function region_cmap(n)
ColorSchemes.distinguishable_colors(n,
[Colors.RGB(0.85, 0.6, 0.6), Colors.RGB(0.6, 0.85, 0.6), Colors.RGB(0.6, 0.6, 0.85)];
lchoices = range(70; stop = 80, length = 5),
cchoices = range(25; stop = 65, length = 15),
hchoices = range(20; stop = 360, length = 15))
return ColorSchemes.distinguishable_colors(
n,
[Colors.RGB(0.85, 0.6, 0.6), Colors.RGB(0.6, 0.85, 0.6), Colors.RGB(0.6, 0.6, 0.85)];
lchoices = range(70; stop = 80, length = 5),
cchoices = range(25; stop = 65, length = 15),
hchoices = range(20; stop = 360, length = 15)
)
end

"""
Expand All @@ -38,11 +40,13 @@ RGB{Float64}(1.0, 0.0, 0.0)
"""
function bregion_cmap(n)
ColorSchemes.distinguishable_colors(n,
[Colors.RGB(1.0, 0.0, 0.0), Colors.RGB(0.0, 1.0, 0.0), Colors.RGB(0.0, 0.0, 1.0)];
lchoices = range(50; stop = 75, length = 10),
cchoices = range(75; stop = 100, length = 10),
hchoices = range(20; stop = 360, length = 30))
return ColorSchemes.distinguishable_colors(
n,
[Colors.RGB(1.0, 0.0, 0.0), Colors.RGB(0.0, 1.0, 0.0), Colors.RGB(0.0, 0.0, 1.0)];
lchoices = range(50; stop = 75, length = 10),
cchoices = range(75; stop = 100, length = 10),
hchoices = range(20; stop = 360, length = 30)
)
end

"""
Expand All @@ -56,7 +60,7 @@ julia> rgbtuple("red")
(1.0, 0.0, 0.0)
```
"""
rgbtuple(c) = rgbtuple(parse(Colors.RGB{Float64},c))
rgbtuple(c) = rgbtuple(parse(Colors.RGB{Float64}, c))

"""
$(SIGNATURES)
Expand Down Expand Up @@ -85,7 +89,7 @@ RGB{Float64}(1.0, 0.0, 0.0)
```
"""
rgbcolor(col::Any) = parse(Colors.RGB{Float64},col)
rgbcolor(col::Any) = parse(Colors.RGB{Float64}, col)


"""
Expand Down
49 changes: 27 additions & 22 deletions src/extraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ Extract visible tetrahedra - those intersecting with the planes
Return corresponding points and facets for each region for drawing as mesh (Makie,MeshCat)
or trisurf (pyplot)
"""
function extract_visible_cells3D(coord, cellnodes, cellregions, nregions, xyzcut;
primepoints = zeros(0, 0), Tp = SVector{3, Float32}, Tf = SVector{3, Int32})
function extract_visible_cells3D(
coord, cellnodes, cellregions, nregions, xyzcut;
primepoints = zeros(0, 0), Tp = SVector{3, Float32}, Tf = SVector{3, Int32}
)
all_lt = ones(Bool, 3)
all_gt = ones(Bool, 3)

function take(coord, simplex, xyzcut, all_lt, all_gt)
for idim = 1:3
for idim in 1:3
all_lt[idim] = true
all_gt[idim] = true
for inode = 1:4
for inode in 1:4
c = coord[idim, simplex[inode]] - xyzcut[idim]
all_lt[idim] = all_lt[idim] && (c < 0.0)
all_gt[idim] = all_gt[idim] && (c > 0.0)
Expand All @@ -25,22 +27,22 @@ function extract_visible_cells3D(coord, cellnodes, cellregions, nregions, xyzcut
tke = false
tke = tke || (!all_lt[1]) && (!all_gt[1]) && (!all_gt[2]) && (!all_gt[3])
tke = tke || (!all_lt[2]) && (!all_gt[2]) && (!all_gt[1]) && (!all_gt[3])
tke = tke || (!all_lt[3]) && (!all_gt[3]) && (!all_gt[1]) && (!all_gt[2])
return tke = tke || (!all_lt[3]) && (!all_gt[3]) && (!all_gt[1]) && (!all_gt[2])
end

faces = [Vector{Tf}(undef, 0) for iregion = 1:nregions]
points = [Vector{Tp}(undef, 0) for iregion = 1:nregions]
faces = [Vector{Tf}(undef, 0) for iregion in 1:nregions]
points = [Vector{Tp}(undef, 0) for iregion in 1:nregions]

for iregion = 1:nregions
for iprime = 1:size(primepoints, 2)
for iregion in 1:nregions
for iprime in 1:size(primepoints, 2)
@views push!(points[iregion], Tp(primepoints[:, iprime]))
end
end
tet = zeros(Int32, 4)

for itet = 1:size(cellnodes, 2)
for itet in 1:size(cellnodes, 2)
iregion = cellregions[itet]
for i = 1:4
for i in 1:4
tet[i] = cellnodes[i, itet]
end
if take(coord, tet, xyzcut, all_lt, all_gt)
Expand All @@ -57,7 +59,7 @@ function extract_visible_cells3D(coord, cellnodes, cellregions, nregions, xyzcut
end
end
end
points, faces
return points, faces
end

"""
Expand All @@ -69,15 +71,17 @@ Extract visible boundary faces - those not cut off by the planes
Return corresponding points and facets for each region for drawing as mesh (Makie,MeshCat)
or trisurf (pyplot)
"""
function extract_visible_bfaces3D(coord, bfacenodes, bfaceregions, nbregions, xyzcut;
primepoints = zeros(0, 0), Tp = SVector{3, Float32}, Tf = SVector{3, Int32})
function extract_visible_bfaces3D(
coord, bfacenodes, bfaceregions, nbregions, xyzcut;
primepoints = zeros(0, 0), Tp = SVector{3, Float32}, Tf = SVector{3, Int32}
)
nbfaces = size(bfacenodes, 2)
cutcoord = zeros(3)

function take(coord, simplex, xyzcut)
for idim = 1:3
for idim in 1:3
all_gt = true
for inode = 1:3
for inode in 1:3
c = coord[idim, simplex[inode]] - xyzcut[idim]
all_gt = all_gt && c > 0
end
Expand All @@ -91,18 +95,18 @@ function extract_visible_bfaces3D(coord, bfacenodes, bfaceregions, nbregions, xy
Tc = SVector{3, eltype(coord)}
xcoord = reinterpret(Tc, reshape(coord, (length(coord),)))

faces = [Vector{Tf}(undef, 0) for iregion = 1:nbregions]
points = [Vector{Tp}(undef, 0) for iregion = 1:nbregions]
for iregion = 1:nbregions
for iprime = 1:size(primepoints, 2)
faces = [Vector{Tf}(undef, 0) for iregion in 1:nbregions]
points = [Vector{Tp}(undef, 0) for iregion in 1:nbregions]
for iregion in 1:nbregions
for iprime in 1:size(primepoints, 2)
@views push!(points[iregion], Tp(primepoints[:, iprime]))
end
end

# remove some type instability here
function collct(points, faces)
trinodes = [1, 2, 3]
for i = 1:nbfaces
for i in 1:nbfaces
iregion = bfaceregions[i]
trinodes[1] = bfacenodes[1, i]
trinodes[2] = bfacenodes[2, i]
Expand All @@ -115,7 +119,8 @@ function extract_visible_bfaces3D(coord, bfacenodes, bfaceregions, nbregions, xy
@views push!(faces[iregion], (npts + 1, npts + 2, npts + 3))
end
end
return
end
collct(points, faces)
points, faces
return points, faces
end
Loading

0 comments on commit db82290

Please sign in to comment.