{"size": 808, "ext": "js", "max_stars_repo_path": "src/geometry/2d/closest-pair.test.js", "max_stars_repo_name": "kmamal/math", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/geometry/2d/closest-pair.test.js", "max_issues_repo_name": "kmamal/math", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/geometry/2d/closest-pair.test.js", "max_forks_repo_name": "kmamal/math", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.2, "max_line_length": 62, "alphanum_fraction": 0.5618811881}
const { test } = require('@kmamal/testing')
const N = require('../../domains/number')
const { closestPair } = require('./closest-pair').defineFor(N)
const V2 = require('../../linear-algebra/vec2').defineFor(N)
const { map } = require('@kmamal/util/array/map')

const M = 100

test("geometry.closestPair", (t) => {
	const points = new Array(M)
	map.$$$(points, () => [ Math.random(), Math.random() ])

	let a
	let b
	let dist = Infinity
	for (let i = 1; i < M; i++) {
		const c = points[i]
		for (let j = 0; j < i; j++) {
			const d = points[j]
			const cd = V2.sub(d, c)
			const norm = V2.norm(cd)
			if (norm < dist) {
				a = c
				b = d
				dist = norm
			}
		}
	}

	const result = closestPair(points)

	if (V2.eq(a, result.b)) {
		const tmp = a
		a = b
		b = tmp
	}

	t.equal(result, { a, b, dist })
})
