Skip to content

Conversation

@rickwierenga
Copy link
Member

Summary

Adds a new assign_child_by_anchor() method to the Resource class that allows assigning child resources by aligning anchor points instead of specifying absolute coordinates. This provides a more intuitive and flexible way to position resources relative to each other.

Key Features

  • Anchor-based alignment: Align any combination of anchors (left/center/right, front/center/back, bottom/center/top)
  • Dual syntax support:
    • Tuple syntax: parent_anchor=("c", "c", "b")
    • String syntax: parent_anchor="ccb" (more concise)
  • Default behavior: Defaults to left-front-bottom (LFB) alignment
  • Full integration: Maintains all existing callbacks, validation, and reassignment logic

Example Usage

# Default: align LFB of both resources
parent.assign_child_by_anchor(child)

# Center a child resource
parent.assign_child_by_anchor(child, parent_anchor="ccb", child_anchor="ccb")

# Stack resources on top of each other
parent.assign_child_by_anchor(child, parent_anchor="lft", child_anchor="lfb")

Implementation Details

  • Added helper function _compute_location_from_anchors() to calculate the location from anchor specifications
  • Method internally calls assign_child_resource() with computed location
  • Supports validation of string anchor length (must be exactly 3 characters)
  • Uses named arguments for clarity

Test Plan

  • 17 comprehensive unit tests added covering:
    • Default LFB alignment
    • All x, y, and z anchor combinations (27 subtests)
    • Center-center-bottom alignment
    • Corner alignments (LFB, RBT)
    • Stacking operations
    • Mixed anchor combinations
    • String and tuple syntax
    • Mixed string/tuple usage
    • Long-form anchor names ("center" vs "c")
    • Invalid string anchor length handling
    • Reassignment between parents
    • Callback triggering
  • All 48 resource tests pass
  • Pre-commit hooks pass (formatting, linting)

🤖 Generated with Claude Code

Adds a new method to assign child resources by aligning anchor points
instead of specifying absolute coordinates. This provides a more intuitive
way to position resources relative to each other.

Features:
- Align any combination of anchors (left/center/right, front/center/back, bottom/center/top)
- Support both tuple syntax ("l", "f", "b") and string syntax ("lfb")
- Default to left-front-bottom (LFB) alignment
- Maintain all existing callbacks and validation

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new assign_child_by_anchor() method to the Resource class that enables anchor-based positioning of child resources, providing a more intuitive alternative to calculating absolute coordinates manually.

Changes:

  • Added _compute_location_from_anchors() helper function to calculate relative locations from anchor specifications
  • Added assign_child_by_anchor() method supporting both tuple ("l", "f", "b") and string "lfb" anchor syntax
  • Added 17 comprehensive unit tests covering all anchor combinations, syntax variations, and edge cases

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pylabrobot/resources/resource.py Added _compute_location_from_anchors() helper and assign_child_by_anchor() method with dual syntax support for anchor-based child resource assignment
pylabrobot/resources/resource_tests.py Added TestAssignChildByAnchor test class with 17 comprehensive tests covering all anchor combinations, syntax variations, reassignment, and callbacks

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rickwierenga rickwierenga merged commit 4cb8242 into main Jan 25, 2026
16 checks passed
@rickwierenga rickwierenga deleted the feature/assign-child-by-anchor branch January 25, 2026 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants