Skip to content

Commit

Permalink
applying swiftformat 5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
heckj committed Apr 12, 2024
1 parent caf0033 commit f437389
Show file tree
Hide file tree
Showing 31 changed files with 83 additions and 82 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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/apple/swift-docc-plugin", from: "1.0.0"),
],
targets: [
.target(
Expand Down
12 changes: 6 additions & 6 deletions Sources/Lindenmayer/LSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ public enum LSystem: Sendable {
/// - Parameters:
/// - axiom: An initial module that represents the initial state of the Lindenmayer system..
public static func create(_ axiom: Module) -> ContextualLSystem {
return ContextualLSystem([axiom], state: nil, newStateIndicators: nil)
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 {
return ContextualLSystem(axiom, state: nil, newStateIndicators: nil)
ContextualLSystem(axiom, state: nil, newStateIndicators: nil)
}

/// Creates a new Lindenmayer system from an initial state and using the random number generator you provide.
/// - 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<RNGType>(_ axiom: Module, with prng: RNGType?) -> RandomContextualLSystem<RNGType> {
if let prng = prng {
if let prng {
return RandomContextualLSystem(axiom: [axiom], state: nil, newStateIndicators: nil, prng: RNGWrapper(prng))
}
return RandomContextualLSystem(axiom: [axiom], state: nil, newStateIndicators: nil, prng: RNGWrapper(Xoshiro(seed: 42) as! RNGType))
Expand All @@ -67,7 +67,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.
public static func create<RNGType>(_ axiom: [Module], with prng: RNGType?) -> RandomContextualLSystem<RNGType> {
if let prng = prng {
if let prng {
return RandomContextualLSystem(axiom: axiom, state: nil, newStateIndicators: nil, prng: RNGWrapper(prng))
}
return RandomContextualLSystem(axiom: axiom, state: nil, newStateIndicators: nil, prng: RNGWrapper(Xoshiro(seed: 42) as! RNGType))
Expand All @@ -79,7 +79,7 @@ public enum LSystem: Sendable {
/// - 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<PType, RNGType>(_ axiom: Module, with prng: RNGType?, using parameters: PType) -> ParameterizedRandomContextualLSystem<PType, RNGType> {
if let prng = prng {
if let prng {
return ParameterizedRandomContextualLSystem(axiom: [axiom], state: nil, newStateIndicators: nil, parameters: ParametersWrapper(parameters), prng: RNGWrapper(prng), rules: [])
}
return ParameterizedRandomContextualLSystem(axiom: [axiom], state: nil, newStateIndicators: nil, parameters: ParametersWrapper(parameters), prng: RNGWrapper(Xoshiro(seed: 42) as! RNGType), rules: [])
Expand All @@ -91,7 +91,7 @@ public enum LSystem: Sendable {
/// - 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<PType, RNGType>(_ axiom: [Module], with prng: RNGType?, using parameters: PType) -> ParameterizedRandomContextualLSystem<PType, RNGType> {
if let prng = prng {
if let prng {
return ParameterizedRandomContextualLSystem(axiom: axiom, state: nil, newStateIndicators: nil, parameters: ParametersWrapper(parameters), prng: RNGWrapper(prng), rules: [])
}
return ParameterizedRandomContextualLSystem(axiom: axiom, state: nil, newStateIndicators: nil, parameters: ParametersWrapper(parameters), prng: RNGWrapper(Xoshiro(seed: 42) as! RNGType), rules: [])
Expand Down
8 changes: 4 additions & 4 deletions Sources/Lindenmayer/LSystemTypes/ContextualLSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ public struct ContextualLSystem: LindenmayerSystem {
rules: [Rule] = [])
{
self.axiom = axiom
if let state = state {
if let state {
self.state = state
} else {
self.state = axiom
}
if let newStateIndicators = newStateIndicators {
if let newStateIndicators {
self.newStateIndicators = newStateIndicators
} else {
var stateIndicators: [Bool] = []
Expand All @@ -114,13 +114,13 @@ 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 {
return ContextualLSystem(axiom, state: state, newStateIndicators: newItemIndicators, rules: rules)
ContextualLSystem(axiom, state: state, newStateIndicators: newItemIndicators, rules: rules)
}

/// Resets the L-system to it's initial state, wiping out an existing state while keeping the rules.
/// - Returns: A new L-system with it's state reset to the initial state you set when you created the L-system.
public func reset() -> Self {
return ContextualLSystem(axiom, state: nil, newStateIndicators: newStateIndicators, rules: rules)
ContextualLSystem(axiom, state: nil, newStateIndicators: newStateIndicators, rules: rules)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ public struct ParameterizedRandomContextualLSystem<PType, PRNG>: LindenmayerSyst
// environment that can be evolved based on the rules available.
initialParameters = parameters.unwrap()
self.axiom = axiom
if let state = state {
if let state {
self.state = state
} else {
self.state = axiom
}
if let newStateIndicators = newStateIndicators {
if let newStateIndicators {
self.newStateIndicators = newStateIndicators
} else {
var stateIndicators: [Bool] = []
Expand All @@ -150,7 +150,7 @@ public struct ParameterizedRandomContextualLSystem<PType, PRNG>: 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 {
return ParameterizedRandomContextualLSystem<PType, PRNG>(axiom: axiom, state: state, newStateIndicators: newItemIndicators, parameters: parameters, prng: prng, rules: rules)
ParameterizedRandomContextualLSystem<PType, PRNG>(axiom: axiom, state: state, newStateIndicators: newItemIndicators, parameters: parameters, prng: prng, rules: rules)
}

public func reset() -> Self {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Lindenmayer/LSystemTypes/ParametersWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class ParametersWrapper<PType> {

/// Returns the value type that the parameter wrapper encapsulates.
public func unwrap() -> PType {
return _parameters
_parameters
}

/// Creates a new random number generator wrapper class with the random number generator you provide.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ public struct RandomContextualLSystem<PRNG>: LindenmayerSystem where PRNG: Seede
rules: [Rule] = [])
{
self.axiom = axiom
if let state = state {
if let state {
self.state = state
} else {
self.state = axiom
}
if let newStateIndicators = newStateIndicators {
if let newStateIndicators {
self.newStateIndicators = newStateIndicators
} else {
self.newStateIndicators = []
Expand All @@ -123,7 +123,7 @@ public struct RandomContextualLSystem<PRNG>: 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 {
return RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newItemIndicators, prng: prng, rules: rules)
RandomContextualLSystem(axiom: axiom, state: state, newStateIndicators: newItemIndicators, prng: prng, rules: rules)
}

/// Resets the L-system to it's initial state, wiping out an existing state while keeping the rules.
Expand Down
4 changes: 2 additions & 2 deletions Sources/Lindenmayer/LindenmayerSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public extension LindenmayerSystem {
/// If any modules aren't available, they are `nil`.
func modules(atIndex: Int) -> ModuleSet {
let strict = state[atIndex]

var leftInstance: (any Module)? = nil
if atIndex - 1 > 0 {
leftInstance = state[atIndex - 1]
Expand All @@ -94,7 +94,7 @@ public extension LindenmayerSystem {
if state.count > atIndex + 1 {
let rightInstance = state[atIndex + 1]
}

return ModuleSet(leftInstance: leftInstance, directInstance: strict, rightInstance: rightInstance)
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Lindenmayer/Modules/Module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public protocol Module: CustomStringConvertible, Sendable {
public extension Module {
/// The sequence of two-dimensional oriented rendering commands that you use to represent the module.
var render2D: [TwoDRenderCmd] {
return []
[]
}

/// The three-dimensional oriented rendering command that you use to represent the module.
var render3D: ThreeDRenderCmd {
return RenderCommand.Ignore()
RenderCommand.Ignore()
}
}

Expand Down
7 changes: 4 additions & 3 deletions Sources/Lindenmayer/Rendering/Angle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation
#if canImport(SwiftUI)
@_exported import SwiftUI

/// A geometric angle whose value you access in either radians or degrees.
public typealias Angle = SwiftUI.Angle
#else
Expand Down Expand Up @@ -38,7 +39,7 @@ import Foundation

/// The value of the angle in degrees.
@inlinable public var degrees: Double {
return radians * 180.0 / .pi
radians * 180.0 / .pi
}

/// Creates a new Angle of zero radians.
Expand All @@ -58,11 +59,11 @@ import Foundation

/// Creates a new Angle with the value of radians you provide.
@inlinable public static func radians(_ radians: Double) -> Angle {
return Angle(radians: radians)
Angle(radians: radians)
}

/// Creates a new Angle with the value of degrees you provide.
@inlinable public static func degrees(_ degrees: Double) -> Angle {
return Angle(degrees: degrees)
Angle(degrees: degrees)
}
}
8 changes: 4 additions & 4 deletions Sources/Lindenmayer/Rendering/GraphicsContextRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public struct GraphicsContextRenderer {
/// - 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) {
if let size = size {
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.
let boundingBox = calcBoundingRect(system: lsystem)
Expand Down Expand Up @@ -228,7 +228,7 @@ public struct GraphicsContextRenderer {
}
}

guard let destinationRect = destinationRect else {
guard let destinationRect else {
return path
}

Expand Down Expand Up @@ -263,11 +263,11 @@ public struct GraphicsContextRenderer {
}

func updatedStateWithLineWidth(_ state: PathState, lineWidth: Double) -> PathState {
return PathState(state.angle, state.position, lineWidth, state.lineColor)
PathState(state.angle, state.position, lineWidth, state.lineColor)
}

func updatedStateWithLineColor(_ state: PathState, lineColor: ColorRepresentation) -> PathState {
return PathState(state.angle, state.position, state.lineWidth, lineColor)
PathState(state.angle, state.position, state.lineWidth, lineColor)
}

func updatedStateByTurning(_ state: PathState, angle: Angle, direction: TurnDirection)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Lindenmayer/Rendering/RenderCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public struct ColorRepresentation: Equatable, Sendable {
}

static var black: ColorRepresentation {
return ColorRepresentation(r: 0, g: 0, b: 0)
ColorRepresentation(r: 0, g: 0, b: 0)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public extension simd_float4x4 {

public extension Comparable {
func clamped(to limits: ClosedRange<Self>) -> Self {
return min(max(self, limits.lowerBound), limits.upperBound)
min(max(self, limits.lowerBound), limits.upperBound)
}
}
10 changes: 5 additions & 5 deletions Sources/Lindenmayer/Rendering/Transforms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public extension SceneKitRenderer {
/// - z: The amount to translate along the Z axis.
/// - Returns: A translation transform.
static func translationTransform(x: Float, y: Float, z: Float) -> simd_float4x4 {
return simd_float4x4(
simd_float4x4(
SIMD4<Float>(1, 0, 0, 0),
SIMD4<Float>(0, 1, 0, 0),
SIMD4<Float>(0, 0, 1, 0),
Expand All @@ -30,7 +30,7 @@ public extension SceneKitRenderer {
/// - z: The amount to scale along the Z axis.
/// - Returns: A scaling transform.
static func scalingTransform(x: Float, y: Float, z: Float) -> simd_float4x4 {
return simd_float4x4(
simd_float4x4(
SIMD4<Float>(x, 0, 0, 0),
SIMD4<Float>(0, y, 0, 0),
SIMD4<Float>(0, 0, z, 0),
Expand All @@ -42,7 +42,7 @@ public extension SceneKitRenderer {
/// - Parameter angle: The amount (in radians) to rotate around the Z axis.
/// - Returns: A Z-axis rotation transform.
static func rotationAroundZAxisTransform(angle: Angle) -> simd_float4x4 {
return simd_float4x4(
simd_float4x4(
SIMD4<Float>(cos(Float(angle.radians)), sin(Float(angle.radians)), 0, 0),
SIMD4<Float>(-sin(Float(angle.radians)), cos(Float(angle.radians)), 0, 0),
SIMD4<Float>(0, 0, 1, 0),
Expand All @@ -54,7 +54,7 @@ public extension SceneKitRenderer {
/// - Parameter angle: The amount (in radians) to rotate around the X axis.
/// - Returns: A X-axis rotation transform.
static func rotationAroundXAxisTransform(angle: Angle) -> simd_float4x4 {
return simd_float4x4(
simd_float4x4(
SIMD4<Float>(1, 0, 0, 0),
SIMD4<Float>(0, cos(Float(angle.radians)), sin(Float(angle.radians)), 0),
SIMD4<Float>(0, -sin(Float(angle.radians)), cos(Float(angle.radians)), 0),
Expand All @@ -66,7 +66,7 @@ public extension SceneKitRenderer {
/// - Parameter angle: The amount (in radians) to rotate around the Y axis.
/// - Returns: A Y-axis rotation transform.
static func rotationAroundYAxisTransform(angle: Angle) -> simd_float4x4 {
return simd_float4x4(
simd_float4x4(
SIMD4<Float>(cos(Float(angle.radians)), 0, -sin(Float(angle.radians)), 0),
SIMD4<Float>(0, 1, 0, 0),
SIMD4<Float>(sin(Float(angle.radians)), 0, cos(Float(angle.radians)), 0),
Expand Down
2 changes: 1 addition & 1 deletion Sources/Lindenmayer/Rules/RewriteRuleDirect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ public struct RewriteRuleDirect<DC>: Rule where DC: Module {
extension RewriteRuleDirect: CustomStringConvertible {
/// A description of the rule that details what it matches
public var description: String {
return "Rule(direct)(\(String(describing: matchingType)))"
"Rule(direct)(\(String(describing: matchingType)))"
}
}
2 changes: 1 addition & 1 deletion Sources/Lindenmayer/Rules/RewriteRuleDirectDefines.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ public struct RewriteRuleDirectDefines<DC, PType>: Rule where DC: Module {
extension RewriteRuleDirectDefines: CustomStringConvertible {
/// A description of the rule that details what it matches
public var description: String {
return "Rule(direct)(\(String(describing: matchingType)) w/ parameters: \(String(describing: parameters))"
"Rule(direct)(\(String(describing: matchingType)) w/ parameters: \(String(describing: parameters))"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ public struct RewriteRuleDirectDefinesRNG<DC, PType, PRNG>: Rule where DC: Modul
extension RewriteRuleDirectDefinesRNG: CustomStringConvertible {
/// A description of the rule that details what it matches
public var description: String {
return "Rule(direct)(\(String(describing: matchingType)) w/ parameters: \(String(describing: parameters)) and rng"
"Rule(direct)(\(String(describing: matchingType)) w/ parameters: \(String(describing: parameters)) and rng"
}
}
2 changes: 1 addition & 1 deletion Sources/Lindenmayer/Rules/RewriteRuleDirectRNG.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ public struct RewriteRuleDirectRNG<DC, PRNG>: Rule where DC: Module, PRNG: Seede
extension RewriteRuleDirectRNG: CustomStringConvertible {
/// A description of the rule that details what it matches
public var description: String {
return "Rule(direct)(\(String(describing: matchingType)) w/ rng"
"Rule(direct)(\(String(describing: matchingType)) w/ rng"
}
}
2 changes: 1 addition & 1 deletion Sources/Lindenmayer/Rules/RewriteRuleDirectRight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ public struct RewriteRuleDirectRight<DC, RC>: Rule where DC: Module, RC: Module
extension RewriteRuleDirectRight: CustomStringConvertible {
/// A description of the rule that details what it matches
public var description: String {
return "Rule(direct,right)(\(String(describing: matchingTypes))"
"Rule(direct,right)(\(String(describing: matchingTypes))"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ public struct RewriteRuleDirectRightDefines<DC, RC, PType>: Rule where DC: Modul
extension RewriteRuleDirectRightDefines: CustomStringConvertible {
/// A description of the rule that details what it matches
public var description: String {
return "Rule(direct,right)(\(String(describing: matchingTypes)) w/ parameters: \(String(describing: parameters))"
"Rule(direct,right)(\(String(describing: matchingTypes)) w/ parameters: \(String(describing: parameters))"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ public struct RewriteRuleDirectRightDefinesRNG<DC, RC, PType, PRNG>: Rule where
extension RewriteRuleDirectRightDefinesRNG: CustomStringConvertible {
/// A description of the rule that details what it matches
public var description: String {
return "Rule(direct,right)(\(String(describing: matchingTypes)) w/ parameters: \(String(describing: parameters)) and rng"
"Rule(direct,right)(\(String(describing: matchingTypes)) w/ parameters: \(String(describing: parameters)) and rng"
}
}
2 changes: 1 addition & 1 deletion Sources/Lindenmayer/Rules/RewriteRuleDirectRightRNG.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ public struct RewriteRuleDirectRightRNG<DC, RC, PRNG>: Rule where DC: Module, RC
extension RewriteRuleDirectRightRNG: CustomStringConvertible {
/// A description of the rule that details what it matches
public var description: String {
return "Rule(direct,right)(\(String(describing: matchingTypes)) w/ rng"
"Rule(direct,right)(\(String(describing: matchingTypes)) w/ rng"
}
}
2 changes: 1 addition & 1 deletion Sources/Lindenmayer/Rules/RewriteRuleLeftDirect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ public struct RewriteRuleLeftDirect<LC, DC>: Rule where LC: Module, DC: Module {
extension RewriteRuleLeftDirect: CustomStringConvertible {
/// A description of the rule that details what it matches
public var description: String {
return "Rule(left,direct)(\(String(describing: matchingTypes))"
"Rule(left,direct)(\(String(describing: matchingTypes))"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ public struct RewriteRuleLeftDirectDefines<LC, DC, PType>: Rule where LC: Module
extension RewriteRuleLeftDirectDefines: CustomStringConvertible {
/// A description of the rule that details what it matches
public var description: String {
return "Rule(left,direct)(\(String(describing: matchingTypes)) w/ parameters: \(String(describing: parameters))"
"Rule(left,direct)(\(String(describing: matchingTypes)) w/ parameters: \(String(describing: parameters))"
}
}
Loading

0 comments on commit f437389

Please sign in to comment.