Skip to content

Commit 77c7431

Browse files
committed
convert the manually-written docpages into doccomments and DocC curations
1 parent 14eb453 commit 77c7431

18 files changed

+295
-425
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.build
2+
/.build.ssgc
23
/.vscode
34
/Packages
45
.swiftpm

Sources/Noise/cell.swift

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ extension _CellNoise2D
166166
}
167167
}
168168

169+
/// A type of two-dimensional cellular noise (sometimes called
170+
/// [Worley noise](https://en.wikipedia.org/wiki/Worley_noise), or Voronoi noise), suitable for
171+
/// texturing two-dimensional planes.
172+
///
173+
/// ![preview](png/banner_cell2d.png)
174+
///
175+
/// Unlike many other cell noise implementations, *Noise*’s implementation samples all relevant
176+
/// generating-points, preventing artifacts or discontinuities from ever appearing in the noise.
177+
/// Accordingly, *Noise*’s implementation is heavily optimized to prevent the additional edge
178+
/// cases from impacting the performance of the cell noise.
179+
///
180+
/// Cell noise has a three-dimensional version, ``CellNoise3D``.
169181
public
170182
struct CellNoise2D:_CellNoise2D, HashedNoise
171183
{
@@ -180,6 +192,14 @@ struct CellNoise2D:_CellNoise2D, HashedNoise
180192
self.permutation_table = permutation_table
181193
}
182194

195+
/// Creates an instance with the given `amplitude`, `frequency`, and random `seed` values.
196+
/// Creating an instance generates a new pseudo-random permutation table for that instance,
197+
/// and a new instance does not need to be regenerated to sample the same procedural noise
198+
/// field.
199+
///
200+
/// The given amplitude is adjusted internally to produce output *exactly* within the range
201+
/// of `0 ... amplitude`. However, in practice the cell noise rarely reaches the maximum
202+
/// threshold, as it is often useful to inflate the amplitude to get the desired appearance.
183203
public
184204
init(amplitude:Double, frequency:Double, seed:Int = 0)
185205
{
@@ -188,25 +208,34 @@ struct CellNoise2D:_CellNoise2D, HashedNoise
188208
self.permutation_table = PermutationTable(seed: seed)
189209
}
190210

211+
/// Returns the index numbers of the closest feature point to the given coordinate, and the
212+
/// squared distance from the given coordinate to the feature point. These index numbers can
213+
/// be fed to a color hashing function to produce a
214+
/// [Voronoi diagram](https://en.wikipedia.org/wiki/Voronoi_diagram).
191215
public
192216
func closest_point(_ x:Double, _ y:Double) -> (point:(Int, Int), r2:Double)
193217
{
194218
return self._closest_point(x, y)
195219
}
196220

221+
/// Evaluates the cell noise field at the given coordinates.
197222
public
198223
func evaluate(_ x:Double, _ y:Double) -> Double
199224
{
200225
let (_, r2):((Int, Int), Double) = self.closest_point(x, y)
201226
return self.amplitude * r2
202227
}
203228

229+
/// Evaluates the cell noise field at the given coordinates. The third coordinate is
230+
/// ignored.
204231
public
205232
func evaluate(_ x:Double, _ y:Double, _:Double) -> Double
206233
{
207234
return self.evaluate(x, y)
208235
}
209236

237+
/// Evaluates the cell noise field at the given coordinates. The third and fourth
238+
/// coordinates are ignored.
210239
public
211240
func evaluate(_ x:Double, _ y:Double, _:Double, _:Double) -> Double
212241
{
@@ -518,6 +547,26 @@ extension _CellNoise3D
518547
}
519548
}
520549

550+
/// A type of three-dimensional cellular noise (sometimes called
551+
/// [Worley noise](https://en.wikipedia.org/wiki/Worley_noise), or Voronoi noise), suitable for
552+
/// texturing arbitrary three-dimensional objects.
553+
///
554+
/// ![preview](png/banner_cell3d.png)
555+
///
556+
/// Unlike many other cell noise implementations, *Noise*’s implementation samples all relevant
557+
/// generating-points, preventing artifacts or discontinuities from ever appearing in the noise.
558+
/// Accordingly, *Noise*’s implementation is heavily optimized to prevent the additional edge
559+
/// cases from impacting the performance of the cell noise.
560+
///
561+
/// Three dimensional cell noise is approximately three to four times slower than its
562+
/// [two-dimensional version](doc:CellNoise2D), but has a vastly superior visual appearance,
563+
/// even when sampled in two dimensions.
564+
///
565+
/// `CellNoise3D` is analogous to
566+
/// [Blender Voronoi noise](https://docs.blender.org/manual/en/dev/render/cycles/nodes/types/textures/voronoi.html),
567+
/// with the *Distance Squared* metric. The *Scale* of Blender Voronoi noise is identical to the
568+
/// ``frequency`` of `CellNoise3D`; its range is approximately `0 ... 10/3` in `CellNoise3D`
569+
/// units.
521570
public
522571
struct CellNoise3D:_CellNoise3D, HashedNoise
523572
{
@@ -532,6 +581,14 @@ struct CellNoise3D:_CellNoise3D, HashedNoise
532581
self.permutation_table = permutation_table
533582
}
534583

584+
/// Creates an instance with the given `amplitude`, `frequency`, and random `seed` values.
585+
/// Creating an instance generates a new pseudo-random permutation table for that instance,
586+
/// and a new instance does not need to be regenerated to sample the same procedural noise
587+
/// field.
588+
///
589+
/// The given amplitude is adjusted internally to produce output *exactly* within the range
590+
/// of `0 ... amplitude`. However, in practice the cell noise rarely reaches the maximum
591+
/// threshold, as it is often useful to inflate the amplitude to get the desired appearance.
535592
public
536593
init(amplitude:Double, frequency:Double, seed:Int = 0)
537594
{
@@ -540,25 +597,34 @@ struct CellNoise3D:_CellNoise3D, HashedNoise
540597
self.permutation_table = PermutationTable(seed: seed)
541598
}
542599

600+
/// Returns the index numbers of the closest feature point to the given coordinate, and the
601+
/// squared distance from the given coordinate to the feature point. These index numbers can
602+
/// be fed to a color hashing function to produce a
603+
/// [Voronoi diagram](https://en.wikipedia.org/wiki/Voronoi_diagram).
543604
public
544605
func closest_point(_ x:Double, _ y:Double, _ z:Double) -> (point:(Int, Int, Int), r2:Double)
545606
{
546607
return self._closest_point(x, y, z)
547608
}
548609

610+
/// Evaluates the cell noise field at the given `x, y` coordinates, supplying `0` for the
611+
/// missing `z` coordinate.
549612
public
550613
func evaluate(_ x:Double, _ y:Double) -> Double
551614
{
552615
return self.evaluate(x, y, 0)
553616
}
554617

618+
/// Evaluates the cell noise field at the given coordinates.
555619
public
556620
func evaluate(_ x:Double, _ y:Double, _ z:Double) -> Double
557621
{
558622
let (_, r2):((Int, Int, Int), Double) = self.closest_point(x, y, z)
559623
return self.amplitude * r2
560624
}
561625

626+
/// Evaluates the cell noise field at the given coordinates. The fourth coordinate is
627+
/// ignored.
562628
public
563629
func evaluate(_ x:Double, _ y:Double, _ z:Double, _:Double) -> Double
564630
{

Sources/Noise/compounds.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/// A generic [fractal brownian motion](https://thebookofshaders.com/13/) noise generator,
2+
/// capable of overlaying multiple instances of procedural ``Noise`` at increasing frequencies.
3+
///
4+
/// ![preview](png/banner_FBM.png)
15
public
26
struct FBM<Source>:Noise where Source:Noise
37
{
@@ -34,6 +38,12 @@ struct FBM<Source>:Noise where Source:Noise
3438
self.generators = []
3539
}
3640

41+
/// Creates an instance with the given number of `octaves` of noise. The given `amplitude`
42+
/// is the amplitude of the first octave of noise, and is multiplied by `persistence` for
43+
/// each successive octave. The given `frequency` is the frequency of the first octave of
44+
/// noise, and is multiplied by the `lacunarity` for each successive octave. The `seed`
45+
/// value is passed through to the first octave of noise, and is incremented for each
46+
/// successive octave.
3747
@available(*, unavailable, message: "use init(_:octaves:persistence:lacunarity:) instead")
3848
public
3949
init(amplitude:Double, frequency:Double, octaves:Int, persistence:Double = 0.75, lacunarity:Double = 2, seed:Int = 0)

Sources/Noise/disk.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/// A point sampler capable of producing uniform and roughly-evenly spaced pseudo-random point
2+
/// distributions in the plane. Disk sampling is sometimes referred to as
3+
/// [Poisson sampling](https://en.wikipedia.org/wiki/Supersampling#Poisson_disc).
4+
///
5+
/// ![preview](png/banner_disk2d.png)
6+
///
7+
/// Disk samples are not a noise field — its generation is inherently sequential, as opposed to
8+
/// most procedural noise fields which are embarrassingly parallel. Thus, disk samples have no
9+
/// concept of *evaluation*; the entire sample set must be generated as a whole.
10+
///
11+
/// Disk samples have an internal state, which is advanced every time the point generator runs.
12+
/// In many ways, disk samples have more in common with pseudo-random number generators than
13+
/// they do with procedural noise fields.
114
public
215
struct DiskSampler2D
316
{
@@ -17,6 +30,9 @@ struct DiskSampler2D
1730
private static
1831
let candidate_table_bitmask:Int = 0b1111111111 // 1023
1932

33+
/// Creates an instance with the given fixed random `seed`. This process calculates a random
34+
/// table used internally in the sample generation step. The same instance can be reused to
35+
/// generate multiple, different point distributions.
2036
public
2137
init(seed:Int = 0)
2238
{
@@ -46,6 +62,13 @@ struct DiskSampler2D
4662
self.candidate_ring = candidate_ring
4763
}
4864

65+
/// Generates a set of sample points that are spaced no less than `radius` apart over a
66+
/// region sized `width` by `height` . Up to `k` candidate points will be used to generate
67+
/// each sample point; higher values of `k` yield more compact point distributions, but take
68+
/// longer to run. The `seed` point specifies the first point that is added to the
69+
/// distribution, and influences where subsequent sample points are added. This `seed` is
70+
/// orthogonal to the `seed` supplied in the initializer. If `seed` is left `nil`, the seed
71+
/// point is placed at the center of the region.
4972
public mutating
5073
func generate(radius:Double, width:Int, height:Int, k:Int = 32, seed:(Double, Double)? = nil) -> [(Double, Double)]
5174
{

Sources/Noise/docs.docc/README.md

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,30 @@
1-
# ``Noise``
1+
# ``/Noise``
22

33
Generate and combine commonly used procedural noise patterns and distributions.
44

5-
*This wiki documents features present in* [Noise *1.0.0*](https://github.com/tayloraswift/noise/releases/tag/1.0.0). *Many new features are currently being added to* [`master`](https://github.com/tayloraswift/noise/tree/master) *for* Noise *2.0.0, and several types and methods will be deprecated or removed for 2.0.0, including* [`SimplexNoise2D`](struct-SimplexNoise2D.md).
6-
***
7-
8-
## Symbols
5+
## Topics
96

107
### Protocols
118

12-
#### `protocol` [`Noise`](protocol-Noise.md)
13-
> A procedural noise generator.
14-
15-
### Structures
16-
17-
#### `struct` [`SimplexNoise2D`](struct-SimplexNoise2D.md)
18-
> A type of two-dimensional gradient noise (sometimes called [Perlin noise](https://en.wikipedia.org/wiki/Perlin_noise)), suitable for texturing two-dimensional planes. Simplex noise is supported in the library mainly because it has historical significance; it has since been superseded by the less popular, but more powerful and more efficient super-simplex noise.
19-
20-
#### `struct` [`SuperSimplexNoise2D`](struct-SuperSimplexNoise2D.md)
21-
> A type of two-dimensional gradient noise (sometimes called [Perlin noise](https://en.wikipedia.org/wiki/Perlin_noise)), suitable for texturing two-dimensional planes. Super-simplex noise is an improved version of simplex noise which runs faster and scales better to higher dimensions.
9+
- ``Noise``
2210

11+
### Noise generators
2312

24-
#### `struct` [`SuperSimplexNoise3D`](struct-SuperSimplexNoise3D.md)
25-
> A type of three-dimensional gradient noise (sometimes called [Perlin noise](https://en.wikipedia.org/wiki/Perlin_noise)), suitable for texturing arbitrary three-dimensional objects.
13+
- ``SimplexNoise2D``
14+
- ``GradientNoise2D``
15+
- ``GradientNoise3D``
16+
- ``CellNoise2D``
17+
- ``CellNoise3D``
2618

27-
#### `struct` [`CellNoise2D`](struct-CellNoise2D.md)
28-
> A type of two-dimensional cellular noise (sometimes called [Worley noise](https://en.wikipedia.org/wiki/Worley_noise), or Voronoi noise), suitable for texturing two-dimensional planes.
19+
### Noise composition
2920

30-
#### `struct` [`CellNoise3D`](struct-CellNoise3D.md)
31-
> A type of three-dimensional cellular noise (sometimes called [Worley noise](https://en.wikipedia.org/wiki/Worley_noise), or Voronoi noise), suitable for texturing arbitrary three-dimensional objects.
21+
- ``FBM``
3222

33-
#### `struct` [`DiskSampler2D`](struct-DiskSampler2D.md)
34-
> A point sampler capable of producing uniform and roughly-evenly spaced pseudo-random point distributions in the plane. Disk sampling is sometimes referred to as [Poisson sampling](https://en.wikipedia.org/wiki/Supersampling#Poisson_disc).
23+
### Pattern generators
3524

36-
#### `struct` [`FBM`](struct-FBM.md)
37-
> A generic [fractal brownian motion](https://thebookofshaders.com/13/) noise generator, capable of overlaying multiple instances of procedural [noise](protocol-Noise.md) at increasing frequencies.
25+
- ``DiskSampler2D``
3826

39-
#### `struct` [`PermutationTable`](struct-PermutationTable.md)
40-
> An 8-bit permutation table useful for generating pseudo-random hash values.
27+
### Psuedo-random number generators
4128

42-
#### `struct` [`RandomXorshift`](struct-RandomXorshift.md)
43-
> A cryptographically unsecure 128-bit [Xorshift](https://en.wikipedia.org/wiki/Xorshift) pseudo-random number generator.
29+
- ``PermutationTable``
30+
- ``RandomXorshift``

Sources/Noise/docs.docc/protocol-Noise.md

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)