目录
目录README.md

SwiftyVector

SwiftyVector provides vector types for Swift.

let a: Vector2 = [2.0, 1.0]
let b: Vector2 = [-3.0, 6.0]

let sum        = a + b                 // [-1.0, 7.0]
let difference = a - b                 // [5.0, -5.0]
let product    = a * 2                 // [4.0, 2.0]
let quotient   = a / 2                 // [1.0, 0.5]

let length     = a.length              // 2.23607
let distance   = a.distance(from: b)   // 6.08276

let dotProduct = a.dotProduct(with: b) // 0.0
let angle      = a.angle(from: b)      // 1.5708

let c: Vector3 = [1.0, 2.0, -2.0]
let unit       = c.unit                // [0.333333, 0.666667, -0.666667]

// interoperability with CoreGraphics
let v = Vector2(CGPoint(x: 2.0, y: 3.0))
let p = CGPoint(v)

With SwiftyVector, CGPoint can be also used as a Vector.

import SwiftyVector
import CoreGraphics

// CGPoint as a Vector
let a: CGPoint = [2.0, 1.0]
let b: CGPoint = [-3.0, 6.0]

let sum        = a + b                 // [-1.0, 7.0]
let difference = a - b                 // [5.0, -5.0]
let product    = a * 2                 // [4.0, 2.0]
let quotient   = a / 2                 // [1.0, 0.5]

let length     = a.length              // 2.23607
let distance   = a.distance(from: b)   // 6.08276

let dotProduct = a.dotProduct(with: b) // 0.0
let angle      = a.angle(from: b)      // 1.5708

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/koher/SwiftyVector.git", from: "0.3.0"),
]

Carthage

github "koher/SwiftyVector" ~> 0.3.0

License

MIT

关于
83.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号