Source:
Donut math: how donut.c works