๐Ÿ’œLineShape

SwiftUI โŸฉ Drawing โŸฉ Shape โŸฉ Helper Shapes โŸฉ

// 2022.02.10

import SwiftUI

/// a line (invisible shape) relative to a rect.
/// ```
/// LineShape([0,0], [1,1])
/// ```
struct LineShape: Shape {
    let p1: UnitPoint
    let p2: UnitPoint
    func path(in rect: CGRect) -> Path {
        Path { path in
            // ๐ŸŒ€Path+ line(), ๐Ÿ…ฟ๏ธ Rectangular
            path.line(rect[p1], rect[p2])
        }
    }
}

// convenience init
extension LineShape {
    init(_ p1: UnitPoint, _ p2: UnitPoint) {
        self.init(p1: p1, p2: p2)
    }
}

Last updated