diff --git a/src/algorithms/nncluster.jl b/src/algorithms/nncluster.jl index 0a0c519..a52af29 100644 --- a/src/algorithms/nncluster.jl +++ b/src/algorithms/nncluster.jl @@ -2,7 +2,7 @@ NearestNeighborCluster <: NeutralLandscapeMaker NearestNeighborCluster(; p=0.5, n=:rook) - NearestNeighborCluster(p, n) + NearestNeighborCluster(p, [n=:rook]) Create a random cluster nearest-neighbour neutral landscape model with values ranging 0-1. `p` sets the density of original clusters, and `n` @@ -11,7 +11,7 @@ sets the neighborhood for clustering (see `?label` for neighborhood options) @kwdef struct NearestNeighborCluster <: NeutralLandscapeMaker p::Float64 = 0.5 n::Symbol = :rook - function NearestNeighborCluster(p::Float64, n::Symbol) + function NearestNeighborCluster(p::Float64, n::Symbol = :rook) @assert p > 0 @assert n ∈ (:rook, :queen, :diagonal) new(p,n) diff --git a/src/algorithms/nnelement.jl b/src/algorithms/nnelement.jl index 2c96b98..a5ba8cf 100644 --- a/src/algorithms/nnelement.jl +++ b/src/algorithms/nnelement.jl @@ -2,7 +2,7 @@ NearestNeighborElement <: NeutralLandscapeMaker NearestNeighborElement(; n=3, k=1) - NearestNeighborElement(n, k) + NearestNeighborElement(n, [k=1]) Assigns a value to each patch using a k-NN algorithmm with `n` initial clusters and `k` neighbors. The default is to use three cluster and a single neighbor. diff --git a/src/algorithms/perlinnoise.jl b/src/algorithms/perlinnoise.jl index 8af04f8..3265682 100644 --- a/src/algorithms/perlinnoise.jl +++ b/src/algorithms/perlinnoise.jl @@ -2,7 +2,7 @@ PerlinNoise <: NeutralLandscapeMaker PerlinNoise(; kw...) - PerlinNoise(periods, octaves, lacunarity, persistance, valley) + PerlinNoise(periods, [octaves=1, lacunarity=2, persistance=0.5, valley=:u]) Create a Perlin noise neutral landscape model with values ranging 0-1. @@ -13,7 +13,7 @@ Create a Perlin noise neutral landscape model with values ranging 0-1. - `octaves::Int=1`: the number of octaves that will form the Perlin noise. - `lacunarity::Int=2` : the rate at which the frequency of periods increases for each octive. -- `persistance::Real=0.5` : the rate at which the amplitude of periods decreases for each +- `persistance::Float64=0.5` : the rate at which the amplitude of periods decreases for each octive. - `valley::Symbol=`:u`: the kind of valley bottom that will be mimicked: `:u` produces u-shaped valleys, `:v` produces v-shaped valleys, and `:-` produces flat bottomed @@ -23,12 +23,15 @@ Note: This is a memory-intensive algorithm with some settings. Be careful using prime numbers for `period` when also using a large array size, high lacuarity and/or many octaves. Memory use scales with the lowest common multiple of `periods`. """ -@kwdef struct PerlinNoise{PT<:Real} <: NeutralLandscapeMaker +@kwdef struct PerlinNoise <: NeutralLandscapeMaker periods::Tuple{Int,Int} = (1, 1) octaves::Int = 1 lacunarity::Int = 2 - persistance::PT = 0.5 + persistance::Float64 = 0.5 valley::Symbol = :u + function PerlinNoise(periods, octaves=1, lacunarity=2, persistance=0.5, valley=:u) + new(periods, octaves, lacunarity, persistance, valley) + end end function _landscape!(A, alg::PerlinNoise) diff --git a/src/algorithms/rectangularcluster.jl b/src/algorithms/rectangularcluster.jl index a1443a6..f2b6ff6 100644 --- a/src/algorithms/rectangularcluster.jl +++ b/src/algorithms/rectangularcluster.jl @@ -2,7 +2,7 @@ RectangularCluster <: NeutralLandscapeMaker RectangularCluster(; minimum=2, maximum=4) - RectangularCluster(minimum, maximum) + RectangularCluster(minimum, [maximum=4]) Fills the landscape with rectangles containing a random value. The size of each rectangle/patch is between `minimum` and `maximum` (the two can be equal for a @@ -11,9 +11,9 @@ fixed size rectangle). @kwdef struct RectangularCluster <: NeutralLandscapeMaker minimum::Integer = 2 maximum::Integer = 4 - function RectangularCluster(x::T, y::T) where {T <: Integer} - @assert 0 < x <= y - new(x, y) + function RectangularCluster(minimum::T, maximum::T=4) where {T <: Integer} + @assert 0 < minimum <= maximum + new(minimum, maximum) end end diff --git a/src/algorithms/wavesurface.jl b/src/algorithms/wavesurface.jl index af43347..fa86d82 100644 --- a/src/algorithms/wavesurface.jl +++ b/src/algorithms/wavesurface.jl @@ -2,7 +2,7 @@ WaveSurface <: NeutralLandscapeMaker WaveSurface(; direction=360rand(), periods=1) - WaveSurface(direction, periods) + WaveSurface(direction, [periods=1]) Creates a sinusoidal landscape with a `direction` and a number of `periods`. If neither are specified, there will be a single period of random direction. @@ -10,9 +10,9 @@ neither are specified, there will be a single period of random direction. @kwdef struct WaveSurface <: NeutralLandscapeMaker direction::Float64 = 360rand() periods::Int64 = 1 - function WaveSurface(x::T, y::K) where {T <: Real, K <: Integer} - @assert y >= 1 - new(mod(x, 360.0), y) + function WaveSurface(direction::T, periods::K = 1) where {T <: Real, K <: Integer} + @assert periods >= 1 + new(mod(direction, 360.0), periods) end end diff --git a/test/rand.jl b/test/rand.jl index 5fa675a..2b08295 100644 --- a/test/rand.jl +++ b/test/rand.jl @@ -2,14 +2,39 @@ using NeutralLandscapes, Test algorithms = ( DiamondSquare(), + DiamondSquare(; H=0.2), + DiamondSquare(0.4), + DiscreteVoronoi(), + DiscreteVoronoi(; n=2), + DiscreteVoronoi(3), + DistanceGradient(), + DistanceGradient(; sources=[2]), + DistanceGradient([1, 2]), EdgeGradient(), + EdgeGradient(; direction=120.0), + EdgeGradient(90.0), MidpointDisplacement(), + MidpointDisplacement(;), NearestNeighborElement(), + NearestNeighborElement(; k=1), + NearestNeighborElement(2), + NearestNeighborCluster(), + # NearestNeighborCluster(; n=:queen), + NearestNeighborCluster(; n=:diagonal), + NearestNeighborCluster(0.2, :diagonal), NoGradient(), PerlinNoise(), + PerlinNoise(; octaves=3, lacunarity=3, persistance=0.3), + PerlinNoise((1, 2), 3, 2, 0.2), PlanarGradient(), + PlanarGradient(; direction=120.0), + PlanarGradient(90), RectangularCluster(), + RectangularCluster(; maximum=5), + RectangularCluster(2), WaveSurface(), + WaveSurface(90.0), + WaveSurface(; periods=2), ) sizes = (50, 200), (100, 100), (301, 87)