-
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.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
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,40 @@ | ||
import Foundation | ||
|
||
internal extension Geometry3D { | ||
func applyingTopEdgeProfile(profile: EdgeProfile, at z: Double, shape: (any Geometry2D)?, method: EdgeProfile.Method) -> any Geometry3D { | ||
let slice = shape ?? projection(slicingAtZ: z - 0.01) | ||
let subtraction = profile.negativeMask(shape: slice, method: method) | ||
.translated(z: z) | ||
return subtracting(subtraction) | ||
} | ||
|
||
func applyingBottomEdgeProfile(profile: EdgeProfile, at z: Double, shape: (any Geometry2D)?, method: EdgeProfile.Method) -> any Geometry3D { | ||
let slice = shape ?? projection(slicingAtZ: z + 0.01) | ||
let subtraction = profile.negativeMask(shape: slice, method: method) | ||
.flipped(along: .z) | ||
.translated(z: z) | ||
return subtracting(subtraction) | ||
} | ||
} | ||
|
||
public extension Geometry3D { | ||
func applyingTopEdgeProfile(_ profile: EdgeProfile, at z: Double? = nil, shape: (any Geometry2D)? = nil, method: EdgeProfile.Method) -> any Geometry3D { | ||
if let z { | ||
return applyingTopEdgeProfile(profile: profile, at: z, shape: shape, method: method) | ||
} else { | ||
return measuringBounds { _, box in | ||
return applyingTopEdgeProfile(profile: profile, at: box.maximum.z, shape: shape, method: method) | ||
} | ||
} | ||
} | ||
|
||
func applyingBottomEdgeProfile(_ profile: EdgeProfile, at z: Double? = nil, shape: (any Geometry2D)? = nil, method: EdgeProfile.Method) -> any Geometry3D { | ||
if let z { | ||
return applyingBottomEdgeProfile(profile: profile, at: z, shape: shape, method: method) | ||
} else { | ||
return measuringBounds { _, box in | ||
return applyingBottomEdgeProfile(profile: profile, at: box.minimum.z, shape: shape, method: method) | ||
} | ||
} | ||
} | ||
} |
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