Struct ViewportPoint
- Namespace
- FlowGraph.Core.Coordinates
- Assembly
- FlowGraph.Core.dll
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.
public readonly record struct ViewportPoint : IEquatable<ViewportPoint>
- Implements
- Inherited Members
- Extension Methods
Constructors
ViewportPoint(double, double)
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.
public ViewportPoint(double X, double Y)
Parameters
Properties
X
public double X { get; init; }
Property Value
Y
public double Y { get; init; }
Property Value
Zero
The origin point (0, 0) in viewport space.
public static ViewportPoint Zero { get; }
Property Value
Methods
DistanceSquaredTo(ViewportPoint)
Calculates the squared distance to another point (faster than DistanceTo).
public double DistanceSquaredTo(ViewportPoint other)
Parameters
otherViewportPoint
Returns
DistanceTo(ViewportPoint)
Calculates the distance to another point.
public double DistanceTo(ViewportPoint other)
Parameters
otherViewportPoint
Returns
GetEdgePanDirection(ViewportRect, double)
Gets the direction(s) in which this point is near the edge.
public ViewportVector GetEdgePanDirection(ViewportRect bounds, double edgeDistance)
Parameters
boundsViewportRectThe viewport bounds to check against.
edgeDistancedoubleThe distance from edge to trigger.
Returns
- ViewportVector
A vector indicating the pan direction (negative = pan in that direction).
IsNearEdge(ViewportRect, double)
Checks if this point is within a distance from an edge of a bounding box. Useful for auto-pan edge detection.
public bool IsNearEdge(ViewportRect bounds, double edgeDistance)
Parameters
boundsViewportRectThe viewport bounds to check against.
edgeDistancedoubleThe distance from edge to trigger.
Returns
- bool
True if the point is within edgeDistance of any edge.
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
Operators
operator +(ViewportPoint, ViewportVector)
Adds a vector to this point, producing a new point.
public static ViewportPoint operator +(ViewportPoint point, ViewportVector vector)
Parameters
pointViewportPointvectorViewportVector
Returns
operator -(ViewportPoint, ViewportPoint)
Calculates the vector between two points.
public static ViewportVector operator -(ViewportPoint a, ViewportPoint b)
Parameters
Returns
operator -(ViewportPoint, ViewportVector)
Subtracts a vector from this point, producing a new point.
public static ViewportPoint operator -(ViewportPoint point, ViewportVector vector)
Parameters
pointViewportPointvectorViewportVector