Skip to content

pointDistanceSquared

Returns the squared euclidean distance between two points.

The distance before the square root is taken. Comparing squared distances ranks points by distance just as well and skips the Math.sqrt, so the layout code uses this whenever it only needs to know which of several points is nearest.

import {pointDistanceSquared} from "@d3plus/math";

pointDistanceSquared([40, 160], [200, 40]);

Parameters

import {pointDistanceSquared} from "@d3plus/math";
p1requiredPoint

The first point, which should always be an [x, y] formatted Array.

p2requiredPoint

The second point, which should always be an [x, y] formatted Array.