Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ RectangularCluster #12

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/src/gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ heatmap(rand(EdgeGradient(), (45, 45)))

```@example gallery
heatmap(rand(WaveSurface(), (45, 45)))
```

## Rectangular cluster

```@example gallery
heatmap(rand(RectangularCluster(), (45, 45)))
```
1 change: 1 addition & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ NoGradient
PlanarGradient
EdgeGradient
WaveSurface
RectangularCluster
```

## Landscape generating function
Expand Down
3 changes: 3 additions & 0 deletions src/NeutralLandscapes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ export EdgeGradient
include(joinpath("algorithms", "wavesurface.jl"))
export WaveSurface

include(joinpath("algorithms", "rectangularcluster.jl"))
export RectangularCluster

end # module
28 changes: 28 additions & 0 deletions src/algorithms/rectangularcluster.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
RectangularCluster

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
fixed size rectangle).
"""
struct RectangularCluster <: NeutralLandscapeMaker
minimum::Integer
maximum::Integer
function RectangularCluster(x::T, y::T) where {T <: Integer}
@assert 0 < x <= y
new(x, y)
end
end

RectangularCluster() = RectangularCluster(2,4)

function _landscape!(mat, alg::RectangularCluster)
mat .= -1.0
while minimum(mat) == -1.0
width, height = rand(alg.minimum:alg.maximum, 2)
row = rand(1:(size(mat,1)-(width-1)))
col = rand(1:(size(mat,2)-(height-1)))
mat[row:(row+(width-1)) , col:(col+(height-1))] .= rand()
end
return mat
end