Skip to content

Instantly share code, notes, and snippets.

@thanhluu
Created May 9, 2016 13:28
Show Gist options
  • Save thanhluu/89dae3932ab730b6a79482f337d7a8e6 to your computer and use it in GitHub Desktop.
Save thanhluu/89dae3932ab730b6a79482f337d7a8e6 to your computer and use it in GitHub Desktop.
IntSwiftS1V3T2
import UIKit
//struct Rectangle {
// var length: Int
// var width: Int
//
// var area: Int {
// return length * width
// }
//}
//
//let r1 = Rectangle(length: 5, width: 10)
//
//r1.area
struct Point {
var x: Int = 0
var y: Int = 0
}
struct Size {
var width: Int = 0
var height: Int = 0
}
struct Rectangle {
var origin = Point()
var size = Size()
var center: Point {
get {
let centerX = origin.x + size.width/2
let centerY = origin.y + size.height/2
return Point(x: centerX, y: centerY)
}
set(centerValue) {
origin.x = centerValue.x - size.width/2
origin.y = centerValue.y - size.height/2
}
}
}
var rect = Rectangle()
print(rect.center)
rect.center = Point(x:10, y:15)
print(rect.center)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment