Skip to content

Commit

Permalink
Merge branch 'clips-path'
Browse files Browse the repository at this point in the history
  • Loading branch information
swhitty committed Feb 11, 2025
2 parents d3ebe6e + 7376d39 commit 5cf0c3e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
9 changes: 8 additions & 1 deletion SwiftDraw/LayerTree.CommandGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,19 @@ extension LayerTree {

func renderCommands(forClip shapes: [ClipShape], using rule: FillRule?) -> [RendererCommand<P.Types>] {
guard !shapes.isEmpty else { return [] }
let paths = shapes.map { provider.createPath(from: .path($0.makePath())) }
let paths = shapes.map { clip in
if clip.transform == .identity {
return provider.createPath(from: clip.shape)
} else {
return provider.createPath(from: .path(clip.shape.path.applying(matrix: clip.transform)))
}
}
let clipPath = provider.createPath(from: paths)
let rule = provider.createFillRule(from: rule ?? .nonzero)
return [.setClip(path: clipPath, rule: rule)]
}


func renderCommands(forMask layer: Layer?) -> [RendererCommand<P.Types>] {
guard let layer = layer else { return [] }

Expand Down
9 changes: 1 addition & 8 deletions SwiftDraw/LayerTree.Shape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,7 @@ extension LayerTree {

struct ClipShape: Hashable {
var shape: Shape
var transform: Transform.Matrix?

func makePath() -> LayerTree.Path {
guard let transform else {
return shape.path
}
return shape.path.applying(matrix: transform)
}
var transform: Transform.Matrix
}
}

Expand Down
2 changes: 1 addition & 1 deletion SwiftDrawTests/LayerTree.CommandGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ final class LayerTreeCommandGeneratorTests: XCTestCase {
private extension LayerTree.CommandGenerator {

func renderCommands(forClip shapes: [LayerTree.Shape], using rule: LayerTree.FillRule?) -> [RendererCommand<P.Types>] {
renderCommands(forClip: shapes.map { LayerTree.ClipShape(shape: $0) }, using: rule)
renderCommands(forClip: shapes.map { LayerTree.ClipShape(shape: $0, transform: .identity) }, using: rule)
}
}

0 comments on commit 5cf0c3e

Please sign in to comment.