-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
Sources/SwiftSCAD/Operations/Extrude/Edge Profiles/ApplyEdgeProfile.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import Foundation | ||
|
||
internal extension Geometry3D { | ||
func applyingTopEdgeProfile(profile: EdgeProfile, at z: Double, shape: any Geometry2D, method: EdgeProfile.Method) -> any Geometry3D { | ||
let subtraction = profile.negativeMask(shape: shape, method: method) | ||
.translated(z: z) | ||
return subtracting(subtraction) | ||
} | ||
|
||
func applyingBottomEdgeProfile(profile: EdgeProfile, at z: Double, shape: any Geometry2D, method: EdgeProfile.Method) -> any Geometry3D { | ||
let subtraction = profile.negativeMask(shape: shape, method: method) | ||
.flipped(along: .z) | ||
.translated(z: z) | ||
return subtracting(subtraction) | ||
} | ||
} | ||
|
||
public extension Geometry3D { | ||
func applyingTopEdgeProfile(_ profile: EdgeProfile, at z: Double? = nil, method: EdgeProfile.Method, @UnionBuilder2D shape: () -> any Geometry2D) -> any Geometry3D { | ||
let slice = shape() | ||
if let z { | ||
return applyingTopEdgeProfile(profile: profile, at: z, shape: slice, method: method) | ||
} else { | ||
return measuringBounds { _, box in | ||
return applyingTopEdgeProfile(profile: profile, at: box.maximum.z, shape: slice, method: method) | ||
} | ||
} | ||
} | ||
|
||
func applyingTopEdgeProfile(_ profile: EdgeProfile, at z: Double? = nil, method: EdgeProfile.Method) -> any Geometry3D { | ||
if let z { | ||
applyingTopEdgeProfile(profile, at: z, method: method) { | ||
projection(slicingAtZ: z - 0.01) | ||
} | ||
} else { | ||
measuringBounds { _, box in | ||
applyingTopEdgeProfile(profile, at: box.maximum.z, method: method) { | ||
projection(slicingAtZ: box.maximum.z - 0.01) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func applyingBottomEdgeProfile(_ profile: EdgeProfile, at z: Double? = nil, method: EdgeProfile.Method, @UnionBuilder2D shape: () -> any Geometry2D) -> any Geometry3D { | ||
let slice = shape() | ||
if let z { | ||
return applyingBottomEdgeProfile(profile: profile, at: z, shape: slice, method: method) | ||
} else { | ||
return measuringBounds { _, box in | ||
return applyingBottomEdgeProfile(profile: profile, at: box.minimum.z, shape: slice, method: method) | ||
} | ||
} | ||
} | ||
|
||
func applyingBottomEdgeProfile(_ profile: EdgeProfile, at z: Double? = nil, method: EdgeProfile.Method) -> any Geometry3D { | ||
if let z { | ||
applyingBottomEdgeProfile(profile, at: z, method: method) { | ||
projection(slicingAtZ: z + 0.01) | ||
} | ||
} else { | ||
measuringBounds { _, box in | ||
applyingBottomEdgeProfile(profile, at: box.maximum.z, method: method) { | ||
projection(slicingAtZ: box.maximum.z + 0.01) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters