Commit b0028566 authored by h2b's avatar h2b

Fitting error fixed.

parent 3fe442b1
......@@ -61,7 +61,7 @@ class Cell protected (val width: Int, val height: Int, val origin: Pixel) extend
case VCenter (height-h)/2
case Bottom height-h
}
new Cell(w, h, Pixel(x, y))
new Cell(w, h, origin + Pixel(x, y))
}
override def toString = s"Cell($width, $height, $origin)"
......
......@@ -39,10 +39,21 @@ class CellTest extends FunSuite {
assertResult(Cell(100, 100, Pixel(450, 450)))(cell.fit(100, 100))
}
test("fitting default orientation with shifted origin") {
assertResult(Cell(100, 100, Pixel(550, 650)))(cell.at(Pixel(100, 200)).fit(100, 100))
}
test("fitting arbitrary orientations") {
assertResult(Cell(100, 100, Pixel(0, 0)))(cell.fit(100, 100, Cell.Orientation(Left, Top)))
assertResult(Cell(100, 100, Pixel(450, 450)))(cell.fit(100, 100, Cell.Orientation(HCenter, VCenter)))
assertResult(Cell(100, 100, Pixel(900, 900)))(cell.fit(100, 100, Cell.Orientation(Right, Bottom)))
}
test("fitting arbitrary orientations with shifted origin") {
val shifted = cell at Pixel(100, 200)
assertResult(Cell(100, 100, Pixel(100, 200)))(shifted.fit(100, 100, Cell.Orientation(Left, Top)))
assertResult(Cell(100, 100, Pixel(550, 650)))(shifted.fit(100, 100, Cell.Orientation(HCenter, VCenter)))
assertResult(Cell(100, 100, Pixel(1000, 1100)))(shifted.fit(100, 100, Cell.Orientation(Right, Bottom)))
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment