I’ve relased a new library, VoronatorSharp.

VoronatorSharp is a C# library that computes Voronoi diagrams. The Voronoi diagram for a collection of points is the polygons that enclose the areas nearest each of those sites.

Voronoi diagrams have applications in a number of areas such as computer graphics.

This library features:

  • Computes Voronoi diagrams and Delaunay triangulations.
  • Voronoi polygons can be clipped to a rectangular area.
  • Uses a n log(n) sweephull algorithm.
  • The implementation attempts to minimize memory allocations.
  • Integrates with Unity or can be be used standalone.
  • Uses robust orientation code.
  • Handles Voronoi diagrams with only 1 or 2 points, and collinear points.

Using Unity’s TextGenerator.verts

TextGenerator.verts is meant to give the position information of every character in a given string. This is useful in Unity if you need to align something with exactly where some particular text is occuring, if for some reason you are not already using TextMeshPro.

Older Unity versions created 4 verts for every character, which made life easy. But now many non-rendering characters don’t have verts generated for them, and the relationship between verts and characters is undocumented. I’ve reverse engineered it, as best as I can tell:

int? GetVertForPosition(int position, string text, TextGenerator textGenerator)
    var c = 0;
    var vert = 0;
    for (var i = 0; i < position; i++)
        if (textGenerator.characters.Count <= c)
            return null;
        if (!char.IsWhiteSpace(text[i]) && textGenerator.characters[c].charWidth > 0)
            vert += 4;
        if (text[i] != '\n')
    return vert;

Messing with Unity’s GUIDs

I recently released an addon in the Unity asset store. It’s actually two addons: Tessera Pro is a fully featured copy, with complete source code, and Tessera which has cut down features, and you just get a precompiled .dll.

I quickly discovered a big problem – if you upgrade from Tessera to Tessera Pro, then all your scenes become broken. You get this error, which is likely familiar to veteran Unity developers.

I’ll go into what’s happening in general, and how I dealt with it.

Continue reading