@gravity-ui/graph
Version:
Modern graph editor component
37 lines (36 loc) • 1.09 kB
TypeScript
import { TPoint } from "../types/shapes";
/**
* Calculate Euclidean distance between two points
*
* @param p1 First point
* @param p2 Second point
* @returns Distance between the points
*
* @example
* ```typescript
* const distance = vectorDistance({ x: 0, y: 0 }, { x: 3, y: 4 });
* console.log(distance); // 5
* ```
*/
export declare function vectorDistance(p1: TPoint, p2: TPoint): number;
/**
* Calculate squared Euclidean distance between two points
* Faster than vectorDistance as it avoids the square root operation
* Useful for comparisons where the actual distance value is not needed
*
* @param p1 First point
* @param p2 Second point
* @returns Squared distance between the points
*
* @example
* ```typescript
* const distSq = vectorDistanceSquared({ x: 0, y: 0 }, { x: 3, y: 4 });
* console.log(distSq); // 25
*
* // Useful for distance comparisons without sqrt
* if (vectorDistanceSquared(p1, p2) < threshold * threshold) {
* // Point is within threshold
* }
* ```
*/
export declare function vectorDistanceSquared(p1: TPoint, p2: TPoint): number;