31 int k1 = *((
int *) v1), k2 = *((
int *) v2);
43 XLabels_t *xlp =
gv_alloc(
sizeof(XLabels_t));
47 fprintf(stderr,
"out of memory\n");
53 fprintf(stderr,
"out of memory\n");
80 double maxx = xlp->params->bb.UR.x, maxy = xlp->params->bb.UR.y;
81 return (
unsigned)floor(log2(round(fmax(maxx, maxy)))) + 1;
118 int x = p.
x, y = p.
y;
121 for (
int i = n - 1; i >= 0; i--) {
122 int xi = (x >> i) & 1;
123 int yi = (y >> i) & 1;
124 s = 4 *
s + 2 * (unsigned)xi + ((
unsigned)xi ^ (unsigned)yi);
127 y = y ^ (x & (yi - 1));
129 x = x ^ (-xi & (yi - 1));
130 y = y ^ (-xi & (yi - 1));
159 return (imaxx - iminx) * (imaxy - iminy);
169 assert(objp1->
sz.
x == 0 && objp1->
sz.
y == 0);
171 if(! xlp)
return false;
227 if (lp->
set == 0 || clp->set == 0)
229 if ((op->
pos.
x == 0.0 && op->
pos.
y == 0.0) ||
230 (cp->
pos.
x == 0.0 && cp->
pos.
y == 0.0))
264 if (intrsx[i] !=
NULL) {
265 double sa, maxa = 0.0;
272 if (intrsx[i]->lbl) {
276 maxa = fmax(sa, maxa);
296 if (intrsx[i] !=
NULL) {
297 double sa, maxa = 0.0;
304 if (intrsx[i]->lbl) {
308 maxa = fmax(sa, maxa);
332 for (
size_t i = 0; i < xlp->n_objs; i++) {
333 if(objp == &xlp->objs[i])
continue;
334 if(xlp->objs[i].sz.x > 0 && xlp->objs[i].sz.y > 0)
continue;
384 double xincr = (2 * lp->
sz.
x + objp->
sz.
x) / XLXDENOM;
385 double yincr = (2 * lp->
sz.
y + objp->
sz.
y) / XLYDENOM;
403 if (nbp.area < bp.area)
410 if (nbp.area < bp.area)
420 if (nbp.area < bp.area)
427 if (nbp.area < bp.area)
437 if (nbp.area < bp.area)
444 if (nbp.area < bp.area)
451 if (nbp.area < bp.area)
455 if (intrsx[XLPXNY] || intrsx[XLCXNY] || intrsx[XLNXNY] || intrsx[XLPXCY] || intrsx[XLPXPY]) {
456 if (!intrsx[XLCXNY] && !intrsx[XLNXNY]) {
461 lp->
pos.
x += xincr) {
465 if (nbp.area < bp.area)
469 if (!intrsx[XLPXCY] && !intrsx[XLPXPY]) {
474 lp->
pos.
y -= yincr) {
478 if (nbp.area < bp.area)
488 if (intrsx[XLNXPY] || intrsx[XLCXPY] || intrsx[XLPXPY] || intrsx[XLNXCY] || intrsx[XLNXNY]) {
489 if (!intrsx[XLCXPY] && !intrsx[XLPXPY]) {
494 lp->
pos.
x -= xincr) {
498 if (nbp.area < bp.area)
502 if (!intrsx[XLNXCY] && !intrsx[XLNXNY]) {
507 lp->
pos.
y += yincr) {
511 if (nbp.area < bp.area)
524 for (
size_t i = 0; i < xlp->n_objs; i++) {
530 hp->d.data = &xlp->objs[i];
533 pi.
x = hp->d.rect.boundary[0] +
534 (hp->d.rect.boundary[2] - hp->d.rect.boundary[0]) / 2;
535 pi.
y = hp->d.rect.boundary[1] +
536 (hp->d.rect.boundary[3] - hp->d.rect.boundary[1]) / 2;
548 int size=
dtsize(xlp->hdx), freed=0;
549 while(
dtsize(xlp->hdx) ) {
563 for (HDict_t *op =
dtfirst(xlp->hdx); op; op =
dtnext(xlp->hdx, op)) {
565 RTreeInsert(xlp->spdx, &op->d.rect, op->d.data, &xlp->spdx->root, 0);
583 XLabels_t *xlp =
xlnew(objs, n_objs, lbls, n_lbls, params);
603 for (
size_t i = 0; i < n_objs; i++) {
604 if (objs[i].lbl == 0)
609 }
else if(bp.area == 0) {
613 }
else if (params->
force == 1) {
Memory allocation wrappers that exit on failure.
static void * gv_alloc(size_t size)
CDT_API Dtmethod_t * Dtobag
ordered multiset
CDT_API int dtsize(Dt_t *)
CDT_API int dtclose(Dt_t *)
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
static NORETURN void graphviz_exit(int status)
LeafList_t * RTreeSearch(RTree_t *rtp, Node_t *n, Rect_t *r)
void RTreeLeafListFree(LeafList_t *llp)
RTree_t * RTreeOpen(void)
int RTreeClose(RTree_t *rtp)
int RTreeInsert(RTree_t *rtp, Rect_t *r, void *data, Node_t **n, int level)
bool Overlap(const Rect_t *r, const Rect_t *s)
static BestPos_t xlintersections(XLabels_t *xlp, object_t *objp, object_t *intrsx[XLNBR])
static double recordlintrsx(object_t *op, object_t *cp, Rect_t *rp, double a, object_t *intrsx[XLNBR])
int placeLabels(object_t *objs, size_t n_objs, xlabel_t *lbls, size_t n_lbls, label_params_t *params)
static void xlfree(XLabels_t *xlp)
static void xlspdxload(XLabels_t *xlp)
static Rect_t objplp2rect(const object_t *objp)
static double aabbaabb(Rect_t *r, Rect_t *s)
static Rect_t objp2rect(const object_t *op)
static void xlhdxunload(XLabels_t *xlp)
static int getintrsxi(object_t *op, object_t *cp)
static bool lblenclosing(object_t *objp, object_t *objp1)
static int xlinitialize(XLabels_t *xlp)
static XLabels_t * xlnew(object_t *objs, size_t n_objs, xlabel_t *lbls, size_t n_lbls, label_params_t *params)
static BestPos_t xladjust(XLabels_t *xlp, object_t *objp)
static double recordointrsx(object_t *op, object_t *cp, Rect_t *rp, double a, object_t *intrsx[XLNBR])
static Rect_t objplpmks(object_t *objp)
static unsigned int hd_hil_s_from_xy(point p, int n)
static unsigned int xlhorder(XLabels_t *xlp)
static int icompare(void *, void *)
static int xlhdxload(XLabels_t *xlp)