Swiftpack.co - lochiwei/Vector2D as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by lochiwei.
lochiwei/Vector2D 1.0.3
A protocol to turn a normal type into a 2D vector.
⭐️ 2
🕓 2 years ago
.package(url: "https://github.com/lochiwei/Vector2D.git", from: "1.0.3")

Vector2D

🅿️ Vector2D protocol

A protocol to turn a normal type into a 2D vector.

// 🅿️ Vector2D
public protocol Vector2D: ExpressibleByArrayLiteral, Rectangular {
    
    associatedtype Field: FloatingPoint     // support +,-,*,/
    
    // x, y coordinates
    var x: Field { get }
    var y: Field { get }
    
    // initializer
    init(x: Field, y: Field)
    
    // vector addition: u + v
    // (default implementation provided)
    static func + (u: Self, v: Self) -> Self
    
    // additive inverse: -v
    // (default implementation provided)
    static prefix func - (u: Self) -> Self
}

🅿️ Rectangular protocol

public protocol Rectangular {
    var origin: CGPoint { get }
    var size  : CGSize  { get }
}

GitHub

link
Stars: 2
Last commit: 50 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics