From b9cc0cfcf7af91c6ac861619ba36249b039803dc Mon Sep 17 00:00:00 2001 From: Kieran Brown Date: Fri, 4 Sep 2020 11:53:45 -0400 Subject: [PATCH] Create Square.swift --- Sources/Shapes/Square.swift | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Sources/Shapes/Square.swift diff --git a/Sources/Shapes/Square.swift b/Sources/Shapes/Square.swift new file mode 100644 index 0000000..8e944f7 --- /dev/null +++ b/Sources/Shapes/Square.swift @@ -0,0 +1,34 @@ +import SwiftUI + + +public struct Square: Shape { + public init() {} + public func path(in rect: CGRect) -> Path { + + Path { path in + + let length = min(rect.width, rect.height) + + let x = ( + rect.width < rect.height + ? 0 + : (rect.width - length)/2 + ) + rect.minX + + let y = ( + rect.width < rect.height + ? (rect.height - length)/2 + : 0 + ) + rect.minY + + path.addRect( + CGRect( + x: x , + y: y , + width: length, + height: length + ) + ) + } + } +}