From 4bb02d1b531daeb348c60b642d0dc8ab63d34213 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 1 Oct 2016 16:24:04 +0200 Subject: [PATCH] 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 --- lib/wibox/hierarchy.lua | 2 +- spec/wibox/hierarchy_spec.lua | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/wibox/hierarchy.lua b/lib/wibox/hierarchy.lua index ffdc9924..69f03777 100644 --- a/lib/wibox/hierarchy.lua +++ b/lib/wibox/hierarchy.lua @@ -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 diff --git a/spec/wibox/hierarchy_spec.lua b/spec/wibox/hierarchy_spec.lua index 92541bc0..cb04451c 100644 --- a/spec/wibox/hierarchy_spec.lua +++ b/spec/wibox/hierarchy_spec.lua @@ -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()