Added helper stuff to Point and Rect

This commit is contained in:
bdew committed 2013-12-12 18:16:57 +02:00
1 parent 4dbca55ab1
commit 377fe3c27a
3 files changed
+12 -1

No files matched your search

+9
View File
@@ -14,3 +14,12 @@ class Point(val x: Int, val y: Int) {
def +(that: Point) = new Point(this.x + that.x, this.y + that.y)
def -(that: Point) = new Point(this.x - that.x, this.y - that.y)
}
object Point {
import language.implicitConversions
implicit def awt2point(p: java.awt.Point): Point = new Point(p.x, p.y)
implicit def point2awt(p: Point): java.awt.Point = new java.awt.Point(p.x, p.y)
implicit def tuple2point(p: (Int, Int)): Point = new Point(p._1, p._2)
}
+2
View File
@@ -13,4 +13,6 @@ class Rect(val x: Int, val y: Int, val w: Int, val h: Int) {
def this(p: Point, w: Int, h: Int) = this(p.x, p.y, w, h)
def contains(p: Point) = p.x >= x && p.y >= y && p.x <= x + w && p.y <= y + h
def origin = new Point(x, y)
def +(p: Point) = new Rect(origin + p, w, h)
def -(p: Point) = new Rect(origin - p, w, h)
}