Improve FAQ & video rendering, tighten homepage and CSS

This commit is contained in:
Andras Schmelczer 2026-05-04 22:07:30 +01:00
parent 05a1f316e1
commit c69bb0d614
48 changed files with 4689 additions and 1077 deletions

View file

@ -1,8 +1,7 @@
from collections import defaultdict
import numpy as np
from scipy.spatial import Voronoi
from scipy.spatial.qhull import QhullError
from scipy.spatial import QhullError, Voronoi
from shapely import make_valid
from shapely.geometry import MultiPolygon, Polygon
from shapely.ops import unary_union
@ -24,12 +23,15 @@ def compute_voronoi_regions(
# Deduplicate points, keeping one per (location, postcode) pair.
# Multiple postcodes at the same coordinate each get their own point,
# jittered by a tiny offset (0.01m) so Voronoi can distinguish them.
# Coords are rounded to mm precision for stable hashing — UPRN inputs are
# already integer metres, but the float64 cast can introduce ULP noise.
GOLDEN_ANGLE = np.pi * (3.0 - np.sqrt(5.0))
seen: dict[tuple[float, float, str], bool] = {}
unique_pts = []
unique_pcs = []
coord_counts: dict[tuple[float, float], int] = defaultdict(int)
for i in range(len(points)):
coord = (points[i, 0], points[i, 1])
coord = (round(float(points[i, 0]), 3), round(float(points[i, 1]), 3))
key = (coord[0], coord[1], postcodes[i])
if key not in seen:
seen[key] = True
@ -38,11 +40,10 @@ def compute_voronoi_regions(
if jitter_idx == 0:
unique_pts.append(points[i].copy())
else:
# Tiny jitter so Voronoi sees distinct points (0.01m per step)
# Golden-angle spacing distributes any number of jittered
# points evenly around (and outward from) the original coord.
jittered = points[i].copy()
angle = (
2 * np.pi * jitter_idx / max(coord_counts[coord], jitter_idx + 1)
)
angle = jitter_idx * GOLDEN_ANGLE
jittered[0] += 0.01 * np.cos(angle)
jittered[1] += 0.01 * np.sin(angle)
unique_pts.append(jittered)