Skip to content

Commit

Permalink
fix initnoise() (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Sep 15, 2019
1 parent 716977f commit 5520bfd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@

### Changed

- initnoise() is correctly seedable
- center3pts() changed

### Removed

- seednoise()

### Deprecated


## [v1.6.0] - 19 August 2019

### Added
Expand Down
4 changes: 2 additions & 2 deletions src/curves.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ function center3pts(a::Point, b::Point, c::Point)
# do the lines intersect?
crossp = crossproduct(perpAB, perpBC)
if isapprox(crossp, 0)
@info("no circle passes through all three points")
@info("no circle passes through the points $a $b $c")
return Point(0, 0), 0
end
centerX = ((midAB.y * perpAB.x * perpBC.x) +
(midBC.x * perpAB.x * perpBC.y) -
(midAB.x * perpAB.y * perpBC.x) -
(midBC.y * perpAB.x * perpBC.x)) / crossp
centerY = ((centerX - midAB.x) * perpAB.y / perpAB.x) + midAB.y
radius = hypot(centerX - a.x, centerY - a.y)
radius = hypot(abs(centerX - a.x), abs(centerY - a.y))
return Point(centerX, centerY), radius
end

Expand Down
2 changes: 0 additions & 2 deletions src/deprecations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ using Base: @deprecate

@deprecate intersection(pt1::Point, pt2::Point, pt3::Point, pt4::Point) intersectionlines(pt1::Point, pt2::Point, pt3::Point, pt4::Point)

@deprecate seednoise(a::Array{Int64}) seedpatentednoise()

@deprecate polytriangulate!(pt) polytriangulate(pt)
48 changes: 31 additions & 17 deletions src/noise.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@

using Random

"""
seednoise(seed::T=42) where T <: Integer
Change the initial seed value for noise generation.
```
seednoise()
seednoise(12)
```
"""
function seednoise(seed::T=42) where T <: Integer
initsimplexnoise(seed)
end

"""
noise(x) ; detail = 1, persistence = 1.0) # 1D
noise(x, y) ; detail = 1, persistence = 1.0) # 2D
Expand Down Expand Up @@ -88,7 +74,7 @@ function _octaves(coords::Array{T, 1} where T <: Real;
return total / maxval
end

# Most of this file is the original OpenSimplexNoise code.
# Most of this code is the original OpenSimplexNoise code.
# I converted it to Julia but I don't understand it all... [cormullion]

# OpenSimplex Noise
Expand Down Expand Up @@ -203,11 +189,39 @@ const perm = Array{Int8}(undef, 256)
const permGradIndex3D = Array{Int8}(undef, 256)

"""
initnoise(seed::Int=42)
initnoise(seed::Int)
initnoise()
Initialize the noise generation code.
```
julia> initnoise(); noise(1)
0.7453148982810598
julia> initnoise(); noise(1)
0.7027617067916981
```
If you provide an integer seed, it will be used
to seed `Random.seed!()`` when the noise code is initialized:
```
julia> initnoise(41); noise(1) # yesterday
0.7134000046640385
julia> initnoise(41); noise(1) # today
0.7134000046640385
```
"""
function initnoise(seed::Int=42)
function initnoise(seed)
Random.seed!(seed)
for i in 1:256
perm[i] = rand(Int8)
permGradIndex3D[i] = rand(Int8)
end
end

function initnoise()
for i in 1:256
perm[i] = rand(Int8)
permGradIndex3D[i] = rand(Int8)
Expand Down

0 comments on commit 5520bfd

Please sign in to comment.