|
1 | | -import Foundation |
2 | 1 | import Cadova |
3 | 2 |
|
4 | | -/// A bolt with a head, threaded section, and optional point. |
| 3 | +/// A complete bolt fastener with a head, threaded shank, and optional point. |
| 4 | +/// |
| 5 | +/// `Bolt` composes a head shape, drive socket, threaded section (``Screw``), and point |
| 6 | +/// into a full fastener model. For just the bare threaded geometry, use ``Screw``. |
5 | 7 | public struct Bolt: Shape3D { |
6 | 8 | /// The screw thread specification. |
7 | 9 | public let thread: ScrewThread |
@@ -46,36 +48,6 @@ public struct Bolt: Shape3D { |
46 | 48 | self.point = point |
47 | 49 | } |
48 | 50 |
|
49 | | - /// Creates a bolt with a chamfered point. |
50 | | - /// |
51 | | - /// - Parameters: |
52 | | - /// - thread: The screw thread specification. |
53 | | - /// - length: Nominal length of the bolt. |
54 | | - /// - unthreadedLength: Length of the unthreaded portion. |
55 | | - /// - unthreadedDiameter: Diameter of the unthreaded portion. Defaults to the thread's major diameter. |
56 | | - /// - leadinChamferSize: Size of the lead-in chamfer at the bolt tip. |
57 | | - /// - headShape: The bolt head geometry. |
58 | | - /// - socket: Optional drive socket in the head. |
59 | | - public init( |
60 | | - thread: ScrewThread, |
61 | | - length: Double, |
62 | | - unthreadedLength: Double = 0, |
63 | | - unthreadedDiameter: Double? = nil, |
64 | | - leadinChamferSize: Double, |
65 | | - headShape: any BoltHeadShape, |
66 | | - socket: (any BoltHeadSocket)? = nil |
67 | | - ) { |
68 | | - self.init( |
69 | | - thread: thread, |
70 | | - length: length, |
71 | | - unthreadedLength: unthreadedLength, |
72 | | - unthreadedDiameter: unthreadedDiameter, |
73 | | - headShape: headShape, |
74 | | - socket: socket, |
75 | | - point: ProfiledBoltPoint(chamferSize: leadinChamferSize) |
76 | | - ) |
77 | | - } |
78 | | - |
79 | 51 | /// Creates a bolt without threads, for cases where thread detail is unimportant. |
80 | 52 | /// |
81 | 53 | /// - Parameters: |
@@ -130,35 +102,50 @@ public struct Bolt: Shape3D { |
130 | 102 | .withThread(thread) |
131 | 103 | } |
132 | 104 |
|
133 | | - private func clearanceHoleDepth(recessedHead: Bool = false) -> Double { |
134 | | - recessedHead ? (length + headShape.clearanceLength) : (length - headShape.consumedLength) |
| 105 | + /// The entry geometry for a bolt clearance hole. |
| 106 | + public enum ClearanceHoleEntry: Sendable { |
| 107 | + /// No special geometry at the entry. |
| 108 | + case plain |
| 109 | + /// An edge profile applied at the hole opening. |
| 110 | + case edgeProfile (EdgeProfile) |
| 111 | + /// A recess matching the bolt head shape. |
| 112 | + case recessedHead |
135 | 113 | } |
136 | 114 |
|
137 | 115 | /// Creates a clearance hole sized for this bolt. |
138 | 116 | /// |
139 | | - /// - Parameters: |
140 | | - /// - depth: Hole depth. Defaults to the bolt length minus head consumption. |
141 | | - /// - edgeProfile: Optional edge profile at the hole opening. |
142 | | - /// - Returns: A clearance hole configured for this bolt. |
143 | | - public func clearanceHole(depth: Double? = nil, edgeProfile: EdgeProfile? = nil) -> ClearanceHole { |
144 | | - ClearanceHole( |
145 | | - diameter: thread.majorDiameter, |
146 | | - depth: depth ?? clearanceHoleDepth(), |
147 | | - edgeProfile: edgeProfile |
148 | | - ) |
149 | | - } |
150 | | - |
151 | | - /// Creates a clearance hole sized for this bolt, optionally with a recess for the head. |
| 117 | + /// The default depth depends on the entry type: for ``ClearanceHoleEntry/recessedHead``, |
| 118 | + /// the hole extends deep enough to fully recess the head; otherwise, it extends |
| 119 | + /// the bolt length minus the head's consumed length. |
152 | 120 | /// |
153 | 121 | /// - Parameters: |
154 | | - /// - depth: Hole depth. Defaults to a depth that accommodates the full bolt length. |
155 | | - /// - recessedHead: Whether to include a recess matching the bolt head shape. |
| 122 | + /// - depth: Hole depth. Defaults to a depth appropriate for the entry type. |
| 123 | + /// - entry: The geometry at the entry of the hole. Defaults to `.plain`. |
156 | 124 | /// - Returns: A clearance hole configured for this bolt. |
157 | | - public func clearanceHole(depth: Double? = nil, recessedHead: Bool) -> ClearanceHole { |
| 125 | + public func clearanceHole(depth: Double? = nil, entry: ClearanceHoleEntry = .plain) -> ClearanceHole { |
| 126 | + let recessedHead: Bool |
| 127 | + let clearanceEntry: ClearanceHole.Entry |
| 128 | + |
| 129 | + switch entry { |
| 130 | + case .plain: |
| 131 | + recessedHead = false |
| 132 | + clearanceEntry = .plain |
| 133 | + case .edgeProfile(let profile): |
| 134 | + recessedHead = false |
| 135 | + clearanceEntry = .edgeProfile(profile) |
| 136 | + case .recessedHead: |
| 137 | + recessedHead = true |
| 138 | + clearanceEntry = .recess(headShape.recess) |
| 139 | + } |
| 140 | + |
| 141 | + let defaultDepth = recessedHead |
| 142 | + ? (length + headShape.clearanceLength) |
| 143 | + : (length - headShape.consumedLength) |
| 144 | + |
158 | 145 | return ClearanceHole( |
159 | 146 | diameter: thread.majorDiameter, |
160 | | - depth: depth ?? clearanceHoleDepth(recessedHead: true), |
161 | | - boltHeadRecess: recessedHead ? headShape.recess : Empty() |
| 147 | + depth: depth ?? defaultDepth, |
| 148 | + entry: clearanceEntry |
162 | 149 | ) |
163 | 150 | } |
164 | 151 | } |
0 commit comments