Table of Contents

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

X double
Y double

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

double

Y

public double Y { get; init; }

Property Value

double

Zero

The origin point (0, 0) in canvas space.

public static CanvasPoint Zero { get; }

Property Value

CanvasPoint

Methods

DistanceSquaredTo(CanvasPoint)

Calculates the squared distance to another point (faster than DistanceTo).

public double DistanceSquaredTo(CanvasPoint other)

Parameters

other CanvasPoint

Returns

double

DistanceTo(CanvasPoint)

Calculates the distance to another point.

public double DistanceTo(CanvasPoint other)

Parameters

other CanvasPoint

Returns

double

FromCore(Point)

Creates a canvas point from the core Point type.

public static CanvasPoint FromCore(Point point)

Parameters

point Point

Returns

CanvasPoint

FromNode(Node)

Creates a canvas point from a node's position.

public static CanvasPoint FromNode(Node node)

Parameters

node Node

Returns

CanvasPoint

Lerp(CanvasPoint, CanvasPoint, double)

Linearly interpolates between two points.

public static CanvasPoint Lerp(CanvasPoint a, CanvasPoint b, double t)

Parameters

a CanvasPoint
b CanvasPoint
t double

Returns

CanvasPoint

Rounded()

Returns a new point with both coordinates rounded to the nearest integer.

public CanvasPoint Rounded()

Returns

CanvasPoint

SnappedToGrid(double)

Returns a new point snapped to a grid.

public CanvasPoint SnappedToGrid(double gridSize)

Parameters

gridSize double

Returns

CanvasPoint

ToCore()

Converts to the core Point type.

public Point ToCore()

Returns

Point

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

point CanvasPoint
vector CanvasVector

Returns

CanvasPoint

operator -(CanvasPoint, CanvasPoint)

Calculates the vector between two points.

public static CanvasVector operator -(CanvasPoint a, CanvasPoint b)

Parameters

a CanvasPoint
b CanvasPoint

Returns

CanvasVector

operator -(CanvasPoint, CanvasVector)

Subtracts a vector from this point, producing a new point.

public static CanvasPoint operator -(CanvasPoint point, CanvasVector vector)

Parameters

point CanvasPoint
vector CanvasVector

Returns

CanvasPoint