Skip to content

Commit

Permalink
Create Square.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranb662 authored Sep 4, 2020
1 parent d9942d6 commit b9cc0cf
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Sources/Shapes/Square.swift
Original file line number Diff line number Diff line change
@@ -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
)
)
}
}
}

0 comments on commit b9cc0cf

Please sign in to comment.