Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/components/AnchorOffsetOverlay/Board/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Comment on lines +227 to +228
Copy link

Copilot AI Dec 16, 2025

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.

Copilot uses AI. Check for mistakes.

const shouldUseCalculatedOffset =
isMovingComponent ||
!displayOffsetX ||
!displayOffsetY ||
!offsetMatchesStored
Comment on lines +217 to +234
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The conditions !displayOffsetX and !displayOffsetY in shouldUseCalculatedOffset are redundant with the !offsetMatchesStored check, since offsetMatchesStored already requires both stored offsets to be non-null. Consider simplifying the logic to just check isMovingComponent || !offsetMatchesStored for better maintainability.

Copilot uses AI. Check for mistakes.
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}`}>
Expand Down
23 changes: 21 additions & 2 deletions src/components/AnchorOffsetOverlay/Group/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link

Copilot AI Dec 16, 2025

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.

Copilot uses AI. Check for mistakes.

const shouldUseCalculatedOffset =
isMovingComponent ||
!displayOffsetX ||
!displayOffsetY ||
!offsetMatchesStored
Comment on lines +291 to +308
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The conditions !displayOffsetX and !displayOffsetY in shouldUseCalculatedOffset are redundant with the !offsetMatchesStored check, since offsetMatchesStored already requires both stored offsets to be non-null. Consider simplifying the logic to just check isMovingComponent || !offsetMatchesStored for better maintainability.

Copilot uses AI. Check for mistakes.
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
Expand Down