-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ Implementing Fibonacci sampling method for disk, ball and sphere. * 🧪 Adding tests for Fibonacci sampling. * 🚚 Refactoring Fibonnaci Sampling. Added box method, and capacity to alter the ratio number. Also, sampling now preserves the lentype and numtype for the underlying geometry. * 🐛 Fixed ustrip warning. * 🧪 Updated tests for fibonacci sampling. * 📝 Docs for fibonacci sampling. * 📝 Moving Fibonacci Sampling to ContinuousSampling * 🐛 Correcting allocations and fibonacci constructor. * 🚚 Small formatting correction. * 🚚 Refactor using the geom parametrization * 🐛 removing comments and adding distortion for sphere. * 🚚 Adding Ball{🌐} and Sphere{𝔼{3}} * 🧪 Added tests for ArgumentError cases. * 🐛 Fixed formatting * Update src/sampling/fibonacci.jl * Refactoring * Adding license. * Update src/sampling/fibonacci.jl * 🧪 changing test for disk fibonacci sampling. * Refactor tests * Fix T in test --------- Co-authored-by: Júlio Hoffimann <[email protected]>
- Loading branch information
1 parent
3dac1fe
commit 77b2384
Showing
5 changed files
with
113 additions
and
1 deletion.
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
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,50 @@ | ||
# ------------------------------------------------------------------ | ||
# Licensed under the MIT License. See LICENSE in the project root. | ||
# ------------------------------------------------------------------ | ||
|
||
""" | ||
FibonacciSampling(n, ϕ = (1 + √5)/2) | ||
Generate `n` Fibonacci points with parameter `ϕ`. | ||
The golden ratio is used as the default value of `ϕ`, | ||
but other irrational numbers can be used. | ||
See <https://observablehq.com/@meetamit/fibonacci-lattices> | ||
and <https://www.johndcook.com/blog/2023/08/12/fibonacci-lattice>. | ||
""" | ||
struct FibonacciSampling{T<:Real} <: ContinuousSamplingMethod | ||
n::Int | ||
ϕ::T | ||
|
||
function FibonacciSampling(n::Int, ϕ::T) where {T<:Real} | ||
if n ≤ 0 | ||
throw(ArgumentError("Size must be positive")) | ||
end | ||
new{T}(n, ϕ) | ||
end | ||
end | ||
|
||
FibonacciSampling(n::Int) = FibonacciSampling(n, (1 + √5) / 2) | ||
|
||
function sample(geom::Geometry, method::FibonacciSampling) | ||
if paramdim(geom) != 2 | ||
throw(ArgumentError("Fibonacci sampling only defined for 2D geometries")) | ||
end | ||
|
||
fib = _fibmap(geom) | ||
|
||
function point(i) | ||
u = mod(i / method.ϕ, 1) | ||
v = i / (method.n - 1) | ||
geom(fib(u, v)...) | ||
end | ||
|
||
(point(i) for i in 0:(method.n - 1)) | ||
end | ||
|
||
_fibmap(g) = (u, v) -> (u, v) | ||
_fibmap(d::Disk) = (u, v) -> (√u, v) | ||
_fibmap(b::Ball{𝔼{2}}) = (u, v) -> (√u, v) | ||
_fibmap(b::Ball{🌐}) = (u, v) -> (√u, v) | ||
_fibmap(s::Sphere{𝔼{3}}) = (u, v) -> (acos(1 - 2v) / π, u) |
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