Skip to content

Commit

Permalink
Merge pull request #21 from heckj/doc-edits
Browse files Browse the repository at this point in the history
Doc edits
  • Loading branch information
li3zhen1 authored Oct 31, 2023
2 parents e8fe811 + 54bee9b commit bbcce93
Show file tree
Hide file tree
Showing 33 changed files with 342 additions and 80 deletions.
1 change: 1 addition & 0 deletions Sources/ForceSimulation/ForceLike.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


/// A protocol that represents a force.
///
/// A force takes a simulation state and modifies its node positions and velocities.
public protocol ForceLike {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

## Overview

You can simply create 2D or 3D simulations by using Simulation2D or Simulation3D:
Create 2D or 3D simulations by using Simulation2D or Simulation3D.
For example, the following code creates a 2D force simulation.

```swift

Expand All @@ -30,4 +31,4 @@ for i in 0..<120 {

```

See [Example](https://github.com/li3zhen1/Grape/tree/main/Examples/ForceDirectedGraphExample) for more details.
See [Examples](https://github.com/li3zhen1/Grape/tree/main/Examples) for example Xcode projects.
56 changes: 32 additions & 24 deletions Sources/ForceSimulation/ForceSimulation.docc/Documentation.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# ``ForceSimulation``

Run force simulation on any dimensions.
Run force simulation within any number of dimensions.

## Overview

`ForceSimulation` is a force simulation library that enables you to create any dimensional simulation with velocity Verlet integration. The basic concepts of simulations and forces can be found here: [Force simulations - D3](https://d3js.org/d3-force/simulation).
The `ForceSimulation` library enables you to create any dimensional simulation that uses velocity Verlet integration.

For more information on force simulations, read: [Force simulations - D3](https://d3js.org/d3-force/simulation).


@Image(source: "ForceDirectedGraph.png", alt: "An example of 2D force directied graph.")
Expand All @@ -20,25 +22,31 @@ Run force simulation on any dimensions.
* ``Simulation3D``
* ``SimulationKD``

### Creating forces in a simulation

* ``Simulation2D/CenterForce``
* ``Simulation2D/CollideForce``
* ``Simulation2D/LinkForce``
* ``Simulation2D/ManyBodyForce``
* ``Simulation2D/DirectionForce2D``
* ``Simulation2D/RadialForce``

* ``Simulation3D/CenterForce``
* ``Simulation3D/CollideForce``
* ``Simulation3D/LinkForce``
* ``Simulation3D/ManyBodyForce``
* ``Simulation3D/DirectionForce3D``
* ``Simulation3D/RadialForce``

* ``SimulationKD/CenterForce``
* ``SimulationKD/CollideForce``
* ``SimulationKD/LinkForce``
* ``SimulationKD/ManyBodyForce``
* ``SimulationKD/DirectionForce``
* ``SimulationKD/RadialForce``
### Spatial data structures

- ``Quadtree``
- ``QuadtreeDelegate``
- ``QuadBox``
- ``Octree``
- ``OctreeDelegate``
- ``OctBox``
- ``NDTree``
- ``NDTreeDelegate``
- ``NDBox``
- ``EdgeID``

### Deterministic Randomness

- ``FloatLinearCongruentialGenerator``
- ``LinearCongruentialGenerator``

### Supporting Protocols

- ``ForceLike``
- ``NDTreeBasedForceLike``
- ``VectorLike``
- ``SimulatableFloatingPoint``

### Error Types

- ``ManyBodyForce2DError``
48 changes: 48 additions & 0 deletions Sources/ForceSimulation/ForceSimulation.docc/Simulation2D.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# ``ForceSimulation/Simulation2D``

A force-simulation for distributed layout within a two-dimensional space.

## Topics

### Creating a 2D force simulation

- ``init(nodeIds:alpha:alphaMin:alphaDecay:alphaTarget:velocityDecay:setInitialStatus:)``

### Creating forces for the simulation

- ``createCenterForce(center:strength:)``
- ``CenterForce``
- ``createCollideForce(radius:strength:iterationsPerTick:)``
- ``CollideForce``
- ``createLinkForce(_:stiffness:originalLength:iterationsPerTick:)-652gu``
- ``createLinkForce(_:stiffness:originalLength:iterationsPerTick:)-9iwy5``
- ``LinkForce``
- ``createManyBodyForce(strength:nodeMass:)``
- ``ManyBodyForce``
- ``createPositionForce(direction:targetOnDirection:strength:)``
- ``DirectionForce2D``
- ``createRadialForce(center:radius:strength:)``
- ``RadialForce``

### Running the simulation

- ``tick(iterationCount:)``
- ``resetAlpha(_:)``

### Inspecting the simulation

- ``alpha``
- ``alphaMin``
- ``alphaDecay``
- ``alphaTarget``
- ``initializedAlpha``
- ``velocityDecay``
- ``forces``

### Inspecting nodes within the simulation

- ``nodeIds``
- ``nodeFixations``
- ``nodePositions``
- ``nodeVelocities``
- ``getIndex(of:)``
48 changes: 48 additions & 0 deletions Sources/ForceSimulation/ForceSimulation.docc/Simulation3D.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# ``ForceSimulation/Simulation3D``

A force-simulation for distributed layout within a three-dimensional space.

## Topics

### Creating a 3D force simulation

- ``init(nodeIds:alpha:alphaMin:alphaDecay:alphaTarget:velocityDecay:setInitialStatus:)``

### Creating forces for the simulation

- ``createCenterForce(center:strength:)``
- ``CenterForce``
- ``createCollideForce(radius:strength:iterationsPerTick:)``
- ``CollideForce``
- ``createLinkForce(_:stiffness:originalLength:iterationsPerTick:)-2bixz``
- ``createLinkForce(_:stiffness:originalLength:iterationsPerTick:)-3sa2n``
- ``LinkForce``
- ``createManyBodyForce(strength:nodeMass:)``
- ``ManyBodyForce``
- ``createPositionForce(direction:targetOnDirection:strength:)``
- ``DirectionForce3D``
- ``createRadialForce(center:radius:strength:)``
- ``RadialForce``

### Running the simulation

- ``tick(iterationCount:)``
- ``resetAlpha(_:)``

### Inspecting the simulation

- ``alpha``
- ``alphaMin``
- ``alphaDecay``
- ``alphaTarget``
- ``initializedAlpha``
- ``velocityDecay``
- ``forces``

### Inspecting nodes within the simulation

- ``nodeIds``
- ``nodeFixations``
- ``nodePositions``
- ``nodeVelocities``
- ``getIndex(of:)``
48 changes: 48 additions & 0 deletions Sources/ForceSimulation/ForceSimulation.docc/SimulationKD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# ``ForceSimulation/SimulationKD``

A force-simulation for distributed layout within a multi-dimensional space.

## Topics

### Creating a multi-dimensional force simulation

- ``init(nodeIds:alpha:alphaMin:alphaDecay:alphaTarget:velocityDecay:setInitialStatus:)``

### Creating forces for the simulation

- ``createCenterForce(center:strength:)``
- ``CenterForce``
- ``createCollideForce(radius:strength:iterationsPerTick:)``
- ``CollideForce``
- ``createLinkForce(_:stiffness:originalLength:iterationsPerTick:)-46ea4``
- ``createLinkForce(_:stiffness:originalLength:iterationsPerTick:)-9opzo``
- ``LinkForce``
- ``createManyBodyForce(strength:nodeMass:)``
- ``ManyBodyForce``
- ``createPositionForce(direction:targetOnDirection:strength:)``
- ``DirectionForce``
- ``createRadialForce(center:radius:strength:)``
- ``RadialForce``

### Running the simulation

- ``tick(iterationCount:)``
- ``resetAlpha(_:)``

### Inspecting the simulation

- ``alpha``
- ``alphaMin``
- ``alphaDecay``
- ``alphaTarget``
- ``initializedAlpha``
- ``velocityDecay``
- ``forces``

### Inspecting nodes within the simulation

- ``nodeIds``
- ``nodeFixations``
- ``nodePositions``
- ``nodeVelocities``
- ``getIndex(of:)``
5 changes: 5 additions & 0 deletions Sources/ForceSimulation/NDTree/NDBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

/// A box in N-dimensional space.
///
/// - Note: `p0` is the minimum point of the box, `p1` is the maximum point of the box.
public struct NDBox<V> where V: VectorLike {
/// the minimum anchor of the box
Expand All @@ -15,6 +16,7 @@ public struct NDBox<V> where V: VectorLike {
public var p1: V

/// Create a box with 2 anchors.
///
/// - Parameters:
/// - p0: anchor
/// - p1: another anchor in the diagonal position of `p0`
Expand All @@ -39,6 +41,7 @@ public struct NDBox<V> where V: VectorLike {
}

/// Create a box with 2 anchors.
///
/// - Parameters:
/// - pMin: minimum anchor of the box
/// - pMax: maximum anchor of the box
Expand Down Expand Up @@ -111,6 +114,7 @@ extension NDBox {
extension NDBox {

/// Get the small box that contains a list points and guarantees the box's size is at least 1x..x1.
///
/// - Parameter points: The points to be covered.
/// - Returns: The box that contains all the points.
@inlinable public static func cover(of points: [V]) -> Self {
Expand Down Expand Up @@ -141,6 +145,7 @@ extension NDBox {
}

/// Get the small box that contains a list points and guarantees the box's size is at least 1x..x1.
///
/// Please note that KeyPath is slow.
///
/// - Parameter
Expand Down
Loading

0 comments on commit bbcce93

Please sign in to comment.