export interface Point {
	x: number;
	y: number;
}

export interface Rect extends Point {
	width: number;
	height: number;
}

export function extractLinkNodePosX(canvasX: (x: number) => number, rect: Rect, grid_size: number) {
	if (rect.x === -1) {
		return canvasX(rect.x);
	}
	if (rect.x === rect.width) {
		return canvasX(rect.x) + rect.width * grid_size;
	}
	return canvasX(rect.x) + rect.x * grid_size + grid_size / 2;
}

export function extractLinkNodePosY(canvasY: (x: number) => number, node: Rect, grid_size: number) {
	if (node.y === -1) {
		return canvasY(node.y);
	}
	if (node.y === node.height) {
		return canvasY(node.y) + node.height * grid_size;
	}
	return canvasY(node.y) + node.y * grid_size + grid_size / 2;
}
