💜LineShape

SwiftUIDrawingShapeHelper Shapes

LineShape (invisible Shape)
// 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

Was this helpful?