Skip to content

Commit

Permalink
Add DocC page
Browse files Browse the repository at this point in the history
  • Loading branch information
li3zhen1 committed Oct 22, 2023
1 parent e29a6bf commit a4ca999
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Creating 2D and 3D simulations


## Overview

You can simply create 2D or 3D simulations by using Simulation2D or Simulation3D:

```swift
import NDTree
import ForceSimulation

struct Node: Identifiable { ... }

let nodeIds: [Node.ID] = ...
let links: [(Node.ID, Node.ID)] = ...

let sim = Simulation2D(nodeIds: nodeIds, alphaDecay: 0.01)
sim.createManyBodyForce(strength: -12)
sim.createLinkForce(links)
sim.createCenterForce(center: [0, 0], strength: 0.4)
sim.createCollideForce(radius: .constant(3))

/// Force is ready to start! run `tick` to iterate the simulation.

for i in 0..<120 {
sim.tick()
let positions = sim.nodePositions
/// Do something with the positions.
}

```

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

Run force simulation on any dimension.

## 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).


@Image(source: "ForceDirectedGraph.png", alt: "An example of 2D force directied graph.")



## Topics


### Creating a simulation

* <doc:Creating2DAnd3DSimulations>
* ``Simulation2D``
* ``Simulation3D``

* ``Simulation``

### Creating forces in a simulation
* ``CenterForce``
* ``CollideForce``
* ``LinkForce``
* ``ManyBodyForce``
* ``DirectionForce``
* ``RadialForce``
* ``ForceLike``
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Sources/ForceSimulation/Simulation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ public final class Simulation<NodeID, V> where NodeID: Hashable, V: VectorLike,

#if canImport(simd)

/// A 2D simulation running on `Double` and `simd_double2` types.
public typealias Simulation2D<NodeID> = Simulation<NodeID, Vector2d> where NodeID: Hashable

/// A 3D simulation running on `Double` and `simd_double2` types.
public typealias Simulation3D<NodeID> = Simulation<NodeID, Vector3d> where NodeID: Hashable

#endif

0 comments on commit a4ca999

Please sign in to comment.