forked from kylebshr/chain-heal-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint.swift
39 lines (29 loc) · 775 Bytes
/
Point.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// Point.swift
// chain-heal
//
// Created by Kyle Bashour on 12/7/15.
// Copyright © 2015 Kyle Bashour. All rights reserved.
//
#if os(Linux)
import Glibc
#endif
import Foundation
/**
* A simple, probably unnecessary, struct for creating a point from two Ints
*/
struct Point {
var x: Int
var y: Int
/**
Find the distance between two Points
- parameter toPoint: The Point we want the distance to
- returns: The distance between this Point and the given Point
*/
func distanceTo(toPoint: Point) -> Double {
// Do the math
let xDistance = x - toPoint.x
let yDistance = y - toPoint.y
return sqrt(Double((xDistance * xDistance) + (yDistance * yDistance)))
}
}