Returns the reference of the closest block of the array.
import { Block, findClosestBlock } from "blockwise";const blockList: Block[] = [ { x: 10, y: 0, w: 1, h: 1 }, { x: 1, y: 1, w: 1, h: 1 }, { x: 10, y: 0, w: 1, h: 1 }];const targetBlock: Block = { x: 0, y: 1, w: 1, h: 1 };const closestBlock: Block = findClosestBlock( blockList, targetBlock);console.log(closestBlock); // { x: 1, y: 1, w: 1, h: 1 } Copy
import { Block, findClosestBlock } from "blockwise";const blockList: Block[] = [ { x: 10, y: 0, w: 1, h: 1 }, { x: 1, y: 1, w: 1, h: 1 }, { x: 10, y: 0, w: 1, h: 1 }];const targetBlock: Block = { x: 0, y: 1, w: 1, h: 1 };const closestBlock: Block = findClosestBlock( blockList, targetBlock);console.log(closestBlock); // { x: 1, y: 1, w: 1, h: 1 }
Returns the reference of the closest block of the array.
Example