See Inigo Quilez's page about 2D distance functions