Skip to content

Commit

Permalink
Use τₐ₀ and τᵣ₀
Browse files Browse the repository at this point in the history
  • Loading branch information
wsshin committed Dec 8, 2021
1 parent e3aa368 commit 42438fc
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
AbbreviatedTypes = "^0.1.4"
AbbreviatedTypes = "^0.2.1"
Makie = "^0.15.0"
julia = "^1.7"

Expand Down
2 changes: 1 addition & 1 deletion src/hyper/cuboid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function surfpt_nearby(x::SReal{N}, s::Cuboid{N}) where {N}
d = s.p * (x - s.c)
n = n .* copysign.(1.0,d) # operation returns SMatrix (reason for leaving n untransposed)
absd = abs.(d)
onbnd = abs.(s.r.-absd) .≤ Base.rtoldefault(Float) .* s.r # basically s.r .≈ absd but faster
onbnd = abs.(s.r.-absd) .≤ τᵣ₀ .* s.r # basically s.r .≈ absd but faster
isout = (s.r.<absd) .| onbnd
= (s.r .- absd) .* cosθ # entries can be negative
if count(isout) == 0 # x strictly inside cuboid; ∆ all positive
Expand Down
2 changes: 1 addition & 1 deletion src/planar/polygon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function surfpt_nearby(x::SReal{2}, s::Polygon{K}) where {K}

# Determine if x is outside of edges, inclusive.
sz = abs.((-)(bounds(s)...)) # SVec{2}
onbnd = abs∆xe .≤ Base.rtoldefault(Float) * max(sz.data...) # SVec{K}
onbnd = abs∆xe .≤ τᵣ₀ * max(sz.data...) # SVec{K}
isout = (∆xe.>0) .| onbnd # SVec{K}

# For x inside the polygon, it is easy to find the closest surface point: we can simply
Expand Down
6 changes: 3 additions & 3 deletions src/planar/sector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ function surfpt_nearby(x::SReal{2}, s::Sector)
# Calculate the closest point in the ρ dimension and outward normal direciton there.
r2 = s.r / 2
ρ = ld - r2 # positive if closer to arc; negative if closer to center
= ld Base.rtoldefault(Float) * r2 ? SVec(cos(s.ϕ₀),sin(s.ϕ₀)) : normalize(d)
= ld τᵣ₀ * r2 ? SVec(cos(s.ϕ₀),sin(s.ϕ₀)) : normalize(d)

surfρ = ρ<0 ? 0.0 : s.r # scalar: closest point to x between center and perimeter point
noutρ = copysign(1.0,ρ) *# SVec{2}: outward direction normal at surfρ

absρ = abs(ρ)
abs∆ρ = abs(r2 - absρ) # radial distance between x and either center or perimeter, whichever closer to x

onbndρ = abs∆ρ Base.rtoldefault(Float) * r2 # basically r2 ≈ ρ but faster
onbndρ = abs∆ρ τᵣ₀ * r2 # basically r2 ≈ ρ but faster
isoutρ = (r2 < absρ) || onbndρ

# Calculate the closest point in the ϕ dimension and outward normal direciton there.
Expand All @@ -67,7 +67,7 @@ function surfpt_nearby(x::SReal{2}, s::Sector)
absϕ = abs(ϕ)
abs∆ϕ = abs(s.∆ϕ2 - absϕ) # angular distance between x and closer side of sector

onbndϕ = abs∆ϕ Base.rtoldefault(Float) * s.∆ϕ2 # basically ∆ϕ2 ≈ ϕ but faster
onbndϕ = abs∆ϕ τᵣ₀ * s.∆ϕ2 # basically ∆ϕ2 ≈ ϕ but faster
isoutϕ = (s.∆ϕ2 < absϕ) || onbndϕ

# Pick the surface point and outward direction normal depending on the location of x.
Expand Down
4 changes: 2 additions & 2 deletions src/prism/prism.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ function surfpt_nearby(x::SReal{3}, s::Prism)
abs∆a = abs(s.h2 - la) # scalar: distance between x and base point closest to x
surfa = SVec(yb.data..., copysign(s.h2, ya)) # SVec{3}: coordinates of base point closest to x
nouta = SVec(0.0, 0.0, copysign(1.0, ya)) # SVec{3}: outward direction normal at surfa
onbnda = abs∆a Base.rtoldefault(Float) * s.h2
onbnda = abs∆a τᵣ₀ * s.h2
isouta = s.h2<la || onbnda

surfb2, noutb2 = surfpt_nearby(yb, s.b) # (SVec{2}, SVec{2}): side point closest to x and outward direction normal to side there
abs∆b = norm(surfb2 - yb) # scalar: distance between x and side point closest to x
surfb = SVec(surfb2.data..., ya) # SVec{3}: coordinates of side point closest to x
noutb = SVec(noutb2.data..., 0.0) # SVec{3}: outward direction normal to side surface at surfb
basesize = abs.((-)(bounds(s.b)...)) # SVec{2}: size of bounding rectancle of base
onbndb = abs∆b Base.rtoldefault(Float) * max(basesize.data...)
onbndb = abs∆b τᵣ₀ * max(basesize.data...)
isoutb = ybs.b || onbndb

if isouta && isoutb # x outside in both axis and base dimensions
Expand Down
2 changes: 1 addition & 1 deletion src/util/plotting.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const EPS_REL = Base.rtoldefault(Float) # machine epsilon
const EPS_REL = τᵣ₀ # machine epsilon

# Define drawshape() and drawshape!() functions.
# hres and vres are the number of sampling points in the corresponding Cartesion derctions.
Expand Down
2 changes: 1 addition & 1 deletion test/cross_section.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

= rand(2)
s2 = translate(s, ∆)
@test all(([r,0], [-r,0], [0,r], [0,-r], [0,0]) .+ Ref(∆) .∈ Ref(s2))
@test all(([r*one⁻,0], [-r*one⁻,0], [0,r*one⁻], [0,-r*one⁻], [0,0]) .+ Ref(∆) .∈ Ref(s2))
@test !any(([r*one⁺,0], [-r*one⁺,0], [0,r*one⁺], [0,-r*one⁺]) .+ Ref(∆) .∈ Ref(s2))

end # @testset "CrossSection, ball"
12 changes: 6 additions & 6 deletions test/cylinder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
@test all([(p = [0.3sx/√2,0.3sy/√2,1.1sz]; surfpt_nearby(1.1p,c) (p, normalize(1.1p-p))) for sx = (-1,1), sy = (-1,1), sz = (-1,1)]) # outside corners
@test all([(p = [0.3sx,0,1.1sz]; surfpt_nearby(1.1p,c) (p, normalize(1.1p-p))) for sx = (-1,1), sz = (-1,1)]) # outside corners
@test all([(p = [0,0.3sy,1.1sz]; surfpt_nearby(1.1p,c) (p, normalize(1.1p-p))) for sy = (-1,1), sz = (-1,1)]) # outside corners
@test all([(p = [0.3sx/√2,0.3sy/√2,1.1sz]; (x,nout) = surfpt_nearby(p,c); (xp && all([sx 0 0; 0 sy 0; 0 0 sz]*nout.≥-10eps()))) for sx = (-1,1), sy = (-1,1), sz = (-1,1)]) # on rims
@test all([(p = [0.3sx,0,1.1sz]; (x,nout) = surfpt_nearby(p,c); (xp && all([sx 0 0; 0 0 sz]*nout.≥-10eps()))) for sx = (-1,1), sz = (-1,1)]) # on rims
@test all([(p = [0,0.3sy,1.1sz]; (x,nout) = surfpt_nearby(p,c); (xp && all([0 sy 0; 0 0 sz]*nout.≥-10eps()))) for sy = (-1,1), sz = (-1,1)]) # on rims
@test all([(p = [0.3sx/√2,0.3sy/√2,1.1sz]; (x,nout) = surfpt_nearby(p,c); (xp && all([sx 0 0; 0 sy 0; 0 0 sz]*nout.≥-10τₐ₀))) for sx = (-1,1), sy = (-1,1), sz = (-1,1)]) # on rims
@test all([(p = [0.3sx,0,1.1sz]; (x,nout) = surfpt_nearby(p,c); (xp && all([sx 0 0; 0 0 sz]*nout.≥-10τₐ₀))) for sx = (-1,1), sz = (-1,1)]) # on rims
@test all([(p = [0,0.3sy,1.1sz]; (x,nout) = surfpt_nearby(p,c); (xp && all([0 sy 0; 0 0 sz]*nout.≥-10τₐ₀))) for sy = (-1,1), sz = (-1,1)]) # on rims
@test all([(p = [0.3sx/√2/2,0.3sy/√2/2,1.1sz]; surfpt_nearby([p[1],p[2],ρ*p[3]],c) (p,[0,0,sz])) for ρ = (one⁻⁻,1,one⁺⁺), sx = (-1,0,1), sy = (-1,0,1), sz = (-1,1)]) # around bases
@test all([(p = [0.3sx,0,1.1sz/2]; surfpt_nearby([ρ*p[1],p[2],p[3]],c) (p,[sx,0,0])) for ρ = (one⁻⁻,1,one⁺⁺), sx = (-1,1), sz = (-1,0,1)]) # around side
@test all([(p = [0,0.3sy,1.1sz/2]; surfpt_nearby([p[1],ρ*p[2],p[3]],c) (p,[0,sy,0])) for ρ = (one⁻⁻,1,one⁺⁺), sy = (-1,1), sz = (-1,0,1)]) # around side
Expand Down Expand Up @@ -42,9 +42,9 @@ end # @testset "Cylinder"
@test all([(p = 0.3(s1*ax1+s2*ax2)/√2+1.1s3*ax3; surfpt_nearby(1.1p,cr) (p, normalize(1.1p-p))) for s1 = (-1,1), s2 = (-1,1), s3 = (-1,1)]) # outside corners
@test all([(p = 0.3s1*ax1+1.1s3*ax3; surfpt_nearby(1.1p,cr) (p, normalize(1.1p-p))) for s1 = (-1,1), s3 = (-1,1)]) # outside corners
@test all([(p = 0.3s2*ax2+1.1s3*ax3; surfpt_nearby(1.1p,cr) (p, normalize(1.1p-p))) for s2 = (-1,1), s3 = (-1,1)]) # outside corners
@test all([(p = 0.3(s1*ax1+s2*ax2)/√2+1.1s3*ax3; (x,nout) = surfpt_nearby(p,cr); (xp && all([s1*ax1 s2*ax2 s3*ax3]'*nout.≥-10eps()) && norm(nout)1)) for s1 = (-1,1), s2 = (-1,1), s3 = (-1,1)]) # on rims
@test all([(p = 0.3s1*ax1+1.1s3*ax3; (x,nout) = surfpt_nearby(p,cr); (xp && all([s1*ax1 s3*ax3]'*nout.≥-10eps()) && norm(nout)1)) for s1 = (-1,1), s3 = (-1,1)]) # on rims
@test all([(p = 0.3s2*ax2+1.1s3*ax3; (x,nout) = surfpt_nearby(p,cr); (xp && all([s2*ax2 s3*ax3]'*nout.≥-10eps()) && norm(nout)1)) for s2 = (-1,1), s3 = (-1,1)]) # on rims
@test all([(p = 0.3(s1*ax1+s2*ax2)/√2+1.1s3*ax3; (x,nout) = surfpt_nearby(p,cr); (xp && all([s1*ax1 s2*ax2 s3*ax3]'*nout.≥-10τₐ₀) && norm(nout)1)) for s1 = (-1,1), s2 = (-1,1), s3 = (-1,1)]) # on rims
@test all([(p = 0.3s1*ax1+1.1s3*ax3; (x,nout) = surfpt_nearby(p,cr); (xp && all([s1*ax1 s3*ax3]'*nout.≥-10τₐ₀) && norm(nout)1)) for s1 = (-1,1), s3 = (-1,1)]) # on rims
@test all([(p = 0.3s2*ax2+1.1s3*ax3; (x,nout) = surfpt_nearby(p,cr); (xp && all([s2*ax2 s3*ax3]'*nout.≥-10τₐ₀) && norm(nout)1)) for s2 = (-1,1), s3 = (-1,1)]) # on rims
@test all([surfpt_nearby(0.3(s1*ax1+s2*ax2)/√2/2+ρ*1.1s3*ax3,cr) (0.3(s1*ax1+s2*ax2)/√2/2+1.1s3*ax3,s3*ax3) for ρ = (one⁻⁻,1,one⁺⁺), s1 = (-1,0,1), s2 = (-1,0,1), s3 = (-1,1)]) # around bases
@test all([surfpt_nearby*0.3s1*ax1+1.1s3*ax3/2,cr) (0.3s1*ax1+1.1s3*ax3/2, s1*ax1) for ρ = (one⁻⁻,1,one⁺⁺), s1 = (-1,1), s3 = (-1,0,1)]) # around side
@test all([surfpt_nearby*0.3s2*ax2+1.1s3*ax3/2,cr) (0.3s2*ax2+1.1s3*ax3/2, s2*ax2) for ρ = (one⁻⁻,1,one⁺⁺), s2 = (-1,1), s3 = (-1,0,1)]) # around side
Expand Down
5 changes: 2 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ using Random: MersenneTwister
using Statistics: mean
using Test

const rtol = Base.rtoldefault(Float)
const one⁻ = 1 - rtol # scale factor slightly less than 1
const one⁺ = 1 + rtol # scare factor slightly greater than 1
const one⁻ = 1 - τᵣ₀ # scale factor slightly less than 1
const one⁺ = 1 + τᵣ₀ # scare factor slightly greater than 1
const one⁻⁻, one⁺⁺ = 0.9, 1.1 # (scale factor less than 1, scale factor greater than 1)

Base.isapprox(a::Tuple, b::Tuple; kws...) = all(p -> isapprox(p...; kws...), zip(a,b))
Expand Down

0 comments on commit 42438fc

Please sign in to comment.