Created
April 24, 2016 10:27
-
-
Save kanetai/aa622643994ec0b8d193eb98f6f887f8 to your computer and use it in GitHub Desktop.
[Swift]Simplified point type for competitive programming
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
typealias Point = (x: Int, y: Int) | |
func ==(lhs: Point, rhs: Point) -> Bool { return lhs.x == rhs.x && lhs.y == rhs.y } | |
func !=(lhs: Point, rhs: Point) -> Bool { return !(lhs == rhs) } | |
func +(lhs: Point, rhs: Point) -> Point { return Point(lhs.x + rhs.x, lhs.y + rhs.y) } | |
func +=(inout lhs: Point, rhs: Point) { lhs.x += rhs.x; lhs.y += rhs.y } | |
func -(lhs: Point, rhs: Point) -> Point { return Point(lhs.x - rhs.x, lhs.y - rhs.y) } | |
func -=(inout lhs: Point, rhs: Point) { lhs.x -= rhs.x; lhs.y -= rhs.y } | |
let neighborhood8: [Point] = [ | |
(0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1) | |
] | |
let neighborhood4: [Point] = [ | |
(0, -1), (1, 0), (0, 1), (-1, 0) | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment