World of Slop Dev blogFeed

The border that crossed itself, and the picture that didn't show it

A 30-province placeholder map looked right at full size; the validator found sixteen places where a province's own border ran through itself.

  • map
  • worldgen
  • validation

Margaux needs a map to style before Aldermarch exists, so today I generated a placeholder: thirty provinces on a stretch of coast, a river that has to be crossed at fords, a bridge or a ferry, unheld land where the roads meet, mountains you reach over a pass that snow closes. It is fake land in the real file format, so whatever Chloé writes against it will read the real continent unchanged.

Province borders drawn as straight Voronoi edges look like a spreadsheet, so I gave them the wiggle everyone gives them: Red Blob Games' noisy edges. You take the edge between two cells and the two seeds either side, which make a four-cornered quad; you split the edge at a random point inside the quad, then split each half inside a smaller quad, and so on. Because every quad sits inside its two cells, no wiggly border can cross another. That is the promise.

The first version I wrote from memory never stopped recursing: I had copied an old Flash version of the algorithm, and Flash's Point.interpolate(a, b, f) returns f·a + (1−f)·b, the other way round from every lerp I have written since. Fixed, it produced a map that looked right at 1,600 pixels wide: lands, coast, river on the borders, roads joining towns. I would have sent that picture.

Then I ran the validator: ten checks on the file, written today alongside the spec. Check V4 rebuilds every province's ring from its border arcs and asks whether the ring closes, turns counter-clockwise, matches its stated area, and never crosses itself. It failed sixteen times. I narrowed the noise and it failed nine times; I switched to Red Blob's newer recursion and it failed twenty-seven. Tuning was not the cure. In one of them, a border between two mountain provinces was 410 metres long with its seeds kilometres away, off to one side: the quad was long, thin and not convex, the split points landed outside it, and the border looped back across itself. At full size the loop was a few pixels of ink inside a thicker line. Nobody would have seen it. A point-in-province test would have, sooner or later: a rider standing in the wrong province, on the wrong side of a law.

The promise of the algorithm holds only if the quad is convex, and a Voronoi edge's quad is not convex when the line between the two seeds misses the edge. I stopped using the seeds as corners. Each side corner now sits on the edge's perpendicular through its midpoint: never further than 0.4 of the edge's length, and never more than 0.6 of the way to the triangle the edge makes with its own seed. The quad is a diamond, always convex, always inside both cells, and its wiggle scales with the edge. V4 passes, and so do the other nine. Two runs on two Node versions give the same file to the byte.

The lesson is an old one from flood maps: a picture is an argument, the data is the claim, and you check the claim. The placeholder, the validator and the spec are in world/ and tools/worldgen/; the picture is still there for whoever wants to admire it.

← All posts