wibox.hierarchy: Fix the matrix_to/from_device

Matrix operations are hard. Apparently I always keep confusing the order
that transformations are applied in the matrix resulting from a matrix
multiplication.

This commit fixes things in wibox.hierarchy that were wrong due to the
wrong order and changes a unit test so that it would now catch the
breakage (and makes sure that it does not happen again).

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-10-01 16:24:04 +02:00
parent 6d8e91f5e2
commit 4bb02d1b53
2 changed files with 8 additions and 8 deletions

View File

@ -126,7 +126,7 @@ function hierarchy_update(self, context, widget, width, height, region, matrix_t
r = hierarchy_new(self._redraw_callback, self._layout_callback, self._callback_arg)
r._parent = self
end
hierarchy_update(r, context, w._widget, w._width, w._height, region, w._matrix, matrix_to_device * w._matrix)
hierarchy_update(r, context, w._widget, w._width, w._height, region, w._matrix, w._matrix * matrix_to_device)
table.insert(self._children, r)
end

View File

@ -124,7 +124,7 @@ describe("wibox.hierarchy", function()
before_each(function()
child = make_widget(nil)
intermediate = make_widget({
make_child(child, 10, 20, matrix.create_translate(0, 5))
make_child(child, 10, 20, matrix.create_translate(0, 5):scale(2, 2))
})
parent = make_widget({
make_child(intermediate, 5, 2, matrix.create_translate(4, 0))
@ -151,33 +151,33 @@ describe("wibox.hierarchy", function()
end)
it("get_matrix_to_parent", function()
assert.is.equal(hierarchy_child:get_matrix_to_parent(), matrix.create_translate(0, 5))
assert.is.equal(hierarchy_child:get_matrix_to_parent(), matrix.create(2, 0, 0, 2, 0, 5))
assert.is.equal(hierarchy_intermediate:get_matrix_to_parent(), matrix.create_translate(4, 0))
assert.is.equal(hierarchy_parent:get_matrix_to_parent(), matrix.identity)
end)
it("get_matrix_to_device", function()
assert.is.equal(hierarchy_child:get_matrix_to_device(), matrix.create_translate(4, 5))
assert.is.equal(hierarchy_child:get_matrix_to_device(), matrix.create(2, 0, 0, 2, 4, 5))
assert.is.equal(hierarchy_intermediate:get_matrix_to_device(), matrix.create_translate(4, 0))
assert.is.equal(hierarchy_parent:get_matrix_to_device(), matrix.identity)
end)
it("get_matrix_from_parent", function()
assert.is.equal(hierarchy_child:get_matrix_from_parent(), matrix.create_translate(0, -5))
assert.is.equal(hierarchy_child:get_matrix_from_parent(), matrix.create(0.5, 0, 0, 0.5, 0, -2.5))
assert.is.equal(hierarchy_intermediate:get_matrix_from_parent(), matrix.create_translate(-4, 0))
assert.is.equal(hierarchy_parent:get_matrix_from_parent(), matrix.identity)
end)
it("get_matrix_from_device", function()
assert.is.equal(hierarchy_child:get_matrix_from_device(), matrix.create_translate(-4, -5))
assert.is.equal(hierarchy_child:get_matrix_from_device(), matrix.create(0.5, 0, 0, 0.5, -2, -2.5))
assert.is.equal(hierarchy_intermediate:get_matrix_from_device(), matrix.create_translate(-4, 0))
assert.is.equal(hierarchy_parent:get_matrix_from_device(), matrix.identity)
end)
it("get_draw_extents", function()
assert.is.same({ hierarchy_child:get_draw_extents() }, { 0, 0, 10, 20 })
assert.is.same({ hierarchy_intermediate:get_draw_extents() }, { 0, 0, 10, 25 })
assert.is.same({ hierarchy_parent:get_draw_extents() }, { 0, 0, 15, 25 })
assert.is.same({ hierarchy_intermediate:get_draw_extents() }, { 0, 0, 20, 45 })
assert.is.same({ hierarchy_parent:get_draw_extents() }, { 0, 0, 24, 45 })
end)
it("get_size", function()