๐Ÿ…ฟ๏ธVector2D

import SwiftUI
import Vector2D

let u = CGPoint(1, 2)    // convenience init
let v = CGPoint(2,-1)
let w: CGPoint = [2, 3]  // expressible by array literal

// linear combinations
u + v          // ( 3, 1)
u - 2 * v      // (-3, 4)
3 * u - 2 * v  // (-1, 8)

// products
u * v          // 4 + 3i : complex number multiplication
u โ€ข v          //  0.0   : inner product
u ร— v          // -5.0   : cross product (directed area)
u ** v         // (2,-2) : memberwise multiplication


let p = CGPoint(1,2) // (1,2)
p + 5 * .i           // (1,2) + 5(1,0) = (6,2)
2 * p - 3 * .j       // (2,4) - 3(0,1) = (2,1)

History

  • 2020.09.30๏ผšโž• CGRect conforms to Vector2D

  • 2020.10.08๏ผšโž• unit vectors: Vector2D.i, Vector2D.j, v / a (scalar division)

  • 2020.10.10๏ผš โžŠ ไฝฟ็”จ associatedtype Field

  • 2020.10.22๏ผšโž• .polar(r, a) (conditional conformance)

Versions

  1. 2020.10.10

  2. 2022.02.09

  3. 2022.03.09

Last updated