Swift Package Index


Makes it easy to use CGPoint as vectors in Swift


  • The latest stable release is 0.4.1. Released 8 months ago.
  • The last commit to master was 8 months ago.

Swift Version Compatibility

  • 0.4.1 and master
    5.3
    5.2
    5.1
    5.0
    4.2
Full build results

Platform Compatibility

  • 0.4.1 and master
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
Full build results

CGPointVector

Build Status

CGPointVector provides the extension for arithmetic operations with CGPoint in Swift, which are convenient when CGPoint values are used as vectors.

let a = CGPoint(x: 1, y: 2), b = CGPoint(x: -3, y: 5)

let sum = a + b // (-2.0, 7.0)
let distance = (b - a).length // 5.0
let direction = (b - a).unit // (-0.8, 0.6)
let rotated = a * CGAffineTransform(rotationAngle: CGFloat.pi / 2) // (-2.0, 1.0)

Usage

import CGPointVector

let a = CGPoint(x: 3.0, y: -4.0)
let b = CGPoint(x: 2.0, y: -5.0)

let sum = a + b // (5.0, -9.0)
let length = a.length // 5.0
let distance = a.distance(from: b) // 1.4142135623731
let unitVector = a.unit // (0.6, -0.8)
let dotProduct = a.dot(b) // 26.0
let angle = a.angle(from: b) // 0.26299473168091936

License

The MIT License