Clipping

Voronoi2This screenshot is basically invisible, in this thumbnail.  Today’s work was clipping Voronoi regions against other regions.  In computer graphics, “clipping” generally means not drawing something;  usually this is in reference to 3D objects.  For example, you might “clip” a 3D model against the viewing area, and then not bother drawing any parts of the 3D model which aren’t at least partly inside the viewing area.

In this case, I’m clipping the new region boundaries against the world boundaries.  You wouldn’t imagine that this sort of thing would be difficult, but..  it’s surprisingly tricky!  (I still seem to have a minor bug in it, which is causing things which extend past the southwest corner of the world borders not to be clipped as they should… so in this screenshot, I’m cleverly looking northeast, thus hiding that bug)

Of course, the reason that this clipping is tricky is that I’m clipping “arbitrary polygon vs. arbitrary other polygon”, instead of the more usual “box vs. box” or “box vs. view frustum” tests that you’d do during rendering, to determine whether it was worth rendering a 3D object at all.

Anyhow.  Math/geometry buffs might be interested to know that I’m using the Weiler-Atherton polygon clipping algorithm, which is probably the best one out there for clipping arbitrary polygons against each other.

I’ll also note that this is the last maths/tech-heavy post for a while.  Now that this is done (apart from that one remaining bug, which I’ll probably ignore), I’m going to be moving back over onto game mechanics again.