Skip to content

Commit 7a5a28d

Browse files
committed
Merge branch 'dev'
2 parents 47f5820 + 3142e59 commit 7a5a28d

File tree

5 files changed

+75
-33
lines changed

5 files changed

+75
-33
lines changed

Sources/Cadova/Abstract Layer/Operations/Extrude/Extrusion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public extension Geometry2D {
5454
} else {
5555
base = self
5656
}
57-
base.extruded(height: height, twist: twist, scale: topScale, divisions: segmentCount)
57+
base.extruded(height: height, twist: twist, scale: topScale, divisions: segmentCount - 1)
5858
}
5959
}
6060
}

Sources/Cadova/Abstract Layer/Operations/Extrude/HelixSweep.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,29 @@ public extension Geometry2D {
2828
let outerRadius = bounds.maximum.x
2929
let lengthPerRev = outerRadius * 2 * .pi
3030

31-
let helixLength = sqrt(pow(lengthPerRev, 2) + pow(pitch, 2)) * revolutions
32-
let totalSegments = Int(max(
33-
Double(segmentation.segmentCount(circleRadius: outerRadius)) * revolutions,
34-
Double(segmentation.segmentCount(length: helixLength))
35-
))
31+
let helixLengthPerRev = sqrt(pow(lengthPerRev, 2) + pow(pitch, 2))
32+
let segmentsPerRevolution = max(
33+
segmentation.segmentCount(circleRadius: outerRadius),
34+
segmentation.segmentCount(length: helixLengthPerRev)
35+
)
36+
let fullRevolutions = max(Int(ceil(revolutions)), 1)
37+
let totalSegments = segmentsPerRevolution * fullRevolutions
3638

37-
extruded(height: lengthPerRev * revolutions, divisions: totalSegments)
39+
extruded(height: lengthPerRev * Double(fullRevolutions), divisions: totalSegments - 1)
3840
.rotated(x: -90°)
3941
.flipped(along: .z)
4042
.warped(operationName: "extrudeAlongHelix", cacheParameters: pitch) {
4143
let turns = $0.y / lengthPerRev
4244
let angle = Angle(turns: turns)
43-
return Vector3D(cos(angle) * $0.x, sin(angle) * $0.x, $0.z + turns * pitch)
45+
return Vector3D(
46+
cos(angle) * $0.x,
47+
sin(angle) * $0.x,
48+
$0.z + turns * pitch
49+
)
50+
}
51+
.intersecting {
52+
Box(x: outerRadius * 2 + 1, y: outerRadius * 2 + 1, z: height)
53+
.aligned(at: .centerXY)
4454
}
4555
.simplified()
4656
}

Sources/Cadova/Values/ShapingFunction+Internal.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ extension ShapingFunction {
77
case easeIn
88
case easeOut
99
case easeInOut
10+
case easeInCubic
11+
case easeOutCubic
1012
case easeInOutCubic
1113
case smoothstep
1214
case smootherstep
@@ -33,6 +35,10 @@ extension ShapingFunction {
3335
hasher.combine(Kind.easeOut)
3436
case .easeInOut:
3537
hasher.combine(Kind.easeInOut)
38+
case .easeInCubic:
39+
hasher.combine(Kind.easeInCubic)
40+
case .easeOutCubic:
41+
hasher.combine(Kind.easeOutCubic)
3642
case .easeInOutCubic:
3743
hasher.combine(Kind.easeInOutCubic)
3844
case .smoothstep:
@@ -76,6 +82,8 @@ extension ShapingFunction {
7682
case (.easeIn, .easeIn),
7783
(.easeOut, .easeOut),
7884
(.easeInOut, .easeInOut),
85+
(.easeInCubic, .easeInCubic),
86+
(.easeOutCubic, .easeOutCubic),
7987
(.easeInOutCubic, .easeInOutCubic),
8088
(.smoothstep, .smoothstep),
8189
(.smootherstep, .smootherstep),
@@ -131,6 +139,10 @@ extension ShapingFunction.Curve: Codable {
131139
self = .easeOut
132140
case .easeInOut:
133141
self = .easeInOut
142+
case .easeInCubic:
143+
self = .easeInCubic
144+
case .easeOutCubic:
145+
self = .easeOutCubic
134146
case .easeInOutCubic:
135147
self = .easeInOutCubic
136148
case .smoothstep:
@@ -181,6 +193,10 @@ extension ShapingFunction.Curve: Codable {
181193
try container.encode(ShapingFunction.Kind.easeOut, forKey: .kind)
182194
case .easeInOut:
183195
try container.encode(ShapingFunction.Kind.easeInOut, forKey: .kind)
196+
case .easeInCubic:
197+
try container.encode(ShapingFunction.Kind.easeInCubic, forKey: .kind)
198+
case .easeOutCubic:
199+
try container.encode(ShapingFunction.Kind.easeOutCubic, forKey: .kind)
184200
case .easeInOutCubic:
185201
try container.encode(ShapingFunction.Kind.easeInOutCubic, forKey: .kind)
186202
case .smoothstep:

Sources/Cadova/Values/ShapingFunction.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public struct ShapingFunction: Sendable, Hashable, Codable {
3636
case .easeIn: { $0 * $0 }
3737
case .easeOut: { 1 - (1 - $0) * (1 - $0) }
3838
case .easeInOut: { $0 < 0.5 ? 2 * $0 * $0 : -2 * $0 * $0 + 4 * $0 - 1 }
39+
case .easeInCubic: { $0 * $0 * $0 }
40+
case .easeOutCubic: { let t = 1 - $0; return 1 - t * t * t }
3941
case .easeInOutCubic: { $0 < 0.5 ? 4 * $0 * $0 * $0 : 0.5 * (2 * $0 - 2) * (2 * $0 - 2) * (2 * $0 - 2) + 1 }
4042
case .smoothstep: { $0 * $0 * (3 - 2 * $0) }
4143
case .smootherstep: { $0 * $0 * $0 * ($0 * (6 * $0 - 15) + 10) }
@@ -81,6 +83,8 @@ internal extension ShapingFunction {
8183
case easeIn
8284
case easeOut
8385
case easeInOut
86+
case easeInCubic
87+
case easeOutCubic
8488
case easeInOutCubic
8589
case smoothstep
8690
case smootherstep
@@ -131,6 +135,18 @@ public extension ShapingFunction {
131135
ShapingFunction(curve: .easeInOut)
132136
}
133137

138+
/// A cubic ease-in function that starts slow and accelerates towards the end.
139+
/// Produces a more pronounced acceleration than the quadratic ``easeIn``.
140+
static var easeInCubic: Self {
141+
ShapingFunction(curve: .easeInCubic)
142+
}
143+
144+
/// A cubic ease-out function that starts fast and decelerates towards the end.
145+
/// Produces a more pronounced deceleration than the quadratic ``easeOut``.
146+
static var easeOutCubic: Self {
147+
ShapingFunction(curve: .easeOutCubic)
148+
}
149+
134150
/// A cubic ease-in-out function that provides a stronger smoothing effect than quadratic easing.
135151
/// It accelerates slowly at the start, speeds up through the middle, and decelerates smoothly at the end.
136152
/// This function is useful for more pronounced easing effects with smoother transitions.

Tests/Tests/golden/examples/example2.json

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@
7575
"kind" : "transform",
7676
"transform" : [
7777
[
78-
-1.618033988749895,
79-
0.5877852522924731,
80-
-3.23606797749979
78+
0.6180339887498948,
79+
0.9510565162951535,
80+
1.2360679774997896
8181
],
8282
[
83-
-1.1755705045849463,
84-
-0.8090169943749475,
85-
-2.3511410091698925
83+
-1.902113032590307,
84+
0.3090169943749474,
85+
-3.804226065180614
8686
],
8787
[
8888
0,
@@ -104,14 +104,14 @@
104104
"kind" : "transform",
105105
"transform" : [
106106
[
107-
2,
108-
0,
109-
4
107+
0.6180339887498948,
108+
-0.9510565162951535,
109+
1.2360679774997896
110110
],
111111
[
112-
0,
113-
1,
114-
0
112+
1.902113032590307,
113+
0.3090169943749474,
114+
3.804226065180614
115115
],
116116
[
117117
0,
@@ -133,14 +133,14 @@
133133
"kind" : "transform",
134134
"transform" : [
135135
[
136-
0.6180339887498948,
137-
-0.9510565162951535,
138-
1.2360679774997896
136+
2,
137+
0,
138+
4
139139
],
140140
[
141-
1.902113032590307,
142-
0.3090169943749474,
143-
3.804226065180614
141+
0,
142+
1,
143+
0
144144
],
145145
[
146146
0,
@@ -191,14 +191,14 @@
191191
"kind" : "transform",
192192
"transform" : [
193193
[
194-
0.6180339887498948,
195-
0.9510565162951535,
196-
1.2360679774997896
194+
-1.618033988749895,
195+
0.5877852522924731,
196+
-3.23606797749979
197197
],
198198
[
199-
-1.902113032590307,
200-
0.3090169943749474,
201-
-3.804226065180614
199+
-1.1755705045849463,
200+
-0.8090169943749475,
201+
-2.3511410091698925
202202
],
203203
[
204204
0,
@@ -253,7 +253,7 @@
253253
"kind" : "extrusion",
254254
"type" : {
255255
"linear" : {
256-
"divisions" : 50,
256+
"divisions" : 49,
257257
"height" : 5,
258258
"scaleTop" : {
259259
"x" : 1,

0 commit comments

Comments
 (0)