Struct CanvasPoint
- Namespace
- FlowGraph.Core.Coordinates
- Assembly
- FlowGraph.Core.dll
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
public readonly record struct CanvasPoint : IEquatable<CanvasPoint>
- Implements
- Inherited Members
- Extension Methods
Examples
var nodePosition = CanvasPoint.FromNode(node);
var portCenter = renderModel.GetPortPosition(node, port, isOutput);
// Type-safe - compiler prevents mixing with ViewportPoint
CanvasPoint canvasPos = context.Coordinates.GetPointerCanvasPosition(e);
Constructors
CanvasPoint(double, double)
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
public CanvasPoint(double X, double Y)
Parameters
Examples
var nodePosition = CanvasPoint.FromNode(node);
var portCenter = renderModel.GetPortPosition(node, port, isOutput);
// Type-safe - compiler prevents mixing with ViewportPoint
CanvasPoint canvasPos = context.Coordinates.GetPointerCanvasPosition(e);
Properties
X
public double X { get; init; }
Property Value
Y
public double Y { get; init; }
Property Value
Zero
The origin point (0, 0) in canvas space.
public static CanvasPoint Zero { get; }
Property Value
Methods
DistanceSquaredTo(CanvasPoint)
Calculates the squared distance to another point (faster than DistanceTo).
public double DistanceSquaredTo(CanvasPoint other)
Parameters
otherCanvasPoint
Returns
DistanceTo(CanvasPoint)
Calculates the distance to another point.
public double DistanceTo(CanvasPoint other)
Parameters
otherCanvasPoint
Returns
FromCore(Point)
Creates a canvas point from the core Point type.
public static CanvasPoint FromCore(Point point)
Parameters
pointPoint
Returns
FromNode(Node)
Creates a canvas point from a node's position.
public static CanvasPoint FromNode(Node node)
Parameters
nodeNode
Returns
Lerp(CanvasPoint, CanvasPoint, double)
Linearly interpolates between two points.
public static CanvasPoint Lerp(CanvasPoint a, CanvasPoint b, double t)
Parameters
aCanvasPointbCanvasPointtdouble
Returns
Rounded()
Returns a new point with both coordinates rounded to the nearest integer.
public CanvasPoint Rounded()
Returns
SnappedToGrid(double)
Returns a new point snapped to a grid.
public CanvasPoint SnappedToGrid(double gridSize)
Parameters
gridSizedouble
Returns
ToCore()
Converts to the core Point type.
public Point ToCore()
Returns
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
Operators
operator +(CanvasPoint, CanvasVector)
Adds a vector to this point, producing a new point.
public static CanvasPoint operator +(CanvasPoint point, CanvasVector vector)
Parameters
pointCanvasPointvectorCanvasVector
Returns
operator -(CanvasPoint, CanvasPoint)
Calculates the vector between two points.
public static CanvasVector operator -(CanvasPoint a, CanvasPoint b)
Parameters
Returns
operator -(CanvasPoint, CanvasVector)
Subtracts a vector from this point, producing a new point.
public static CanvasPoint operator -(CanvasPoint point, CanvasVector vector)
Parameters
pointCanvasPointvectorCanvasVector