hd-utils
Version:
A handy utils for modern JS developers
15 lines (14 loc) • 709 B
TypeScript
import { Point2D, Point3D, PointObject } from "../types";
/**
* @description Finds the Euclidean distance between two 2D or 3D points, accepting input in object or array format. It includes runtime type-checking and throws an error for invalid inputs. The result is the Euclidean distance.
* @example
* const pointObjA = { x: 1, y: 2};
* const pointObjB = { x: 4, y: 5 };
* calculateDistance(pointObjA, pointObjB) //4.242640687119285
*
* const pointArrA = [1, 2, 3];
* const pointArrB = [4, 5, 6];
* calculateDistance(pointArrA, pointArrB) //5.196152422706632
*
*/
export default function calculateDistance(pointA: Point2D | Point3D | PointObject, pointB: Point2D | Point3D | PointObject): number;