Skip to content
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
2 changes: 1 addition & 1 deletion pnoise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def _get_version() -> str:
try:
from importlib.metadata import version
except ModuleNotFoundError:
from importlib_metadata import version
from importlib_metadata import version # type: ignore

return version(__name__)

Expand Down
11 changes: 7 additions & 4 deletions pnoise/pnoise.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""pnoise library"""
"""
Ported from the Processing project - http://processing.org
Copyright (c) 2021 Antoine Beyeler
Copyright (c) 2021-2022 Antoine Beyeler
Copyright (c) 2012-15 The Processing Foundation
Copyright (c) 2004-12 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
Expand Down Expand Up @@ -51,7 +51,7 @@ def perlin(
y: Union[Number, Sequence[Number]],
z: Union[Number, Sequence[Number]],
grid_mode: bool = True,
) -> np.ndarray:
) -> Union[np.ndarray, float]:
"""Compute perlin noise for a range of values.

Each of the x, y, and z argument may be 1D sequence of float. Perlin noise will be
Expand All @@ -65,7 +65,10 @@ def perlin(
if not grid_mode or single:
grid = np.array([x, y, z], dtype=float)
else:
grid = np.array(np.meshgrid(x, y, z, indexing="ij", copy=False), dtype=float)
grid = np.array(
np.meshgrid(np.array(x), np.array(y), np.array(z), indexing="ij", copy=False),
dtype=float,
)

np.abs(grid, out=grid)
grid_i = grid.astype(int)
Expand Down Expand Up @@ -109,7 +112,7 @@ def perlin(
grid[idx] -= 1.0

if single:
return np.asscalar(r)
return float(r.item())
elif not grid_mode:
return r
else:
Expand Down