Capsule.swift 558 B

123456789101112131415
  1. /// A rounded rectangle whose corner radius is equal to half the length of its
  2. /// shortest side.
  3. public struct Capsule: InsettableShape {
  4. /// Creates a ``Capsule`` instance.
  5. public nonisolated init() {}
  6. public nonisolated func path(in bounds: Path.Rect) -> Path {
  7. let radius = min(bounds.width, bounds.height) / 2.0
  8. return RoundedRectangle(cornerRadius: radius).path(in: bounds)
  9. }
  10. public nonisolated func inset(by amount: Double) -> some InsettableShape {
  11. InsettableShapeImpl(inset: amount, base: self)
  12. }
  13. }