Skip to content

Instantly share code, notes, and snippets.

@trilliwon
Created July 29, 2020 10:28
Show Gist options
  • Save trilliwon/501290c7e4b1445a29bb92de223d9a1b to your computer and use it in GitHub Desktop.
Save trilliwon/501290c7e4b1445a29bb92de223d9a1b to your computer and use it in GitHub Desktop.
import CoreGraphics
extension CGPoint {
/// Calculates the distance between two points in 2D space.
/// + returns: The distance from this point to the given point.
func distance(to point: CGPoint) -> CGFloat {
return sqrt(pow(point.x - self.x, 2) + pow(point.y - self.y, 2))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment