[orx-hash-grid] Update README.md

This commit is contained in:
Edwin Jakobs
2023-01-25 09:44:06 +01:00
parent 6a9d51c8db
commit f44084b00f

View File

@@ -4,6 +4,8 @@ A 2D space partitioning for points.
## Usage ## Usage
`orx-hash-grid` provides the classes `HashGrid` and `Cell`, in most cases only `HashGrid` is used.
Create a hash grid for a given radius. Create a hash grid for a given radius.
```kotlin ```kotlin
val grid = HashGrid(radius) val grid = HashGrid(radius)
@@ -27,6 +29,42 @@ for (point in grid.points()) {
// do something with point // do something with point
} }
``` ```
## Extensions to standard library
`orx-hash-grid` provides short-hand extension functions to `List<Vector2>`
<hr>
```kotlin
fun List<Vector2>.filter(radius: Double) : List<Vector2>
```
filters the points in the list such that only points with an inter-distance of `radius` remain.
```kotlin
val points = (0 until 10_000).map { drawer.bounds.uniform() }
val filtered = points.filter(20.0)
```
<hr>
```kotlin
fun List<Vector2>.hashGrid(radius: Double) : HashGrid
```
constructs a (mutable) `HashGrid` containing all points in the list.
```kotlin
val points = (0 until 10_000).map { drawer.bounds.uniform() }
val hashGrid = points.hashGrid(20.0)
```
<hr>
## References
* `orx-noise` uses `HashGrid` to generate Poisson distributed points. [Link](https://github.com/openrndr/orx/blob/master/orx-noise/src/commonMain/kotlin/PoissonDisk.kt)
<!-- __demos__ --> <!-- __demos__ -->
## Demos ## Demos
### DemoFilter01 ### DemoFilter01