Skip to content

Conversation

@Exceluyi
Copy link

@Exceluyi Exceluyi commented Nov 4, 2025

/claim #92
/fixes #92

This PR introduces the ability to rotate components when in "Move Components" mode.

  • A rotation handle (a small circle) has been added to the top-right corner of a selected component's bounding box.
  • Users can click and drag this handle to rotate the component.
  • A new edit_pcb_component_rotation manual edit event is created to store the rotation changes.
  • The component's rotation is visually updated in the PCB viewer.

DEMO VIDEO :

@tscircuit_pcb-viewer.-.Brave.2025-11-04.10-37-52.mp4

This commit introduces the ability to rotate components when in "Move Components" mode.

- A rotation handle (a small circle) has been added to the top-right corner of a selected component's bounding box.
- Users can click and drag this handle to rotate the component.
- A new `edit_pcb_component_rotation` manual edit event is created to store the rotation changes.
- The component's rotation is visually updated in the PCB viewer.
@vercel
Copy link

vercel bot commented Nov 4, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
pcb-viewer Ready Ready Preview Comment Nov 4, 2025 9:52am

Comment on lines +135 to +142
const angle = Math.atan2(
rwMousePoint.y - component.center.y,
rwMousePoint.x - component.center.x,
)
onModifyEditEvent({
edit_event_id: rotationState.edit_event_id,
new_rotation: rotationState.original_rotation + angle,
} as any)
Copy link

Choose a reason for hiding this comment

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

The current rotation implementation causes an abrupt snap when rotation begins because it doesn't account for the initial angle between the mouse and component center.

To create a smoother rotation experience:

  1. Store the initial mouse-to-component angle when rotation starts:
onMouseDown={(e) => {
  // existing code...
  const initialAngle = Math.atan2(
    mouseY - component.center.y,
    mouseX - component.center.x
  );
  setRotationState({
    pcb_component_id: activePcbComponentId!,
    edit_event_id,
    original_rotation,
    initialMouseAngle: initialAngle
  });
}
  1. Then calculate rotation based on the difference between current and initial angles:
onMouseMove={(e) => {
  // existing code...
  const currentAngle = Math.atan2(
    rwMousePoint.y - component.center.y,
    rwMousePoint.x - component.center.x
  );
  const angleDelta = currentAngle - rotationState.initialMouseAngle;
  onModifyEditEvent({
    edit_event_id: rotationState.edit_event_id,
    new_rotation: rotationState.original_rotation + angleDelta,
  });
}

This approach preserves the component's initial orientation and allows for more intuitive rotation control.

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@Exceluyi
Copy link
Author

Exceluyi commented Nov 4, 2025

@seveibar please review

1 similar comment
@Exceluyi
Copy link
Author

Exceluyi commented Nov 4, 2025

@seveibar please review

Copy link
Member

@imrishabh18 imrishabh18 left a comment

Choose a reason for hiding this comment

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

I don't see any rotation of pads in the video. Anyways we will be working on a re-rewrite of the pcb placement this week which will have this feature.

@Exceluyi
Copy link
Author

Exceluyi commented Nov 4, 2025

@imrishabh18 So i should close it or what ?

@Exceluyi Exceluyi closed this Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Rotations when in "Move Components" mode

2 participants