diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 4fd9ea68..781daad8 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -9,21 +9,16 @@ on: jobs: build: - runs-on: macos-14 + runs-on: macos-15 strategy: matrix: run-config: - - { scheme: 'Lindenmayer-Package', destination: 'platform=iOS Simulator,OS=15.5,name=iPhone 8' } - # Xcode on Github Actions supports at best up to macOS 11.6.2 currently... - - { scheme: 'Lindenmayer-Package', destination: 'platform=macOS,arch=x86_64' } + - { scheme: 'Lindenmayer-Package', destination: 'platform=iOS Simulator,OS=18.1,name=iPhone 16' } + - { scheme: 'Lindenmayer-Package', destination: 'platform=macOS' } steps: - uses: actions/checkout@v4 - # default Xcode for macOS 14 image is v15.0.1 - - name: Select Xcode 15.3 - run: sudo xcode-select -s /Applications/Xcode_15.3.app - - name: Show Build SDK run: xcodebuild -showsdks diff --git a/LICENSE b/LICENSE index fb10472a..17012294 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Joseph Heck +Copyright (c) 2021-2024 Joseph Heck Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Package.swift b/Package.swift index 48f32290..83a486d3 100644 --- a/Package.swift +++ b/Package.swift @@ -2,6 +2,13 @@ import PackageDescription +var globalSwiftSettings: [PackageDescription.SwiftSetting] = [ + .enableExperimentalFeature("StrictConcurrency"), + .enableUpcomingFeature("ExistentialAny"), + .enableExperimentalFeature("AccessLevelOnImport"), + .enableUpcomingFeature("InternalImportsByDefault"), +] + let package = Package( name: "Lindenmayer", platforms: [ @@ -19,22 +26,23 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/heckj/SceneKitDebugTools.git", from: "0.1.0"), - .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), + .package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"), ], targets: [ .target( name: "Lindenmayer", dependencies: ["SceneKitDebugTools"], - swiftSettings: [.enableExperimentalFeature("StrictConcurrency")] + swiftSettings: globalSwiftSettings ), .target( name: "LindenmayerViews", dependencies: ["Lindenmayer", "SceneKitDebugTools"], - swiftSettings: [.enableExperimentalFeature("StrictConcurrency")] + swiftSettings: globalSwiftSettings ), .testTarget( name: "LindenmayerTests", dependencies: ["Lindenmayer", "SceneKitDebugTools"] ), - ] + ], + swiftLanguageVersions: [.version("6"), .v5] ) diff --git a/Sources/Lindenmayer/Examples/Examples2D.swift b/Sources/Lindenmayer/Examples/Examples2D.swift index 88655e67..c81a41d2 100644 --- a/Sources/Lindenmayer/Examples/Examples2D.swift +++ b/Sources/Lindenmayer/Examples/Examples2D.swift @@ -15,7 +15,7 @@ public enum Examples2D { struct Internode: Module { // This is the kind of thing that I want external developers using the library to be able to create to represent elements within their L-system. public var name = "I" - public var render2D: [TwoDRenderCmd] = [RenderCommand.Draw(length: 10)] // draws a line 10 units long + public var render2D: [any TwoDRenderCmd] = [RenderCommand.Draw(length: 10)] // draws a line 10 units long public init() {} } @@ -48,7 +48,7 @@ public enum Examples2D { struct Leaf: Module { static let green = ColorRepresentation(r: 0.3, g: 0.56, b: 0.0) public var name = "L" - public var render2D: [TwoDRenderCmd] = [ + public var render2D: [any TwoDRenderCmd] = [ RenderCommand.SetLineWidth(width: 3), RenderCommand.SetColor(representation: green), RenderCommand.Draw(length: 5), @@ -59,7 +59,7 @@ public enum Examples2D { struct Stem: Module { public var name = "I" - public var render2D: [TwoDRenderCmd] = [RenderCommand.Draw(length: 5)] // would be neat to make this green... + public var render2D: [any TwoDRenderCmd] = [RenderCommand.Draw(length: 5)] // would be neat to make this green... } static let stem = Stem() @@ -99,14 +99,14 @@ public enum Examples2D { struct F: Module { public var name = "F" - public var render2D: [TwoDRenderCmd] = [RenderCommand.Draw(length: 10)] + public var render2D: [any TwoDRenderCmd] = [RenderCommand.Draw(length: 10)] } static let f = F() struct G: Module { public var name = "G" - public var render2D: [TwoDRenderCmd] = [RenderCommand.Draw(length: 10)] + public var render2D: [any TwoDRenderCmd] = [RenderCommand.Draw(length: 10)] } static let g = G() diff --git a/Sources/Lindenmayer/Examples/Examples3D.swift b/Sources/Lindenmayer/Examples/Examples3D.swift index 9d9cb33e..2f7f01b5 100644 --- a/Sources/Lindenmayer/Examples/Examples3D.swift +++ b/Sources/Lindenmayer/Examples/Examples3D.swift @@ -41,7 +41,7 @@ public enum Examples3D: Sendable { struct Cyl: Module { public var name = "C" - public var render3D: ThreeDRenderCmd = RenderCommand.Cylinder( + public var render3D: any ThreeDRenderCmd = RenderCommand.Cylinder( length: 10, radius: 1, color: ColorRepresentation(red: 1.0, green: 0.1, blue: 0.1, alpha: 1.0) @@ -50,7 +50,7 @@ public enum Examples3D: Sendable { struct S: Module { public var name = "S" - public var render3D: ThreeDRenderCmd = RenderCommand.Cylinder( + public var render3D: any ThreeDRenderCmd = RenderCommand.Cylinder( length: 5, radius: 2, color: ColorRepresentation(red: 0.1, green: 1.0, blue: 0.1, alpha: 1.0) @@ -146,7 +146,7 @@ public enum Examples3D: Sendable { struct StaticTrunk: Module { public var name = "A°" - public var render3D: ThreeDRenderCmd { + public var render3D: any ThreeDRenderCmd { RenderCommand.Cylinder( length: growthDistance, radius: diameter / 2, @@ -395,7 +395,7 @@ public enum Examples3D: Sendable { struct Stem2: Module { public var name = "i" let length: Double // start at 10 - public var render3D: ThreeDRenderCmd { + public var render3D: any ThreeDRenderCmd { RenderCommand.Cylinder( length: length, radius: length / 10, @@ -407,7 +407,7 @@ public enum Examples3D: Sendable { struct StaticStem2: Module { public var name = "I" let length: Double // start at 10 - public var render3D: ThreeDRenderCmd { + public var render3D: any ThreeDRenderCmd { RenderCommand.Cylinder( length: length, radius: length / 10, @@ -417,19 +417,19 @@ public enum Examples3D: Sendable { } public static let randomBush = LSystem.create(Stem2(length: 1), with: Xoshiro(seed: 42)) - .rewriteWithRNG(directContext: Stem2.self) { stem, rng async -> [Module] in + .rewriteWithRNG(directContext: Stem2.self) { stem, rng async -> [any Module] in let upper: Float = 45.0 let lower: Float = 15.0 - if await rng.p(0.5) { - return await [ + if rng.p(0.5) { + return [ StaticStem2(length: 2), Modules.PitchDown(angle: Angle(degrees: Double(rng.randomFloat(in: lower ... upper)))), Stem2(length: stem.length), ] } else { - return await [ + return [ StaticStem2(length: 2), Modules.PitchUp(angle: Angle(degrees: Double(rng.randomFloat(in: lower ... upper)))), Stem2(length: stem.length), diff --git a/Sources/Lindenmayer/LSystem.swift b/Sources/Lindenmayer/LSystem.swift index 8f089ff8..2a20d398 100644 --- a/Sources/Lindenmayer/LSystem.swift +++ b/Sources/Lindenmayer/LSystem.swift @@ -40,14 +40,14 @@ public enum LSystem: Sendable { /// Creates a new Lindenmayer system from an initial state. /// - Parameters: /// - axiom: An initial module that represents the initial state of the Lindenmayer system.. - public static func create(_ axiom: Module) -> ContextualLSystem { + public static func create(_ axiom: some Module) -> ContextualLSystem { ContextualLSystem([axiom], state: nil, newStateIndicators: nil) } /// Creates a new Lindenmayer system from an initial state. /// - Parameters: /// - axiom: A sequence of modules that represents the initial state of the Lindenmayer system.. - public static func create(_ axiom: [Module]) -> ContextualLSystem { + public static func create(_ axiom: [any Module]) -> ContextualLSystem { ContextualLSystem(axiom, state: nil, newStateIndicators: nil) } @@ -55,7 +55,7 @@ public enum LSystem: Sendable { /// - Parameters: /// - axiom: An initial module that represents the initial state of the Lindenmayer system.. /// - prng: An optional psuedo-random number generator to use for randomness in rule productions. - public static func create(_ axiom: Module, with prng: RNGType?) -> RandomContextualLSystem { + public static func create(_ axiom: some Module, with prng: RNGType?) -> RandomContextualLSystem { if let prng { return RandomContextualLSystem(axiom: [axiom], state: nil, newStateIndicators: nil, prng: RNGWrapper(prng)) } @@ -66,7 +66,7 @@ public enum LSystem: Sendable { /// - Parameters: /// - axiom: A sequence of modules that represents the initial state of the Lindenmayer system.. /// - prng: An optional psuedo-random number generator to use for for randomness in rule productions. - public static func create(_ axiom: [Module], with prng: RNGType?) -> RandomContextualLSystem { + public static func create(_ axiom: [any Module], with prng: RNGType?) -> RandomContextualLSystem { if let prng { return RandomContextualLSystem(axiom: axiom, state: nil, newStateIndicators: nil, prng: RNGWrapper(prng)) } @@ -78,7 +78,7 @@ public enum LSystem: Sendable { /// - axiom: An initial module that represents the initial state of the Lindenmayer system. /// - prng: An optional psuedo-random number generator to use for for randomness in rule productions. /// - parameters: An instance of type you provide that the L-system provides to the rules you create for use as parameters. - public static func create(_ axiom: Module, with prng: RNGType?, using parameters: PType) -> ParameterizedRandomContextualLSystem { + public static func create(_ axiom: some Module, with prng: RNGType?, using parameters: PType) -> ParameterizedRandomContextualLSystem { if let prng { return ParameterizedRandomContextualLSystem(axiom: [axiom], state: nil, newStateIndicators: nil, parameters: parameters, prng: RNGWrapper(prng), rules: []) } @@ -90,7 +90,7 @@ public enum LSystem: Sendable { /// - axiom: A sequence of modules that represents the initial state of the Lindenmayer system.. /// - prng: An optional psuedo-random number generator to use for for randomness in rule productions. /// - parameters: An instance of type you provide that the L-system provides to the rules you create for use as parameters. - public static func create(_ axiom: [Module], with prng: RNGType?, using parameters: PType) -> ParameterizedRandomContextualLSystem { + public static func create(_ axiom: [any Module], with prng: RNGType?, using parameters: PType) -> ParameterizedRandomContextualLSystem { if let prng { return ParameterizedRandomContextualLSystem(axiom: axiom, state: nil, newStateIndicators: nil, parameters: parameters, prng: RNGWrapper(prng), rules: []) } diff --git a/Sources/Lindenmayer/LSystemTypes/ContextualLSystem.swift b/Sources/Lindenmayer/LSystemTypes/ContextualLSystem.swift index 2c08446d..958573cd 100644 --- a/Sources/Lindenmayer/LSystemTypes/ContextualLSystem.swift +++ b/Sources/Lindenmayer/LSystemTypes/ContextualLSystem.swift @@ -55,10 +55,10 @@ import Foundation /// /// - ``ContextualLSystem/reset()`` public struct ContextualLSystem: LindenmayerSystem { - let axiom: [Module] + let axiom: [any Module] /// The sequence of modules that represents the current state of the L-system. - public let state: [Module] + public let state: [any Module] /// An array of Boolean values that indicate if the state in the L-system was newly created in the evolution. /// @@ -66,7 +66,7 @@ public struct ContextualLSystem: LindenmayerSystem { public let newStateIndicators: [Bool] /// The sequence of rules that the L-system uses to process and evolve its state. - public let rules: [Rule] + public let rules: [any Rule] /// Creates a new Lindenmayer system from an initial state sequence and rules you provide. /// - Parameters: @@ -84,10 +84,10 @@ public struct ContextualLSystem: LindenmayerSystem { /// /// let algae = Lsystem.create(A()) /// ``` - public init(_ axiom: [Module], - state: [Module]?, + public init(_ axiom: [any Module], + state: [any Module]?, newStateIndicators: [Bool]?, - rules: [Rule] = []) + rules: [any Rule] = []) { self.axiom = axiom if let state { @@ -113,7 +113,7 @@ public struct ContextualLSystem: LindenmayerSystem { /// /// This function is called from the common ``LindenmayerSystem`` protocol's default implementation to generate an updated /// L-system with a set of new modules. - public func updatedLSystem(with state: [Module], newItemIndicators: [Bool]) -> Self { + public func updatedLSystem(with state: [any Module], newItemIndicators: [Bool]) -> Self { ContextualLSystem(axiom, state: state, newStateIndicators: newItemIndicators, rules: rules) } @@ -133,10 +133,10 @@ public extension ContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewrite(_ direct: DC.Type, where evalClosure: @Sendable @escaping (DC) -> Bool, - produces produceClosure: @Sendable @escaping (DC) -> [Module]) -> Self where DC: Module + produces produceClosure: @Sendable @escaping (DC) -> [any Module]) -> Self where DC: Module { let newRule = RewriteRuleDirect(direct: direct, where: evalClosure, produce: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return ContextualLSystem(axiom, state: state, newStateIndicators: newStateIndicators, rules: newRuleSet) } @@ -147,10 +147,10 @@ public extension ContextualLSystem { /// - produce: A closure that you provide that returns a list of modules to replace the matching module. /// - Returns: A new L-System with the additional rule added. func rewrite(_ direct: DC.Type, - produces produceClosure: @Sendable @escaping (DC) -> [Module]) -> Self where DC: Module + produces produceClosure: @Sendable @escaping (DC) -> [any Module]) -> Self where DC: Module { let newRule = RewriteRuleDirect(direct: direct, where: nil, produce: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return ContextualLSystem(axiom, state: state, newStateIndicators: newStateIndicators, rules: newRuleSet) } @@ -163,10 +163,10 @@ public extension ContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewrite(leftContext: LC.Type, directContext: DC.Type, where evalClosure: @Sendable @escaping (LC, DC) -> Bool, - produces produceClosure: @Sendable @escaping (LC, DC) -> [Module]) -> Self where LC: Module, DC: Module + produces produceClosure: @Sendable @escaping (LC, DC) -> [any Module]) -> Self where LC: Module, DC: Module { let newRule = RewriteRuleLeftDirect(leftType: leftContext, directType: directContext, where: evalClosure, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return ContextualLSystem(axiom, state: state, newStateIndicators: newStateIndicators, rules: newRuleSet) } @@ -177,10 +177,10 @@ public extension ContextualLSystem { /// - produce: A closure that you provide that returns a list of modules to replace the matching module. /// - Returns: A new L-System with the additional rule added. func rewrite(leftContext: LC.Type, directContext: DC.Type, - produces produceClosure: @Sendable @escaping (LC, DC) -> [Module]) -> Self where LC: Module, DC: Module + produces produceClosure: @Sendable @escaping (LC, DC) -> [any Module]) -> Self where LC: Module, DC: Module { let newRule = RewriteRuleLeftDirect(leftType: leftContext, directType: directContext, where: nil, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return ContextualLSystem(axiom, state: state, newStateIndicators: newStateIndicators, rules: newRuleSet) } @@ -193,10 +193,10 @@ public extension ContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewrite(directContext: DC.Type, rightContext: RC.Type, where evalClosure: @Sendable @escaping (DC, RC) -> Bool, - produces produceClosure: @Sendable @escaping (DC, RC) -> [Module]) -> Self where DC: Module, RC: Module + produces produceClosure: @Sendable @escaping (DC, RC) -> [any Module]) -> Self where DC: Module, RC: Module { let newRule = RewriteRuleDirectRight(directType: directContext, rightType: rightContext, where: evalClosure, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return ContextualLSystem(axiom, state: state, newStateIndicators: newStateIndicators, rules: newRuleSet) } @@ -207,10 +207,10 @@ public extension ContextualLSystem { /// - produce: A closure that you provide that returns a list of modules to replace the matching module. /// - Returns: A new L-System with the additional rule added. func rewrite(directContext: DC.Type, rightContext: RC.Type, - produces produceClosure: @Sendable @escaping (DC, RC) -> [Module]) -> Self where DC: Module, RC: Module + produces produceClosure: @Sendable @escaping (DC, RC) -> [any Module]) -> Self where DC: Module, RC: Module { let newRule = RewriteRuleDirectRight(directType: directContext, rightType: rightContext, where: nil, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return ContextualLSystem(axiom, state: state, newStateIndicators: newStateIndicators, rules: newRuleSet) } @@ -223,10 +223,10 @@ public extension ContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewrite(leftContext: LC.Type, directContext: DC.Type, rightContext: RC.Type, where evalClosure: @Sendable @escaping (LC, DC, RC) -> Bool, - produces produceClosure: @Sendable @escaping (LC, DC, RC) -> [Module]) -> Self where LC: Module, DC: Module, RC: Module + produces produceClosure: @Sendable @escaping (LC, DC, RC) -> [any Module]) -> Self where LC: Module, DC: Module, RC: Module { let newRule = RewriteRuleLeftDirectRight(leftType: leftContext, directType: directContext, rightType: rightContext, where: evalClosure, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return ContextualLSystem(axiom, state: state, newStateIndicators: newStateIndicators, rules: newRuleSet) } @@ -237,10 +237,10 @@ public extension ContextualLSystem { /// - produce: A closure that you provide that returns a list of modules to replace the matching module. /// - Returns: A new L-System with the additional rule added. func rewrite(leftContext: LC.Type, directContext: DC.Type, rightContext: RC.Type, - produces produceClosure: @Sendable @escaping (LC, DC, RC) -> [Module]) -> Self where LC: Module, DC: Module, RC: Module + produces produceClosure: @Sendable @escaping (LC, DC, RC) -> [any Module]) -> Self where LC: Module, DC: Module, RC: Module { let newRule = RewriteRuleLeftDirectRight(leftType: leftContext, directType: directContext, rightType: rightContext, where: nil, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return ContextualLSystem(axiom, state: state, newStateIndicators: newStateIndicators, rules: newRuleSet) } diff --git a/Sources/Lindenmayer/LSystemTypes/ParameterizedRandomContextualLSystem.swift b/Sources/Lindenmayer/LSystemTypes/ParameterizedRandomContextualLSystem.swift index 17ecdb1a..90680008 100644 --- a/Sources/Lindenmayer/LSystemTypes/ParameterizedRandomContextualLSystem.swift +++ b/Sources/Lindenmayer/LSystemTypes/ParameterizedRandomContextualLSystem.swift @@ -85,10 +85,10 @@ import Foundation /// - ``ParameterizedRandomContextualLSystem/reset()`` /// public struct ParameterizedRandomContextualLSystem: LindenmayerSystem where PRNG: SeededRandomNumberGenerator, PType: Sendable { - let axiom: [Module] + let axiom: [any Module] /// The current state of the L-system, expressed as a sequence of elements that conform to Module. - public let state: [Module] + public let state: [any Module] /// An array of Boolean values that indicate if the state in the L-system was newly created in the evolution. /// @@ -102,7 +102,7 @@ public struct ParameterizedRandomContextualLSystem: LindenmayerSyst let prng: RNGWrapper /// The sequence of rules that the L-system uses to process and evolve its state. - public let rules: [Rule] + public let rules: [any Rule] /// Creates a new Lindenmayer system from an initial state sequence and rules you provide. /// - Parameters: @@ -112,12 +112,12 @@ public struct ParameterizedRandomContextualLSystem: LindenmayerSyst /// - rules: A collection of rules that the Lindenmayer system applies when you call the evolve function. /// /// Convenient initializers for creating contextual L-systems uses ``LSystem``, calling ``Lindenmayer/LSystem/create(_:with:using:)-1nce9``, or ``Lindenmayer/LSystem/create(_:with:using:)-2nwqc`` - public init(axiom: [Module], - state: [Module]?, + public init(axiom: [any Module], + state: [any Module]?, newStateIndicators: [Bool]?, parameters: PType, prng: RNGWrapper, - rules: [Rule] = []) + rules: [any Rule] = []) { // Using [axiom] instead of [] ensures that we always have a state // environment that can be evolved based on the rules available. @@ -148,7 +148,7 @@ public struct ParameterizedRandomContextualLSystem: LindenmayerSyst /// /// This function is called from the common ``LindenmayerSystem`` protocol's default implementation to generate an updated /// L-system with a set of new modules. - public func updatedLSystem(with state: [Module], newItemIndicators: [Bool]) -> Self { + public func updatedLSystem(with state: [any Module], newItemIndicators: [Bool]) -> Self { ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newItemIndicators, parameters: parameters, prng: prng, rules: rules) } @@ -189,7 +189,7 @@ public extension ParameterizedRandomContextualLSystem { func rewriteWithAll( leftContext: LC.Type, directContext: DC.Type, rightContext: RC.Type, where evalClosure: @Sendable @escaping (LC, DC, RC, PType) -> Bool, - produces produceClosure: @Sendable @escaping (LC, DC, RC, PType, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (LC, DC, RC, PType, RNGWrapper) async -> [any Module] ) -> Self where LC: Module, DC: Module, RC: Module { @@ -200,7 +200,7 @@ public extension ParameterizedRandomContextualLSystem { where: evalClosure, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -214,7 +214,7 @@ public extension ParameterizedRandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewriteWithAll( leftContext: LC.Type, directContext: DC.Type, rightContext: RC.Type, - produces produceClosure: @Sendable @escaping (LC, DC, RC, PType, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (LC, DC, RC, PType, RNGWrapper) async -> [any Module] ) -> Self where LC: Module, DC: Module, RC: Module { @@ -225,7 +225,7 @@ public extension ParameterizedRandomContextualLSystem { where: nil, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -240,7 +240,7 @@ public extension ParameterizedRandomContextualLSystem { func rewriteWithAll( leftContext: LC.Type, directContext: DC.Type, where evalClosure: @Sendable @escaping (LC, DC, PType) -> Bool, - produces produceClosure: @Sendable @escaping (LC, DC, PType, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (LC, DC, PType, RNGWrapper) async -> [any Module] ) -> Self where LC: Module, DC: Module { @@ -251,7 +251,7 @@ public extension ParameterizedRandomContextualLSystem { where: evalClosure, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -264,7 +264,7 @@ public extension ParameterizedRandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewriteWithAll( leftContext: LC.Type, directContext: DC.Type, - produces produceClosure: @Sendable @escaping (LC, DC, PType, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (LC, DC, PType, RNGWrapper) async -> [any Module] ) -> Self where LC: Module, DC: Module { @@ -275,7 +275,7 @@ public extension ParameterizedRandomContextualLSystem { where: nil, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -290,7 +290,7 @@ public extension ParameterizedRandomContextualLSystem { func rewriteWithAll( directContext: DC.Type, rightContext: RC.Type, where evalClosure: @Sendable @escaping (DC, RC, PType) -> Bool, - produces produceClosure: @Sendable @escaping (DC, RC, PType, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (DC, RC, PType, RNGWrapper) async -> [any Module] ) -> Self where DC: Module, RC: Module { @@ -301,7 +301,7 @@ public extension ParameterizedRandomContextualLSystem { where: evalClosure, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -314,7 +314,7 @@ public extension ParameterizedRandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewriteWithAll( directContext: DC.Type, rightContext: RC.Type, - produces produceClosure: @Sendable @escaping (DC, RC, PType, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (DC, RC, PType, RNGWrapper) async -> [any Module] ) -> Self where DC: Module, RC: Module { @@ -325,7 +325,7 @@ public extension ParameterizedRandomContextualLSystem { where: nil, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -339,7 +339,7 @@ public extension ParameterizedRandomContextualLSystem { func rewriteWithAll( directContext: DC.Type, where evalClosure: @Sendable @escaping (DC, PType) -> Bool, - produces produceClosure: @Sendable @escaping (DC, PType, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (DC, PType, RNGWrapper) async -> [any Module] ) -> Self where DC: Module { @@ -350,7 +350,7 @@ public extension ParameterizedRandomContextualLSystem { where: evalClosure, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -362,7 +362,7 @@ public extension ParameterizedRandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewriteWithAll( directContext: DC.Type, - produces produceClosure: @Sendable @escaping (DC, PType, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (DC, PType, RNGWrapper) async -> [any Module] ) -> Self where DC: Module { @@ -373,7 +373,7 @@ public extension ParameterizedRandomContextualLSystem { where: nil, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -393,7 +393,7 @@ public extension ParameterizedRandomContextualLSystem { func rewriteWithParams( leftContext: LC.Type, directContext: DC.Type, rightContext: RC.Type, where evalClosure: @Sendable @escaping (LC, DC, RC, PType) -> Bool, - produces produceClosure: @Sendable @escaping (LC, DC, RC, PType) async -> [Module] + produces produceClosure: @Sendable @escaping (LC, DC, RC, PType) async -> [any Module] ) -> Self where LC: Module, DC: Module, RC: Module { @@ -403,7 +403,7 @@ public extension ParameterizedRandomContextualLSystem { where: evalClosure, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -417,7 +417,7 @@ public extension ParameterizedRandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewriteWithParams( leftContext: LC.Type, directContext: DC.Type, rightContext: RC.Type, - produces produceClosure: @Sendable @escaping (LC, DC, RC, PType) async -> [Module] + produces produceClosure: @Sendable @escaping (LC, DC, RC, PType) async -> [any Module] ) -> Self where LC: Module, DC: Module, RC: Module { @@ -427,7 +427,7 @@ public extension ParameterizedRandomContextualLSystem { where: nil, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -442,7 +442,7 @@ public extension ParameterizedRandomContextualLSystem { func rewriteWithParams( leftContext: LC.Type, directContext: DC.Type, where evalClosure: @Sendable @escaping (LC, DC, PType) -> Bool, - produces produceClosure: @Sendable @escaping (LC, DC, PType) async -> [Module] + produces produceClosure: @Sendable @escaping (LC, DC, PType) async -> [any Module] ) -> Self where LC: Module, DC: Module { @@ -452,7 +452,7 @@ public extension ParameterizedRandomContextualLSystem { where: evalClosure, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -465,7 +465,7 @@ public extension ParameterizedRandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewriteWithParams( leftContext: LC.Type, directContext: DC.Type, - produces produceClosure: @Sendable @escaping (LC, DC, PType) async -> [Module] + produces produceClosure: @Sendable @escaping (LC, DC, PType) async -> [any Module] ) -> Self where LC: Module, DC: Module { @@ -475,7 +475,7 @@ public extension ParameterizedRandomContextualLSystem { where: nil, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -490,7 +490,7 @@ public extension ParameterizedRandomContextualLSystem { func rewriteWithParams( directContext: DC.Type, rightContext: RC.Type, where evalClosure: @Sendable @escaping (DC, RC, PType) -> Bool, - produces produceClosure: @Sendable @escaping (DC, RC, PType) async -> [Module] + produces produceClosure: @Sendable @escaping (DC, RC, PType) async -> [any Module] ) -> Self where DC: Module, RC: Module { @@ -500,7 +500,7 @@ public extension ParameterizedRandomContextualLSystem { where: evalClosure, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -513,7 +513,7 @@ public extension ParameterizedRandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewriteWithParams( directContext: DC.Type, rightContext: RC.Type, - produces produceClosure: @Sendable @escaping (DC, RC, PType) async -> [Module] + produces produceClosure: @Sendable @escaping (DC, RC, PType) async -> [any Module] ) -> Self where DC: Module, RC: Module { @@ -523,7 +523,7 @@ public extension ParameterizedRandomContextualLSystem { where: nil, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -537,7 +537,7 @@ public extension ParameterizedRandomContextualLSystem { func rewriteWithParams( directContext: DC.Type, where evalClosure: @Sendable @escaping (DC, PType) -> Bool, - produces produceClosure: @Sendable @escaping (DC, PType) async -> [Module] + produces produceClosure: @Sendable @escaping (DC, PType) async -> [any Module] ) -> Self where DC: Module { @@ -547,7 +547,7 @@ public extension ParameterizedRandomContextualLSystem { where: evalClosure, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -559,7 +559,7 @@ public extension ParameterizedRandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewriteWithParams( directContext: DC.Type, - produces produceClosure: @Sendable @escaping (DC, PType) async -> [Module] + produces produceClosure: @Sendable @escaping (DC, PType) async -> [any Module] ) -> Self where DC: Module { @@ -569,7 +569,7 @@ public extension ParameterizedRandomContextualLSystem { where: nil, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -589,7 +589,7 @@ public extension ParameterizedRandomContextualLSystem { func rewriteWithRNG( leftContext: LC.Type, directContext: DC.Type, rightContext: RC.Type, where evalClosure: @Sendable @escaping (LC, DC, RC) -> Bool, - produces produceClosure: @Sendable @escaping (LC, DC, RC, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (LC, DC, RC, RNGWrapper) async -> [any Module] ) -> Self where LC: Module, DC: Module, RC: Module { @@ -599,7 +599,7 @@ public extension ParameterizedRandomContextualLSystem { where: evalClosure, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -613,7 +613,7 @@ public extension ParameterizedRandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewriteWithRNG( leftContext: LC.Type, directContext: DC.Type, rightContext: RC.Type, - produces produceClosure: @Sendable @escaping (LC, DC, RC, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (LC, DC, RC, RNGWrapper) async -> [any Module] ) -> Self where LC: Module, DC: Module, RC: Module { @@ -623,7 +623,7 @@ public extension ParameterizedRandomContextualLSystem { where: nil, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -638,8 +638,7 @@ public extension ParameterizedRandomContextualLSystem { func rewriteWithRNG( leftContext: LC.Type, directContext: DC.Type, where evalClosure: @Sendable @escaping (LC, DC) -> Bool, - produces produceClosure: @Sendable @escaping (LC, DC, RNGWrapper) async -> [Module] - ) -> Self + produces produceClosure: @Sendable @escaping (LC, DC, RNGWrapper) async -> [any Module]) -> Self where LC: Module, DC: Module { let rule = RewriteRuleLeftDirectRNG( @@ -648,7 +647,7 @@ public extension ParameterizedRandomContextualLSystem { where: evalClosure, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -661,7 +660,7 @@ public extension ParameterizedRandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewriteWithRNG( leftContext: LC.Type, directContext: DC.Type, - produces produceClosure: @Sendable @escaping (LC, DC, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (LC, DC, RNGWrapper) async -> [any Module] ) -> Self where LC: Module, DC: Module { @@ -671,7 +670,7 @@ public extension ParameterizedRandomContextualLSystem { where: nil, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -687,7 +686,7 @@ public extension ParameterizedRandomContextualLSystem { func rewriteWithRNG( directContext: DC.Type, rightContext: RC.Type, where evalClosure: @Sendable @escaping (DC, RC) -> Bool, - produces produceClosure: @Sendable @escaping (DC, RC, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (DC, RC, RNGWrapper) async -> [any Module] ) -> Self where DC: Module, RC: Module { @@ -697,7 +696,7 @@ public extension ParameterizedRandomContextualLSystem { where: evalClosure, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -710,7 +709,7 @@ public extension ParameterizedRandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewriteWithRNG( directContext: DC.Type, rightContext: RC.Type, - produces produceClosure: @Sendable @escaping (DC, RC, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (DC, RC, RNGWrapper) async -> [any Module] ) -> Self where DC: Module, RC: Module { @@ -720,7 +719,7 @@ public extension ParameterizedRandomContextualLSystem { where: nil, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -734,7 +733,7 @@ public extension ParameterizedRandomContextualLSystem { func rewriteWithRNG( directContext: DC.Type, where evalClosure: @Sendable @escaping (DC) -> Bool, - produces produceClosure: @Sendable @escaping (DC, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (DC, RNGWrapper) async -> [any Module] ) -> Self where DC: Module { @@ -744,7 +743,7 @@ public extension ParameterizedRandomContextualLSystem { where: evalClosure, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -756,7 +755,7 @@ public extension ParameterizedRandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewriteWithRNG( directContext: DC.Type, - produces produceClosure: @Sendable @escaping (DC, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (DC, RNGWrapper) async -> [any Module] ) -> Self where DC: Module { @@ -766,7 +765,7 @@ public extension ParameterizedRandomContextualLSystem { where: nil, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -781,10 +780,10 @@ public extension ParameterizedRandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewrite(_ direct: DC.Type, where evalClosure: @Sendable @escaping (DC) -> Bool, - produces produceClosure: @Sendable @escaping (DC) -> [Module]) -> Self where DC: Module + produces produceClosure: @Sendable @escaping (DC) -> [any Module]) -> Self where DC: Module { let newRule = RewriteRuleDirect(direct: direct, where: evalClosure, produce: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -795,10 +794,10 @@ public extension ParameterizedRandomContextualLSystem { /// - produce: A closure that you provide that returns a list of modules to replace the matching module. /// - Returns: A new L-System with the additional rule added. func rewrite(_ direct: DC.Type, - produces produceClosure: @Sendable @escaping (DC) -> [Module]) -> Self where DC: Module + produces produceClosure: @Sendable @escaping (DC) -> [any Module]) -> Self where DC: Module { let newRule = RewriteRuleDirect(direct: direct, where: nil, produce: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -811,10 +810,10 @@ public extension ParameterizedRandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewrite(leftContext: LC.Type, directContext: DC.Type, where evalClosure: @Sendable @escaping (LC, DC) -> Bool, - produces produceClosure: @Sendable @escaping (LC, DC) -> [Module]) -> Self where LC: Module, DC: Module + produces produceClosure: @Sendable @escaping (LC, DC) -> [any Module]) -> Self where LC: Module, DC: Module { let newRule = RewriteRuleLeftDirect(leftType: leftContext, directType: directContext, where: evalClosure, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -825,10 +824,10 @@ public extension ParameterizedRandomContextualLSystem { /// - produce: A closure that you provide that returns a list of modules to replace the matching module. /// - Returns: A new L-System with the additional rule added. func rewrite(leftContext: LC.Type, directContext: DC.Type, - produces produceClosure: @Sendable @escaping (LC, DC) -> [Module]) -> Self where LC: Module, DC: Module + produces produceClosure: @Sendable @escaping (LC, DC) -> [any Module]) -> Self where LC: Module, DC: Module { let newRule = RewriteRuleLeftDirect(leftType: leftContext, directType: directContext, where: nil, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -841,10 +840,10 @@ public extension ParameterizedRandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewrite(directContext: DC.Type, rightContext: RC.Type, where evalClosure: @Sendable @escaping (DC, RC) -> Bool, - produces produceClosure: @Sendable @escaping (DC, RC) -> [Module]) -> Self where DC: Module, RC: Module + produces produceClosure: @Sendable @escaping (DC, RC) -> [any Module]) -> Self where DC: Module, RC: Module { let newRule = RewriteRuleDirectRight(directType: directContext, rightType: rightContext, where: evalClosure, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -855,10 +854,10 @@ public extension ParameterizedRandomContextualLSystem { /// - produce: A closure that you provide that returns a list of modules to replace the matching module. /// - Returns: A new L-System with the additional rule added. func rewrite(directContext: DC.Type, rightContext: RC.Type, - produces produceClosure: @Sendable @escaping (DC, RC) -> [Module]) -> Self where DC: Module, RC: Module + produces produceClosure: @Sendable @escaping (DC, RC) -> [any Module]) -> Self where DC: Module, RC: Module { let newRule = RewriteRuleDirectRight(directType: directContext, rightType: rightContext, where: nil, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -871,10 +870,10 @@ public extension ParameterizedRandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewrite(leftContext: LC.Type, directContext: DC.Type, rightContext: RC.Type, where evalClosure: @Sendable @escaping (LC, DC, RC) -> Bool, - produces produceClosure: @Sendable @escaping (LC, DC, RC) -> [Module]) -> Self where LC: Module, DC: Module, RC: Module + produces produceClosure: @Sendable @escaping (LC, DC, RC) -> [any Module]) -> Self where LC: Module, DC: Module, RC: Module { let newRule = RewriteRuleLeftDirectRight(leftType: leftContext, directType: directContext, rightType: rightContext, where: evalClosure, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } @@ -885,10 +884,10 @@ public extension ParameterizedRandomContextualLSystem { /// - produce: A closure that you provide that returns a list of modules to replace the matching module. /// - Returns: A new L-System with the additional rule added. func rewrite(leftContext: LC.Type, directContext: DC.Type, rightContext: RC.Type, - produces produceClosure: @Sendable @escaping (LC, DC, RC) -> [Module]) -> Self where LC: Module, DC: Module, RC: Module + produces produceClosure: @Sendable @escaping (LC, DC, RC) -> [any Module]) -> Self where LC: Module, DC: Module, RC: Module { let newRule = RewriteRuleLeftDirectRight(leftType: leftContext, directType: directContext, rightType: rightContext, where: nil, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return ParameterizedRandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: parameters, prng: prng, rules: newRuleSet) } diff --git a/Sources/Lindenmayer/LSystemTypes/RandomContextualLSystem.swift b/Sources/Lindenmayer/LSystemTypes/RandomContextualLSystem.swift index d72ebab5..e35b29ba 100644 --- a/Sources/Lindenmayer/LSystemTypes/RandomContextualLSystem.swift +++ b/Sources/Lindenmayer/LSystemTypes/RandomContextualLSystem.swift @@ -64,10 +64,10 @@ import Foundation /// - ``RandomContextualLSystem/reset()`` /// public struct RandomContextualLSystem: LindenmayerSystem where PRNG: SeededRandomNumberGenerator { - let axiom: [Module] + let axiom: [any Module] /// The sequence of modules that represents the current state of the L-system. - public let state: [Module] + public let state: [any Module] /// An array of Boolean values that indicate if the state in the L-system was newly created in the evolution. /// @@ -77,7 +77,7 @@ public struct RandomContextualLSystem: LindenmayerSystem where PRNG: Seede let prng: RNGWrapper /// The sequence of rules that the L-system uses to process and evolve its state. - public let rules: [Rule] + public let rules: [any Rule] /// Creates a new Lindenmayer system from an initial state sequence and rules you provide. /// - Parameters: @@ -88,11 +88,11 @@ public struct RandomContextualLSystem: LindenmayerSystem where PRNG: Seede /// /// Convenient initializers for creating contextual L-systems uses ``LSystem``, /// calling ``Lindenmayer/LSystem/create(_:with:using:)-1nce9``, or ``Lindenmayer/LSystem/create(_:with:using:)-2nwqc``. - public init(axiom: [Module], - state: [Module]?, + public init(axiom: [any Module], + state: [any Module]?, newStateIndicators: [Bool]?, prng: RNGWrapper, - rules: [Rule] = []) + rules: [any Rule] = []) { self.axiom = axiom if let state { @@ -118,7 +118,7 @@ public struct RandomContextualLSystem: LindenmayerSystem where PRNG: Seede /// /// This function is called from the common ``LindenmayerSystem`` protocol's default implementation to generate an updated /// L-system with a set of new modules. - public func updatedLSystem(with state: [Module], newItemIndicators: [Bool]) -> Self { + public func updatedLSystem(with state: [any Module], newItemIndicators: [Bool]) -> Self { RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newItemIndicators, prng: prng, rules: rules) } @@ -144,7 +144,7 @@ public extension RandomContextualLSystem { func rewriteWithRNG( leftContext: LC.Type, directContext: DC.Type, rightContext: RC.Type, where evalClosure: @Sendable @escaping (LC, DC, RC) -> Bool, - produces produceClosure: @Sendable @escaping (LC, DC, RC, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (LC, DC, RC, RNGWrapper) async -> [any Module] ) -> Self where LC: Module, DC: Module, RC: Module { @@ -154,7 +154,7 @@ public extension RandomContextualLSystem { where: evalClosure, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, prng: prng, rules: newRuleSet) } @@ -168,7 +168,7 @@ public extension RandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewriteWithRNG( leftContext: LC.Type, directContext: DC.Type, rightContext: RC.Type, - produces produceClosure: @Sendable @escaping (LC, DC, RC, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (LC, DC, RC, RNGWrapper) async -> [any Module] ) -> Self where LC: Module, DC: Module, RC: Module { @@ -178,7 +178,7 @@ public extension RandomContextualLSystem { where: nil, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, prng: prng, rules: newRuleSet) } @@ -193,7 +193,7 @@ public extension RandomContextualLSystem { func rewriteWithRNG( leftContext: LC.Type, directContext: DC.Type, where evalClosure: @Sendable @escaping (LC, DC) -> Bool, - produces produceClosure: @Sendable @escaping (LC, DC, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (LC, DC, RNGWrapper) async -> [any Module] ) -> Self where LC: Module, DC: Module { @@ -203,7 +203,7 @@ public extension RandomContextualLSystem { where: evalClosure, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, prng: prng, rules: newRuleSet) } @@ -216,7 +216,7 @@ public extension RandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewriteWithRNG( leftContext: LC.Type, directContext: DC.Type, - produces produceClosure: @Sendable @escaping (LC, DC, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (LC, DC, RNGWrapper) async -> [any Module] ) -> Self where LC: Module, DC: Module { @@ -226,7 +226,7 @@ public extension RandomContextualLSystem { where: nil, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, prng: prng, rules: newRuleSet) } @@ -242,7 +242,7 @@ public extension RandomContextualLSystem { func rewriteWithRNG( directContext: DC.Type, rightContext: RC.Type, where evalClosure: @Sendable @escaping (DC, RC) -> Bool, - produces produceClosure: @Sendable @escaping (DC, RC, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (DC, RC, RNGWrapper) async -> [any Module] ) -> Self where DC: Module, RC: Module { @@ -252,7 +252,7 @@ public extension RandomContextualLSystem { where: evalClosure, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, prng: prng, rules: newRuleSet) } @@ -265,7 +265,7 @@ public extension RandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewriteWithRNG( directContext: DC.Type, rightContext: RC.Type, - produces produceClosure: @Sendable @escaping (DC, RC, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (DC, RC, RNGWrapper) async -> [any Module] ) -> Self where DC: Module, RC: Module { @@ -275,7 +275,7 @@ public extension RandomContextualLSystem { where: nil, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, prng: prng, rules: newRuleSet) } @@ -289,7 +289,7 @@ public extension RandomContextualLSystem { func rewriteWithRNG( directContext: DC.Type, where evalClosure: @Sendable @escaping (DC) -> Bool, - produces produceClosure: @Sendable @escaping (DC, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (DC, RNGWrapper) async -> [any Module] ) -> Self where DC: Module { @@ -299,7 +299,7 @@ public extension RandomContextualLSystem { where: evalClosure, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, prng: prng, rules: newRuleSet) } @@ -311,7 +311,7 @@ public extension RandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewriteWithRNG( directContext: DC.Type, - produces produceClosure: @Sendable @escaping (DC, RNGWrapper) async -> [Module] + produces produceClosure: @Sendable @escaping (DC, RNGWrapper) async -> [any Module] ) -> Self where DC: Module { @@ -321,7 +321,7 @@ public extension RandomContextualLSystem { where: nil, produces: produceClosure ) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [rule]) return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, prng: prng, rules: newRuleSet) } @@ -338,10 +338,10 @@ public extension RandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewrite(_ direct: DC.Type, where evalClosure: @Sendable @escaping (DC) -> Bool, - produces produceClosure: @Sendable @escaping (DC) -> [Module]) -> Self where DC: Module + produces produceClosure: @Sendable @escaping (DC) -> [any Module]) -> Self where DC: Module { let newRule = RewriteRuleDirect(direct: direct, where: evalClosure, produce: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, prng: prng, rules: newRuleSet) } @@ -352,10 +352,10 @@ public extension RandomContextualLSystem { /// - produce: A closure that you provide that returns a list of modules to replace the matching module. /// - Returns: A new L-System with the additional rule added. func rewrite(_ direct: DC.Type, - produces produceClosure: @Sendable @escaping (DC) -> [Module]) -> Self where DC: Module + produces produceClosure: @Sendable @escaping (DC) -> [any Module]) -> Self where DC: Module { let newRule = RewriteRuleDirect(direct: direct, where: nil, produce: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, prng: prng, rules: newRuleSet) } @@ -368,10 +368,10 @@ public extension RandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewrite(leftContext: LC.Type, directContext: DC.Type, where evalClosure: @Sendable @escaping (LC, DC) -> Bool, - produces produceClosure: @Sendable @escaping (LC, DC) -> [Module]) -> Self where LC: Module, DC: Module + produces produceClosure: @Sendable @escaping (LC, DC) -> [any Module]) -> Self where LC: Module, DC: Module { let newRule = RewriteRuleLeftDirect(leftType: leftContext, directType: directContext, where: evalClosure, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, prng: prng, rules: newRuleSet) } @@ -382,10 +382,10 @@ public extension RandomContextualLSystem { /// - produce: A closure that you provide that returns a list of modules to replace the matching module. /// - Returns: A new L-System with the additional rule added. func rewrite(leftContext: LC.Type, directContext: DC.Type, - produces produceClosure: @Sendable @escaping (LC, DC) -> [Module]) -> Self where LC: Module, DC: Module + produces produceClosure: @Sendable @escaping (LC, DC) -> [any Module]) -> Self where LC: Module, DC: Module { let newRule = RewriteRuleLeftDirect(leftType: leftContext, directType: directContext, where: nil, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, prng: prng, rules: newRuleSet) } @@ -398,10 +398,10 @@ public extension RandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewrite(directContext: DC.Type, rightContext: RC.Type, where evalClosure: @Sendable @escaping (DC, RC) -> Bool, - produces produceClosure: @Sendable @escaping (DC, RC) -> [Module]) -> Self where DC: Module, RC: Module + produces produceClosure: @Sendable @escaping (DC, RC) -> [any Module]) -> Self where DC: Module, RC: Module { let newRule = RewriteRuleDirectRight(directType: directContext, rightType: rightContext, where: evalClosure, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, prng: prng, rules: newRuleSet) } @@ -412,10 +412,10 @@ public extension RandomContextualLSystem { /// - produce: A closure that you provide that returns a list of modules to replace the matching module. /// - Returns: A new L-System with the additional rule added. func rewrite(directContext: DC.Type, rightContext: RC.Type, - produces produceClosure: @Sendable @escaping (DC, RC) -> [Module]) -> Self where DC: Module, RC: Module + produces produceClosure: @Sendable @escaping (DC, RC) -> [any Module]) -> Self where DC: Module, RC: Module { let newRule = RewriteRuleDirectRight(directType: directContext, rightType: rightContext, where: nil, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, prng: prng, rules: newRuleSet) } @@ -428,10 +428,10 @@ public extension RandomContextualLSystem { /// - Returns: A new L-System with the additional rule added. func rewrite(leftContext: LC.Type, directContext: DC.Type, rightContext: RC.Type, where evalClosure: @Sendable @escaping (LC, DC, RC) -> Bool, - produces produceClosure: @Sendable @escaping (LC, DC, RC) -> [Module]) -> Self where LC: Module, DC: Module, RC: Module + produces produceClosure: @Sendable @escaping (LC, DC, RC) -> [any Module]) -> Self where LC: Module, DC: Module, RC: Module { let newRule = RewriteRuleLeftDirectRight(leftType: leftContext, directType: directContext, rightType: rightContext, where: evalClosure, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, prng: prng, rules: newRuleSet) } @@ -442,10 +442,10 @@ public extension RandomContextualLSystem { /// - produce: A closure that you provide that returns a list of modules to replace the matching module. /// - Returns: A new L-System with the additional rule added. func rewrite(leftContext: LC.Type, directContext: DC.Type, rightContext: RC.Type, - produces produceClosure: @Sendable @escaping (LC, DC, RC) -> [Module]) -> Self where LC: Module, DC: Module, RC: Module + produces produceClosure: @Sendable @escaping (LC, DC, RC) -> [any Module]) -> Self where LC: Module, DC: Module, RC: Module { let newRule = RewriteRuleLeftDirectRight(leftType: leftContext, directType: directContext, rightType: rightContext, where: nil, produces: produceClosure) - var newRuleSet: [Rule] = rules + var newRuleSet: [any Rule] = rules newRuleSet.append(contentsOf: [newRule]) return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newStateIndicators, prng: prng, rules: newRuleSet) } diff --git a/Sources/Lindenmayer/LindenmayerSystem.swift b/Sources/Lindenmayer/LindenmayerSystem.swift index 51f3584f..b0e7c214 100644 --- a/Sources/Lindenmayer/LindenmayerSystem.swift +++ b/Sources/Lindenmayer/LindenmayerSystem.swift @@ -39,7 +39,7 @@ import Foundation /// - ``Lindenmayer/LindenmayerSystem/reset()`` public protocol LindenmayerSystem: Sendable { /// The sequence of modules that represents the current state of the L-system. - var state: [Module] { get } + var state: [any Module] { get } /// An array of Boolean values that indicate if the state in the L-system was newly created in the evolution. /// @@ -47,7 +47,7 @@ public protocol LindenmayerSystem: Sendable { var newStateIndicators: [Bool] { get } /// The sequence of rules that the L-system uses to process and evolve its state. - var rules: [Rule] { get } + var rules: [any Rule] { get } /// The L-system evolved by a number of iterations you provide. /// - Parameter iterations: The number of times to evolve the L-system. @@ -72,7 +72,7 @@ public protocol LindenmayerSystem: Sendable { /// /// This function is called from the common ``LindenmayerSystem`` protocol's default implementation to generate an updated /// L-system with a set of new modules. - func updatedLSystem(with state: [Module], newItemIndicators: [Bool]) -> Self + func updatedLSystem(with state: [any Module], newItemIndicators: [Bool]) -> Self } // MARK: - default implementations @@ -108,7 +108,7 @@ public extension LindenmayerSystem { // TODO(heckj): revisit this with async methods in mind, creating tasks for each iteration // in order to run the whole suite of the state in parallel for a new result. Await the whole // kit for a final resolution. - var newState: [Module] = [] + var newState: [any Module] = [] var newStateIndicatorArray: [Bool] = [] var newStateIndexLocation = 0 for index in 0 ..< state.count { @@ -116,7 +116,7 @@ public extension LindenmayerSystem { // Iterate through the rules, finding the first rule to match // based on calling 'evaluate' on each of the rules in sequence. - let maybeRule: Rule? = rules.first(where: { $0.evaluate(moduleSet) }) + let maybeRule: (any Rule)? = rules.first(where: { $0.evaluate(moduleSet) }) if let foundRule = maybeRule { // If a rule was found, then use it to generate the modules that // replace this element in the sequence. diff --git a/Sources/Lindenmayer/Modules/BuiltinModules.swift b/Sources/Lindenmayer/Modules/BuiltinModules.swift index 079d3047..236a69ad 100644 --- a/Sources/Lindenmayer/Modules/BuiltinModules.swift +++ b/Sources/Lindenmayer/Modules/BuiltinModules.swift @@ -35,11 +35,11 @@ public extension Modules { struct TurnLeft: Module { public let name = RenderCommand.turnLeft.name public let angle: Angle - public var render2D: [TwoDRenderCmd] { + public var render2D: [any TwoDRenderCmd] { [RenderCommand.TurnLeft(angle: angle)] } - public var render3D: ThreeDRenderCmd { + public var render3D: any ThreeDRenderCmd { RenderCommand.TurnLeft(angle: angle) } @@ -52,11 +52,11 @@ public extension Modules { struct TurnRight: Module { public let name = RenderCommand.turnRight.name public let angle: Angle - public var render2D: [TwoDRenderCmd] { + public var render2D: [any TwoDRenderCmd] { [RenderCommand.TurnRight(angle: angle)] } - public var render3D: ThreeDRenderCmd { + public var render3D: any ThreeDRenderCmd { RenderCommand.TurnRight(angle: angle) } @@ -69,11 +69,11 @@ public extension Modules { struct Draw: Module { public let name = RenderCommand.draw.name public let length: Double - public var render2D: [TwoDRenderCmd] { + public var render2D: [any TwoDRenderCmd] { [RenderCommand.Draw(length: length)] } - public var render3D: ThreeDRenderCmd { + public var render3D: any ThreeDRenderCmd { RenderCommand.Draw(length: length) } @@ -86,11 +86,11 @@ public extension Modules { struct Move: Module { public let name = RenderCommand.move.name public let length: Double - public var render2D: [TwoDRenderCmd] { + public var render2D: [any TwoDRenderCmd] { [RenderCommand.Move(length: length)] } - public var render3D: ThreeDRenderCmd { + public var render3D: any ThreeDRenderCmd { RenderCommand.Move(length: length) } @@ -102,11 +102,11 @@ public extension Modules { /// A module that informs a renderer that the L-system representation should branch. struct Branch: Module { public let name = RenderCommand.branch.name - public var render2D: [TwoDRenderCmd] { + public var render2D: [any TwoDRenderCmd] { [RenderCommand.Branch()] } - public var render3D: ThreeDRenderCmd { + public var render3D: any ThreeDRenderCmd { RenderCommand.Branch() } @@ -117,11 +117,11 @@ public extension Modules { struct EndBranch: Module { public let name = RenderCommand.endBranch.name - public var render2D: [TwoDRenderCmd] { + public var render2D: [any TwoDRenderCmd] { [RenderCommand.EndBranch()] } - public var render3D: ThreeDRenderCmd { + public var render3D: any ThreeDRenderCmd { RenderCommand.EndBranch() } @@ -132,11 +132,11 @@ public extension Modules { struct RollLeft: Module { public let name = RenderCommand.rollLeft.name public let angle: Angle - public var render2D: [TwoDRenderCmd] { + public var render2D: [any TwoDRenderCmd] { [] } - public var render3D: ThreeDRenderCmd { + public var render3D: any ThreeDRenderCmd { RenderCommand.RollLeft(angle: angle) } @@ -149,11 +149,11 @@ public extension Modules { struct RollRight: Module { public let name = RenderCommand.rollRight.name public let angle: Angle - public var render2D: [TwoDRenderCmd] { + public var render2D: [any TwoDRenderCmd] { [] } - public var render3D: ThreeDRenderCmd { + public var render3D: any ThreeDRenderCmd { RenderCommand.RollRight(angle: angle) } @@ -166,11 +166,11 @@ public extension Modules { struct PitchUp: Module { public let name = RenderCommand.pitchUp.name public let angle: Angle - public var render2D: [TwoDRenderCmd] { + public var render2D: [any TwoDRenderCmd] { [] } - public var render3D: ThreeDRenderCmd { + public var render3D: any ThreeDRenderCmd { RenderCommand.PitchUp(angle: angle) } @@ -183,11 +183,11 @@ public extension Modules { struct PitchDown: Module { public let name = RenderCommand.pitchDown.name public let angle: Angle - public var render2D: [TwoDRenderCmd] { + public var render2D: [any TwoDRenderCmd] { [] } - public var render3D: ThreeDRenderCmd { + public var render3D: any ThreeDRenderCmd { RenderCommand.PitchDown(angle: angle) } @@ -199,11 +199,11 @@ public extension Modules { /// A module that informs the renderer to roll around its current heading so that the upward vector is as vertical as possible. struct RollUpToVertical: Module { public let name = RenderCommand.rollUpToVertical.name - public var render2D: [TwoDRenderCmd] { + public var render2D: [any TwoDRenderCmd] { [] } - public var render3D: ThreeDRenderCmd { + public var render3D: any ThreeDRenderCmd { RenderCommand.rollUpToVertical } diff --git a/Sources/Lindenmayer/Modules/DebugModule.swift b/Sources/Lindenmayer/Modules/DebugModule.swift index d816f0f0..111ff66f 100644 --- a/Sources/Lindenmayer/Modules/DebugModule.swift +++ b/Sources/Lindenmayer/Modules/DebugModule.swift @@ -40,7 +40,7 @@ import Foundation /// public class DebugModule: Identifiable { /// The abstract, underlying module instance with which you initialized the wrapper. - public let module: Module + public let module: any Module /// A Boolean value that indicates whether the module was newly added in the last evolution of the L-System. public let new: Bool /// The location of the module within an L-system's state. @@ -78,7 +78,7 @@ public class DebugModule: Identifiable { /// - m: The module to use to initialize the debug module. /// - at: The location within the state of an L-system. /// - isNew: A Boolean value that indicates the module was created in the last evolution. - public init(_ m: Module, at: Int, isNew: Bool = false) { + public init(_ m: any Module, at: Int, isNew: Bool = false) { id = at module = m new = isNew diff --git a/Sources/Lindenmayer/Modules/Module.swift b/Sources/Lindenmayer/Modules/Module.swift index 34795e31..ab4a0ca1 100644 --- a/Sources/Lindenmayer/Modules/Module.swift +++ b/Sources/Lindenmayer/Modules/Module.swift @@ -32,21 +32,21 @@ public protocol Module: CustomStringConvertible, Sendable { /// Use a single character or very short string for the name, as it's used in textual descriptions of the state of an L-system. var name: String { get } /// Returns a sequence of render commands to display the content in 2-dimensionals. - var render2D: [TwoDRenderCmd] { get } + var render2D: [any TwoDRenderCmd] { get } /// Returns a sequence of render commands to display the content in 3-dimensionals. - var render3D: ThreeDRenderCmd { get } + var render3D: any ThreeDRenderCmd { get } } // MARK: - Default Implementations of computed properties for 2D and 3D rendering commands of a module. public extension Module { /// The sequence of two-dimensional oriented rendering commands that you use to represent the module. - var render2D: [TwoDRenderCmd] { + var render2D: [any TwoDRenderCmd] { [] } /// The three-dimensional oriented rendering command that you use to represent the module. - var render3D: ThreeDRenderCmd { + var render3D: any ThreeDRenderCmd { RenderCommand.Ignore() } } diff --git a/Sources/Lindenmayer/Modules/ModuleSet.swift b/Sources/Lindenmayer/Modules/ModuleSet.swift index baa85971..4d7ce28d 100644 --- a/Sources/Lindenmayer/Modules/ModuleSet.swift +++ b/Sources/Lindenmayer/Modules/ModuleSet.swift @@ -20,25 +20,25 @@ import Foundation /// public struct ModuleSet { /// The module to the left (earlier) in the L-systems's state sequence. - let leftInstance: Module? + let leftInstance: (any Module)? /// The type of the module to the left. - let leftInstanceType: Module.Type? + let leftInstanceType: (any Module.Type)? /// The module instance. - let directInstance: Module + let directInstance: any Module /// The type of the module instance. - let directInstanceType: Module.Type + let directInstanceType: any Module.Type /// The module to the right (later) in the L-system's state sequence. - let rightInstance: Module? + let rightInstance: (any Module)? /// The type of the module to the right. - let rightInstanceType: Module.Type? + let rightInstanceType: (any Module.Type)? /// Creates a new module set with a module. /// - Parameters: /// - directInstance: The module instance. /// - directInstanceType: The type of the module. - public init(directInstance: Module) { + public init(directInstance: some Module) { self.directInstance = directInstance directInstanceType = type(of: directInstance) leftInstance = nil @@ -55,7 +55,7 @@ public struct ModuleSet { /// - directInstanceType: The type of the module. /// - rightInstance: The module to the right (later) in the L-system's state sequence. /// - rightInstanceType: The type fo the module to the right. - public init(leftInstance: Module?, directInstance: Module, rightInstance: Module?) { + public init(leftInstance: (any Module)?, directInstance: any Module, rightInstance: (any Module)?) { if let left = leftInstance { self.leftInstance = left leftInstanceType = type(of: left) diff --git a/Sources/Lindenmayer/PRNG/RNGWrapper.swift b/Sources/Lindenmayer/PRNG/RNGWrapper.swift index 3032147d..1fe853eb 100644 --- a/Sources/Lindenmayer/PRNG/RNGWrapper.swift +++ b/Sources/Lindenmayer/PRNG/RNGWrapper.swift @@ -73,7 +73,7 @@ public actor RNGWrapper: Sendable where PRNG: SeededRandomNumberGenerator /// Returns a single module randomly selected from the list you provide. /// - Parameter from: The sequence of modules to choose from. - func select(_ from: [Module]) -> Module { + func select(_ from: [any Module]) -> any Module { #if DEBUG _invokeCount += 1 #endif diff --git a/Sources/Lindenmayer/Rendering/Angle.swift b/Sources/Lindenmayer/Rendering/Angle.swift index c66bf02c..55c6e754 100644 --- a/Sources/Lindenmayer/Rendering/Angle.swift +++ b/Sources/Lindenmayer/Rendering/Angle.swift @@ -7,7 +7,7 @@ import Foundation #if canImport(SwiftUI) - @_exported import SwiftUI + @_exported public import SwiftUI /// A geometric angle whose value you access in either radians or degrees. public typealias Angle = SwiftUI.Angle diff --git a/Sources/Lindenmayer/Rendering/GraphicsContextRenderer.swift b/Sources/Lindenmayer/Rendering/GraphicsContextRenderer.swift index e4a55bef..8b3191db 100644 --- a/Sources/Lindenmayer/Rendering/GraphicsContextRenderer.swift +++ b/Sources/Lindenmayer/Rendering/GraphicsContextRenderer.swift @@ -6,7 +6,7 @@ // import CoreGraphics -import SwiftUI +public import SwiftUI struct PathState { var angle: Angle @@ -69,7 +69,7 @@ public struct GraphicsContextRenderer { /// - context: The SwiftUI graphics context into which to draw. /// - size: The optional size of the available graphics context. If provided, the function pre-calculates the size of the rendered L-system and adjusts the drawing to fill the space available. @available(macOS 12.0, iOS 15.0, *) - public func draw(_ lsystem: LindenmayerSystem, into context: inout GraphicsContext, ofSize size: CGSize? = nil) { + public func draw(_ lsystem: any LindenmayerSystem, into context: inout GraphicsContext, ofSize size: CGSize? = nil) { if let size { // This is less pretty, because we have to process the whole damn thing to figure out the end-result // size prior to running the commands... grrr. @@ -138,7 +138,7 @@ public struct GraphicsContextRenderer { /// Returns a Core Graphics rectangle after processing the L-System you provide to identify the boundaries of the 2D rendering. /// - Parameter system: The L-System to process. /// - Returns: The CGRect that represents the boundaries of the draw commands. - public func calcBoundingRect(system: LindenmayerSystem) -> CGRect { + public func calcBoundingRect(system: any LindenmayerSystem) -> CGRect { var stateStack: [PathState] = [] var currentState = PathState() var minY: Double = 0 @@ -189,7 +189,7 @@ public struct GraphicsContextRenderer { /// - modules: The modules that make up the state of an ``LindenmayerSystem``. /// - destinationRect: An optional rectangle that, if provided, the path will be scaled into. /// - Returns: The path that draws the 2D representation of the provided ``LindenmayerSystem`` modules. - func path(modules: [Module], forRect destinationRect: CGRect? = nil) -> CGPath { + func path(modules: [any Module], forRect destinationRect: CGRect? = nil) -> CGPath { let path = CGMutablePath() path.move(to: CGPoint(x: 0, y: 0)) diff --git a/Sources/Lindenmayer/Rendering/SIMD_Float4x4+Extensions.swift b/Sources/Lindenmayer/Rendering/SIMD_Float4x4+Extensions.swift index 465f6591..93d79073 100644 --- a/Sources/Lindenmayer/Rendering/SIMD_Float4x4+Extensions.swift +++ b/Sources/Lindenmayer/Rendering/SIMD_Float4x4+Extensions.swift @@ -6,7 +6,7 @@ // import Foundation -import simd +public import simd public extension simd_float4x4 { /// Returns a multi-line string that represents the simd4x4 matrix for easier visual reading. diff --git a/Sources/Lindenmayer/Rendering/SceneKitRenderer.swift b/Sources/Lindenmayer/Rendering/SceneKitRenderer.swift index 53b41953..52cc48b8 100644 --- a/Sources/Lindenmayer/Rendering/SceneKitRenderer.swift +++ b/Sources/Lindenmayer/Rendering/SceneKitRenderer.swift @@ -7,7 +7,7 @@ import CoreGraphics import Foundation -import SceneKit +public import SceneKit import SceneKitDebugTools import simd @@ -129,7 +129,7 @@ public struct SceneKitRenderer { /// Returns a new SceneKit scene by rendering the states of the L-system you provide into a 3D model. /// - Parameter lsystem: The L-System to be displayed. - public func generateScene(lsystem: LindenmayerSystem) -> SCNScene { + public func generateScene(lsystem: any LindenmayerSystem) -> SCNScene { generateScene(lsystem: lsystem).0 } @@ -138,7 +138,7 @@ public struct SceneKitRenderer { /// /// This method is intended to be used for visualizing the state elements. /// The sequence of transforms is generated from the updates to the rotations and translations that occur during the rendering process. - public func generateScene(lsystem: LindenmayerSystem) -> (SCNScene, [matrix_float4x4]) { + public func generateScene(lsystem: any LindenmayerSystem) -> (SCNScene, [matrix_float4x4]) { let scene = SCNScene() // create and add a camera to the scene let cameraNode = SCNNode() diff --git a/Sources/Lindenmayer/Rendering/Transforms.swift b/Sources/Lindenmayer/Rendering/Transforms.swift index 7ca8480a..776bc3b1 100644 --- a/Sources/Lindenmayer/Rendering/Transforms.swift +++ b/Sources/Lindenmayer/Rendering/Transforms.swift @@ -5,7 +5,7 @@ // import Foundation -import simd +public import simd public extension SceneKitRenderer { /// Creates a 3D translation transform that scales by the values you provide. diff --git a/Sources/Lindenmayer/Rules/RewriteRuleDirect.swift b/Sources/Lindenmayer/Rules/RewriteRuleDirect.swift index c3b4c8d6..26791046 100644 --- a/Sources/Lindenmayer/Rules/RewriteRuleDirect.swift +++ b/Sources/Lindenmayer/Rules/RewriteRuleDirect.swift @@ -32,7 +32,7 @@ public struct RewriteRuleDirect: Rule where DC: Module { public var parametricEval: (@Sendable (DC) -> Bool)? /// The signature of the produce closure that provides a module and expects a sequence of modules. - public typealias SingleMatchProducesList = @Sendable (DC) -> [Module] + public typealias SingleMatchProducesList = @Sendable (DC) -> [any Module] /// The closure that provides the L-system state for the current, previous, and next nodes in the state sequence and expects an array of state elements with which to replace the current state. public let produceClosure: SingleMatchProducesList @@ -79,7 +79,7 @@ public struct RewriteRuleDirect: Rule where DC: Module { /// Invokes the rule's produce closure with the modules provided. /// - Parameter matchSet: The module instances to pass to the produce closure. /// - Returns: A sequence of modules that the produce closure returns. - public func produce(_ matchSet: ModuleSet) -> [Module] { + public func produce(_ matchSet: ModuleSet) -> [any Module] { guard let directInstance = matchSet.directInstance as? DC else { return [] } diff --git a/Sources/Lindenmayer/Rules/RewriteRuleDirectDefines.swift b/Sources/Lindenmayer/Rules/RewriteRuleDirectDefines.swift index 3ee0e0e9..62c6578e 100644 --- a/Sources/Lindenmayer/Rules/RewriteRuleDirectDefines.swift +++ b/Sources/Lindenmayer/Rules/RewriteRuleDirectDefines.swift @@ -36,7 +36,7 @@ public struct RewriteRuleDirectDefines: Rule where DC: Module, PType: let parameters: PType /// The signature of the produce closure that provides a module and expects a sequence of modules. - public typealias SingleMatchProducesList = @Sendable (DC, PType) async -> [Module] + public typealias SingleMatchProducesList = @Sendable (DC, PType) async -> [any Module] /// The closure that provides the L-system state for the current, previous, and next nodes in the state sequence and expects an array of state elements with which to replace the current state. public let produceClosure: SingleMatchProducesList @@ -85,7 +85,7 @@ public struct RewriteRuleDirectDefines: Rule where DC: Module, PType: /// Invokes the rule's produce closure with the modules provided. /// - Parameter matchSet: The module instances to pass to the produce closure. /// - Returns: A sequence of modules that the produce closure returns. - public func produce(_ matchSet: ModuleSet) async -> [Module] { + public func produce(_ matchSet: ModuleSet) async -> [any Module] { guard let directInstance = matchSet.directInstance as? DC else { return [] } diff --git a/Sources/Lindenmayer/Rules/RewriteRuleDirectDefinesRNG.swift b/Sources/Lindenmayer/Rules/RewriteRuleDirectDefinesRNG.swift index 5d8d38c2..e643f445 100644 --- a/Sources/Lindenmayer/Rules/RewriteRuleDirectDefinesRNG.swift +++ b/Sources/Lindenmayer/Rules/RewriteRuleDirectDefinesRNG.swift @@ -39,7 +39,7 @@ public struct RewriteRuleDirectDefinesRNG: Rule where DC: Modul var prng: RNGWrapper /// The signature of the produce closure that provides a module and expects a sequence of modules. - public typealias SingleMatchProducesList = @Sendable (DC, PType, RNGWrapper) async -> [Module] + public typealias SingleMatchProducesList = @Sendable (DC, PType, RNGWrapper) async -> [any Module] /// The closure that provides the L-system state for the current, previous, and next nodes in the state sequence and expects an array of state elements with which to replace the current state. public let produceClosure: SingleMatchProducesList @@ -91,7 +91,7 @@ public struct RewriteRuleDirectDefinesRNG: Rule where DC: Modul /// Invokes the rule's produce closure with the modules provided. /// - Parameter matchSet: The module instances to pass to the produce closure. /// - Returns: A sequence of modules that the produce closure returns. - public func produce(_ matchSet: ModuleSet) async -> [Module] { + public func produce(_ matchSet: ModuleSet) async -> [any Module] { guard let directInstance = matchSet.directInstance as? DC else { return [] } diff --git a/Sources/Lindenmayer/Rules/RewriteRuleDirectRNG.swift b/Sources/Lindenmayer/Rules/RewriteRuleDirectRNG.swift index be882308..b3da8664 100644 --- a/Sources/Lindenmayer/Rules/RewriteRuleDirectRNG.swift +++ b/Sources/Lindenmayer/Rules/RewriteRuleDirectRNG.swift @@ -36,7 +36,7 @@ public struct RewriteRuleDirectRNG: Rule where DC: Module, PRNG: Seede var prng: RNGWrapper /// The signature of the produce closure that provides a module and expects a sequence of modules. - public typealias SingleMatchProducesList = @Sendable (DC, RNGWrapper) async -> [Module] + public typealias SingleMatchProducesList = @Sendable (DC, RNGWrapper) async -> [any Module] /// The closure that provides the L-system state for the current, previous, and next nodes in the state sequence and expects an array of state elements with which to replace the current state. public let produceClosure: SingleMatchProducesList @@ -86,7 +86,7 @@ public struct RewriteRuleDirectRNG: Rule where DC: Module, PRNG: Seede /// Invokes the rule's produce closure with the modules provided. /// - Parameter matchSet: The module instances to pass to the produce closure. /// - Returns: A sequence of modules that the produce closure returns. - public func produce(_ matchSet: ModuleSet) async -> [Module] { + public func produce(_ matchSet: ModuleSet) async -> [any Module] { guard let directInstance = matchSet.directInstance as? DC else { return [] } diff --git a/Sources/Lindenmayer/Rules/RewriteRuleDirectRight.swift b/Sources/Lindenmayer/Rules/RewriteRuleDirectRight.swift index 1d980a9d..8ff73f69 100644 --- a/Sources/Lindenmayer/Rules/RewriteRuleDirectRight.swift +++ b/Sources/Lindenmayer/Rules/RewriteRuleDirectRight.swift @@ -32,7 +32,7 @@ public struct RewriteRuleDirectRight: Rule where DC: Module, RC: Module public var parametricEval: (@Sendable (DC, RC) -> Bool)? /// The signature of the produce closure that provides a module and expects a sequence of modules. - public typealias RightMatchProducesList = @Sendable (DC, RC) -> [Module] + public typealias RightMatchProducesList = @Sendable (DC, RC) -> [any Module] /// The closure that provides the L-system state for the current, previous, and next nodes in the state sequence and expects an array of state elements with which to replace the current state. public let produceClosure: RightMatchProducesList @@ -83,7 +83,7 @@ public struct RewriteRuleDirectRight: Rule where DC: Module, RC: Module /// Invokes the rule's produce closure with the modules provided. /// - Parameter matchSet: The module instances to pass to the produce closure. /// - Returns: A sequence of modules that the produce closure returns. - public func produce(_ matchSet: ModuleSet) -> [Module] { + public func produce(_ matchSet: ModuleSet) -> [any Module] { guard let directInstance = matchSet.directInstance as? DC, let rightInstance = matchSet.rightInstance as? RC else { diff --git a/Sources/Lindenmayer/Rules/RewriteRuleDirectRightDefines.swift b/Sources/Lindenmayer/Rules/RewriteRuleDirectRightDefines.swift index f2671314..198c81fb 100644 --- a/Sources/Lindenmayer/Rules/RewriteRuleDirectRightDefines.swift +++ b/Sources/Lindenmayer/Rules/RewriteRuleDirectRightDefines.swift @@ -35,7 +35,7 @@ public struct RewriteRuleDirectRightDefines: Rule where DC: Modul public let parametricEval: Eval? public typealias Eval = @Sendable (DC, RC, PType) -> Bool /// The signature of the produce closure that provides a module and expects a sequence of modules. - public typealias CombinationMatchProducesList = @Sendable (DC, RC, PType) async -> [Module] + public typealias CombinationMatchProducesList = @Sendable (DC, RC, PType) async -> [any Module] /// The closure that provides the L-system state for the current, previous, and next nodes in the state sequence and expects an array of state elements with which to replace the current state. public let produceClosure: CombinationMatchProducesList @@ -88,7 +88,7 @@ public struct RewriteRuleDirectRightDefines: Rule where DC: Modul /// Invokes the rule's produce closure with the modules provided. /// - Parameter matchSet: The module instances to pass to the produce closure. /// - Returns: A sequence of modules that the produce closure returns. - public func produce(_ matchSet: ModuleSet) async -> [Module] { + public func produce(_ matchSet: ModuleSet) async -> [any Module] { guard let directInstance = matchSet.directInstance as? DC, let rightInstance = matchSet.rightInstance as? RC else { diff --git a/Sources/Lindenmayer/Rules/RewriteRuleDirectRightDefinesRNG.swift b/Sources/Lindenmayer/Rules/RewriteRuleDirectRightDefinesRNG.swift index 061fb856..1e02e7c0 100644 --- a/Sources/Lindenmayer/Rules/RewriteRuleDirectRightDefinesRNG.swift +++ b/Sources/Lindenmayer/Rules/RewriteRuleDirectRightDefinesRNG.swift @@ -38,7 +38,7 @@ public struct RewriteRuleDirectRightDefinesRNG: Rule where public let parametricEval: Eval? public typealias Eval = @Sendable (DC, RC, PType) -> Bool /// The signature of the produce closure that provides a module and expects a sequence of modules. - public typealias CombinationMatchProducesList = @Sendable (DC, RC, PType, RNGWrapper) async -> [Module] + public typealias CombinationMatchProducesList = @Sendable (DC, RC, PType, RNGWrapper) async -> [any Module] /// The closure that provides the L-system state for the current, previous, and next nodes in the state sequence and expects an array of state elements with which to replace the current state. public let produceClosure: CombinationMatchProducesList @@ -93,7 +93,7 @@ public struct RewriteRuleDirectRightDefinesRNG: Rule where /// Invokes the rule's produce closure with the modules provided. /// - Parameter matchSet: The module instances to pass to the produce closure. /// - Returns: A sequence of modules that the produce closure returns. - public func produce(_ matchSet: ModuleSet) async -> [Module] { + public func produce(_ matchSet: ModuleSet) async -> [any Module] { guard let directInstance = matchSet.directInstance as? DC, let rightInstance = matchSet.rightInstance as? RC else { diff --git a/Sources/Lindenmayer/Rules/RewriteRuleDirectRightRNG.swift b/Sources/Lindenmayer/Rules/RewriteRuleDirectRightRNG.swift index bd79173d..a83bd747 100644 --- a/Sources/Lindenmayer/Rules/RewriteRuleDirectRightRNG.swift +++ b/Sources/Lindenmayer/Rules/RewriteRuleDirectRightRNG.swift @@ -35,7 +35,7 @@ public struct RewriteRuleDirectRightRNG: Rule where DC: Module, RC public var parametricEval: (@Sendable (DC, RC) -> Bool)? /// The signature of the produce closure that provides a module and expects a sequence of modules. - public typealias CombinationMatchProducesList = @Sendable (DC, RC, RNGWrapper) async -> [Module] + public typealias CombinationMatchProducesList = @Sendable (DC, RC, RNGWrapper) async -> [any Module] /// The closure that provides the L-system state for the current, previous, and next nodes in the state sequence and expects an array of state elements with which to replace the current state. public let produceClosure: CombinationMatchProducesList @@ -88,7 +88,7 @@ public struct RewriteRuleDirectRightRNG: Rule where DC: Module, RC /// Invokes the rule's produce closure with the modules provided. /// - Parameter matchSet: The module instances to pass to the produce closure. /// - Returns: A sequence of modules that the produce closure returns. - public func produce(_ matchSet: ModuleSet) async -> [Module] { + public func produce(_ matchSet: ModuleSet) async -> [any Module] { guard let directInstance = matchSet.directInstance as? DC, let rightInstance = matchSet.rightInstance as? RC else { diff --git a/Sources/Lindenmayer/Rules/RewriteRuleLeftDirect.swift b/Sources/Lindenmayer/Rules/RewriteRuleLeftDirect.swift index 334fa33a..200f4c69 100644 --- a/Sources/Lindenmayer/Rules/RewriteRuleLeftDirect.swift +++ b/Sources/Lindenmayer/Rules/RewriteRuleLeftDirect.swift @@ -32,7 +32,7 @@ public struct RewriteRuleLeftDirect: Rule where LC: Module, DC: Module { public var parametricEval: (@Sendable (LC, DC) -> Bool)? /// The signature of the produce closure that provides a module and expects a sequence of modules. - public typealias LeftMatchProducesList = @Sendable (LC, DC) -> [Module] + public typealias LeftMatchProducesList = @Sendable (LC, DC) -> [any Module] /// The closure that provides the L-system state for the current, previous, and next nodes in the state sequence and expects an array of state elements with which to replace the current state. public let produceClosure: LeftMatchProducesList @@ -84,7 +84,7 @@ public struct RewriteRuleLeftDirect: Rule where LC: Module, DC: Module { /// Invokes the rule's produce closure with the modules provided. /// - Parameter matchSet: The module instances to pass to the produce closure. /// - Returns: A sequence of modules that the produce closure returns. - public func produce(_ matchSet: ModuleSet) -> [Module] { + public func produce(_ matchSet: ModuleSet) -> [any Module] { guard let directInstance = matchSet.directInstance as? DC, let leftInstance = matchSet.leftInstance as? LC else { diff --git a/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectDefines.swift b/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectDefines.swift index 9bbffde7..f25da678 100644 --- a/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectDefines.swift +++ b/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectDefines.swift @@ -35,7 +35,7 @@ public struct RewriteRuleLeftDirectDefines: Rule where LC: Module public let parametricEval: Eval? public typealias Eval = @Sendable (LC, DC, PType) -> Bool /// The signature of the produce closure that provides a module and expects a sequence of modules. - public typealias CombinationMatchProducesList = @Sendable (LC, DC, PType) async -> [Module] + public typealias CombinationMatchProducesList = @Sendable (LC, DC, PType) async -> [any Module] /// The closure that provides the L-system state for the current, previous, and next nodes in the state sequence and expects an array of state elements with which to replace the current state. public let produceClosure: CombinationMatchProducesList @@ -89,7 +89,7 @@ public struct RewriteRuleLeftDirectDefines: Rule where LC: Module /// Invokes the rule's produce closure with the modules provided. /// - Parameter matchSet: The module instances to pass to the produce closure. /// - Returns: A sequence of modules that the produce closure returns. - public func produce(_ matchSet: ModuleSet) async -> [Module] { + public func produce(_ matchSet: ModuleSet) async -> [any Module] { guard let leftInstance = matchSet.leftInstance as? LC, let directInstance = matchSet.directInstance as? DC diff --git a/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectDefinesRNG.swift b/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectDefinesRNG.swift index 66f68f4e..bd07b6e2 100644 --- a/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectDefinesRNG.swift +++ b/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectDefinesRNG.swift @@ -39,7 +39,7 @@ public struct RewriteRuleLeftDirectDefinesRNG: Rule where L public let parametricEval: Eval? public typealias Eval = @Sendable (LC, DC, PType) -> Bool /// The signature of the produce closure that provides a module and expects a sequence of modules. - public typealias CombinationMatchProducesList = @Sendable (LC, DC, PType, RNGWrapper) async -> [Module] + public typealias CombinationMatchProducesList = @Sendable (LC, DC, PType, RNGWrapper) async -> [any Module] /// The closure that provides the L-system state for the current, previous, and next nodes in the state sequence and expects an array of state elements with which to replace the current state. public let produceClosure: CombinationMatchProducesList @@ -95,7 +95,7 @@ public struct RewriteRuleLeftDirectDefinesRNG: Rule where L /// Invokes the rule's produce closure with the modules provided. /// - Parameter matchSet: The module instances to pass to the produce closure. /// - Returns: A sequence of modules that the produce closure returns. - public func produce(_ matchSet: ModuleSet) async -> [Module] { + public func produce(_ matchSet: ModuleSet) async -> [any Module] { guard let leftInstance = matchSet.leftInstance as? LC, let directInstance = matchSet.directInstance as? DC else { diff --git a/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRNG.swift b/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRNG.swift index be22e8d2..c62bdaee 100644 --- a/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRNG.swift +++ b/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRNG.swift @@ -35,7 +35,7 @@ public struct RewriteRuleLeftDirectRNG: Rule where LC: Module, DC: public var parametricEval: (@Sendable (LC, DC) -> Bool)? /// The signature of the produce closure that provides a module and expects a sequence of modules. - public typealias CombinationMatchProducesList = @Sendable (LC, DC, RNGWrapper) async -> [Module] + public typealias CombinationMatchProducesList = @Sendable (LC, DC, RNGWrapper) async -> [any Module] /// The closure that provides the L-system state for the current, previous, and next nodes in the state sequence and expects an array of state elements with which to replace the current state. public let produceClosure: CombinationMatchProducesList @@ -88,7 +88,7 @@ public struct RewriteRuleLeftDirectRNG: Rule where LC: Module, DC: /// Invokes the rule's produce closure with the modules provided. /// - Parameter matchSet: The module instances to pass to the produce closure. /// - Returns: A sequence of modules that the produce closure returns. - public func produce(_ matchSet: ModuleSet) async -> [Module] { + public func produce(_ matchSet: ModuleSet) async -> [any Module] { guard let leftInstance = matchSet.leftInstance as? LC, let directInstance = matchSet.directInstance as? DC else { diff --git a/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRight.swift b/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRight.swift index 75ac9afd..03bf918f 100644 --- a/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRight.swift +++ b/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRight.swift @@ -32,7 +32,7 @@ public struct RewriteRuleLeftDirectRight: Rule where LC: Module, DC: public var parametricEval: (@Sendable (LC, DC, RC) -> Bool)? /// The signature of the produce closure that provides a module and expects a sequence of modules. - public typealias CombinationMatchProducesList = @Sendable (LC, DC, RC) -> [Module] + public typealias CombinationMatchProducesList = @Sendable (LC, DC, RC) -> [any Module] /// The closure that provides the L-system state for the current, previous, and next nodes in the state sequence and expects an array of state elements with which to replace the current state. public let produceClosure: CombinationMatchProducesList @@ -84,7 +84,7 @@ public struct RewriteRuleLeftDirectRight: Rule where LC: Module, DC: /// Invokes the rule's produce closure with the modules provided. /// - Parameter matchSet: The module instances to pass to the produce closure. /// - Returns: A sequence of modules that the produce closure returns. - public func produce(_ matchSet: ModuleSet) -> [Module] { + public func produce(_ matchSet: ModuleSet) -> [any Module] { guard let leftInstance = matchSet.leftInstance as? LC, let directInstance = matchSet.directInstance as? DC, let rightInstance = matchSet.rightInstance as? RC diff --git a/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRightDefines.swift b/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRightDefines.swift index 5f4730b6..c0224c30 100644 --- a/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRightDefines.swift +++ b/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRightDefines.swift @@ -35,7 +35,7 @@ public struct RewriteRuleLeftDirectRightDefines: Rule where L public let parametricEval: Eval? public typealias Eval = @Sendable (LC, DC, RC, PType) -> Bool /// The signature of the produce closure that provides a module and expects a sequence of modules. - public typealias CombinationMatchProducesList = @Sendable (LC, DC, RC, PType) async -> [Module] + public typealias CombinationMatchProducesList = @Sendable (LC, DC, RC, PType) async -> [any Module] /// The closure that provides the L-system state for the current, previous, and next nodes in the state sequence and expects an array of state elements with which to replace the current state. public let produceClosure: CombinationMatchProducesList @@ -90,7 +90,7 @@ public struct RewriteRuleLeftDirectRightDefines: Rule where L /// Invokes the rule's produce closure with the modules provided. /// - Parameter matchSet: The module instances to pass to the produce closure. /// - Returns: A sequence of modules that the produce closure returns. - public func produce(_ matchSet: ModuleSet) async -> [Module] { + public func produce(_ matchSet: ModuleSet) async -> [any Module] { guard let leftInstance = matchSet.leftInstance as? LC, let directInstance = matchSet.directInstance as? DC, let rightInstance = matchSet.rightInstance as? RC diff --git a/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRightDefinesRNG.swift b/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRightDefinesRNG.swift index 9abe2131..35e7d1cd 100644 --- a/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRightDefinesRNG.swift +++ b/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRightDefinesRNG.swift @@ -39,7 +39,7 @@ public struct RewriteRuleLeftDirectRightDefinesRNG: Rul public let parametricEval: Eval? public typealias Eval = @Sendable (LC, DC, RC, PType) -> Bool /// The signature of the produce closure that provides a module and expects a sequence of modules. - public typealias CombinationMatchProducesList = @Sendable (LC, DC, RC, PType, RNGWrapper) async -> [Module] + public typealias CombinationMatchProducesList = @Sendable (LC, DC, RC, PType, RNGWrapper) async -> [any Module] /// The closure that provides the L-system state for the current, previous, and next nodes in the state sequence and expects an array of state elements with which to replace the current state. public let produceClosure: CombinationMatchProducesList @@ -96,7 +96,7 @@ public struct RewriteRuleLeftDirectRightDefinesRNG: Rul /// Invokes the rule's produce closure with the modules provided. /// - Parameter matchSet: The module instances to pass to the produce closure. /// - Returns: A sequence of modules that the produce closure returns. - public func produce(_ matchSet: ModuleSet) async -> [Module] { + public func produce(_ matchSet: ModuleSet) async -> [any Module] { guard let leftInstance = matchSet.leftInstance as? LC, let directInstance = matchSet.directInstance as? DC, let rightInstance = matchSet.rightInstance as? RC diff --git a/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRightRNG.swift b/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRightRNG.swift index f41a1c79..d8ba0752 100644 --- a/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRightRNG.swift +++ b/Sources/Lindenmayer/Rules/RewriteRuleLeftDirectRightRNG.swift @@ -35,7 +35,7 @@ public struct RewriteRuleLeftDirectRightRNG: Rule where LC: Mo public var parametricEval: (@Sendable (LC, DC, RC) -> Bool)? /// The signature of the produce closure that provides a module and expects a sequence of modules. - public typealias CombinationMatchProducesList = @Sendable (LC, DC, RC, RNGWrapper) async -> [Module] + public typealias CombinationMatchProducesList = @Sendable (LC, DC, RC, RNGWrapper) async -> [any Module] /// The closure that provides the L-system state for the current, previous, and next nodes in the state sequence and expects an array of state elements with which to replace the current state. public let produceClosure: CombinationMatchProducesList @@ -89,7 +89,7 @@ public struct RewriteRuleLeftDirectRightRNG: Rule where LC: Mo /// Invokes the rule's produce closure with the modules provided. /// - Parameter matchSet: The module instances to pass to the produce closure. /// - Returns: A sequence of modules that the produce closure returns. - public func produce(_ matchSet: ModuleSet) async -> [Module] { + public func produce(_ matchSet: ModuleSet) async -> [any Module] { guard let leftInstance = matchSet.leftInstance as? LC, let directInstance = matchSet.directInstance as? DC, let rightInstance = matchSet.rightInstance as? RC diff --git a/Sources/Lindenmayer/Rules/Rule.swift b/Sources/Lindenmayer/Rules/Rule.swift index 6791c42d..29bb2c85 100644 --- a/Sources/Lindenmayer/Rules/Rule.swift +++ b/Sources/Lindenmayer/Rules/Rule.swift @@ -26,5 +26,5 @@ public protocol Rule: Sendable { /// Returns a sequence of modules based on the existing module, and potentially it's contextual position with the module to the right and left. /// - Returns: The sequence of modules that replaces the current module during evolution. - func produce(_ matchSet: ModuleSet) async -> [Module] + func produce(_ matchSet: ModuleSet) async -> [any Module] } diff --git a/Sources/LindenmayerViews/Debug/RollToVerticalTestView.swift b/Sources/LindenmayerViews/Debug/RollToVerticalTestView.swift index 3e1d8c5f..0e660923 100644 --- a/Sources/LindenmayerViews/Debug/RollToVerticalTestView.swift +++ b/Sources/LindenmayerViews/Debug/RollToVerticalTestView.swift @@ -9,7 +9,7 @@ import Lindenmayer import SceneKit import SceneKitDebugTools import simd -import SwiftUI +public import SwiftUI @MainActor public struct RollToVerticalTestView: View { diff --git a/Sources/LindenmayerViews/Dynamic2DLSystemViews.swift b/Sources/LindenmayerViews/Dynamic2DLSystemViews.swift index 09eec172..3e8e84c0 100644 --- a/Sources/LindenmayerViews/Dynamic2DLSystemViews.swift +++ b/Sources/LindenmayerViews/Dynamic2DLSystemViews.swift @@ -5,7 +5,7 @@ // Created by Joseph Heck on 12/15/21. // -import Lindenmayer +public import Lindenmayer 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. @@ -21,7 +21,7 @@ public struct Dynamic2DLSystemViews: View { case barnsleyFern public var id: String { rawValue } /// The example seed L-system - public var lsystem: LindenmayerSystem { + public var lsystem: any LindenmayerSystem { switch self { case .algae: Examples2D.algae diff --git a/Sources/LindenmayerViews/Examples/Monopodial4Examples.swift b/Sources/LindenmayerViews/Examples/Monopodial4Examples.swift index b4db1f0b..d8fadcaa 100644 --- a/Sources/LindenmayerViews/Examples/Monopodial4Examples.swift +++ b/Sources/LindenmayerViews/Examples/Monopodial4Examples.swift @@ -7,16 +7,16 @@ import Lindenmayer import SceneKit -import SwiftUI +public import SwiftUI /// A view that presents the 4 SceneKit scenes that include example trees with a monopodial structure built in to Lindenmayer. /// /// The set of trees match the examples of figure 2.6 in [The Algorithmic Beauty of Plants](http://algorithmicbotany.org/papers/abop/abop.pdf) on page 56. public struct Monopodial4Examples: View { - @State var system1: LindenmayerSystem - @State var system2: LindenmayerSystem - @State var system3: LindenmayerSystem - @State var system4: LindenmayerSystem + @State var system1: any LindenmayerSystem + @State var system2: any LindenmayerSystem + @State var system3: any LindenmayerSystem + @State var system4: any LindenmayerSystem let renderer = SceneKitRenderer() public var body: some View { VStack { diff --git a/Sources/LindenmayerViews/Examples/Sympodial4Examples.swift b/Sources/LindenmayerViews/Examples/Sympodial4Examples.swift index 92807f72..04b18c24 100644 --- a/Sources/LindenmayerViews/Examples/Sympodial4Examples.swift +++ b/Sources/LindenmayerViews/Examples/Sympodial4Examples.swift @@ -7,16 +7,16 @@ import Lindenmayer import SceneKit -import SwiftUI +public import SwiftUI /// A view that presents the 4 SceneKit scenes that include example trees with a sympodial structure built in to Lindenmayer. /// /// The set of trees match the example in figure 2.7 of [The Algorithmic Beauty of Plants](http://algorithmicbotany.org/papers/abop/abop.pdf) on page 59. public struct Sympodial4Examples: View { - @State var system1: LindenmayerSystem - @State var system2: LindenmayerSystem - @State var system3: LindenmayerSystem - @State var system4: LindenmayerSystem + @State var system1: any LindenmayerSystem + @State var system2: any LindenmayerSystem + @State var system3: any LindenmayerSystem + @State var system4: any LindenmayerSystem let renderer = SceneKitRenderer() public var body: some View { VStack { diff --git a/Sources/LindenmayerViews/LSystem3DControlView.swift b/Sources/LindenmayerViews/LSystem3DControlView.swift index 51c11b0b..3aed99ba 100644 --- a/Sources/LindenmayerViews/LSystem3DControlView.swift +++ b/Sources/LindenmayerViews/LSystem3DControlView.swift @@ -5,7 +5,7 @@ // Created by Joseph Heck on 1/8/22. // -import Lindenmayer +public import Lindenmayer import SceneKit import SceneKitDebugTools import SwiftUI diff --git a/Sources/LindenmayerViews/LSystem3DModel.swift b/Sources/LindenmayerViews/LSystem3DModel.swift index 415bdaed..8d80f738 100644 --- a/Sources/LindenmayerViews/LSystem3DModel.swift +++ b/Sources/LindenmayerViews/LSystem3DModel.swift @@ -5,10 +5,10 @@ // Created by Joseph Heck on 1/8/22. // -@preconcurrency import Combine +@preconcurrency public import Combine import Foundation -import Lindenmayer -import SceneKit +public import Lindenmayer +public import SceneKit import SceneKitDebugTools import SwiftUI /// A class that provides an observable model around a base L-system. @@ -17,7 +17,7 @@ import SwiftUI /// The model emits `ObservableObject` change notifications when the number of iterations is changed. @MainActor public class LSystem3DModel: ObservableObject { - @Published public var system: LindenmayerSystem + @Published public var system: any LindenmayerSystem let renderer = SceneKitRenderer() let _baseSystem = Examples3D.sympodialTree @@ -62,7 +62,7 @@ public class LSystem3DModel: ObservableObject { /// Creates a new L-System model with the L-System you provide. /// - Parameter system: The L-System to expose and control with the model. - public init(system: LindenmayerSystem) { + public init(system: any LindenmayerSystem) { self.system = system objectWillChange = ObservableObjectPublisher() (_scene, _transformSequence) = renderer.generateScene(lsystem: _baseSystem) diff --git a/Sources/LindenmayerViews/Lsystem2DView.swift b/Sources/LindenmayerViews/Lsystem2DView.swift index 7a5c34a3..1eea550b 100644 --- a/Sources/LindenmayerViews/Lsystem2DView.swift +++ b/Sources/LindenmayerViews/Lsystem2DView.swift @@ -5,7 +5,7 @@ // Created by Joseph Heck on 12/12/21. // -import Lindenmayer +public import Lindenmayer import SwiftUI /// A view that provides a 2D rendering of the L-system provide, and optionally metrics associated with the L-system. @@ -14,7 +14,7 @@ import SwiftUI public struct Lsystem2DView: View { let iterations: Int let displayMetrics: Bool - @State var system: LindenmayerSystem + @State var system: any LindenmayerSystem let renderer = GraphicsContextRenderer() public var body: some View { VStack { @@ -29,7 +29,7 @@ public struct Lsystem2DView: View { } } - public init(system: LindenmayerSystem, iterations: Int, displayMetrics: Bool = false) { + public init(system: any LindenmayerSystem, iterations: Int, displayMetrics: Bool = false) { self.system = system self.iterations = iterations self.displayMetrics = displayMetrics diff --git a/Sources/LindenmayerViews/Lsystem3DView.swift b/Sources/LindenmayerViews/Lsystem3DView.swift index 7bf764e6..fc87e178 100644 --- a/Sources/LindenmayerViews/Lsystem3DView.swift +++ b/Sources/LindenmayerViews/Lsystem3DView.swift @@ -5,7 +5,7 @@ // Created by Joseph Heck on 12/18/21. // -import Lindenmayer +public import Lindenmayer import SceneKit import SwiftUI @@ -13,7 +13,7 @@ import SwiftUI @MainActor public struct Lsystem3DView: View { let displayMetrics: Bool - @State var system: LindenmayerSystem + @State var system: any LindenmayerSystem func generateScene() -> SCNScene { let x = SceneKitRenderer() return x.generateScene(lsystem: system).0 @@ -52,7 +52,7 @@ public struct Lsystem3DView: View { } } - public init(system: LindenmayerSystem, displayMetrics: Bool = false) { + public init(system: any LindenmayerSystem, displayMetrics: Bool = false) { self.displayMetrics = displayMetrics self.system = system } diff --git a/Sources/LindenmayerViews/ViewComponents/EmptyModuleSummaryView.swift b/Sources/LindenmayerViews/ViewComponents/EmptyModuleSummaryView.swift index 442c72be..44e72dbc 100644 --- a/Sources/LindenmayerViews/ViewComponents/EmptyModuleSummaryView.swift +++ b/Sources/LindenmayerViews/ViewComponents/EmptyModuleSummaryView.swift @@ -5,7 +5,7 @@ // Created by Joseph Heck on 1/13/22. // -import SwiftUI +public import SwiftUI /// An empty view that takes up the same space as a module summary view. public struct EmptyModuleSummaryView: View { diff --git a/Sources/LindenmayerViews/ViewComponents/HorizontalLSystemStateView.swift b/Sources/LindenmayerViews/ViewComponents/HorizontalLSystemStateView.swift index d1b1fda4..325e4e5d 100644 --- a/Sources/LindenmayerViews/ViewComponents/HorizontalLSystemStateView.swift +++ b/Sources/LindenmayerViews/ViewComponents/HorizontalLSystemStateView.swift @@ -5,14 +5,14 @@ // Created by Joseph Heck on 1/11/22. // -import Lindenmayer +public import Lindenmayer import SwiftUI /// A view that displays a horizontal collection of summary of the modules of an Lsystem at the size choice you provide. @available(macOS 12.0, iOS 15.0, *) public struct HorizontalLSystemStateView: View { let size: SummarySizes - let system: LindenmayerSystem + let system: any LindenmayerSystem public var body: some View { HStack(alignment: .top, spacing: 1) { ForEach(0 ..< system.state.count, id: \.self) { @@ -22,7 +22,7 @@ public struct HorizontalLSystemStateView: View { } } - public init(size: SummarySizes, system: LindenmayerSystem) { + public init(size: SummarySizes, system: any LindenmayerSystem) { self.size = size self.system = system } diff --git a/Sources/LindenmayerViews/ViewComponents/LSystemMetrics.swift b/Sources/LindenmayerViews/ViewComponents/LSystemMetrics.swift index c5b94f98..7a97aa5b 100644 --- a/Sources/LindenmayerViews/ViewComponents/LSystemMetrics.swift +++ b/Sources/LindenmayerViews/ViewComponents/LSystemMetrics.swift @@ -5,12 +5,12 @@ // Created by Joseph Heck on 12/16/21. // -import Lindenmayer +public import Lindenmayer import SwiftUI /// A view that provides the size of the state of an L-system and a textual representation of that state. public struct LSystemMetrics: View { - @State var system: LindenmayerSystem + @State var system: any LindenmayerSystem public var body: some View { VStack { Text("State size: \(system.state.count)") @@ -23,7 +23,7 @@ public struct LSystemMetrics: View { } } - public init(system: LindenmayerSystem) { + public init(system: any LindenmayerSystem) { self.system = system } } diff --git a/Sources/LindenmayerViews/ViewComponents/ModuleDetailView.swift b/Sources/LindenmayerViews/ViewComponents/ModuleDetailView.swift index 3c7aeb86..0a9ad18a 100644 --- a/Sources/LindenmayerViews/ViewComponents/ModuleDetailView.swift +++ b/Sources/LindenmayerViews/ViewComponents/ModuleDetailView.swift @@ -4,7 +4,7 @@ // // Created by Joseph Heck on 1/10/22. // -import Lindenmayer +public import Lindenmayer import SwiftUI /// A view that provides a detailed view of a module. diff --git a/Sources/LindenmayerViews/ViewComponents/ModuleSummaryView.swift b/Sources/LindenmayerViews/ViewComponents/ModuleSummaryView.swift index f5afdc85..802b3c6d 100644 --- a/Sources/LindenmayerViews/ViewComponents/ModuleSummaryView.swift +++ b/Sources/LindenmayerViews/ViewComponents/ModuleSummaryView.swift @@ -4,7 +4,7 @@ // // Created by Joseph Heck on 1/10/22. // -import Lindenmayer +public import Lindenmayer import SwiftUI /// A view that represents a summary view of a single debug module from an L-system at the size you choose. diff --git a/Sources/LindenmayerViews/ViewComponents/StateSelectorView.swift b/Sources/LindenmayerViews/ViewComponents/StateSelectorView.swift index 61b44471..396c181f 100644 --- a/Sources/LindenmayerViews/ViewComponents/StateSelectorView.swift +++ b/Sources/LindenmayerViews/ViewComponents/StateSelectorView.swift @@ -6,14 +6,14 @@ // import Combine -import Lindenmayer +public import Lindenmayer import SwiftUI /// A view that provides a visual representation of the states of an L-system and allows the person viewing it to select an index position from that L-system's state. @available(macOS 12.0, iOS 15.0, *) @MainActor public struct StateSelectorView: View { - @State var system: LindenmayerSystem + @State var system: any LindenmayerSystem let _withDetailView: Bool // state for the related views that show stuff @Binding var indexPosition: Int @@ -194,7 +194,7 @@ public struct StateSelectorView: View { } } - public init(system: LindenmayerSystem, position: Binding, withDetailView: Bool = false) { + public init(system: any LindenmayerSystem, position: Binding, withDetailView: Bool = false) { self.system = system _withDetailView = withDetailView _indexPosition = position diff --git a/Sources/LindenmayerViews/ViewComponents/WindowedSmallModuleView.swift b/Sources/LindenmayerViews/ViewComponents/WindowedSmallModuleView.swift index 15d81b31..fb16806f 100644 --- a/Sources/LindenmayerViews/ViewComponents/WindowedSmallModuleView.swift +++ b/Sources/LindenmayerViews/ViewComponents/WindowedSmallModuleView.swift @@ -5,7 +5,7 @@ // Created by Joseph Heck on 1/10/22. // -import Lindenmayer +public import Lindenmayer import SwiftUI /// A view that displays a window of a set of modules at the index location and window size that you choose for the L-system you provide. @@ -14,7 +14,7 @@ import SwiftUI @available(macOS 12.0, iOS 15.0, *) public struct WindowedSmallModuleView: View { let size: SummarySizes - @State var system: LindenmayerSystem + @State var system: any LindenmayerSystem let position: Int let windowSize: Int @@ -99,7 +99,7 @@ public struct WindowedSmallModuleView: View { } } - public init(size: SummarySizes, system: LindenmayerSystem, position: Int, windowSize: Int = 9) { + public init(size: SummarySizes, system: any LindenmayerSystem, position: Int, windowSize: Int = 9) { self.size = size self.system = system self.position = position diff --git a/Tests/LindenmayerTests/RollUpToVerticalTests.swift b/Tests/LindenmayerTests/RollUpToVerticalTests.swift index d8c6e53c..459a137e 100644 --- a/Tests/LindenmayerTests/RollUpToVerticalTests.swift +++ b/Tests/LindenmayerTests/RollUpToVerticalTests.swift @@ -15,7 +15,7 @@ final class RollUpToVerticalTests: XCTestCase { // NOTE(heckj): When transcribing a 4x4 matrix, the initializer uses // 'COLUMNS', not rows - so create simd_float4x4 matrices by vertical columns: // top to bottom, left to right. - static var transform_119 = simd_float4x4( + static let transform_119 = simd_float4x4( simd_float4(-1.1513867, -0.12829041, 2.2153668, 0.0), simd_float4(2.173691, 0.43699712, 1.155033, 0.0), simd_float4(-0.44651538, 2.458165, -0.08971556, 0.0), diff --git a/Tests/LindenmayerTests/RuleTests.swift b/Tests/LindenmayerTests/RuleTests.swift index e528b15b..3499230b 100644 --- a/Tests/LindenmayerTests/RuleTests.swift +++ b/Tests/LindenmayerTests/RuleTests.swift @@ -6,8 +6,6 @@ final class RuleTests: XCTestCase { var name: String = "foo" } - let foo = Foo() - func testRuleDefaults() throws { let r = RewriteRuleDirectRNG(directType: Examples2D.Internode.self, prng: RNGWrapper(Xoshiro(seed: 0)), @@ -18,7 +16,7 @@ final class RuleTests: XCTestCase { return [ctx] } XCTAssertNotNil(r) - let moduleSet = ModuleSet(directInstance: foo) + let moduleSet = ModuleSet(directInstance: Foo()) XCTAssertEqual(r.evaluate(moduleSet), false) } @@ -27,7 +25,7 @@ final class RuleTests: XCTestCase { prng: RNGWrapper(Xoshiro(seed: 0)), where: nil) { _, _ -> [Module] in - [self.foo] + [Foo()] } let moduleSet = ModuleSet(directInstance: Examples2D.Internode()) @@ -39,9 +37,9 @@ final class RuleTests: XCTestCase { prng: RNGWrapper(Xoshiro(seed: 0)), where: nil) { _, _ -> [Module] in - [self.foo] + [Foo()] } - let moduleSet = ModuleSet(directInstance: foo) + let moduleSet = ModuleSet(directInstance: Foo()) XCTAssertEqual(r.evaluate(moduleSet), false) } @@ -50,7 +48,7 @@ final class RuleTests: XCTestCase { prng: RNGWrapper(Xoshiro(seed: 0)), where: nil) { _, _ -> [Module] in - [self.foo] + [Foo()] } let moduleSet = ModuleSet(leftInstance: nil, directInstance: Examples2D.Internode(), @@ -63,7 +61,7 @@ final class RuleTests: XCTestCase { prng: RNGWrapper(Xoshiro(seed: 0)), where: nil) { _, _ -> [Module] in - [self.foo] + [Foo()] } let moduleSet = ModuleSet(leftInstance: Foo(), directInstance: Examples2D.Internode(), @@ -77,7 +75,7 @@ final class RuleTests: XCTestCase { prng: RNGWrapper(Xoshiro(seed: 0)), where: nil) { _, _ -> [Module] in - [self.foo] + [Foo()] } let moduleSet = ModuleSet(leftInstance: Foo(), directInstance: Examples2D.Internode(),