Creates an instance of CoordinateSystem and attaches it to a canvas rendering context. The CoordinateSystem will use this context to apply transformations and perform hit testing.
the CanvasRenderingContext2D to attach to the CoordinateSystem
Attaches a diagram to the CoordinateSystem, allowing it to access diagram-level information such as the grid.
the IDiagram to attach to the CoordinateSystem
Applies the current viewport transformation to the specified canvas context, including zooming and panning.
the CanvasRenderingContext2D to apply the transformation to
Resets the transformation of the specified canvas context to the identity matrix, effectively removing any zooming or panning.
the CanvasRenderingContext2D to reset the transformation for
Converts the specified coordinates to the nearest grid point, if a grid is defined and forced.
the x-coordinate to convert
the y-coordinate to convert
Optionalgrid: IGridan optional grid to use for snapping, defaults to the diagram's grid if not provided
the nearest grid point
Converts the specified canvas coordinates to diagram coordinates, applying the current zoom and pan transformations, and optionally snapping to the grid.
the x-coordinate in canvas space
the y-coordinate in canvas space
Optionalgrid: IGrid | "ignore_grid"an optional grid to use for snapping, defaults to the diagram's grid if not provided
the corresponding point in diagram coordinates
Converts the specified pointer event coordinates to diagram coordinates, applying the current zoom and pan transformations, and optionally snapping to the grid.
the PointerEvent to convert
Optionalgrid: IGrid | "ignore_grid"an optional grid to use for snapping, defaults to the diagram's grid if not provided
the corresponding point in diagram coordinates
Converts the specified point from canvas coordinates to diagram coordinates, applying the current zoom and pan transformations, and optionally snapping to the grid.
the corresponding point in diagram coordinates
Converts the specified point from diagram coordinates to canvas coordinates, applying the current zoom and pan transformations.
the corresponding point in canvas coordinates
Calculates the bounding rectangle for a given node, taking into account its geometry and rotation. If the node has multiple points, it calculates the bounding rectangle defined by the top-left and bottom-right points. If the node is rotated, it calculates the bounding rectangle after rotation to ensure that it encompasses the entire shape.
the INode for which to calculate the bounding rectangle
OptionalwithAngle: booleanwhether to take the node's rotation angle into account when calculating the bounding rectangle.
the calculated bounding rectangle
Detects whether a given point (x, y) is within the stroke of a specified path, taking into account an optional line width. This method is useful for hit testing when determining if a user interaction (like a mouse click) occurred on the border of a shape.
the Path2D object representing the shape's stroke
the x-coordinate of the point to test
the y-coordinate of the point to test
OptionallineWidth: numberoptional line width to consider for the stroke
true if the point is within the stroke, false otherwise
Detects whether a given point (x, y) is within the path of a specified shape. This method is useful for hit testing when determining if a user interaction (like a mouse click) occurred inside a shape.
the Path2D object representing the shape's path
the x-coordinate of the point to test
the y-coordinate of the point to test
true if the point is within the path, false otherwise
CoordinateSystem is a utility class that manages the transformation between diagram coordinates and canvas coordinates, including handling zooming, panning, and grid snapping. It provides methods to convert points between the diagram's coordinate system and the canvas coordinate system, as well as methods to apply the current viewport transformation to a canvas context. The class also includes functionality to snap points to a grid if the grid is forced, and to calculate bounding rectangles for nodes based on their geometry and rotation.