Skip to content

Commit

Permalink
Add Environment.tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasf committed Feb 20, 2024
1 parent dd0ad42 commit a3b213f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Sources/SwiftSCAD/Environment/Tolerance.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Foundation

private extension Environment {
static let key = Environment.ValueKey(rawValue: "SwiftSCAD.Tolerance")

func settingTolerance(_ tolerance: Double) -> Environment {
setting(key: Self.key, value: tolerance)
}
}

public extension Environment {
var tolerance: Double {
self[Self.key] as? Double ?? 0
}
}

public extension Geometry3D {
func withTolerance(_ tolerance: Double) -> any Geometry3D {
withEnvironment { enviroment in
enviroment.settingTolerance(tolerance)
}
}
}

public extension Geometry2D {
func withTolerance(_ tolerance: Double) -> any Geometry2D {
withEnvironment { enviroment in
enviroment.settingTolerance(tolerance)
}
}
}

0 comments on commit a3b213f

Please sign in to comment.