Skip to content

Commit

Permalink
Updated testing for extrudecurve
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin-Mattheus-Moerman committed Mar 30, 2024
1 parent 2d0b80f commit 53f1825
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 16 deletions.
26 changes: 25 additions & 1 deletion examples/demo_extrudecurve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using Rotations
using LinearAlgebra

# Example curve
r = 1
r = 1.0
nc = 16
Vc = circlepoints(r,nc;dir=:cw)

Expand All @@ -20,24 +20,48 @@ F1,V1 = extrudecurve(Vc,d;s=1, n=n, close_loop=true,face_type=:quad)
F2,V2 = extrudecurve(Vc,d;s=0, n=n, close_loop=true,face_type=:tri)
F3,V3 = extrudecurve(Vc,d;s=-1, n=n, close_loop=true,face_type=:tri_slash)

n = normalizevector(Vec{3, Float64}(1.0,0.0,1.0))
F4,V4 = extrudecurve(Vc,d;s=1, n=n, close_loop=true,face_type=:quad)
F5,V5 = extrudecurve(Vc,d;s=0, n=n, close_loop=true,face_type=:quad)
F6,V6 = extrudecurve(Vc,d;s=-1, n=n, close_loop=true,face_type=:quad)


M1 = GeometryBasics.Mesh(V1,F1)
M2 = GeometryBasics.Mesh(V2,F2)
M3 = GeometryBasics.Mesh(V3,F3)
M4 = GeometryBasics.Mesh(V4,F4)
M5 = GeometryBasics.Mesh(V5,F5)
M6 = GeometryBasics.Mesh(V6,F6)

## Visualization
fig = Figure(size=(1200,1200))

ax1 = Axis3(fig[1, 1], aspect = :data, limits=(-r,r,-r,r,-d,d),xlabel = "X", ylabel = "Y", zlabel = "Z", title = """Extruded s=1, face_type="quad" """)
hp1 = lines!(ax1,Vc,color=:red,linewidth=6, transparency=true, depth_shift=-1.0f-3)
hp2 = poly!(ax1,M1, strokewidth=1,color=:white, strokecolor=:black, shading = FastShading, transparency=false)
# normalplot(ax1,M1)

ax2 = Axis3(fig[1, 2], aspect = :data, limits=(-r,r,-r,r,-d,d), xlabel = "X", ylabel = "Y", zlabel = "Z", title = """Extruded s=0, face_type="tri" """)
hp1 = lines!(ax2,Vc,color=:red,linewidth=6, transparency=true, depth_shift=-1.0f-3)
hp2 = poly!(ax2,M2, strokewidth=1,color=:white, strokecolor=:black, shading = FastShading, transparency=false)
# normalplot(ax2,M2)

ax3 = Axis3(fig[1, 3], aspect = :data, limits=(-r,r,-r,r,-d,d), xlabel = "X", ylabel = "Y", zlabel = "Z", title = """Extruded s=-1, face_type="tri_slash" """)
hp1 = lines!(ax3,Vc,color=:red,linewidth=6, transparency=true, depth_shift=-1.0f-3)
hp2 = poly!(ax3,M3, strokewidth=1,color=:white, strokecolor=:black, shading = FastShading, transparency=false)
# normalplot(ax3,M3)

ax1 = Axis3(fig[2, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = """Extruded s=1, face_type="quad" """)
hp1 = lines!(ax1,Vc,color=:red,linewidth=6, transparency=true, depth_shift=-1.0f-3)
hp2 = poly!(ax1,M4, strokewidth=1,color=:white, strokecolor=:black, shading = FastShading, transparency=false)

ax2 = Axis3(fig[2, 2], aspect = :data,xlabel = "X", ylabel = "Y", zlabel = "Z", title = """Extruded s=0, face_type="tri" """)
hp1 = lines!(ax2,Vc,color=:red,linewidth=6, transparency=true, depth_shift=-1.0f-3)
hp2 = poly!(ax2,M5, strokewidth=1,color=:white, strokecolor=:black, shading = FastShading, transparency=false)

ax3 = Axis3(fig[2, 3], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = """Extruded s=-1, face_type="tri_slash" """)
hp1 = lines!(ax3,Vc,color=:red,linewidth=6, transparency=true, depth_shift=-1.0f-3)
hp2 = poly!(ax3,M6, strokewidth=1,color=:white, strokecolor=:black, shading = FastShading, transparency=false)

# Legend(fig[1, 4],[hp1,hp2],["Input curve","Surface"])

Expand Down
1 change: 1 addition & 0 deletions src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2181,6 +2181,7 @@ function extrudecurve(V1,d; s=1, n=Point{3, Float64}(0.0,0.0,1.0),num_steps=noth
p = d.*n
elseif isone(-s) # Against n from V1
p = -d.*n
V1 = reverse(V1)
elseif iszero(s) # Extrude both ways from V1
p = d.*n
V1 = [(eltype(V1))(v.-p./2) for v V1] #Shift V1 in negative direction
Expand Down
2 changes: 1 addition & 1 deletion test/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.2"
manifest_format = "2.0"
project_hash = "b2413e1db49fabe8a81b1e8be16be9ebe5ec8c7e"
project_hash = "4901c9910c3e3d2094f5a5e0c1b806bf97e87f4b"

[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
114 changes: 100 additions & 14 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Test, FileIO, Comodo, Comodo.GeometryBasics, Statistics
using Test, FileIO, Comodo, Comodo.GeometryBasics, Statistics, LinearAlgebra

# ConnectivitySet

Expand Down Expand Up @@ -1780,42 +1780,128 @@ end
@testset "Curve" begin
V = Point3{Float64}[[0.0,0.0,0.0],[0.25,0.0,0.0],[0.75,0.0,0.0],[1.75,0.0,0.0]]
r = pointspacingmean(V)
@test isapprox(r,mean(norm.(diff(V,dims=1))),atol = eps_tol)
@test isapprox(r,mean(norm.(diff(V,dims=1))),atol = eps_level)
end

@testset "Edges" begin
V = Point3{Float64}[[0.0,0.0,0.0],[0.25,0.0,0.0],[0.75,0.0,0.0],[1.75,0.0,0.0]]
E = LineFace{Int64}[[1,2],[2,3],[3,4]]
r = pointspacingmean(E,V)
@test isapprox(r,mean(norm.(diff(V,dims=1))),atol = eps_tol)
@test isapprox(r,mean(norm.(diff(V,dims=1))),atol = eps_level)
end

@testset "Faces" begin
V = Point3{Float64}[[0.0,0.0,0.0],[0.25,0.0,0.0],[0.25,0.5,0.0],[0,0.5,0.0],[0.0,0.0,0.0]]
F = QuadFace{Int64}[[1,2,3,4]]
r = pointspacingmean(F,V)
@test isapprox(r,mean(norm.(diff(V,dims=1))),atol = eps_tol)
@test isapprox(r,mean(norm.(diff(V,dims=1))),atol = eps_level)
end
end


@testset "extrudecurve" begin
@testset "extrudecurve" verbose = true begin
eps_level = 0.001
r = 1
r = 1.0
nc = 16
d = 3.0
Vc = circlepoints(r, nc; dir=:cw)
F, V = extrudecurve(Vc, d; s=1, close_loop=true, face_type=:quad)
num_steps = 5

@testset "Direction (s) variations" begin
F, V = extrudecurve(Vc, d; s=1, n=[0.0,0.0,1.0], num_steps=num_steps, close_loop=true, face_type=:quad)
z = [v[3] for v in V]
zMax = maximum(z)
zMin = minimum(z)
@test isapprox(zMax,d,atol = eps_level) && isapprox(zMin,0.0,atol = eps_level)

F, V = extrudecurve(Vc, d; s=0, n=[0.0,0.0,1.0], num_steps=num_steps, close_loop=true, face_type=:quad)
z = [v[3] for v in V]
zMax = maximum(z)
zMin = minimum(z)
@test isapprox(zMax,d/2,atol = eps_level) && isapprox(zMin,-d/2,atol = eps_level)

F, V = extrudecurve(Vc, d; s=-1, n=[0.0,0.0,1.0], num_steps=num_steps, close_loop=true, face_type=:quad)
z = [v[3] for v in V]
zMax = maximum(z)
zMin = minimum(z)
@test isapprox(zMax,0.0,atol = eps_level) && isapprox(zMin,-d,atol = eps_level)
end

@testset "Direction (n) variations" begin
n=[0.0,0.0,1.0] # Upward
F, V = extrudecurve(Vc, d; s=1, n=n, num_steps=num_steps, close_loop=true, face_type=:quad)
z = [v[3] for v in V]
zMax = maximum(z)
zMin = minimum(z)
@test isapprox(zMax,d,atol = eps_level) && isapprox(zMin,0.0,atol = eps_level)

n=[0.0,0.0,-1.0] # Downward
F, V = extrudecurve(Vc, d; s=1, n=n, num_steps=num_steps, close_loop=true, face_type=:quad)
z = [v[3] for v in V]
zMax = maximum(z)
zMin = minimum(z)
@test isapprox(zMax,0.0,atol = eps_level) && isapprox(zMin,-d,atol = eps_level)

n = normalizevector([1.0,0.0,1.0]) # 45 degree direction upward
F, V = extrudecurve(Vc, d; s=1, n=n, num_steps=num_steps, close_loop=true, face_type=:quad)
z = [v[3] for v in V]
zMax = maximum(z)
zMin = minimum(z)
@test isapprox(zMax,sqrt(2.0)*d/2,atol = eps_level) && isapprox(zMin,0.0,atol = eps_level)
end

@testset "face_type=:quad" begin
F, V = extrudecurve(Vc, d; s=1, n=[0.0,0.0,1.0], num_steps=num_steps, close_loop=true, face_type=:quad)
z = [v[3] for v in V]
zMax = maximum(z)
zMin = minimum(z)

@test V isa Vector{Point3{Float64}}
@test length(V) == 128
@test isapprox(V[1], [1.0, 0.0, 0.0], atol=eps_level)
@test F isa Vector{QuadFace{Int64}}
@test length(F) == nc*(num_steps-1)

@test F isa Vector{QuadFace{Int64}}
@test length(F) == 112
@test F[1] == [17, 18, 2, 1]
end
ind = round.(Int64,range(1,length(V),5))
@test V isa Vector{Point3{Float64}}
@test isapprox(zMax,d,atol = eps_level) && isapprox(zMin,0.0,atol = eps_level)
@test isapprox(V[ind],Point3{Float64}[[1.0, 0.0, 0.0], [2.83276944882399e-16, -1.0, 0.75],
[-0.9238795325112867, -0.3826834323650899, 1.5], [-0.38268343236509034, 0.9238795325112865, 2.25],
[0.9238795325112865, 0.3826834323650904, 3.0]],atol = eps_level)
end

@testset "face_type=:tri_slash" begin
F, V = extrudecurve(Vc, d; s=1, n=[0.0,0.0,1.0], num_steps=num_steps, close_loop=true, face_type=:tri_slash)
z = [v[3] for v in V]
zMax = maximum(z)
zMin = minimum(z)

@test F isa Vector{TriangleFace{Int64}}
@test length(F) == (nc*(num_steps-1))*2

ind = round.(Int64,range(1,length(V),5))
@test V isa Vector{Point3{Float64}}
@test isapprox(zMax,d,atol = eps_level) && isapprox(zMin,0.0,atol = eps_level)
@test isapprox(V[ind],Point3{Float64}[[1.0, 0.0, 0.0], [2.83276944882399e-16, -1.0, 0.75],
[-0.9238795325112867, -0.3826834323650899, 1.5], [-0.38268343236509034, 0.9238795325112865, 2.25],
[0.9238795325112865, 0.3826834323650904, 3.0]],atol = eps_level)
end

@testset "face_type=:tri" begin
F, V = extrudecurve(Vc, d; s=1, n=[0.0,0.0,1.0], num_steps=num_steps, close_loop=true, face_type=:tri)
z = [v[3] for v in V]
zMax = maximum(z)
zMin = minimum(z)

@test F isa Vector{TriangleFace{Int64}}
@test length(F) == (nc*(num_steps-1))*2

ind = round.(Int64,range(1,length(V),5))
@test V isa Vector{Point3{Float64}}
@test isapprox(zMax,d,atol = eps_level) && isapprox(zMin,0.0,atol = eps_level)
@test isapprox(V[ind],Point3{Float64}[[1.0, 0.0, 0.0], [-0.1913417161825446, -0.9619397662556435, 0.75],
[-0.9238795325112867, -0.3826834323650899, 1.5], [-0.19134171618254525, 0.9619397662556433, 2.25],
[0.9238795325112865, 0.3826834323650904, 3.0]],atol = eps_level)
end

end


@testset "separate vertices" begin
Expand Down

0 comments on commit 53f1825

Please sign in to comment.