Skip to content

Commit

Permalink
Fix issue where rounded corners algorithm would return incorrect path…
Browse files Browse the repository at this point in the history
… for shapes without any rounded corners
  • Loading branch information
calda committed Feb 17, 2023
1 parent 4e51b71 commit 7042a72
Show file tree
Hide file tree
Showing 2 changed files with 1,538 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/Private/Utility/Primitives/BezierPathRoundExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ extension BezierPath {
uniquePath.addVertex(elements[i].vertex)
}

var pathHasRoundedCorner = false

for elementIndex in 0..<uniquePath.elements.count {
currentVertex = uniquePath.elements[elementIndex].vertex

Expand All @@ -96,6 +98,9 @@ extension BezierPath {
continue
}

// Track whether or not this path has at least one rounded corner
pathHasRoundedCorner = true

// Do not round start and end if not closed
if !newPath.closed, elementIndex == 0 || elementIndex == uniquePath.elements.count - 1 {
newPath.addVertex(currentVertex)
Expand Down Expand Up @@ -142,6 +147,12 @@ extension BezierPath {
}
}

// If we didn't need to apply the corner radius to any of the corners,
// just use the original given path instead of modifying it.
if !pathHasRoundedCorner {
return self
}

return newPath
}
}
Loading

0 comments on commit 7042a72

Please sign in to comment.