Skip to content

Commit

Permalink
Add Sendable conformance for value types
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasf committed Jul 8, 2024
1 parent c9f2b13 commit 5d95ea7
Show file tree
Hide file tree
Showing 28 changed files with 42 additions and 43 deletions.
14 changes: 7 additions & 7 deletions Sources/SwiftSCAD/Environment/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import Foundation
/// `Environment` provides a flexible container for environment-specific values influencing the rendering of geometries.
///
/// You can use `Environment` to customize settings and attributes that affect child geometries within SwiftSCAD. Modifiers allow for dynamic adjustments of the environment, which can be applied to geometries to affect their rendering or behavior.
public struct Environment {
private let values: [ValueKey: Any]
public struct Environment: Sendable {
private let values: [ValueKey: any Sendable]

public init() {
self.init(values: [:])
}

init(values: [ValueKey: Any]) {
init(values: [ValueKey: any Sendable]) {
self.values = values
}

/// Returns a new environment by adding new values to the current environment.
///
/// - Parameter newValues: A dictionary of values to add to the environment.
/// - Returns: A new `Environment` instance with the added values.
public func setting(_ newValues: [ValueKey: Any]) -> Environment {
public func setting(_ newValues: [ValueKey: any Sendable]) -> Environment {
Environment(values: values.merging(newValues, uniquingKeysWith: { $1 }))
}

Expand All @@ -28,7 +28,7 @@ public struct Environment {
/// - key: The key for the value to update or add.
/// - value: The new value to set. If `nil`, the key is removed from the environment.
/// - Returns: A new `Environment` instance with the updated values.
public func setting(key: ValueKey, value: Any?) -> Environment {
public func setting(key: ValueKey, value: (any Sendable)?) -> Environment {
var values = self.values
values[key] = value
return Environment(values: values)
Expand All @@ -38,14 +38,14 @@ public struct Environment {
///
/// - Parameter key: The key of the value to access.
/// - Returns: The value associated with `key` if it exists; otherwise, `nil`.
public subscript(key: ValueKey) -> Any? {
public subscript(key: ValueKey) -> (any Sendable)? {
values[key]
}
}

public extension Environment {
/// Represents a key for environment values.
struct ValueKey: RawRepresentable, Hashable {
struct ValueKey: RawRepresentable, Hashable, Sendable {
public var rawValue: String

public init(rawValue: String) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSCAD/Environment/Facets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

public extension Environment {
/// An enumeration representing the method for calculating the number of facets (or segments) used in rendering circular geometries.
enum Facets {
enum Facets: Sendable {
/// Specifies a fixed number of facets for all circles, regardless of size.
case fixed (Int)

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSCAD/Environment/Operation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public extension Environment {
private static let key = Environment.ValueKey(rawValue: "SwiftSCAD.Operation")

/// Represents a geometric operation, specifically for determining if geometries are being added or subtracted.
enum Operation {
enum Operation: Sendable {
/// Represents the addition of geometries.
case addition
/// Represents the subtraction of geometries, typically used for creating holes or negative spaces within another geometry.
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftSCAD/Operations/Alignment/Alignment.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public enum AxisAlignment: Equatable {
public enum AxisAlignment: Equatable, Sendable {
case min
case mid
case max
Expand All @@ -14,7 +14,7 @@ public enum AxisAlignment: Equatable {
}
}

public struct GeometryAlignment2D: Equatable {
public struct GeometryAlignment2D: Equatable, Sendable {
internal let x: AxisAlignment?
internal let y: AxisAlignment?

Expand All @@ -33,7 +33,7 @@ public struct GeometryAlignment2D: Equatable {
}
}

public struct GeometryAlignment3D: Equatable {
public struct GeometryAlignment3D: Equatable, Sendable {
internal let x: AxisAlignment?
internal let y: AxisAlignment?
internal let z: AxisAlignment?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

/// The profile of an edge
public enum EdgeProfile: Equatable {
public enum EdgeProfile: Equatable, Sendable {
/// Represents an edge modified to be rounded.
/// - Parameter radius: The radius of the curvature applied to the edge, determining the degree of roundness.
case fillet (radius: Double)
Expand Down
3 changes: 1 addition & 2 deletions Sources/SwiftSCAD/Shapes/2D/Text/Environment+Text.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

internal extension Environment {
struct TextAttributes {
struct TextAttributes: Sendable {
var font: String?
var fontStyle: String?
var fontSize: Double?
Expand Down Expand Up @@ -35,7 +35,6 @@ internal extension Environment {
e = e.settingTextAttribute(\.fontSize, value: size)
}
return e

}

func withTextAlignment(horizontal: Text.HorizontalAlignment? = nil, vertical: Text.VerticalAlignment? = nil) -> Environment {
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftSCAD/Shapes/2D/Text/Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public struct Text: Geometry2D {
/// An enumeration representing the horizontal alignment options for text geometry.
///
/// Use these options with ``Geometry2D/usingTextAlignment(horizontal:vertical:)`` to set the horizontal alignment of your text geometry.
public enum HorizontalAlignment: String {
public enum HorizontalAlignment: String, Sendable {
/// Aligns the text to the left.
case left
/// Centers the text horizontally.
Expand All @@ -40,7 +40,7 @@ public struct Text: Geometry2D {
/// - `bottom`: Aligns the text to the bottom.
///
/// Use these options with ``Geometry2D/usingTextAlignment(horizontal:vertical:)`` to set the vertical alignment of your text geometry.
public enum VerticalAlignment: String {
public enum VerticalAlignment: String, Sendable {
/// Aligns the text to the top.
case top
/// Centers the text vertically.
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSCAD/Values/Angle/Angle.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

/// A value representing a geometric angle
public struct Angle {
public struct Angle: Sendable {
/// The angle expressed in radians
public let radians: Double

Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftSCAD/Values/Axis/Axes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public protocol Axes {

/// A set of cartesian axes in two dimensions (X and/or Y)

public struct Axes2D: Axes, OptionSet, Hashable {
public struct Axes2D: Axes, OptionSet, Hashable, Sendable {
public typealias Axis = Axis2D

public let rawValue: Int
Expand Down Expand Up @@ -46,7 +46,7 @@ public struct Axes2D: Axes, OptionSet, Hashable {

/// A set of cartesian axes in three dimensions (X, Y and/or Z)

public struct Axes3D: Axes, OptionSet, Hashable {
public struct Axes3D: Axes, OptionSet, Hashable, Sendable {
public typealias Axis = Axis3D

public let rawValue: Int
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftSCAD/Values/Axis/Axis.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Foundation

/// One of the cartesian axes in two dimensions (X or Y)
public enum Axis2D: Int, CaseIterable {
public enum Axis2D: Int, CaseIterable, Sendable {
case x
case y
}

/// An enumeration representing the three Cartesian axes in a three-dimensional space: X, Y, and Z.
public enum Axis3D: Int, CaseIterable {
public enum Axis3D: Int, CaseIterable, Sendable {
case x
case y
case z
Expand All @@ -28,7 +28,7 @@ public enum Axis3D: Int, CaseIterable {
}

/// A direction along an axis
public enum AxisDirection {
public enum AxisDirection: Sendable {
/// The positive direction along an axis
case positive
/// The negative direction along an axis
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSCAD/Values/Bezier/BezierCurve.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

internal struct BezierCurve <V: Vector> {
internal struct BezierCurve <V: Vector>: Sendable {
let controlPoints: [V]

init(controlPoints: [V]) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSCAD/Values/Bezier/BezierPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public typealias BezierPath3D = BezierPath<Vector3D>
/// You can create a `BezierPath` by providing a starting point and adding curves and line segments to the path. 2D paths can be used to create `Polygon` shapes.
///
/// To create a `BezierPath`, start with the `init(startPoint:)` initializer, specifying the starting point of the path. Then, you can chain calls to `addingLine(to:)`, `addingQuadraticCurve(controlPoint:end:)`, and `addingCubicCurve(controlPoint1:controlPoint2:end:)` to build a complete path.
public struct BezierPath <V: Vector> {
public struct BezierPath <V: Vector>: Sendable {
let startPoint: V
let curves: [BezierCurve<V>]

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSCAD/Values/Boundary/Boundary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
public typealias Boundary2D = Boundary<Vector2D>
public typealias Boundary3D = Boundary<Vector3D>

public struct Boundary<V: Vector> {
public struct Boundary<V: Vector>: Sendable {
internal let points: [V]

internal init(points: [V]) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSCAD/Values/Boundary/BoundingBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public typealias BoundingBox2D = BoundingBox<Vector2D>
public typealias BoundingBox3D = BoundingBox<Vector3D>

/// An axis-aligned bounding volume defined by its minimum and maximum corners, used to calculate and represent the bounding area or volume of shapes or points in a generic vector space.
public struct BoundingBox<V: Vector> {
public struct BoundingBox<V: Vector>: Sendable {
/// The minimum corner point of the bounding volume, typically representing the "lower" corner in geometric space.
public let minimum: V
/// The maximum corner point of the bounding volume, typically representing the "upper" corner in geometric space.
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftSCAD/Values/Color.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation

public enum Color {
public enum Color: Sendable {
case components (red: Double, green: Double, blue: Double, alpha: Double)
case named (Name, alpha: Double)

public enum Name: String {
public enum Name: String, Sendable {
case lavender
case thistle
case plum
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

internal struct RectangleCornerRadii {
internal struct RectangleCornerRadii: Sendable {
let minXminY: Double
let maxXminY: Double
let maxXmaxY: Double
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSCAD/Values/Corners/RectangleCorners.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Foundation
/// `RectangleCorners` allows for specifying and manipulating individual corners or groups of corners of a rectangle.
/// It is used for operations that involve corner-specific modifications, such as rounding corners.

public struct RectangleCorners: OptionSet, Hashable {
public struct RectangleCorners: OptionSet, Hashable, Sendable {
public let rawValue: Int

public init(rawValue: Int) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSCAD/Values/Corners/RoundedCornerStyle.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

/// Represents the style of rounded corners.
public enum RoundedCornerStyle {
public enum RoundedCornerStyle: Sendable {
/// A regular circular corner.
case circular
/// A squircular corner, forming a more natural and continuous curve.
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftSCAD/Values/Rotation3D.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation

/// A structure representing a rotation in 3D space.
public struct Rotation3D {
public struct Rotation3D: Sendable {
internal var rotation: Rotation

internal enum Rotation {
internal enum Rotation: Sendable {
case eulerAngles (x: Angle, y: Angle, z: Angle)
case axis (Vector3D, angle: Angle)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSCAD/Values/SCADValue.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

protocol SCADValue {
protocol SCADValue: Sendable {
var scadString: String { get }
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSCAD/Values/Transforms/AffineTransform.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public protocol AffineTransform {
public protocol AffineTransform: Sendable {
associatedtype Vector: SwiftSCAD.Vector
associatedtype Rotation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import simd
#endif

/// An `AffineTransform2D` represents a 2D affine transformation using a 3x3 matrix.
public struct AffineTransform2D: AffineTransform, Equatable {
public struct AffineTransform2D: AffineTransform, Equatable, Sendable {
private var matrix: Matrix3x3

internal init(_ matrix: Matrix3x3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import simd
#endif

/// An `AffineTransform3D` represents a 3D affine transformation using a 4x4 matrix.
public struct AffineTransform3D: AffineTransform, Equatable {
public struct AffineTransform3D: AffineTransform, Equatable, Sendable {
private var matrix: Matrix4x4

private init(_ matrix: Matrix4x4) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

internal struct BasicMatrix3x3: Equatable {
internal struct BasicMatrix3x3: Equatable, Sendable {
typealias Row = [Double]
typealias Column = [Double]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

internal struct BasicMatrix4x4: Equatable {
internal struct BasicMatrix4x4: Equatable, Sendable {
typealias Row = [Double]
typealias Column = [Double]

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSCAD/Values/Vectors/Vector.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public protocol Vector {
public protocol Vector: Sendable {
associatedtype Axes: SwiftSCAD.Axes
associatedtype Transform: AffineTransform where Transform.Vector == Self

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSCAD/Values/Vectors/Vector2D.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Foundation
/// let v2: Vector2D = [10, 15]
/// ```
///
public struct Vector2D: ExpressibleByArrayLiteral, SCADValue, Hashable {
public struct Vector2D: ExpressibleByArrayLiteral, SCADValue, Hashable, Sendable {
public var x: Double
public var y: Double

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSCAD/Values/Vectors/Vector3D.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Foundation
/// let v1 = Vector3D(x: 10, y: 15, z: 5)
/// let v2: Vector3D = [10, 15, 5]
/// ```
public struct Vector3D: ExpressibleByArrayLiteral, SCADValue, Hashable {
public struct Vector3D: ExpressibleByArrayLiteral, SCADValue, Hashable, Sendable {
public var x: Double
public var y: Double
public var z: Double
Expand Down

0 comments on commit 5d95ea7

Please sign in to comment.