35 const int k1 = *(
int *)v1;
36 const int k2 = *(
int *)v2;
47 XLabels_t *xlp =
gv_alloc(
sizeof(XLabels_t));
51 fprintf(stderr,
"out of memory\n");
78 double maxx = obj_bb.
UR.
x, maxy = obj_bb.
UR.
y;
79 return (
unsigned)floor(log2(round(fmax(maxx, maxy)))) + 1;
115 int x = p.
x, y = p.
y;
118 for (
unsigned i = n - 1; n > 0; i--) {
119 int xi = (x >> i) & 1;
120 int yi = (y >> i) & 1;
121 s = 4 *
s + 2 * (unsigned)xi +
122 ((
unsigned)xi ^ (unsigned)yi);
125 y = y ^ (x & (yi - 1));
127 x = x ^ (-xi & (yi - 1));
128 y = y ^ (-xi & (yi - 1));
148 double iminx = fmax(r.
boundary[0],
s.boundary[0]);
150 double iminy = fmax(r.
boundary[1],
s.boundary[1]);
152 double imaxx = fmin(r.
boundary[2],
s.boundary[2]);
154 double imaxy = fmin(r.
boundary[3],
s.boundary[3]);
155 return (imaxx - iminx) * (imaxy - iminy);
165 assert(objp1->
sz.
x == 0 && objp1->
sz.
y == 0);
217 if (!lp->
set || !clp->set)
219 if ((op->
pos.
x == 0.0 && op->
pos.
y == 0.0) ||
220 (cp->
pos.
x == 0.0 && cp->
pos.
y == 0.0))
251 if (intrsx[i] !=
NULL) {
252 double sa, maxa = 0.0;
259 if (intrsx[i]->lbl) {
263 maxa = fmax(sa, maxa);
281 if (intrsx[i] !=
NULL) {
282 double sa, maxa = 0.0;
289 if (intrsx[i]->lbl) {
293 maxa = fmax(sa, maxa);
310 BestPos_t bp = {.pos = objp->
lbl->
pos};
312 for (
size_t i = 0; i < xlp->n_objs; i++) {
313 if (objp == &xlp->objs[i])
315 if (xlp->objs[i].sz.x > 0 && xlp->objs[i].sz.y > 0)
365 double xincr = (2 * lp->
sz.
x + objp->
sz.
x) / XLXDENOM;
366 double yincr = (2 * lp->
sz.
y + objp->
sz.
y) / XLYDENOM;
383 if (nbp.area < bp.area)
390 if (nbp.area < bp.area)
400 if (nbp.area < bp.area)
407 if (nbp.area < bp.area)
417 if (nbp.area < bp.area)
424 if (nbp.area < bp.area)
431 if (nbp.area < bp.area)
435 if (intrsx[XLPXNY] || intrsx[XLCXNY] || intrsx[XLNXNY] || intrsx[XLPXCY] ||
437 if (!intrsx[XLCXNY] && !intrsx[XLNXNY]) {
445 if (nbp.area < bp.area)
449 if (!intrsx[XLPXCY] && !intrsx[XLPXPY]) {
457 if (nbp.area < bp.area)
466 if (intrsx[XLNXPY] || intrsx[XLCXPY] || intrsx[XLPXPY] || intrsx[XLNXCY] ||
468 if (!intrsx[XLCXPY] && !intrsx[XLPXPY]) {
476 if (nbp.area < bp.area)
480 if (!intrsx[XLNXCY] && !intrsx[XLNXNY]) {
488 if (nbp.area < bp.area)
501 const unsigned order =
xlhorder(obj_bb);
503 for (
size_t i = 0; i < xlp->n_objs; i++) {
504 HDict_t *hp =
gv_alloc(
sizeof(HDict_t));
506 hp->d.data = &xlp->objs[i];
509 const double x = hp->d.rect.boundary[0] +
510 (hp->d.rect.boundary[2] - hp->d.rect.boundary[0]) / 2;
511 const double y = hp->d.rect.boundary[1] +
512 (hp->d.rect.boundary[3] - hp->d.rect.boundary[1]) / 2;
513 assert(x >= INT_MIN && x <= INT_MAX);
514 assert(y >= INT_MIN && y <= INT_MAX);
515 const point pi = {.
x = (int)x, .y = (
int)y};
526 for (HDict_t *op =
dtfirst(xlp->hdx); op; op =
dtnext(xlp->hdx, op)) {
528 RTreeInsert(xlp->spdx, op->d.rect, op->d.data, &xlp->spdx->root);
543 XLabels_t *xlp =
xlnew(objs, n_objs);
565 for (
size_t i = 0; i < n_objs; i++) {
566 if (objs[i].lbl == 0)
568 const BestPos_t bp =
xladjust(xlp, &objs[i]);
571 }
else if (bp.area == 0) {
572 objs[i].
lbl->
pos = bp.pos;
574 }
else if (params->
force) {
575 objs[i].
lbl->
pos = bp.pos;
Memory allocation wrappers that exit on failure.
static void * gv_alloc(size_t size)
CDT_API Dtmethod_t * Dtobag
ordered multiset
CDT_API int dtclose(Dt_t *)
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
static NORETURN void graphviz_exit(int status)
static void freef(void *ident)
void RTreeLeafListFree(LeafList_t *llp)
RTree_t * RTreeOpen(void)
void RTreeClose(RTree_t *rtp)
int RTreeInsert(RTree_t *rtp, Rect_t r, void *data, Node_t **n)
LeafList_t * RTreeSearch(RTree_t *rtp, Node_t *n, Rect_t r)
bool Overlap(const Rect_t r, const Rect_t s)
double boundary[NUMSIDES]
bool force
if true, all labels must be placed
bool set
true if the position has been set (input/output)
static BestPos_t xlintersections(XLabels_t *xlp, object_t *objp, object_t *intrsx[XLNBR])
static double aabbaabb(Rect_t r, Rect_t s)
static double recordlintrsx(object_t *op, object_t *cp, Rect_t *rp, double a, object_t *intrsx[XLNBR])
static unsigned int xlhorder(boxf obj_bb)
static int xlhdxload(XLabels_t *xlp, boxf obj_bb)
static void xlfree(XLabels_t *xlp)
static void xlspdxload(XLabels_t *xlp)
static Rect_t objplp2rect(const object_t *objp)
static Rect_t objp2rect(const object_t *op)
static double recordointrsx(object_t *op, object_t *cp, Rect_t rp, double a, object_t *intrsx[XLNBR])
static XLabels_t * xlnew(object_t *objs, size_t n_objs)
static int getintrsxi(object_t *op, object_t *cp)
static bool lblenclosing(object_t *objp, object_t *objp1)
static BestPos_t xladjust(XLabels_t *xlp, object_t *objp)
int placeLabels(object_t *objs, size_t n_objs, const label_params_t *params)
static Rect_t objplpmks(object_t *objp)
static unsigned hd_hil_s_from_xy(point p, unsigned n)
static int xlinitialize(XLabels_t *xlp, boxf obj_bb)
static int icompare(void *, void *)