Swiftpack.co - Package - koher/SwiftyVector

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

Github

link
Stars: 6
Help us keep the lights on

Dependencies

Used By

Total: 1

Releases

0.3.2 - Jul 27, 2018

let vector: Vector2 = ...
let point: CGPoint = CGPoint(vector)
let vectorf: Vector2f = Vector2f(point)

Supported "CG" types are

  • CGPoint
  • CGSize
  • CGVector

0.3.1 - Apr 11, 2018

0.3.0 - Apr 11, 2018

  • Renamed the package to SwiftyVector
  • Any Scalar supports
    • Vector*f
    • CGPoint
  • Compound assignment operators

0.2.1 - Mar 12, 2018

0.2.0 - Mar 12, 2018

  • Changes types of elements from Float to Double
  • Supports Carthage
    • Makes it possible to use Swiftor for iOS, tvOS and watchOS
  • Vector4
  • Interoperability with CoreGraphics
    • Between Vector2 and CGPoint/CGSize