# Rendered images land here.
out := "images"

# List the recipes.
default:
    @just --list --unsorted

# Render one PNG into images/, e.g. `just image relief --seed 7 --cells 12`.
image mode="relief" *flags:
    cargo run --quiet --release --example image --features png -- \
        --mode {{mode}} --out {{out}}/{{mode}}.png {{flags}}

# 4K relief wallpaper, e.g. `just wallpaper 1 --palette azure`. 3841x2161.
wallpaper seed="1" *flags:
    cargo run --quiet --release --example image --features png -- \
        --mode relief --cells 9,16 --detail 240 --seed {{seed}} \
        --out {{out}}/wallpaper-4k-{{seed}}.png {{flags}}

# The same 4K picture square instead, 3841x3841.
wallpaper-square seed="1" *flags:
    cargo run --quiet --release --example image --features png -- \
        --mode relief --cells 8 --detail 480 --seed {{seed}} \
        --out {{out}}/wallpaper-4k-square-{{seed}}.png {{flags}}

# A lit sphere out of a 4D field, e.g. `just globe 3 --palette crimson`.
globe seed="1" *flags:
    cargo run --quiet --release --example image --features png -- \
        --mode globe --size 1440 --seed {{seed}} \
        --out {{out}}/globe-{{seed}}.png {{flags}}

# A coat of hair combed by the field, e.g. `just hair 3 --palette crimson`.
hair seed="1" *flags:
    cargo run --quiet --release --example image --features png -- \
        --mode hair --size 1440 --count 90000 --seed {{seed}} \
        --out {{out}}/hair-{{seed}}.png {{flags}}

# The same coat coloured by the relief of the field, e.g.
# `just hair-color 7 --palette azure`. The strands are the grey coat; the
# colour under them is the glossy height map.
hair-color seed="1" *flags:
    cargo run --quiet --release --example image --features png -- \
        --mode hair --tint --size 1440 --count 90000 --seed {{seed}} \
        --out {{out}}/hair-color-{{seed}}.png {{flags}}

# The same coat at 4K, 3841x2161. Strands are counted against the pixels, so
# this needs proportionally more of them to stay as dense.
hair-wallpaper seed="1" *flags:
    cargo run --quiet --release --example image --features png -- \
        --mode hair --cells 5,9 --size 3841x2161 --count 360000 --seed {{seed}} \
        --out {{out}}/hair-4k-{{seed}}.png {{flags}}

# The glossy liquid look at screen size, one file per seed.
liquid seed="1" *flags:
    cargo run --quiet --release --example image --features png -- \
        --mode relief --cells 9,16 --seed {{seed}} \
        --out {{out}}/liquid-{{seed}}.png {{flags}}

# Every mode at once, for comparing them side by side.
gallery:
    cargo run --quiet --release --example render --features png -- {{out}}

# Every mode and option the renderer takes.
options:
    @cargo run --quiet --release --example image --features png -- --help

# Open a rendered image (macOS).
show file:
    open {{file}}

# Run the tests, GPU and PNG paths included.
test:
    cargo test --features "png gpu"

# Add the slow multi-dispatch GPU test.
test-all:
    cargo test --release --features "png gpu" -- --include-ignored

# Lint every feature combination, warnings included.
lint:
    cargo clippy --all-targets -- -D warnings
    cargo clippy --all-targets --features png -- -D warnings
    cargo clippy --all-targets --features gpu -- -D warnings
    cargo clippy --all-targets --features "png gpu" -- -D warnings
    cargo clippy --all-targets --features python -- -D warnings

# Format the code.
fmt:
    cargo fmt

# Local interpreter maturin installs into. `python` on PATH is often another
# one, which is why `python examples/noise.py` fails until this venv is active.
venv := ".venv"
py := venv / "bin/python"

# Python extension, for `import perlin_noise`. Creates `.venv` if needed.
python:
    #!/usr/bin/env bash
    set -euo pipefail
    if [[ ! -x {{py}} ]]; then
        python3 -m venv {{venv}}
        {{py}} -m pip install -q maturin
    fi
    {{py}} -m maturin develop --release
    echo "Installed into {{py}}."
    echo "Run examples with:  just python-noise"
    echo "Or:  source {{venv}}/bin/activate   then   python examples/noise.py"

# The Python tests. Run `just python` first so the module is importable.
test-python:
    {{py}} -c "import perlin_noise, inspect; assert inspect.getdoc(perlin_noise.Instance)"
    {{py}} -m pytest tests/test_perlin_noise.py -q

# Sample a field from Python. Needs `just python` first.
python-noise:
    {{py}} examples/noise.py

# One PNG per rendering mode, into images/. Twin of `just gallery`.
python-render:
    {{py}} examples/render.py {{out}}

# Hair helper, Hair() knobs, and Renderer.hair.
python-hair:
    {{py}} examples/hair.py {{out}}

# What to run before committing.
check: fmt lint test

# Drop build output and rendered images.
clean:
    cargo clean
    rm -rf {{out}}
