Skip to content

Instantly share code, notes, and snippets.

@msnazarow
Created January 9, 2023 07:06
Show Gist options
  • Save msnazarow/7caf9495c47b7d9cdc31626ea2fb22fc to your computer and use it in GitHub Desktop.
Save msnazarow/7caf9495c47b7d9cdc31626ea2fb22fc to your computer and use it in GitHub Desktop.
HalfCircle
struct TopHalfCircle: Shape {
func path(in rect: CGRect) -> Path {
var path = Path()
path.addArc(
center: .zero,
radius: 1,
startAngle: .radians(.pi),
endAngle: .zero,
clockwise: false
)
let transform = CGAffineTransform.identity
.translatedBy(x: rect.origin.x + 0.5 * rect.size.width, y: rect.size.height)
.scaledBy(x: rect.width / 2, y: rect.height)
return path.applying(transform)
}
}
struct BottomHalfCircle: Shape {
func path(in rect: CGRect) -> Path {
var path = Path()
path.addArc(
center: .zero,
radius: 1,
startAngle: .zero,
endAngle: .radians(.pi),
clockwise: false
)
let transform = CGAffineTransform.identity
.translatedBy(x: rect.origin.x + 0.5 * rect.size.width, y: 0)
.scaledBy(x: rect.width / 2, y: rect.height)
return path.applying(transform)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment