-
Notifications
You must be signed in to change notification settings - Fork 61
Prefer calculated anchor offsets when moving #553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,7 @@ export const BoardAnchorOffsetOverlay = ({ | |
| const isShowingAnchorOffsets = useGlobalStore( | ||
| (state) => state.is_showing_group_anchor_offsets, | ||
| ) | ||
| const isMovingComponent = useGlobalStore((s) => s.is_moving_component) | ||
|
|
||
| if (!isShowingAnchorOffsets && hoveredComponentIds.length === 0) { | ||
| return null | ||
|
|
@@ -213,8 +214,26 @@ export const BoardAnchorOffsetOverlay = ({ | |
| const shouldShowYLabel = | ||
| yLineLength > VISUAL_CONFIG.MIN_LINE_LENGTH_FOR_LABEL | ||
|
|
||
| const xLabelText = `Board Δx: ${displayOffsetX ? displayOffsetX : offsetX.toFixed(2)}mm` | ||
| const yLabelText = `Board Δy: ${displayOffsetX ? displayOffsetX : offsetY.toFixed(2)}mm` | ||
| // Always show calculated offset when component is being moved or when stored offset doesn't match current position | ||
| const storedOffsetX = displayOffsetX | ||
| ? parseFloat(displayOffsetX) | ||
| : null | ||
| const storedOffsetY = displayOffsetY | ||
| ? parseFloat(displayOffsetY) | ||
| : null | ||
| const offsetMatchesStored = | ||
| storedOffsetX !== null && | ||
| storedOffsetY !== null && | ||
| Math.abs(offsetX - storedOffsetX) < 0.01 && // Allow small tolerance for floating point precision | ||
| Math.abs(offsetY - storedOffsetY) < 0.01 | ||
|
|
||
| const shouldUseCalculatedOffset = | ||
| isMovingComponent || | ||
| !displayOffsetX || | ||
| !displayOffsetY || | ||
| !offsetMatchesStored | ||
|
Comment on lines
+217
to
+234
|
||
| const xLabelText = `Board Δx: ${shouldUseCalculatedOffset ? offsetX.toFixed(2) : displayOffsetX || offsetX.toFixed(2)}mm` | ||
| const yLabelText = `Board Δy: ${shouldUseCalculatedOffset ? offsetY.toFixed(2) : displayOffsetY || offsetY.toFixed(2)}mm` | ||
|
|
||
| return ( | ||
| <g key={`${target.board.pcb_board_id}-${targetId}-${target.type}`}> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,6 +92,7 @@ export const GroupAnchorOffsetOverlay = ({ | |
| const isShowingAnchorOffsets = useGlobalStore( | ||
| (s) => s.is_showing_group_anchor_offsets, | ||
| ) | ||
| const isMovingComponent = useGlobalStore((s) => s.is_moving_component) | ||
|
|
||
| if (!isShowingAnchorOffsets && hoveredComponentIds.length === 0) { | ||
| return null | ||
|
|
@@ -287,8 +288,26 @@ export const GroupAnchorOffsetOverlay = ({ | |
| const shouldShowYLabel = | ||
| yLineLength > VISUAL_CONFIG.MIN_LINE_LENGTH_FOR_LABEL | ||
|
|
||
| const xLabelText = `Δx: ${displayOffsetX ? displayOffsetX : offsetX.toFixed(2)}mm` | ||
| const yLabelText = `Δy: ${displayOffsetY ? displayOffsetY : offsetY.toFixed(2)}mm` | ||
| // Always show calculated offset when component is being moved or when stored offset doesn't match current position | ||
| const storedOffsetX = displayOffsetX | ||
| ? parseFloat(displayOffsetX) | ||
| : null | ||
| const storedOffsetY = displayOffsetY | ||
| ? parseFloat(displayOffsetY) | ||
| : null | ||
| const offsetMatchesStored = | ||
| storedOffsetX !== null && | ||
| storedOffsetY !== null && | ||
| Math.abs(offsetX - storedOffsetX) < 0.01 && // Allow small tolerance for floating point precision | ||
| Math.abs(offsetY - storedOffsetY) < 0.01 | ||
|
Comment on lines
+301
to
+302
|
||
|
|
||
| const shouldUseCalculatedOffset = | ||
| isMovingComponent || | ||
| !displayOffsetX || | ||
| !displayOffsetY || | ||
| !offsetMatchesStored | ||
|
Comment on lines
+291
to
+308
|
||
| const xLabelText = `Δx: ${shouldUseCalculatedOffset ? offsetX.toFixed(2) : displayOffsetX || offsetX.toFixed(2)}mm` | ||
| const yLabelText = `Δy: ${shouldUseCalculatedOffset ? offsetY.toFixed(2) : displayOffsetY || offsetY.toFixed(2)}mm` | ||
|
|
||
| return ( | ||
| <g | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tolerance value 0.01 is a magic number that appears in both Board and Group overlay components. Consider extracting it to a named constant in VISUAL_CONFIG or a shared constants file for better maintainability and consistency.