refactor(xyhandle): cleanup
This commit is contained in:
@@ -3,18 +3,15 @@ import type { HandleType, XYPosition, Handle, InternalNodeBase, NodeLookup } fro
|
|||||||
|
|
||||||
function getNodesWithinDistance(position: XYPosition, nodeLookup: NodeLookup, distance: number): InternalNodeBase[] {
|
function getNodesWithinDistance(position: XYPosition, nodeLookup: NodeLookup, distance: number): InternalNodeBase[] {
|
||||||
const nodes: InternalNodeBase[] = [];
|
const nodes: InternalNodeBase[] = [];
|
||||||
|
const rect = {
|
||||||
|
x: position.x - distance,
|
||||||
|
y: position.y - distance,
|
||||||
|
width: distance * 2,
|
||||||
|
height: distance * 2,
|
||||||
|
};
|
||||||
|
|
||||||
for (const node of nodeLookup.values()) {
|
for (const node of nodeLookup.values()) {
|
||||||
const rect = {
|
if (getOverlappingArea(rect, nodeToRect(node)) > 0) {
|
||||||
x: position.x - distance,
|
|
||||||
y: position.y - distance,
|
|
||||||
width: distance * 2,
|
|
||||||
height: distance * 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
const overlappingArea = getOverlappingArea(rect, nodeToRect(node));
|
|
||||||
|
|
||||||
if (overlappingArea > 0) {
|
|
||||||
nodes.push(node);
|
nodes.push(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,7 +19,10 @@ function getNodesWithinDistance(position: XYPosition, nodeLookup: NodeLookup, di
|
|||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this distance is used for the area around the user pointer
|
||||||
|
// while doing a connection for finding the closest nodes
|
||||||
const ADDITIONAL_DISTANCE = 250;
|
const ADDITIONAL_DISTANCE = 250;
|
||||||
|
|
||||||
export function getClosestHandle(
|
export function getClosestHandle(
|
||||||
position: XYPosition,
|
position: XYPosition,
|
||||||
connectionRadius: number,
|
connectionRadius: number,
|
||||||
@@ -33,6 +33,7 @@ export function getClosestHandle(
|
|||||||
let minDistance = Infinity;
|
let minDistance = Infinity;
|
||||||
|
|
||||||
const closeNodes = getNodesWithinDistance(position, nodeLookup, connectionRadius + ADDITIONAL_DISTANCE);
|
const closeNodes = getNodesWithinDistance(position, nodeLookup, connectionRadius + ADDITIONAL_DISTANCE);
|
||||||
|
|
||||||
for (const node of closeNodes) {
|
for (const node of closeNodes) {
|
||||||
const allHandles = [...(node.internals.handleBounds?.source ?? []), ...(node.internals.handleBounds?.target ?? [])];
|
const allHandles = [...(node.internals.handleBounds?.source ?? []), ...(node.internals.handleBounds?.target ?? [])];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user