Public
Edited
Feb 15, 2023
2 forks
17 stars
Insert cell
Insert cell
Insert cell
Insert cell
toeplitz = function (points) {
const test = testSquare(points);
let min = 0;
let solution;

for (let i = 0; i < points.length; i++) {
for (let j = 0; j < i; j++) {
const a = points[i];
const b = points[j];
const dist2 = (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2;
if (dist2 <= min) continue;
const m = [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2]; // center
const n = [(b[1] - a[1]) / 2, (a[0] - b[0]) / 2]; // normal
const c = [m[0] - n[0], m[1] - n[1]];
const d = [m[0] + n[0], m[1] + n[1]];
const t = test(a, c, b, d);
if (t) {
min = dist2;
solution = t;
}
}
}
return solution;
}
Insert cell
points = (feature) => {
const path = svg`<path d="${geopath(feature)}" stroke=black fill=none>`;
const l = path.getTotalLength();

// shuffling makes the algorithm a bit faster
return d3.shuffle(d3.range(0, l)).map((i) => {
const p = path.getPointAtLength(i);
return [p.x, p.y];
});
}
Insert cell
geopath = d3.geoPath().projection(projection)
Insert cell
function testSquare(points) {
const q = d3.quadtree(points);
return (a, c, b, d) =>
(c = q.find(...c, 1)) && (d = q.find(...d, 1)) && [a, c, b, d];
}
Insert cell
topo = d3.json(
"https://cdn.jsdelivr.net/npm/visionscarto-world-atlas@0.1.0/world/110m.json"
)
Insert cell
world = topojson.feature(topo, topo.objects.countries)
Insert cell
land = topojson.feature(topo, topo.objects.land)
Insert cell
projection = d3
.geoMercator()
.rotate([-10, 0])
.fitExtent(
[
[0, 0],
[width, height]
],
{ type: "Sphere" }
)
Insert cell
height = width
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more