triangulation, some horrible code