Skip to content

feat: add motion length to visualiser tooltip for G0/G1/G2/G3 - #159

Merged
misiekhardcore merged 4 commits into
mainfrom
forge/ws-e4184c02
Sep 30, 2026
Merged

misiekhardcore merged 4 commits into
mainfrom
forge/ws-e4184c02

Conversation

@misiekhardcore

Copy link
Copy Markdown
Contributor

Motion Length in Visualiser Tooltip

This PR adds motion length calculation and display for all linear and arc motion commands (G0, G1, G2, G3) in the 3D visualizer tooltip.

Changes

Type Definition (src/visualizer/types.ts)

Added a required length: number property to PathSegment. This ensures every segment has a computable length - even zero-length segments (full circles, no-move commands) are valid and meaningful.

Path Extraction (src/visualizer/GCodePathExtractor.ts)

The extractor now calculates length during segment creation:

  • Linear moves: Euclidean distance: √((x₂-x₁)² + (y₂-y₁)² + (z₂-z₁)²)
  • Arcs: Chord length from first to last interpolated point
  • G28 returns: Each rapid segment's individual length

A sanity check ensures lengths are non-negative.

Tooltip Display (src/webview/components/InfoPanel.tsx)

The tooltip now shows motion length alongside existing information:

Type: Feed
Line 15: G1 X5 Y-12 Z8 F200
Feed: 200
X:0.000 Y:-12.000 Z:8.000 → X:5.000 Y:-7.000 Z:16.000
Length: 15.264
I:3.500 J:2.000
[Go to line 15]

Tests (src/test/GCodePathExtractor.test.ts)

Added 10 new test cases covering:

  • Linear moves with single/multiple axes (G0, G1)
  • Incremental mode lengths (G91)
  • Arc chords (G2, G3) including full circles
  • R-word arc format
  • Multi-axis arc movement

All 1438 existing tests continue to pass.

Example Usage

Hovering over a segment now shows:

Type: Rapid
Line 10: G0 X5 Y-12 Z8
X:0.000 Y:-12.000 Z:8.000 → X:5.000 Y:-7.000 Z:16.000
Length: 15.264

The length is computed in work units (mm or inches depending on machine settings).

Testing

npm test              # All 1438 tests pass
npm run build         # Compiles successfully

- Add  property to PathSegment interface (required, never null)
- Calculate chord length during path extraction:
  * Linear moves (G0, G1): Euclidean distance from start to end point
  * Arcs (G2, G3): Chord length from first to last interpolated point
  * G28 returns: Each rapid segment's individual length
- Display motion length in tooltip alongside coordinates and feed/spindle info
- Add comprehensive unit tests for:
  * Linear moves with all three axes
  * Incremental mode (G91)
  * Full circle arcs (zero chord length)
  * Multi-axis arc chords
  * Variable-based movements
- Add `length` property to PathSegment interface (required, never null)
- Calculate chord length during path extraction:
  * Linear moves (G0, G1): Euclidean distance from start to end point
  * Arcs (G2, G3): Chord length from first to last interpolated point
  * G28 returns: Each rapid segment's individual length
- Display motion length in tooltip alongside coordinates and feed/spindle info
- Add comprehensive unit tests for:
  * Linear moves with all three axes
  * Incremental mode (G91)
  * Full circle arcs (zero chord length)
  * Multi-axis arc chords
  * Variable-based movements
- Remove  property from PathSegment interface
- Calculate Euclidean distance on-the-fly in InfoPanel.tsx:
  * Math.hypot(end.x - start.x, end.y - start.y, end.z - start.z)
  * Applied during tooltip render for display only
- Update GCodePathExtractor to no longer store lengths during extraction
- Remove test cases that accessed segment.length (now internal implementation detail)

This keeps the domain layer simpler and makes length calculation a pure
visualization concern rather than a path data attribute.
The 'on-the-fly length' tests added to GCodePathExtractor.test.ts are unnecessary.
They test basic Math.hypot functionality which is unrelated to the extractor,
and don't verify that InfoPanel correctly displays motion lengths. The feature
is already verified by e2e screenshots and manual testing.
@misiekhardcore
misiekhardcore merged commit b7cd492 into main Sep 30, 2026
7 checks passed
@misiekhardcore
misiekhardcore deleted the forge/ws-e4184c02 branch September 30, 2026 10:30
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.

1 participant