Skip to content

Commit

Permalink
Add ApplyEdgeProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasf committed Jul 13, 2024
1 parent 69347e1 commit 5cb521e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,15 @@ internal extension EdgeProfile {
func mask(shape: any Geometry2D, extrusionHeight: Double, method: EdgeProfile.Method) -> any Geometry3D {
profileShape.mask(shape: shape, extrusionHeight: extrusionHeight, method: method)
}

func negativeMask(shape: any Geometry2D, method: EdgeProfile.Method) -> any Geometry3D {
let height = profileShape.height
return shape
.offset(amount: 0.01, style: .round)
.extruded(height: height + 0.01)
.subtracting {
profileShape.mask(shape: shape, extrusionHeight: height, method: method)
}
.translated(z: -height)
}
}

0 comments on commit 5cb521e

Please sign in to comment.