Skip to content

Repository files navigation

CGPointVector

CGPointVector CI

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

leta=CGPoint(x:1, y:2),b=CGPoint(x:-3, y:5)letsum= a + b // (-2.0, 7.0)
letdistance=(b - a).length // 5.0
letdirection=(b - a).unit // (-0.8, 0.6)
letrotated= a * CGAffineTransform(rotationAngle:CGFloat.pi /2) // (-2.0, 1.0)

Usage

import CGPointVector
leta=CGPoint(x:3.0, y:-4.0)letb=CGPoint(x:2.0, y:-5.0)letsum= a + b // (5.0, -9.0)
letlength= a.length // 5.0
letdistance= a.distance(from: b) // 1.4142135623731
letunitVector= a.unit // (0.6, -0.8)
letdotProduct= a.dot(b) // 26.0
letangle= a.angle(from: b) // 0.26299473168091936

License

The MIT License

About

Makes it easy to use CGPoint as vectors in Swift

Resources

Stars

41 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages