Table of Contents

Namespace FlowGraph.Core.Coordinates

Classes

TypedCoordinateTransformer

Default implementation of ITypedCoordinateTransformer.

TypedCoordinateTransformerExtensions

Extension methods for ITypedCoordinateTransformer.

Structs

CanvasPoint

A point in canvas coordinate space (logical graph coordinates).

Canvas coordinates represent the logical position of elements in the graph. Node positions, port centers, edge endpoints all use canvas coordinates. These values are stable regardless of zoom/pan - a node at (100, 200) stays at (100, 200) even when the user zooms or pans.

When to use:

  • Node positions (node.Position)
  • Port centers calculated from node geometry
  • Edge start/end points
  • Hit testing against graph elements
  • Selection bounds in graph space
CanvasRect

A rectangle in canvas coordinate space.

Canvas rectangles represent bounded regions in the graph coordinate space. Node bounds, selection areas, and visible regions are expressed as canvas rects.

CanvasVector

A vector/delta in canvas coordinate space.

Canvas vectors represent movements, offsets, and distances in canvas space. Unlike canvas points, vectors are relative (they represent the difference between two points, not an absolute position).

When to use:

  • Drag distances in canvas space
  • Node movement offsets
  • Snap offsets
  • Collision avoidance adjustments
ViewportPoint

A point in viewport coordinate space (screen/control coordinates).

Viewport coordinates represent positions within the visible canvas control. (0,0) is the top-left of the canvas control, and values increase to the right and down. These coordinates change as the user pans and zooms - a node at canvas (100, 200) will appear at different viewport positions depending on the current zoom/pan state.

When to use:

  • Auto-pan edge detection (checking if cursor is near viewport edges)
  • Fixed UI positioning (tooltips, menus that don't pan/zoom)
  • Direct rendering to DrawingContext (after converting from canvas)
  • Viewport bounds calculations

Important: Viewport coordinates assume (0,0) is at the canvas control's origin. If the canvas is embedded in a larger control with margins/toolbars, you may need to account for offsets when converting from parent control coordinates.

ViewportRect

A rectangle in viewport coordinate space.

Viewport rectangles represent bounded regions in screen/control space. The most common use is representing the viewport bounds itself (the visible area).

ViewportVector

A vector/delta in viewport coordinate space.

Viewport vectors represent movements and distances in screen/control space. They are affected by zoom - the same canvas distance appears as a larger viewport distance at higher zoom levels.

Interfaces

ITypedCoordinateTransformer

Type-safe coordinate transformer that converts between canvas and viewport coordinate spaces.

This interface provides compile-time type safety for coordinate conversions by using distinct types for canvas and viewport coordinates. This prevents accidental mixing of coordinate spaces, which is a common source of bugs in pan/zoom implementations.

Coordinate Space Relationships:

Viewport → Canvas:  canvas = (viewport - offset) / zoom
Canvas → Viewport:  viewport = canvas * zoom + offset