Skip to content

Commit

Permalink
Add Repair{10} transform
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Nov 15, 2023
1 parent e1c1ad3 commit 889b565
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
44 changes: 34 additions & 10 deletions src/transforms/repair.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ Perform repairing operation with code `K`.
## Available operations
- K = 0: duplicated vertices and faces are removed
- K = 1: unused vertices are removed
- K = 2: non-manifold faces are removed
- K = 3: degenerate faces are removed
- K = 4: non-manifold vertices are removed
- K = 5: non-manifold vertices are split by threshold
- K = 6: close vertices are merged (given a radius)
- K = 7: faces are coherently oriented
- K = 8: zero-area ears are removed
- K = 9: rings of polygon are sorted
- K = 0: duplicated vertices and faces are removed
- K = 1: unused vertices are removed
- K = 2: non-manifold faces are removed
- K = 3: degenerate faces are removed
- K = 4: non-manifold vertices are removed
- K = 5: non-manifold vertices are split by threshold
- K = 6: close vertices are merged (given a radius)
- K = 7: faces are coherently oriented
- K = 8: zero-area ears are removed
- K = 9: rings of polygon are sorted
- K = 10: outer rings are expanded
## Examples
Expand Down Expand Up @@ -142,3 +143,26 @@ function repair9(r::AbstractVector{<:Ring})

Ring.(newverts), newinds
end

# ---------------
# OPERATION (10)
# ---------------

function apply(::Repair{10}, poly::PolyArea)
t = _expand10(poly)
r = rings(poly)
n, c = apply(t, first(r))
PolyArea([n; r[2:end]]), (t, c)
end

function revert(::Repair{10}, poly::PolyArea, c)
r = rings(poly)
o = revert(c[1], first(r), c[2])
PolyArea([o; r[2:end]])
end

apply(::Repair{10}, poly::Ngon) = poly, nothing

revert(::Repair{10}, poly::Ngon, cache) = poly

_expand10(g::Geometry{Dim,T}) where {Dim,T} = Expand(ntuple(i -> T(1) + 10atol(T), Dim))
12 changes: 12 additions & 0 deletions test/transforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,18 @@

@testset "Repair{9}" begin end

@testset "Repair{10}" begin
outer = Ring(P2[(0, 0), (0, 3), (2, 3), (2, 2), (3, 2), (3, 0)])
inner = Ring(P2[(1, 1), (1, 2), (2, 2), (2, 1)])
poly = PolyArea(outer, inner)
repair = Repair{10}()
rpoly, cache = TB.apply(repair, poly)
@test nvertices(rpoly) == nvertices(poly)
@test length(first(rings(rpoly))) > length(first(rings(poly)))
opoly = TB.revert(repair, rpoly, cache)
@test opoly == poly
end

@testset "Bridge" begin
# https://github.com/JuliaGeometry/Meshes.jl/issues/566
outer = Ring(P2(6, 4), P2(6, 7), P2(1, 6), P2(1, 1), P2(5, 2))
Expand Down

0 comments on commit 889b565

Please sign in to comment.