Published
Edited
Aug 31, 2021
1 fork
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
path = svg`<path d="${d3.geoPath().projection(projection)(
world
)}" stroke=black fill=none>`
Insert cell
points = (replay,
d3.shuffle(
d3.range(0, path.getTotalLength(), sample).map((i) => {
const p = path.getPointAtLength(i);
return [p.x, p.y];
})
))
Insert cell
toeplitz = {
let min = 0;
let solution = [];
let candidates = [];
let steps = 0;
let k;

for (let i = 0; i < points.length; i++) {
for (let j = 0; j < i; j++) {
k = (i * (i + 1) + (j + 1)) / 2;
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]];
if (steps++ % 100000 === 0)
yield {
test: [a, c, b, d],
solution,
candidates,
dist: Math.sqrt(min),
k
};
const t = testSquare(a, c, b, d);
if (t) {
min = dist2;
candidates.push((solution = t));
yield { test: t, solution: t, candidates, dist: Math.sqrt(min), k };
}
}
}
yield { test: [], solution, candidates, dist: Math.sqrt(min) };
}
Insert cell
quad = d3.quadtree(points)
Insert cell
sample = 1 // sample every pixel (try 3 for faster convergence)
Insert cell
function testSquare(a, c, b, d) {
c = quad.find(...c, sample);
if (c != null) {
d = quad.find(...d, sample);
if (d != null) {
return [a, c, b, d];
}
}
}
Insert cell
world = fetch("https://cdn.jsdelivr.net/npm/world-atlas@2/land-110m.json")
.then((d) => d.json())
.then((d) => topojson.feature(d, d.objects.land))
Insert cell
projection = d3.geoBertin1953().fitExtent(
[
[0, 0],
[width, height]
],
world
)
Insert cell
height = 600
Insert cell
d3 = require("d3@7", "d3-geo-projection@3")
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