Skip to content

Commit a6d4c91

Browse files
committed
Merge branch 'dev'
2 parents f291664 + fabfcce commit a6d4c91

File tree

16 files changed

+294
-14
lines changed

16 files changed

+294
-14
lines changed

.github/workflows/swift.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ jobs:
3030
3131
- name: Build
3232
run: swift build -v
33+
34+
- name: Test
35+
run: swift test -v

Package.resolved

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let package = Package(
1010
.executable(name: "Helical-Demo", targets: ["Demo"]),
1111
],
1212
dependencies: [
13-
.package(url: "https://github.com/tomasf/Cadova.git", .upToNextMinor(from: "0.5.2")),
13+
.package(url: "https://github.com/tomasf/Cadova.git", .upToNextMinor(from: "0.6.0")),
1414
],
1515
targets: [
1616
.target(
@@ -22,6 +22,11 @@ let package = Package(
2222
name: "Demo",
2323
dependencies: ["Cadova", "Helical"],
2424
swiftSettings: [.interoperabilityMode(.Cxx)]
25+
),
26+
.testTarget(
27+
name: "HelicalTests",
28+
dependencies: ["Helical", "Cadova"],
29+
swiftSettings: [.interoperabilityMode(.Cxx)]
2530
)
2631
]
2732
)

Sources/Demo/bolts.stl

-27.7 MB
Binary file not shown.

Sources/Demo/main.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ struct Repertoire: Shape3D {
6666
}
6767
}
6868

69-
await Project(options: .format3D(.stl)) {
69+
await Project(packageRelative: "Models") {
70+
Environment {
71+
$0.segmentation = .adaptive(minAngle: 5°, minSize: 0.5)
72+
}
73+
7074
await Model("bolts") {
7175
Repertoire(contents: bolts)
7276
}

Sources/Demo/nutsAndWashers.stl

-10.5 MB
Binary file not shown.

Sources/Helical/Bolt/Parts/Sockets/Phillips.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ internal struct PhillipsMetrics: Sendable {
3333
switch size {
3434
case .ph0:
3535
crossDistanceBetweenCorners = 0.61
36-
cornerWidth = 0.3
36+
cornerWidth = 0.310
3737
bottomWidth = 0.81
3838
slotWidth = 0.35
3939
filletRadius = 0.3
40-
cornerAcrossAngle = 135° //???
40+
cornerAcrossAngle = 136°
4141
cornerSlant = 7°
4242

4343
case .ph1:
4444
crossDistanceBetweenCorners = 0.97
45-
cornerWidth = 0.45
45+
cornerWidth = 0.435
4646
bottomWidth = 1.27
4747
slotWidth = 0.55
4848
filletRadius = 0.5
@@ -51,7 +51,7 @@ internal struct PhillipsMetrics: Sendable {
5151

5252
case .ph2:
5353
crossDistanceBetweenCorners = 1.47
54-
cornerWidth = 0.82
54+
cornerWidth = 0.815
5555
bottomWidth = 2.29
5656
slotWidth = 0.7
5757
filletRadius = 0.6
@@ -60,7 +60,7 @@ internal struct PhillipsMetrics: Sendable {
6060

6161
case .ph3:
6262
crossDistanceBetweenCorners = 2.41
63-
cornerWidth = 2.0
63+
cornerWidth = 2.005
6464
bottomWidth = 3.81
6565
slotWidth = 0.85
6666
filletRadius = 0.8
@@ -69,7 +69,7 @@ internal struct PhillipsMetrics: Sendable {
6969

7070
case .ph4:
7171
crossDistanceBetweenCorners = 3.48
72-
cornerWidth = 2.4
72+
cornerWidth = 2.415
7373
bottomWidth = 5.08
7474
slotWidth = 1.25
7575
filletRadius = 1

Sources/Helical/Nut/Nut.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public struct Nut: Shape3D {
2727
let minorDiameter = thread.minorDiameter + tolerance
2828
shape
2929
.subtracting {
30-
Screw(thread: thread, length: shape.threadedDepth)
30+
let offset = 1e-3
31+
Screw(thread: thread, length: shape.threadedDepth + 2 * offset)
32+
.translated(z: -offset)
3133

3234
if let (depth, length) = leadIns.leading?.resolved(for: thread) {
3335
Cylinder(bottomDiameter: minorDiameter + 2 * depth, topDiameter: minorDiameter, height: length)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import Testing
2+
import Helical
3+
import Cadova
4+
5+
private func isClose(_ a: Double, _ b: Double, tolerance: Double = 1e-9) -> Bool { abs(a - b) < tolerance }
6+
7+
struct CountersunkHeadTests {
8+
@Test func `height is (topDiameter - boltDiameter) / 2 × tan(angle / 2)`() {
9+
let noLens = CountersunkBoltHeadShape(angle: 90°, topDiameter: 10, boltDiameter: 5)
10+
#expect(isClose(noLens.height, 2.5, tolerance: 1e-6))
11+
12+
// 82° uses angle/2 = 41°, not the full angle
13+
let angled = CountersunkBoltHeadShape(angle: 82°, topDiameter: 8, boltDiameter: 4)
14+
#expect(isClose(angled.height, 2.0 * tan(41°), tolerance: 1e-6))
15+
}
16+
17+
@Test func `lens height adds to total height but not consumed length`() {
18+
let shape = CountersunkBoltHeadShape(angle: 90°, topDiameter: 10, boltDiameter: 5, lensHeight: 1)
19+
#expect(isClose(shape.height, 3.5, tolerance: 1e-6))
20+
#expect(isClose(shape.consumedLength, 2.5, tolerance: 1e-6))
21+
}
22+
23+
@Test func `consumed length equals height minus lens height`() {
24+
let shape = CountersunkBoltHeadShape(angle: 90°, topDiameter: 12, boltDiameter: 6, lensHeight: 1.5)
25+
#expect(isClose(shape.consumedLength, shape.height - 1.5))
26+
}
27+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Testing
2+
import Helical
3+
4+
private func isClose(_ a: Double, _ b: Double, tolerance: Double = 1e-9) -> Bool { abs(a - b) < tolerance }
5+
6+
struct EdisonScrewTests {
7+
// pitchDiameter is computed via the knuckle threadform arc formula —
8+
// several steps of non-trivial math over stored major/minor/pitch values.
9+
@Test func `pitch diameter is computed correctly from arc formula`() {
10+
// E27: h=1.25, pitch=3.62, radius≈0.96772 → pitchDiameter≈25.75
11+
#expect(isClose(ScrewThread.e27.pitchDiameter, 25.75, tolerance: 1e-3))
12+
13+
// E5.5: radius=17/60, d=9/60=0.15 → pitchDiameter = 5.5 - 0.3 = 5.2 (exact)
14+
#expect(isClose(ScrewThread.e5p5.pitchDiameter, 5.2, tolerance: 1e-6))
15+
}
16+
}

0 commit comments

Comments
 (0)