Skip to content

Commit

Permalink
compiler struggling with examples and type inference, most warnings s…
Browse files Browse the repository at this point in the history
…orted
  • Loading branch information
heckj committed Apr 13, 2024
1 parent fd85d2c commit 882f7a5
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 14 deletions.
6 changes: 4 additions & 2 deletions Sources/Lindenmayer/Examples/Examples3D.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ public enum Examples3D: Sendable {
/// ![A screenshot showing four rendered trees that correspond to the parameters as described in The Algorithmic Beauty of Plants for figure 2.6](rendered_2_6_trees.png)
///
/// The example source for this L-system is [available on GitHub](https://github.com/heckj/Lindenmayer/blob/main/Sources/Lindenmayer/Examples3D.swift).
public static let monopodialTree = LSystem.create(
///

public static let monopodialTree: ParameterizedRandomContextualLSystem<MonopodialDefn, Xoshiro> = LSystem.create(
[Trunk(growthDistance: defines.trunklength, diameter: defines.trunkdiameter)],
with: Xoshiro(seed: 42),
using: defines
Expand Down Expand Up @@ -349,7 +351,7 @@ public enum Examples3D: Sendable {
/// ![A screenshot showing four rendered trees that correspond to the parameters as described in The Algorithmic Beauty of Plants for figure 2.7](rendered_2_7_trees.png)
///
/// The example source for this L-system is [available on GitHub](https://github.com/heckj/Lindenmayer/blob/main/Sources/Lindenmayer/Examples3D.swift).
public static let sympodialTree = LSystem.create(
public static let sympodialTree: ParameterizedRandomContextualLSystem<SympodialDefn, Xoshiro> = LSystem.create(
MainBranch(growthDistance: 10, diameter: 1),
with: Xoshiro(seed: 0),
using: figure2_7A
Expand Down
10 changes: 3 additions & 7 deletions Sources/Lindenmayer/PRNG/RNGWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Foundation
///
/// - ``RNGWrapper/resetRNG(seed:)``
///
public actor RNGWrapper<PRNG> where PRNG: SeededRandomNumberGenerator {
public actor RNGWrapper<PRNG>: Sendable where PRNG: SeededRandomNumberGenerator {
private var _prng: PRNG
#if DEBUG
var _invokeCount: UInt64 = 0
Expand All @@ -48,12 +48,8 @@ public actor RNGWrapper<PRNG> where PRNG: SeededRandomNumberGenerator {

/// Creates a new random number generator wrapper class with the random number generator you provide.
/// - Parameter prng: A random number generator.
public init(_ prng: PRNG, seed: UInt64? = nil) {
if let seedValue = seed {
_prng = PRNG(seed: seedValue)
} else {
_prng = prng
}
public init(_ prng: PRNG) {
_prng = prng
}

/// Returns a random float value within the range you provide.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Lindenmayer/PRNG/SeededRandomNumberGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
/// The protocol includes an adjustable position property that represents the current location within the space of random numbers that the random number generates.
/// The seed value is preserved and unchanged, allowing the seeded random number generator to be interrogated and replicated.
/// When applied to a pseudo-random number generator, with a given seed and position, the next random number should be completely deterministic.
public protocol SeededRandomNumberGenerator: RandomNumberGenerator {
public protocol SeededRandomNumberGenerator: RandomNumberGenerator, Sendable {
/// The seed for the random number generator.
var seed: UInt64 { get }

Expand Down
2 changes: 1 addition & 1 deletion Sources/Lindenmayer/PRNG/Xoshiro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/// A pseudo-random number generator that produces random numbers based on an initial seed.
///
/// The algorithm for the generation is xoshiro256, based on the [public domain implementation](http://xoshiro.di.unimi.it).
public struct Xoshiro: SeededRandomNumberGenerator {
public struct Xoshiro: SeededRandomNumberGenerator, Sendable {
/// The initial seed for pseuo-random number generation.
public let seed: UInt64

Expand Down
1 change: 1 addition & 0 deletions Sources/LindenmayerViews/Dynamic2DLSystemViews.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI

/// A view that allows you to choose from a collection of the built-in 2D L-systems and display the 2D representation of the L-system at the number of iterations that you select in the view.
@available(macOS 12.0, iOS 15.0, *)
@MainActor
public struct Dynamic2DLSystemViews: View {
enum TwoDExamples: String, CaseIterable, Identifiable {
case algae
Expand Down
1 change: 1 addition & 0 deletions Sources/LindenmayerViews/LSystem3DControlView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import SwiftUI
/// The controls within the view allow you to select the number of iterations for the L-system.
/// Within the resulting L-system's state, you can select each state of the L-system, which points the 3D camera at that node and highlights it.
/// The view is intended to provide a visualization with sufficient detail about the state and its representation for debugging how an L-system is represented in 3D.
@MainActor
public struct LSystem3DControlView: View {
var model: LSystem3DModel
@State private var iterations = 1
Expand Down
9 changes: 6 additions & 3 deletions Sources/LindenmayerViews/LSystem3DModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
// Created by Joseph Heck on 1/8/22.
//

import Combine
@preconcurrency import Combine
import Foundation
import Lindenmayer
@preconcurrency import SceneKit
import SceneKit
import SceneKitDebugTools
import SwiftUI

/// A class that provides an observable model around a base L-system.
///
/// The module manages the number of evolutions of an L-system, and provides updated 3D SceneKit scenes as you change the number of evolutions.
/// The model emits `ObservableObject` change notifications when the number of iterations is changed.
@MainActor
public class LSystem3DModel: ObservableObject {
@Published public var system: LindenmayerSystem
let renderer = SceneKitRenderer()
Expand All @@ -24,7 +25,7 @@ public class LSystem3DModel: ObservableObject {
var _scene: SCNScene
var _transformSequence: [matrix_float4x4]

public var objectWillChange = Combine.ObservableObjectPublisher()
public let objectWillChange: ObservableObjectPublisher

public var scene: SCNScene {
_scene
Expand Down Expand Up @@ -63,6 +64,7 @@ public class LSystem3DModel: ObservableObject {
/// - Parameter system: The L-System to expose and control with the model.
public init(system: LindenmayerSystem) {
self.system = system
objectWillChange = ObservableObjectPublisher()
(_scene, _transformSequence) = renderer.generateScene(lsystem: _baseSystem)
let headingIndicator = DebugNodes.headingIndicator()
_scene.rootNode.addChildNode(headingIndicator)
Expand All @@ -71,6 +73,7 @@ public class LSystem3DModel: ObservableObject {
/// Creates a default L-System model using the sympodial tree example.
public init() {
system = _baseSystem
objectWillChange = ObservableObjectPublisher()
(_scene, _transformSequence) = renderer.generateScene(lsystem: _baseSystem)
let headingIndicator = DebugNodes.headingIndicator()
_scene.rootNode.addChildNode(headingIndicator)
Expand Down
1 change: 1 addition & 0 deletions Sources/LindenmayerViews/Lsystem2DView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI

/// A view that provides a 2D rendering of the L-system provide, and optionally metrics associated with the L-system.
@available(macOS 12.0, iOS 15.0, *)
@MainActor
public struct Lsystem2DView: View {
let iterations: Int
let displayMetrics: Bool
Expand Down
1 change: 1 addition & 0 deletions Sources/LindenmayerViews/Lsystem3DView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SceneKit
import SwiftUI

/// A view that provides a 3D rendering of the L-system provide, and optionally metrics associated with the L-system.
@MainActor
public struct Lsystem3DView: View {
let displayMetrics: Bool
@State var system: LindenmayerSystem
Expand Down

0 comments on commit 882f7a5

Please sign in to comment.