/* Given a set of vertices, compute the convex hull using the Graham scan algorithm. */ cairo_status_t _cairo_hull_compute (cairo_pen_vertex_t *vertices, int *num_vertices) { cairo_hull_t hull_stack[CAIRO_STACK_ARRAY_LENGTH (cairo_hull_t)]; cairo_hull_t *hull; int num_hull = *num_vertices; if (CAIRO_INJECT_FAULT ()) return _cairo_error (CAIRO_STATUS_NO_MEMORY); if (num_hull > ARRAY_LENGTH (hull_stack)) { hull = _cairo_malloc_ab (num_hull, sizeof (cairo_hull_t)); if (unlikely (hull == XNULL)) return _cairo_error (CAIRO_STATUS_NO_MEMORY); } else { hull = hull_stack; } _cairo_hull_init (hull, vertices, num_hull); qsort (hull + 1, num_hull - 1, sizeof (cairo_hull_t), _cairo_hull_vertex_compare); _cairo_hull_eliminate_concave (hull, num_hull); _cairo_hull_to_pen (hull, vertices, num_vertices); if (hull != hull_stack) xmemory_free (hull); return CAIRO_STATUS_SUCCESS; }
/* Given a set of vertices, compute the convex hull using the Graham scan algorithm. */ cairo_status_t _cairo_hull_compute (cairo_pen_vertex_t *vertices, int *num_vertices) { cairo_hull_t *hull; int num_hull = *num_vertices; hull = _cairo_hull_create (vertices, num_hull); if (hull == NULL) return CAIRO_STATUS_NO_MEMORY; qsort (hull + 1, num_hull - 1, sizeof (cairo_hull_t), _cairo_hull_vertex_compare); _cairo_hull_eliminate_concave (hull, num_hull); _cairo_hull_to_pen (hull, vertices, num_vertices); free (hull); return CAIRO_STATUS_SUCCESS; }