class Geometry · Computations

Match

Matches the points of one set with the points of another.

Static methods

pointsWithPointsstatic

static pointsWithPoints(set1: Point[], set2: Point[]): number[]

Matches each point of the first set to a point of the second set so that the total distance of all pairs is as small as possible.

Each point of set2 is used at most once. If set1 has more points, the extra ones get −1; if set2 has more, some of its points stay unused. Because the total distance is minimal, no two pairs cross when drawn as segments (uncrossing them would make the total shorter); only points on one line can give overlapping segments. The time grows with the cube of the larger count (Hungarian method). A coordinate that is not a number throws.

set1
The first set of points.
set2
The second set of points.

Returns For each point of set1, the index of its partner in set2, or −1.