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 <noreply@anthropic.com>
This commit is contained in:
parent
c15d836e79
commit
354faca838
12 changed files with 28 additions and 51 deletions
|
|
@ -1041,23 +1041,6 @@ PyObject* UIGrid::get_grid_h(PyUIGridObject* self, void* closure) {
|
||||||
return PyLong_FromLong(self->data->grid_h);
|
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
|
// #181 - Return size as Vector
|
||||||
PyObject* UIGrid::get_size(PyUIGridObject* self, void* closure) {
|
PyObject* UIGrid::get_size(PyUIGridObject* self, void* closure) {
|
||||||
auto& box = self->data->box;
|
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_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_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},
|
{"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},
|
{"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},
|
{"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},
|
{"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) {
|
bool UIGrid::setProperty(const std::string& name, const sf::Vector2f& value) {
|
||||||
if (name == "position") {
|
if (name == "size") {
|
||||||
position = value;
|
|
||||||
box.setPosition(position);
|
|
||||||
output.setPosition(position);
|
|
||||||
markCompositeDirty(); // #144 - Position change, texture still valid
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (name == "size") {
|
|
||||||
box.setSize(value);
|
box.setSize(value);
|
||||||
output.setTextureRect(sf::IntRect(0, 0, box.getSize().x, box.getSize().y));
|
output.setTextureRect(sf::IntRect(0, 0, box.getSize().x, box.getSize().y));
|
||||||
markDirty(); // #144 - Size change
|
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 {
|
bool UIGrid::getProperty(const std::string& name, sf::Vector2f& value) const {
|
||||||
if (name == "position") {
|
if (name == "size") {
|
||||||
value = position;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (name == "size") {
|
|
||||||
value = box.getSize();
|
value = box.getSize();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -3338,7 +3309,7 @@ bool UIGrid::hasProperty(const std::string& name) const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Vector2f properties
|
// Vector2f properties
|
||||||
if (name == "position" || name == "size" || name == "center" || name == "origin") {
|
if (name == "size" || name == "center" || name == "origin") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// #106: Shader uniform properties
|
// #106: Shader uniform properties
|
||||||
|
|
|
||||||
|
|
@ -107,8 +107,6 @@ public:
|
||||||
static PyObject* get_grid_size(PyUIGridObject* self, void* closure);
|
static PyObject* get_grid_size(PyUIGridObject* self, void* closure);
|
||||||
static PyObject* get_grid_w(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_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 PyObject* get_size(PyUIGridObject* self, void* closure);
|
||||||
static int set_size(PyUIGridObject* self, PyObject* value, void* closure);
|
static int set_size(PyUIGridObject* self, PyObject* value, void* closure);
|
||||||
static PyObject* get_center(PyUIGridObject* self, void* closure);
|
static PyObject* get_center(PyUIGridObject* self, void* closure);
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ ui = dijkstra_debug.children
|
||||||
ui.append(grid)
|
ui.append(grid)
|
||||||
|
|
||||||
# Position and scale
|
# Position and scale
|
||||||
grid.position = (50, 50)
|
grid.pos = (50, 50)
|
||||||
grid.size = (400, 400) # 10*40
|
grid.size = (400, 400) # 10*40
|
||||||
|
|
||||||
# Add title
|
# Add title
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,7 @@ ui.append(grid)
|
||||||
|
|
||||||
# Scale and position grid for better visibility
|
# Scale and position grid for better visibility
|
||||||
grid.size = (560, 400) # 14*40, 10*40
|
grid.size = (560, 400) # 14*40, 10*40
|
||||||
grid.position = (120, 60)
|
grid.pos = (120, 60)
|
||||||
|
|
||||||
# Add title
|
# Add title
|
||||||
title = mcrfpy.Caption(pos=(250, 10), text="Dijkstra Pathfinding Interactive")
|
title = mcrfpy.Caption(pos=(250, 10), text="Dijkstra Pathfinding Interactive")
|
||||||
|
|
|
||||||
|
|
@ -291,7 +291,7 @@ ui.append(grid)
|
||||||
|
|
||||||
# Scale and position grid for better visibility
|
# Scale and position grid for better visibility
|
||||||
grid.size = (560, 400) # 14*40, 10*40
|
grid.size = (560, 400) # 14*40, 10*40
|
||||||
grid.position = (120, 60)
|
grid.pos = (120, 60)
|
||||||
|
|
||||||
# Add title
|
# Add title
|
||||||
title = mcrfpy.Caption(pos=(250, 10), text="Enhanced Dijkstra Pathfinding")
|
title = mcrfpy.Caption(pos=(250, 10), text="Enhanced Dijkstra Pathfinding")
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ ui = dijkstra_test.children
|
||||||
ui.append(grid)
|
ui.append(grid)
|
||||||
|
|
||||||
# Position and scale grid
|
# Position and scale grid
|
||||||
grid.position = (50, 50)
|
grid.pos = (50, 50)
|
||||||
grid.size = (500, 300)
|
grid.size = (500, 300)
|
||||||
|
|
||||||
# Add title
|
# Add title
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ entity.update_visibility()
|
||||||
print("Setting up UI...")
|
print("Setting up UI...")
|
||||||
ui = vis_test.children
|
ui = vis_test.children
|
||||||
ui.append(grid)
|
ui.append(grid)
|
||||||
grid.position = (50, 50)
|
grid.pos = (50, 50)
|
||||||
grid.size = (300, 300)
|
grid.size = (300, 300)
|
||||||
|
|
||||||
# Test perspective
|
# Test perspective
|
||||||
|
|
|
||||||
|
|
@ -39,14 +39,22 @@ def test_grid_vectors():
|
||||||
assert center.y == 75.0, f"grid.center.y should be 75.0, got {center.y}"
|
assert center.y == 75.0, f"grid.center.y should be 75.0, got {center.y}"
|
||||||
print(" PASS: grid.center returns Vector")
|
print(" PASS: grid.center returns Vector")
|
||||||
|
|
||||||
# Test grid.position returns a Vector
|
# Test grid.pos returns a Vector
|
||||||
position = grid.position
|
pos = grid.pos
|
||||||
print(f" grid.position = {position}")
|
print(f" grid.pos = {pos}")
|
||||||
assert hasattr(position, 'x'), f"grid.position should have .x attribute, got {type(position)}"
|
assert hasattr(pos, 'x'), f"grid.pos should have .x attribute, got {type(pos)}"
|
||||||
assert hasattr(position, 'y'), f"grid.position should have .y attribute, got {type(position)}"
|
assert hasattr(pos, 'y'), f"grid.pos should have .y attribute, got {type(pos)}"
|
||||||
assert position.x == 100.0, f"grid.position.x should be 100.0, got {position.x}"
|
assert pos.x == 100.0, f"grid.pos.x should be 100.0, got {pos.x}"
|
||||||
assert position.y == 150.0, f"grid.position.y should be 150.0, got {position.y}"
|
assert pos.y == 150.0, f"grid.pos.y should be 150.0, got {pos.y}"
|
||||||
print(" PASS: grid.position returns Vector")
|
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!")
|
print("Issue #179 tests PASSED!")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ def visual_test(timer, runtime):
|
||||||
# Set up minimal UI for visual test
|
# Set up minimal UI for visual test
|
||||||
ui = astar_test.children
|
ui = astar_test.children
|
||||||
ui.append(grid)
|
ui.append(grid)
|
||||||
grid.position = (50, 50)
|
grid.pos = (50, 50)
|
||||||
grid.size = (400, 400)
|
grid.size = (400, 400)
|
||||||
|
|
||||||
astar_test.activate()
|
astar_test.activate()
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ def check_visual(timer, runtime):
|
||||||
# Set up minimal UI to test rendering
|
# Set up minimal UI to test rendering
|
||||||
ui = test.children
|
ui = test.children
|
||||||
ui.append(grid)
|
ui.append(grid)
|
||||||
grid.position = (50, 50)
|
grid.pos = (50, 50)
|
||||||
grid.size = (250, 250)
|
grid.size = (250, 250)
|
||||||
|
|
||||||
test.activate()
|
test.activate()
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ print(f" Visible cells after move: {visible_count}")
|
||||||
# Set up UI
|
# Set up UI
|
||||||
ui = visibility_test.children
|
ui = visibility_test.children
|
||||||
ui.append(grid)
|
ui.append(grid)
|
||||||
grid.position = (50, 50)
|
grid.pos = (50, 50)
|
||||||
grid.size = (600, 450) # 20*30, 15*30
|
grid.size = (600, 450) # 20*30, 15*30
|
||||||
|
|
||||||
# Add title
|
# Add title
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ if path:
|
||||||
# Set up UI
|
# Set up UI
|
||||||
ui = visual_test.children
|
ui = visual_test.children
|
||||||
ui.append(grid)
|
ui.append(grid)
|
||||||
grid.position = (50, 50)
|
grid.pos = (50, 50)
|
||||||
grid.size = (250, 250)
|
grid.size = (250, 250)
|
||||||
|
|
||||||
# Add title
|
# Add title
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue