-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename Sphere to Ball (sphere is surface; ball is volume)
- Loading branch information
Showing
9 changed files
with
43 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export Ball | ||
|
||
mutable struct Ball{N,N²,D} <: Shape{N,N²,D} | ||
c::SVector{N,Float64} # center of ball | ||
r::Float64 # radius | ||
data::D # auxiliary data | ||
Ball{N,N²,D}(c,r,data) where {N,N²,D} = new(c,r,data) # suppress default outer constructor | ||
end | ||
|
||
Ball(c::SVector{N,<:Real}, r::Real, data::D=nothing) where {N,D} = Ball{N,N*N,D}(c, r, data) | ||
Ball(c::AbstractVector{<:Real}, r::Real, data=nothing) = (N = length(c); Ball(SVector{N}(c), r, data)) | ||
|
||
Base.:(==)(s1::Ball, s2::Ball) = s1.c==s2.c && s1.r==s2.r && s1.data==s2.data | ||
Base.isapprox(s1::Ball, s2::Ball) = s1.c≈s2.c && s1.r≈s2.r && s1.data==s2.data | ||
Base.hash(s::Ball, h::UInt) = hash(s.c, hash(s.r, hash(s.data, hash(:Ball, h)))) | ||
|
||
Base.in(x::SVector{N,<:Real}, s::Ball{N}) where {N} = sum(abs2, x - s.c) ≤ s.r^2 | ||
|
||
function surfpt_nearby(x::SVector{N,<:Real}, s::Ball{N}) where {N} | ||
nout = x==s.c ? SVector(ntuple(k -> k==1 ? 1.0 : 0.0, Val(N))) : # nout = e₁ for x == s.c | ||
normalize(x-s.c) | ||
return s.c+s.r*nout, nout | ||
end | ||
|
||
translate(s::Ball{N,N²,D}, ∆::SVector{N,<:Real}) where {N,N²,D} = Ball{N,N²,D}(s.c+∆, s.r, s.data) | ||
|
||
bounds(s::Ball) = (s.c.-s.r, s.c.+s.r) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
@testset "KDTree" begin | ||
s = [Sphere([i,0], 1) for i in 2:4] | ||
s0 = Sphere([0,0], 1) | ||
s = [Ball([i,0], 1) for i in 2:4] | ||
s0 = Ball([0,0], 1) | ||
s = [s0, s0, s0, s0, s...] | ||
@test_nowarn KDTree(s) # must not generate StackOverflowError | ||
|
||
s = Shape{2,4}[Sphere([i,0], 1, i) for i in 0:20] | ||
s = Shape{2,4}[Ball([i,0], 1, i) for i in 0:20] | ||
kd = KDTree(s) | ||
@test GeometryPrimitives.depth(kd) == 3 | ||
@test findfirst([10.1,0], kd).data == 10 | ||
@test findfirst([10.1,1], kd) == nothing | ||
@test checktree(kd, s) | ||
|
||
s = Shape{3,9}[Sphere(SVector(randn(rng),randn(rng),randn(rng)), 0.01) for i=1:100] | ||
s = Shape{3,9}[Ball(SVector(randn(rng),randn(rng),randn(rng)), 0.01) for i=1:100] | ||
@test checktree(KDTree(s), s) | ||
s = Shape{3,9}[Sphere(SVector(randn(rng),randn(rng),randn(rng)), 0.1) for i=1:100] | ||
s = Shape{3,9}[Ball(SVector(randn(rng),randn(rng),randn(rng)), 0.1) for i=1:100] | ||
@test checktree(KDTree(s), s) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters