Skip to content

Commit dcfcab2

Browse files
committed
fix index issue
1 parent f048111 commit dcfcab2

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

isaaclab_arena/relations/object_placer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,16 @@ def _generate_initial_positions(
152152
first_anchor = next(obj for obj in objects if obj in anchor_objects)
153153
anchor_bbox = first_anchor.get_world_bounding_box()
154154

155+
cx, cy, cz = float(anchor_bbox.center[0, 0]), float(anchor_bbox.center[0, 1]), float(anchor_bbox.center[0, 2])
156+
155157
positions: dict[Object | ObjectReference, tuple[float, float, float]] = {}
156158
for obj in objects:
157159
if obj in anchor_objects:
158160
positions[obj] = obj.get_initial_pose().position_xyz
159161
elif any(isinstance(r, On) for r in obj.get_relations()):
160162
positions[obj] = self._compute_on_guided_position(obj, anchor_objects, anchor_bbox, generator)
161163
else:
162-
positions[obj] = anchor_bbox.center # no spatial guidance; solver handles placement
164+
positions[obj] = (cx, cy, cz)
163165
return positions
164166

165167
def _get_on_parent_world_bbox(
@@ -220,7 +222,7 @@ def _compute_on_guided_position(
220222
)
221223

222224
# Z: place child's bottom face at parent top + clearance
223-
z = parent_bbox.max_point[0, 2] + on_relation.clearance_m - child_bbox.min_point[0, 2]
225+
z = float(parent_bbox.max_point[0, 2] + on_relation.clearance_m - child_bbox.min_point[0, 2])
224226

225227
return (x, y, z)
226228

@@ -251,7 +253,7 @@ def _sample_axis_position(
251253
low = parent_min - child_min
252254
high = parent_max - child_max
253255
if low >= high:
254-
return (parent_min + parent_max) / 2.0
256+
return float((parent_min + parent_max) / 2.0)
255257
return float(low + (high - low) * torch.rand(1, generator=generator).item())
256258

257259
def _validate_on_relations(

isaaclab_arena/tests/test_object_placer_init.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ def test_on_init_x_y_within_parent_footprint():
4040
child_bbox = box.get_bounding_box()
4141
desk_world = desk.get_world_bounding_box()
4242

43-
assert x + child_bbox.min_point[0] >= desk_world.min_point[0] - 1e-6
44-
assert x + child_bbox.max_point[0] <= desk_world.max_point[0] + 1e-6
45-
assert y + child_bbox.min_point[1] >= desk_world.min_point[1] - 1e-6
46-
assert y + child_bbox.max_point[1] <= desk_world.max_point[1] + 1e-6
43+
assert x + child_bbox.min_point[0, 0] >= desk_world.min_point[0, 0] - 1e-6
44+
assert x + child_bbox.max_point[0, 0] <= desk_world.max_point[0, 0] + 1e-6
45+
assert y + child_bbox.min_point[0, 1] >= desk_world.min_point[0, 1] - 1e-6
46+
assert y + child_bbox.max_point[0, 1] <= desk_world.max_point[0, 1] + 1e-6
4747

4848

4949
def test_on_init_z_places_bottom_at_parent_top():
@@ -63,8 +63,8 @@ def test_on_init_z_places_bottom_at_parent_top():
6363
child_bbox = box.get_bounding_box()
6464
desk_world = desk.get_world_bounding_box()
6565

66-
child_bottom = z + child_bbox.min_point[2]
67-
expected_bottom = desk_world.max_point[2] + clearance_m
66+
child_bottom = z + child_bbox.min_point[0, 2]
67+
expected_bottom = desk_world.max_point[0, 2] + clearance_m
6868
assert abs(child_bottom - expected_bottom) < 1e-6
6969

7070

@@ -88,8 +88,8 @@ def test_on_init_clamps_to_center_when_child_wider_than_parent():
8888

8989
x, y, _ = positions[big_box]
9090
desk_world = desk.get_world_bounding_box()
91-
center_x = (desk_world.min_point[0] + desk_world.max_point[0]) / 2.0
92-
center_y = (desk_world.min_point[1] + desk_world.max_point[1]) / 2.0
91+
center_x = (desk_world.min_point[0, 0] + desk_world.max_point[0, 0]) / 2.0
92+
center_y = (desk_world.min_point[0, 1] + desk_world.max_point[0, 1]) / 2.0
9393

9494
assert abs(x - center_x) < 1e-6
9595
assert abs(y - center_y) < 1e-6
@@ -109,7 +109,7 @@ def test_no_on_relation_initializes_at_anchor_center():
109109

110110
x, y, z = positions[box]
111111
desk_world = desk.get_world_bounding_box()
112-
center = desk_world.center
112+
center = desk_world.center[0]
113113

114114
assert abs(x - center[0]) < 1e-6
115115
assert abs(y - center[1]) < 1e-6
@@ -138,11 +138,11 @@ def test_on_non_anchor_parent_with_anchor_grandparent_uses_proxy():
138138
desk_world = desk.get_world_bounding_box()
139139

140140
# Mug's parent (plate) is non-anchor with On(desk): uses desk's bbox as proxy
141-
assert desk_world.min_point[0] <= x <= desk_world.max_point[0]
142-
assert desk_world.min_point[1] <= y <= desk_world.max_point[1]
141+
assert desk_world.min_point[0, 0] <= x <= desk_world.max_point[0, 0]
142+
assert desk_world.min_point[0, 1] <= y <= desk_world.max_point[0, 1]
143143
# Z: desk top (0.1) + clearance (0.0) - mug bbox min_z (0.0) = 0.1
144144
mug_bbox = mug.get_bounding_box()
145-
assert abs(z - (desk_world.max_point[2] + 0.0 - mug_bbox.min_point[2])) < 1e-6
145+
assert abs(z - (desk_world.max_point[0, 2] + 0.0 - mug_bbox.min_point[0, 2])) < 1e-6
146146

147147

148148
def test_on_non_anchor_parent_without_on_uses_fallback_bbox():
@@ -167,10 +167,10 @@ def test_on_non_anchor_parent_without_on_uses_fallback_bbox():
167167
desk_world = desk.get_world_bounding_box()
168168

169169
# Parent (stand) has no On relation: falls back to desk's world bbox
170-
assert desk_world.min_point[0] <= x <= desk_world.max_point[0]
171-
assert desk_world.min_point[1] <= y <= desk_world.max_point[1]
170+
assert desk_world.min_point[0, 0] <= x <= desk_world.max_point[0, 0]
171+
assert desk_world.min_point[0, 1] <= y <= desk_world.max_point[0, 1]
172172
# Z: desk.max_z (fallback) + clearance (0.0) - mug.min_z (0.0) = 0.1
173-
assert abs(z - (desk_world.max_point[2] + 0.0 - mug.get_bounding_box().min_point[2])) < 1e-6
173+
assert abs(z - (desk_world.max_point[0, 2] + 0.0 - mug.get_bounding_box().min_point[0, 2])) < 1e-6
174174

175175

176176
def test_on_init_reproducible_with_placement_seed():

0 commit comments

Comments
 (0)