-
-
Save johndpope/aba6cab5eeb14993a426f0e6af0841de to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CGPoint : Hashable { | |
func distance(point: CGPoint) -> Float { | |
let dx = Float(x - point.x) | |
let dy = Float(y - point.y) | |
return sqrt((dx * dx) + (dy * dy)) | |
} | |
public var hashValue: Int { | |
// iOS Swift Game Development Cookbook | |
// https://books.google.se/books?id=QQY_CQAAQBAJ&pg=PA304&lpg=PA304&dq=swift+CGpoint+hashvalue&source=bl&ots=1hp2Fph274&sig=LvT36RXAmNcr8Ethwrmpt1ynMjY&hl=sv&sa=X&ved=0CCoQ6AEwAWoVChMIu9mc4IrnxgIVxXxyCh3CSwSU#v=onepage&q=swift%20CGpoint%20hashvalue&f=false | |
return x.hashValue << 32 ^ y.hashValue | |
} | |
} | |
func ==(lhs: CGPoint, rhs: CGPoint) -> Bool { | |
return lhs.distance(rhs) < 0.000001 //CGPointEqualToPoint(lhs, rhs) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment