From 354faca83898a00eba1a74c2ddca8756c163eb87 Mon Sep 17 00:00:00 2001 From: John McCardle Date: Thu, 9 Apr 2026 22:18:30 -0400 Subject: [PATCH] Remove redundant Grid.position alias, keep only Grid.pos, closes #308 Grid.position was a redundant alias for Grid.pos. Removed get_position/ set_position functions, getsetters entry, and setProperty/getProperty/ hasProperty branches. Updated all tests to use grid.pos. Co-Authored-By: Claude Opus 4.6 --- src/UIGrid.cpp | 35 ++----------------- src/UIGrid.h | 2 -- tests/integration/dijkstra_debug.py | 2 +- tests/integration/dijkstra_interactive.py | 2 +- .../dijkstra_interactive_enhanced.py | 2 +- tests/integration/dijkstra_test.py | 2 +- .../simple_interactive_visibility.py | 2 +- .../issue_179_181_grid_vectors_test.py | 24 ++++++++----- tests/unit/test_astar.py | 2 +- tests/unit/test_path_colors.py | 2 +- tests/unit/test_visibility.py | 2 +- tests/unit/test_visual_path.py | 2 +- 12 files changed, 28 insertions(+), 51 deletions(-) diff --git a/src/UIGrid.cpp b/src/UIGrid.cpp index 4876857..2deca60 100644 --- a/src/UIGrid.cpp +++ b/src/UIGrid.cpp @@ -1041,23 +1041,6 @@ PyObject* UIGrid::get_grid_h(PyUIGridObject* self, void* closure) { return PyLong_FromLong(self->data->grid_h); } -PyObject* UIGrid::get_position(PyUIGridObject* self, void* closure) { - // #179 - Return position as Vector (consistent with get_size, get_grid_size) - return PyVector(self->data->position).pyObject(); -} - -int UIGrid::set_position(PyUIGridObject* self, PyObject* value, void* closure) { - float x, y; - if (!PyArg_ParseTuple(value, "ff", &x, &y)) { - PyErr_SetString(PyExc_ValueError, "Position must be a tuple of two floats"); - return -1; - } - self->data->position = sf::Vector2f(x, y); // Update base class position - self->data->box.setPosition(self->data->position); // Sync box position - self->data->output.setPosition(self->data->position); // Sync output sprite position - return 0; -} - // #181 - Return size as Vector PyObject* UIGrid::get_size(PyUIGridObject* self, void* closure) { auto& box = self->data->box; @@ -2591,7 +2574,6 @@ PyGetSetDef UIGrid::getsetters[] = { {"grid_size", (getter)UIGrid::get_grid_size, NULL, "Grid dimensions (grid_w, grid_h)", NULL}, {"grid_w", (getter)UIGrid::get_grid_w, NULL, "Grid width in cells", NULL}, {"grid_h", (getter)UIGrid::get_grid_h, NULL, "Grid height in cells", NULL}, - {"position", (getter)UIGrid::get_position, (setter)UIGrid::set_position, "Position of the grid (x, y)", NULL}, {"pos", (getter)UIDrawable::get_pos, (setter)UIDrawable::set_pos, "Position of the grid as Vector", (void*)PyObjectsEnum::UIGRID}, {"grid_pos", (getter)UIDrawable::get_grid_pos, (setter)UIDrawable::set_grid_pos, "Position in parent grid's tile coordinates (only when parent is Grid)", (void*)PyObjectsEnum::UIGRID}, {"size", (getter)UIGrid::get_size, (setter)UIGrid::set_size, "Size of the grid as Vector (width, height)", NULL}, @@ -3207,14 +3189,7 @@ bool UIGrid::setProperty(const std::string& name, float value) { } bool UIGrid::setProperty(const std::string& name, const sf::Vector2f& value) { - if (name == "position") { - position = value; - box.setPosition(position); - output.setPosition(position); - markCompositeDirty(); // #144 - Position change, texture still valid - return true; - } - else if (name == "size") { + if (name == "size") { box.setSize(value); output.setTextureRect(sf::IntRect(0, 0, box.getSize().x, box.getSize().y)); markDirty(); // #144 - Size change @@ -3307,11 +3282,7 @@ bool UIGrid::getProperty(const std::string& name, float& value) const { } bool UIGrid::getProperty(const std::string& name, sf::Vector2f& value) const { - if (name == "position") { - value = position; - return true; - } - else if (name == "size") { + if (name == "size") { value = box.getSize(); return true; } @@ -3338,7 +3309,7 @@ bool UIGrid::hasProperty(const std::string& name) const { return true; } // Vector2f properties - if (name == "position" || name == "size" || name == "center" || name == "origin") { + if (name == "size" || name == "center" || name == "origin") { return true; } // #106: Shader uniform properties diff --git a/src/UIGrid.h b/src/UIGrid.h index fee9220..42a9fdc 100644 --- a/src/UIGrid.h +++ b/src/UIGrid.h @@ -107,8 +107,6 @@ public: static PyObject* get_grid_size(PyUIGridObject* self, void* closure); static PyObject* get_grid_w(PyUIGridObject* self, void* closure); static PyObject* get_grid_h(PyUIGridObject* self, void* closure); - static PyObject* get_position(PyUIGridObject* self, void* closure); - static int set_position(PyUIGridObject* self, PyObject* value, void* closure); static PyObject* get_size(PyUIGridObject* self, void* closure); static int set_size(PyUIGridObject* self, PyObject* value, void* closure); static PyObject* get_center(PyUIGridObject* self, void* closure); diff --git a/tests/integration/dijkstra_debug.py b/tests/integration/dijkstra_debug.py index fc4c953..cf5045d 100644 --- a/tests/integration/dijkstra_debug.py +++ b/tests/integration/dijkstra_debug.py @@ -144,7 +144,7 @@ ui = dijkstra_debug.children ui.append(grid) # Position and scale -grid.position = (50, 50) +grid.pos = (50, 50) grid.size = (400, 400) # 10*40 # Add title diff --git a/tests/integration/dijkstra_interactive.py b/tests/integration/dijkstra_interactive.py index 145edfa..c494093 100644 --- a/tests/integration/dijkstra_interactive.py +++ b/tests/integration/dijkstra_interactive.py @@ -199,7 +199,7 @@ ui.append(grid) # Scale and position grid for better visibility grid.size = (560, 400) # 14*40, 10*40 -grid.position = (120, 60) +grid.pos = (120, 60) # Add title title = mcrfpy.Caption(pos=(250, 10), text="Dijkstra Pathfinding Interactive") diff --git a/tests/integration/dijkstra_interactive_enhanced.py b/tests/integration/dijkstra_interactive_enhanced.py index 1ddb09d..ccf1fa6 100644 --- a/tests/integration/dijkstra_interactive_enhanced.py +++ b/tests/integration/dijkstra_interactive_enhanced.py @@ -291,7 +291,7 @@ ui.append(grid) # Scale and position grid for better visibility grid.size = (560, 400) # 14*40, 10*40 -grid.position = (120, 60) +grid.pos = (120, 60) # Add title title = mcrfpy.Caption(pos=(250, 10), text="Enhanced Dijkstra Pathfinding") diff --git a/tests/integration/dijkstra_test.py b/tests/integration/dijkstra_test.py index 0a2c34f..65e7842 100644 --- a/tests/integration/dijkstra_test.py +++ b/tests/integration/dijkstra_test.py @@ -124,7 +124,7 @@ ui = dijkstra_test.children ui.append(grid) # Position and scale grid -grid.position = (50, 50) +grid.pos = (50, 50) grid.size = (500, 300) # Add title diff --git a/tests/integration/simple_interactive_visibility.py b/tests/integration/simple_interactive_visibility.py index 1c70a0f..76a9dd2 100644 --- a/tests/integration/simple_interactive_visibility.py +++ b/tests/integration/simple_interactive_visibility.py @@ -35,7 +35,7 @@ entity.update_visibility() print("Setting up UI...") ui = vis_test.children ui.append(grid) -grid.position = (50, 50) +grid.pos = (50, 50) grid.size = (300, 300) # Test perspective diff --git a/tests/regression/issue_179_181_grid_vectors_test.py b/tests/regression/issue_179_181_grid_vectors_test.py index e177935..2eb3705 100644 --- a/tests/regression/issue_179_181_grid_vectors_test.py +++ b/tests/regression/issue_179_181_grid_vectors_test.py @@ -39,14 +39,22 @@ def test_grid_vectors(): assert center.y == 75.0, f"grid.center.y should be 75.0, got {center.y}" print(" PASS: grid.center returns Vector") - # Test grid.position returns a Vector - position = grid.position - print(f" grid.position = {position}") - assert hasattr(position, 'x'), f"grid.position should have .x attribute, got {type(position)}" - assert hasattr(position, 'y'), f"grid.position should have .y attribute, got {type(position)}" - assert position.x == 100.0, f"grid.position.x should be 100.0, got {position.x}" - assert position.y == 150.0, f"grid.position.y should be 150.0, got {position.y}" - print(" PASS: grid.position returns Vector") + # Test grid.pos returns a Vector + pos = grid.pos + print(f" grid.pos = {pos}") + assert hasattr(pos, 'x'), f"grid.pos should have .x attribute, got {type(pos)}" + assert hasattr(pos, 'y'), f"grid.pos should have .y attribute, got {type(pos)}" + assert pos.x == 100.0, f"grid.pos.x should be 100.0, got {pos.x}" + assert pos.y == 150.0, f"grid.pos.y should be 150.0, got {pos.y}" + print(" PASS: grid.pos returns Vector") + + # Verify grid.position alias was removed (#308) + try: + _ = grid.position + print(" FAIL: grid.position should not exist but it does!") + sys.exit(1) + except AttributeError: + print(" PASS: grid.position correctly removed (#308)") print("Issue #179 tests PASSED!") diff --git a/tests/unit/test_astar.py b/tests/unit/test_astar.py index ac39a05..28d5c9b 100644 --- a/tests/unit/test_astar.py +++ b/tests/unit/test_astar.py @@ -121,7 +121,7 @@ def visual_test(timer, runtime): # Set up minimal UI for visual test ui = astar_test.children ui.append(grid) -grid.position = (50, 50) +grid.pos = (50, 50) grid.size = (400, 400) astar_test.activate() diff --git a/tests/unit/test_path_colors.py b/tests/unit/test_path_colors.py index 027b76d..35ffddc 100644 --- a/tests/unit/test_path_colors.py +++ b/tests/unit/test_path_colors.py @@ -77,7 +77,7 @@ def check_visual(timer, runtime): # Set up minimal UI to test rendering ui = test.children ui.append(grid) -grid.position = (50, 50) +grid.pos = (50, 50) grid.size = (250, 250) test.activate() diff --git a/tests/unit/test_visibility.py b/tests/unit/test_visibility.py index 42b10bb..38fa22f 100644 --- a/tests/unit/test_visibility.py +++ b/tests/unit/test_visibility.py @@ -137,7 +137,7 @@ print(f" Visible cells after move: {visible_count}") # Set up UI ui = visibility_test.children ui.append(grid) -grid.position = (50, 50) +grid.pos = (50, 50) grid.size = (600, 450) # 20*30, 15*30 # Add title diff --git a/tests/unit/test_visual_path.py b/tests/unit/test_visual_path.py index b6561ef..684698d 100644 --- a/tests/unit/test_visual_path.py +++ b/tests/unit/test_visual_path.py @@ -66,7 +66,7 @@ if path: # Set up UI ui = visual_test.children ui.append(grid) -grid.position = (50, 50) +grid.pos = (50, 50) grid.size = (250, 250) # Add title