Debian Codegraph @

src/gen/lib/label/xlabels__c.java

raw symbols SCIP
1 /* ========================================================================
2 * PlantUML : a free UML diagram generator
3 * ========================================================================
4 *
5 * Project Info: http://plantuml.com
6 *
7 * If you like this project or if you find it useful, you can support us at:
8 *
9 * http://plantuml.com/patreon (only 1$ per month!)
10 * http://plantuml.com/paypal
11 *
12 * This file is part of Smetana.
13 * Smetana is a partial translation of Graphviz/Dot sources from C to Java.
14 *
15 * (C) Copyright 2009-2020, Arnaud Roques
16 *
17 * This translation is distributed under the same Licence as the original C program:
18 *
19 *************************************************************************
20 * Copyright (c) 2011 AT&T Intellectual Property
21 * All rights reserved. This program and the accompanying materials
22 * are made available under the terms of the Eclipse Public License v1.0
23 * which accompanies this distribution, and is available at
24 * http://www.eclipse.org/legal/epl-v10.html
25 *
26 * Contributors: See CVS logs. Details at http://www.graphviz.org/
27 *************************************************************************
28 *
29 * THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
30 * LICENSE ("AGREEMENT"). [Eclipse Public License - v 1.0]
31 *
32 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
33 * RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
34 *
35 * You may obtain a copy of the License at
36 *
37 * http://www.eclipse.org/legal/epl-v10.html
38 *
39 * Unless required by applicable law or agreed to in writing, software
40 * distributed under the License is distributed on an "AS IS" BASIS,
41 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42 * See the License for the specific language governing permissions and
43 * limitations under the License.
44 *
45 */
46 package gen.lib.label;
47 import static gen.lib.cdt.dtclose__c.dtclose;
48 import static gen.lib.cdt.dtopen__c.dtopen;
49 import static gen.lib.label.index__c.RTreeClose;
50 import static gen.lib.label.index__c.RTreeInsert;
51 import static gen.lib.label.index__c.RTreeLeafListFree;
52 import static gen.lib.label.index__c.RTreeOpen;
53 import static gen.lib.label.index__c.RTreeSearch;
54 import static smetana.core.JUtils.EQ;
55 import static smetana.core.JUtilsDebug.ENTERING;
56 import static smetana.core.JUtilsDebug.LEAVING;
57 import static smetana.core.Macro.N;
58 import static smetana.core.Macro.UNSUPPORTED;
59 import h.ST_BestPos_t;
60 import h.ST_HDict_t;
61 import h.ST_LeafList_t;
62 import h.ST_Node_t___;
63 import h.ST_RTree;
64 import h.ST_Rect_t;
65 import h.ST_XLabels_t;
66 import h.ST_dt_s;
67 import h.ST_dtdisc_s;
68 import h.ST_label_params_t;
69 import h.ST_object_t;
70 import h.ST_point;
71 import h.ST_pointf;
72 import h.ST_xlabel_t;
73 import smetana.core.Memory;
74 import smetana.core.Z;
75 import smetana.core.__ptr__;
76 public class xlabels__c {
77 //1 9k44uhd5foylaeoekf3llonjq
78 // extern Dtmethod_t* Dtset
79
80
81 //1 1ahfywsmzcpcig2oxm7pt9ihj
82 // extern Dtmethod_t* Dtbag
83
84
85 //1 anhghfj3k7dmkudy2n7rvt31v
86 // extern Dtmethod_t* Dtoset
87
88
89 //1 5l6oj1ux946zjwvir94ykejbc
90 // extern Dtmethod_t* Dtobag
91
92
93 //1 2wtf222ak6cui8cfjnw6w377z
94 // extern Dtmethod_t* Dtlist
95
96
97 //1 d1s1s6ibtcsmst88e3057u9r7
98 // extern Dtmethod_t* Dtstack
99
100
101 //1 axa7mflo824p6fspjn1rdk0mt
102 // extern Dtmethod_t* Dtqueue
103
104
105 //1 ega812utobm4xx9oa9w9ayij6
106 // extern Dtmethod_t* Dtdeque
107
108
109 //1 cyfr996ur43045jv1tjbelzmj
110 // extern Dtmethod_t* Dtorder
111
112
113 //1 wlofoiftbjgrrabzb2brkycg
114 // extern Dtmethod_t* Dttree
115
116
117 //1 12bds94t7voj7ulwpcvgf6agr
118 // extern Dtmethod_t* Dthash
119
120
121 //1 9lqknzty480cy7zsubmabkk8h
122 // extern Dtmethod_t _Dttree
123
124
125 //1 bvn6zkbcp8vjdhkccqo1xrkrb
126 // extern Dtmethod_t _Dthash
127
128
129 //1 9lidhtd6nsmmv3e7vjv9e10gw
130 // extern Dtmethod_t _Dtlist
131
132
133 //1 34ujfamjxo7xn89u90oh2k6f8
134 // extern Dtmethod_t _Dtqueue
135
136
137 //1 3jy4aceckzkdv950h89p4wjc8
138 // extern Dtmethod_t _Dtstack
139
140
141 //1 1lrfssuxf2e1e5pvk6j7qrff6
142 // extern int Verbose
143
144
145 //1 17dmpzc4uhvmrcx0x00aw2gbc
146 // Dtdisc_t Hdisc =
147
148
149
150
151 //3 5p3ac8qk4gnne5hj1dc21ysi
152 // static int icompare(Dt_t * dt, void * v1, void * v2, Dtdisc_t * disc)
153 public static int icompare(ST_dt_s dt, Object v1, Object v2, ST_dtdisc_s disc) {
154 ENTERING("5p3ac8qk4gnne5hj1dc21ysi","icompare");
155 try {
156 Integer k1 = (Integer) v1;
157 Integer k2 = (Integer) v2;
158 return k1 - k2;
159 } finally {
160 LEAVING("5p3ac8qk4gnne5hj1dc21ysi","icompare");
161 }
162 }
163
164
165
166
167 //3 88mbfm305igsr7cew5qx6yldp
168 // static XLabels_t *xlnew(object_t * objs, int n_objs, xlabel_t * lbls, int n_lbls, label_params_t * params)
169 public static ST_XLabels_t xlnew(ST_object_t.Array objs, int n_objs, ST_xlabel_t.Array lbls, int n_lbls, ST_label_params_t params) {
170 ENTERING("88mbfm305igsr7cew5qx6yldp","xlnew");
171 try {
172 ST_XLabels_t xlp;
173 xlp = new ST_XLabels_t();
174 /* used to load the rtree in hilbert space filling curve order */
175 xlp.setPtr("hdx", dtopen(Z.z().Hdisc, Z.z().Dtobag));
176 if (N(xlp.hdx)) {
177 UNSUPPORTED("4t1y5iinm4310lkpvbal1spve"); // fprintf(stderr, "out of memory\n");
178 UNSUPPORTED("3m406diamp5s5kwcqtwo4pshf"); // goto bad;
179 }
180 /* for querying intersection candidates */
181 xlp.setPtr("spdx", RTreeOpen());
182 if (N(xlp.spdx)) {
183 UNSUPPORTED("4t1y5iinm4310lkpvbal1spve"); // fprintf(stderr, "out of memory\n");
184 UNSUPPORTED("3m406diamp5s5kwcqtwo4pshf"); // goto bad;
185 }
186 /* save arg pointers in the handle */
187 xlp.objs = objs;
188 xlp.setInt("n_objs", n_objs);
189 xlp.lbls = lbls;
190 xlp.setInt("n_lbls", n_lbls);
191 xlp.setPtr("params", params);
192 return (ST_XLabels_t) xlp;
193 } finally {
194 LEAVING("88mbfm305igsr7cew5qx6yldp","xlnew");
195 }
196 //UNSUPPORTED("98zx7s9vt8t1s5x9l35evcxnz"); // bad:
197 //UNSUPPORTED("66s40csd2ivd8rx4h2ut8oai5"); // if (xlp->hdx)
198 //UNSUPPORTED("8mg8tqxa78f1nfk4jh9drw2n0"); // dtclose(xlp->hdx);
199 //UNSUPPORTED("b9uy03exphaovgyz5t4gru409"); // if (xlp->spdx)
200 //UNSUPPORTED("4cfpl6hom6vo3btrjlhfmn6mi"); // RTreeClose(xlp->spdx);
201 //UNSUPPORTED("dms04fhv1vao18v2p0lmk80xf"); // free(xlp);
202 //UNSUPPORTED("5oxhd3fvp0gfmrmz12vndnjt"); // return 0;
203 //UNSUPPORTED("c24nfmv9i7o5eoqaymbibp7m7"); // }
204 }
205
206
207
208
209 //3 apvhod2s1yjb8717rb7gie2kb
210 // static void xlfree(XLabels_t * xlp)
211 public static void xlfree(ST_XLabels_t xlp) {
212 ENTERING("apvhod2s1yjb8717rb7gie2kb","xlfree");
213 try {
214 RTreeClose((ST_RTree) xlp.spdx);
215 Memory.free(xlp);
216 } finally {
217 LEAVING("apvhod2s1yjb8717rb7gie2kb","xlfree");
218 }
219 }
220
221
222
223
224 //3 6lz36gkh8fla3z6f0lxniy368
225 // static int floorLog2(unsigned int n)
226 public static int floorLog2(int n) {
227 ENTERING("6lz36gkh8fla3z6f0lxniy368","floorLog2");
228 try {
229 int pos = 0;
230 if (n == 0)
231 return -1;
232 if (n >= 1 << 16) {
233 n >>= 16;
234 pos += 16;
235 }
236 if (n >= 1 << 8) {
237 n >>= 8;
238 pos += 8;
239 }
240 if (n >= 1 << 4) {
241 n >>= 4;
242 pos += 4;
243 }
244 if (n >= 1 << 2) {
245 n >>= 2;
246 pos += 2;
247 }
248 if (n >= 1 << 1) {
249 pos += 1;
250 }
251 return pos;
252 } finally {
253 LEAVING("6lz36gkh8fla3z6f0lxniy368","floorLog2");
254 }
255 }
256
257
258
259
260 //3 uvnzthcpf4xiih05gxie2rx1
261 // unsigned int xlhorder(XLabels_t * xlp)
262 public static int xlhorder(ST_XLabels_t xlp) {
263 ENTERING("uvnzthcpf4xiih05gxie2rx1","xlhorder");
264 try {
265 double maxx = xlp.params.bb.UR.x;
266 double maxy = xlp.params.bb.UR.y;
267 return floorLog2(maxx > maxy ? (int)maxx : (int)maxy) + 1;
268 } finally {
269 LEAVING("uvnzthcpf4xiih05gxie2rx1","xlhorder");
270 }
271 }
272
273
274
275
276 //3 9lkyvq87bawe3yon7bdwvcjzq
277 // static unsigned int hd_hil_s_from_xy(point p, int n)
278 public static int hd_hil_s_from_xy(ST_point p, int n) {
279 ENTERING("9lkyvq87bawe3yon7bdwvcjzq","hd_hil_s_from_xy");
280 try {
281 return hd_hil_s_from_xy_((ST_point) p.copy(), n);
282 } finally {
283 LEAVING("9lkyvq87bawe3yon7bdwvcjzq","hd_hil_s_from_xy");
284 }
285 }
286 private static int hd_hil_s_from_xy_(ST_point p, int n) {
287 int i, x = p.x, y = p.y, xi, yi;
288 int s;
289 s = 0; /* Initialize. */
290 for (i = n - 1; i >= 0; i--) {
291 xi = (x >> i) & 1; /* Get bit i of x. */
292 yi = (y >> i) & 1; /* Get bit i of y. */
293 s = 4 * s + 2 * xi + (xi ^ yi); /* Append two bits to s. */
294 x = x ^ y; /* These 3 lines swap */
295 y = y ^ (x & (yi - 1)); /* x and y if yi = 0. */
296 x = x ^ y;
297 x = x ^ (-xi & (yi - 1)); /* Complement x and y if */
298 y = y ^ (-xi & (yi - 1)); /* xi = 1 and yi = 0. */
299 }
300 return s;
301 }
302
303
304
305
306 //3 bpkzwylrchx5wta1qhytfgbtr
307 // static double aabbaabb(Rect_t * r, Rect_t * s)
308 public static double aabbaabb(ST_Rect_t r, ST_Rect_t s) {
309 ENTERING("bpkzwylrchx5wta1qhytfgbtr","aabbaabb");
310 try {
311 /* per dimension if( max < omin || min > omax) */
312 double iminx, iminy, imaxx, imaxy;
313 if (r.boundary[2] < s.boundary[0] || r.boundary[0] > s.boundary[2])
314 return 0;
315 if (r.boundary[3] < s.boundary[1] || r.boundary[1] > s.boundary[3])
316 return 0;
317 /* if we get here we have an intersection */
318 /* rightmost left edge of the 2 rectangles */
319 iminx =
320 r.boundary[0] > s.boundary[0] ? r.boundary[0] : s.boundary[0];
321 /* upmost bottom edge */
322 iminy =
323 r.boundary[1] > s.boundary[1] ? r.boundary[1] : s.boundary[1];
324 /* leftmost right edge */
325 imaxx =
326 r.boundary[2] < s.boundary[2] ? r.boundary[2] : s.boundary[2];
327 /* downmost top edge */
328 imaxy =
329 r.boundary[3] < s.boundary[3] ? r.boundary[3] : s.boundary[3];
330 return (imaxx - iminx) * (imaxy - iminy);
331 } finally {
332 LEAVING("bpkzwylrchx5wta1qhytfgbtr","aabbaabb");
333 }
334 }
335
336
337
338
339 //3 2g71cq6f8w5jbmbnn2x9y5qfq
340 // static int lblenclosing(object_t * objp, object_t * objp1)
341 public static boolean lblenclosing(ST_object_t objp, ST_object_t objp1) {
342 ENTERING("2g71cq6f8w5jbmbnn2x9y5qfq","lblenclosing");
343 try {
344 ST_xlabel_t.Array xlp = (ST_xlabel_t.Array) objp.lbl;
345 // assert(objp1->sz.x == 0 && objp1->sz.y == 0);
346 if(N(xlp)) return false;
347 return objp1.pos.x > xlp.getStruct().pos.x &&
348 objp1.pos.x < (xlp.getStruct().pos.x + xlp.getStruct().sz.y) &&
349 objp1.pos.y > xlp.getStruct().pos.y &&
350 objp1.pos.y < (xlp.getStruct().pos.y + xlp.getStruct().sz.y);
351 // UNSUPPORTED("exdts7f2bpam5122kabq2b86c"); // return objp1->pos.x > xlp->pos.x &&
352 // UNSUPPORTED("99uxf5dqw5nzdymlzfj764uol"); // objp1->pos.x < (xlp->pos.x + xlp->sz.x) &&
353 // UNSUPPORTED("epx7s3oiw75fuioasz208w1k1"); // objp1->pos.y > xlp->pos.y &&
354 // UNSUPPORTED("29g3tye8vebllnv9b91xyntzi"); // objp1->pos.y < (xlp->pos.y + xlp->sz.y);
355 // UNSUPPORTED("c24nfmv9i7o5eoqaymbibp7m7"); // }
356 } finally {
357 LEAVING("2g71cq6f8w5jbmbnn2x9y5qfq","lblenclosing");
358 }
359 }
360
361
362
363
364
365 //3 dq1wkb4oxshdggv6cwtgas6m
366 // static void objp2rect(object_t * op, Rect_t * r)
367 public static void objp2rect(ST_object_t op, ST_Rect_t r) {
368 ENTERING("dq1wkb4oxshdggv6cwtgas6m","objp2rect");
369 try {
370 r.boundary[0]=((int)op.pos.x);
371 r.boundary[1]=((int)op.pos.y);
372 r.boundary[2]=((int)(op.pos.x+op.sz.x));
373 r.boundary[3]=((int)(op.pos.y+op.sz.y));
374 } finally {
375 LEAVING("dq1wkb4oxshdggv6cwtgas6m","objp2rect");
376 }
377 }
378
379
380
381
382 //3 71b5ttp3xs7lo9fqgb7ypyqgx
383 // static void objplp2rect(object_t * objp, Rect_t * r)
384 public static void objplp2rect(ST_object_t objp, ST_Rect_t r) {
385 ENTERING("71b5ttp3xs7lo9fqgb7ypyqgx","objplp2rect");
386 try {
387 ST_xlabel_t.Array lp = (ST_xlabel_t.Array) objp.lbl;
388 r.boundary[0]=((int)lp.getStruct().pos.x);
389 r.boundary[1]=((int)lp.getStruct().pos.y);
390 r.boundary[2]=((int)(lp.getStruct().pos.x+lp.getStruct().sz.x));
391 r.boundary[3]=((int)(lp.getStruct().pos.y+lp.getStruct().sz.y));
392 } finally {
393 LEAVING("71b5ttp3xs7lo9fqgb7ypyqgx","objplp2rect");
394 }
395 }
396
397
398
399
400 //3 ksqjbiie0e6vvaeawdxriie5
401 // static Rect_t objplpmks(XLabels_t * xlp, object_t * objp)
402 public static ST_Rect_t objplpmks(ST_XLabels_t xlp, ST_object_t objp) {
403 ENTERING("ksqjbiie0e6vvaeawdxriie5","objplpmks");
404 try {
405 final ST_Rect_t rect = new ST_Rect_t();
406 final ST_pointf p = new ST_pointf();
407 p.setDouble("x", 0);
408 p.setDouble("y", 0);
409 if (objp.lbl!=null)
410 p.___(objp.lbl.getStruct().sz);
411 rect.boundary[0]=((int) Math.floor(objp.pos.x - p.x));
412 rect.boundary[1]=((int) Math.floor(objp.pos.y - p.y));
413 rect.boundary[2]=((int) Math.ceil(objp.pos.x + objp.sz.x + p.x));
414 // assert(rect.boundary[2] < INT_MAX);
415 rect.boundary[3]=((int) Math.ceil(objp.pos.y + objp.sz.y + p.y));
416 // assert(rect.boundary[3] < INT_MAX);
417 return rect;
418 } finally {
419 LEAVING("ksqjbiie0e6vvaeawdxriie5","objplpmks");
420 }
421 }
422
423
424
425
426 //3 calnhom3s9dqvvi6crrz3h2wp
427 // static int getintrsxi(XLabels_t * xlp, object_t * op, object_t * cp)
428 public static int getintrsxi(ST_XLabels_t xlp, ST_object_t op, ST_object_t cp) {
429 ENTERING("calnhom3s9dqvvi6crrz3h2wp","getintrsxi");
430 try {
431 int i = -1;
432 ST_xlabel_t.Array lp = (ST_xlabel_t.Array) op.lbl, clp = (ST_xlabel_t.Array) cp.lbl;
433 assert(lp != clp);
434 if (lp.getStruct().set == 0 || clp.getStruct().set == 0)
435 return i;
436 UNSUPPORTED("bofpvwtmumoe1ckgnlgbwg8bt"); // if ((op->pos.x == 0.0 && op->pos.y == 0.0) ||
437 UNSUPPORTED("f039op8rn0jopi9r8kora4cwz"); // (cp->pos.x == 0.0 && cp->pos.y == 0.0))
438 UNSUPPORTED("11drvggon8u61uz4iw75insly"); // return i;
439 UNSUPPORTED("5t4dji6xy0hdyx5wguao13hy5"); // if (cp->pos.y < op->pos.y)
440 UNSUPPORTED("kx0a7gocqji2ms0neepjemp0"); // if (cp->pos.x < op->pos.x)
441 UNSUPPORTED("al11nyatzn20y82ligyxw6doz"); // i = 0;
442 UNSUPPORTED("6u28hrhgdf9tpy6v85nmoma8q"); // else if (cp->pos.x > op->pos.x)
443 UNSUPPORTED("3nbwdw3wfkpmnrf8loezvflkx"); // i = 2;
444 UNSUPPORTED("9352ql3e58qs4fzapgjfrms2s"); // else
445 UNSUPPORTED("akdfo982ws6tlct2c4wlm7hdb"); // i = 1;
446 UNSUPPORTED("6h2iz13c1pog9oqz0a4f1sqth"); // else if (cp->pos.y > op->pos.y)
447 UNSUPPORTED("kx0a7gocqji2ms0neepjemp0"); // if (cp->pos.x < op->pos.x)
448 UNSUPPORTED("2rdl000508m132a9u1h076lba"); // i = 6;
449 UNSUPPORTED("6u28hrhgdf9tpy6v85nmoma8q"); // else if (cp->pos.x > op->pos.x)
450 UNSUPPORTED("7p6vu0p80gdkcsj4l5hz59dqb"); // i = 8;
451 UNSUPPORTED("9352ql3e58qs4fzapgjfrms2s"); // else
452 UNSUPPORTED("69apu46xpi0gdi4dt1tir6dbh"); // i = 7;
453 UNSUPPORTED("73lwftxejfwwrm0v22inmutya"); // else if (cp->pos.x < op->pos.x)
454 UNSUPPORTED("9t0t38axcdz9uuxxaxd4e5oi2"); // i = 3;
455 UNSUPPORTED("an605gtk4m1ql9srrrj5k6dah"); // else if (cp->pos.x > op->pos.x)
456 UNSUPPORTED("cmp9l0lizmu0ars1jf1oxdms"); // i = 5;
457 UNSUPPORTED("ahwo5hst5k1gyq20ve63ahe81"); // return i;
458 UNSUPPORTED("c24nfmv9i7o5eoqaymbibp7m7"); // }
459
460 throw new UnsupportedOperationException();
461 } finally {
462 LEAVING("calnhom3s9dqvvi6crrz3h2wp","getintrsxi");
463 }
464 }
465
466
467
468
469 //3 52awwxu810dg9a2pjq45aomam
470 // static double recordointrsx(XLabels_t * xlp, object_t * op, object_t * cp, Rect_t * rp, double a, object_t * intrsx[9])
471 public static double recordointrsx(ST_XLabels_t xlp, ST_object_t op, ST_object_t cp, ST_Rect_t rp, double a, ST_object_t[] intrsx) {
472 ENTERING("52awwxu810dg9a2pjq45aomam","recordointrsx");
473 try {
474 int i = getintrsxi(xlp, op, cp);
475 if (i < 0)
476 i = 5;
477 if (intrsx[i] != null) {
478 double sa, maxa = 0.0;
479 final ST_Rect_t srect = new ST_Rect_t();
480 /* keep maximally overlapping object */
481 objp2rect(intrsx[i], srect);
482 sa = aabbaabb(rp, srect);
483 if (sa > a)
484 maxa = sa;
485 /*keep maximally overlapping label */
486 if (intrsx[i].lbl!=null) {
487 objplp2rect(intrsx[i], srect);
488 sa = aabbaabb(rp, srect);
489 if (sa > a)
490 maxa = sa > maxa ? sa : maxa;
491 }
492 if (maxa > 0.0)
493 return maxa;
494 /*replace overlapping label/object pair */
495 intrsx[i] = cp;
496 return a;
497 }
498 intrsx[i] = cp;
499 return a;
500 } finally {
501 LEAVING("52awwxu810dg9a2pjq45aomam","recordointrsx");
502 }
503 }
504
505
506
507
508 //3 2umrncgkunxoyeuc8i9hd5pwa
509 // static double recordlintrsx(XLabels_t * xlp, object_t * op, object_t * cp, Rect_t * rp, double a, object_t * intrsx[9])
510 public static double recordlintrsx(ST_XLabels_t xlp, ST_object_t op, ST_object_t cp, ST_Rect_t rp, double a, ST_object_t intrsx[]) {
511 ENTERING("2umrncgkunxoyeuc8i9hd5pwa","recordlintrsx");
512 try {
513 int i = getintrsxi(xlp, op, cp);
514 if (i < 0)
515 i = 5;
516 if (intrsx[i] != null) {
517 double sa, maxa = 0.0;
518 final ST_Rect_t srect = new ST_Rect_t();
519 /* keep maximally overlapping object */
520 objp2rect(intrsx[i], srect);
521 sa = aabbaabb(rp, srect);
522 if (sa > a)
523 maxa = sa;
524 /*keep maximally overlapping label */
525 if (intrsx[i].lbl!=null) {
526 objplp2rect(intrsx[i], srect);
527 sa = aabbaabb(rp, srect);
528 if (sa > a)
529 maxa = sa > maxa ? sa : maxa;
530 }
531 if (maxa > 0.0)
532 return maxa;
533 /*replace overlapping label/object pair */
534 intrsx[i] = cp;
535 return a;
536 }
537 intrsx[i] = cp;
538 return a;
539 } finally {
540 LEAVING("2umrncgkunxoyeuc8i9hd5pwa","recordlintrsx");
541 }
542 }
543
544
545
546
547 //3 2td62i5hus8obwt8j1lo3ddj9
548 // static BestPos_t xlintersections(XLabels_t * xlp, object_t * objp, object_t * intrsx[9])
549 public static ST_BestPos_t xlintersections(ST_XLabels_t xlp, ST_object_t objp, ST_object_t intrsx[]) {
550 ENTERING("2td62i5hus8obwt8j1lo3ddj9","xlintersections");
551 try {
552 return (ST_BestPos_t) xlintersections_(xlp, objp, intrsx).copy();
553 } finally {
554 LEAVING("2td62i5hus8obwt8j1lo3ddj9","xlintersections");
555 }
556 }
557
558 private static ST_BestPos_t xlintersections_(ST_XLabels_t xlp, ST_object_t objp, ST_object_t intrsx[]) {
559 int i;
560 ST_LeafList_t ilp, llp;
561 final ST_Rect_t rect = new ST_Rect_t();
562 final ST_Rect_t srect = new ST_Rect_t();
563 final ST_BestPos_t bp = new ST_BestPos_t();
564 // assert(objp->lbl);
565 bp.setInt("n", 0);
566 bp.setDouble("area", 0.0);
567 bp.setStruct("pos", objp.lbl.getStruct().pos);
568 for(i=0; i<xlp.n_objs; i++) {
569 if (EQ(objp, xlp.objs.plus(i).getStruct())) continue;
570 if(xlp.objs.get(i).sz.x > 0 && xlp.objs.get(i).sz.y > 0) continue;
571 if(lblenclosing(objp, (ST_object_t) xlp.objs.plus(i).getStruct())) {
572 bp.setInt("n", bp.n+1);
573 }
574 }
575 objplp2rect((ST_object_t) objp.getStruct(), rect);
576 llp = RTreeSearch((ST_RTree)xlp.spdx, (ST_Node_t___)xlp.spdx.root, rect);
577 if (N(llp))
578 return bp;
579 for (ilp = llp; ilp!=null; ilp = (ST_LeafList_t) ilp.next) {
580 double a, ra;
581 // WARNING FOR TRANSLATION
582 // In the C code, "data" was used. However ST_Branch_t is very close to ST_Leaf_t
583 // So in Java version, ST_Leaf_t has been removed and ST_Branch_t is used instead
584 ST_object_t cp = (ST_object_t) ilp.leaf.child;
585 if (EQ(cp, objp))
586 continue;
587 /*label-object intersect */
588 objp2rect((ST_object_t) cp.getStruct(), srect);
589 a = aabbaabb(rect, srect);
590 if (a > 0.0) {
591 ra = recordointrsx(xlp, objp, cp, rect, a, intrsx);
592 bp.setInt("n", bp.n+1);
593 bp.setDouble("area", bp.area+ra);
594 }
595 /*label-label intersect */
596 if (N(cp.lbl) || N(cp.lbl.getStruct().set))
597 continue;
598 objplp2rect((ST_object_t) cp.getStruct(), srect);
599 a = aabbaabb(rect, srect);
600 if (a > 0.0) {
601 ra = recordlintrsx(xlp, objp, cp, rect, a, intrsx);
602 bp.setInt("n", bp.n+1);
603 bp.setDouble("area", bp.area+ra);
604 }
605 }
606 RTreeLeafListFree(llp);
607 return bp;
608 }
609
610
611
612
613 //3 8rxvucqsqnqej6h8p1osfnk4b
614 // static BestPos_t xladjust(XLabels_t * xlp, object_t * objp)
615 public static ST_BestPos_t xladjust(ST_XLabels_t xlp, ST_object_t objp) {
616 ENTERING("8rxvucqsqnqej6h8p1osfnk4b","xladjust");
617 try {
618 return (ST_BestPos_t) xladjust_(xlp, objp).copy();
619 } finally {
620 LEAVING("8rxvucqsqnqej6h8p1osfnk4b","xladjust");
621 }
622 }
623 private static ST_BestPos_t xladjust_(ST_XLabels_t xlp, ST_object_t objp) {
624 ST_xlabel_t.Array lp = (ST_xlabel_t.Array) objp.lbl; // ST_xlabel_t
625 double xincr = ((2 * lp.getStruct().sz.x + objp.sz.x)) / 8;
626 double yincr = ((2 * lp.getStruct().sz.y + objp.sz.y)) / 2;
627 ST_object_t intrsx[] = new ST_object_t[9];
628 final ST_BestPos_t bp = new ST_BestPos_t();
629 final ST_BestPos_t nbp = new ST_BestPos_t();
630 // assert(objp->lbl);
631 // memset(intrsx, 0, sizeof(intrsx));
632 /*x left */
633 lp.getStruct().pos.setDouble("x", objp.pos.x - lp.getStruct().sz.x);
634 /*top */
635 lp.getStruct().pos.setDouble("y", objp.pos.y + objp.sz.y);
636 bp.___(xlintersections(xlp, objp, intrsx));
637 if (bp.n == 0)
638 return bp;
639 /*mid */
640 lp.getStruct().pos.setDouble("y", objp.pos.y);
641 nbp.___(xlintersections(xlp, objp, intrsx));
642 if (nbp.n == 0)
643 return nbp;
644 if (nbp.area < bp.area)
645 bp.___(nbp);
646 /*bottom */
647 lp.getStruct().pos.setDouble("y", objp.pos.y - lp.getStruct().sz.y);
648 nbp.___(xlintersections(xlp, objp, intrsx));
649 if (nbp.n == 0)
650 return nbp;
651 if (nbp.area < bp.area)
652 bp.___(nbp);
653 /*x mid */
654 lp.getStruct().pos.setDouble("x", objp.pos.x);
655 /*top */
656 lp.getStruct().pos.setDouble("y", objp.pos.y + objp.sz.y);
657 nbp.___(xlintersections(xlp, objp, intrsx));
658 if (nbp.n == 0)
659 return nbp;
660 if (nbp.area < bp.area)
661 bp.___(nbp);
662 /*bottom */
663 lp.getStruct().pos.setDouble("y", objp.pos.y - lp.getStruct().sz.y);
664 nbp.___(xlintersections(xlp, objp, intrsx));
665 if (nbp.n == 0)
666 return nbp;
667 if (nbp.area < bp.area)
668 bp.___(nbp);
669 /*x right */
670 lp.getStruct().pos.setDouble("x", objp.pos.x + objp.sz.x);
671 /*top */
672 lp.getStruct().pos.setDouble("y", objp.pos.y + objp.sz.y);
673 nbp.___(xlintersections(xlp, objp, intrsx));
674 if (nbp.n == 0)
675 return nbp;
676 if (nbp.area < bp.area)
677 bp.___(nbp);
678 /*mid */
679 lp.getStruct().pos.setDouble("y", objp.pos.y);
680 nbp.___(xlintersections(xlp, objp, intrsx));
681 if (nbp.n == 0)
682 return nbp;
683 if (nbp.area < bp.area)
684 bp.___(nbp);
685 /*bottom */
686 lp.getStruct().pos.setDouble("y", objp.pos.y - lp.getStruct().sz.y);
687 nbp.___(xlintersections(xlp, objp, intrsx));
688 if (nbp.n == 0)
689 return nbp;
690 if (nbp.area < bp.area)
691 bp.___(nbp);
692 /*sliding from top left */
693 if (intrsx[6]!=null || intrsx[7]!=null || intrsx[8]!=null || intrsx[3]!=null || intrsx[0]!=null) { /* have to move */
694 UNSUPPORTED("c5acs4cl77hgu5j6nmhk090uz"); // if (!intrsx[7] && !intrsx[8]) { /* some room right? */
695 UNSUPPORTED("ez8sbh237xdqdjeewev2ys74y"); // /* slide along upper edge */
696 UNSUPPORTED("ajgw2jggmwmofm77lgbx5eo2n"); // for (lp->pos.x = objp->pos.x - lp->sz.x,
697 UNSUPPORTED("nwfhss2g67z5exjkorj0brd"); // lp->pos.y = objp->pos.y + objp->sz.y;
698 UNSUPPORTED("eav75dwa3f3ieedr9mnov3a6u"); // lp->pos.x <= (objp->pos.x + objp->sz.x);
699 UNSUPPORTED("38u334kkfej5n3r31uv1afw9q"); // lp->pos.x += xincr) {
700 UNSUPPORTED("8pbum2o0fs86ceaiuxv4efbb6"); // nbp = xlintersections(xlp, objp, intrsx);
701 UNSUPPORTED("5xx7o143ftoj0rhyhg1hqgioa"); // if (nbp.n == 0)
702 UNSUPPORTED("eqanxe9w90oki7yqvwyzpfcw1"); // return nbp;
703 UNSUPPORTED("8yd6g3a3f0g09gmu5f67vah0x"); // if (nbp.area < bp.area)
704 UNSUPPORTED("d6ac36j6lh6qspxwnn3vi0uc3"); // bp = nbp;
705 UNSUPPORTED("6t98dcecgbvbvtpycwiq2ynnj"); // }
706 UNSUPPORTED("flupwh3kosf3fkhkxllllt1"); // }
707 UNSUPPORTED("4w0qgfnt6kpuhb381pmra3ln4"); // if (!intrsx[3] && !intrsx[0]) { /* some room down? */
708 UNSUPPORTED("6st33ex0udr4mk4sa9vd119uz"); // /* slide down left edge */
709 UNSUPPORTED("ajgw2jggmwmofm77lgbx5eo2n"); // for (lp->pos.x = objp->pos.x - lp->sz.x,
710 UNSUPPORTED("nwfhss2g67z5exjkorj0brd"); // lp->pos.y = objp->pos.y + objp->sz.y;
711 UNSUPPORTED("eolwmrajeldp9gf9ug6ue0gx2"); // lp->pos.y >= (objp->pos.y - lp->sz.y);
712 UNSUPPORTED("bz3822dbe0xnwj4nm7pf39kae"); // lp->pos.y -= yincr) {
713 UNSUPPORTED("8pbum2o0fs86ceaiuxv4efbb6"); // nbp = xlintersections(xlp, objp, intrsx);
714 UNSUPPORTED("5xx7o143ftoj0rhyhg1hqgioa"); // if (nbp.n == 0)
715 UNSUPPORTED("eqanxe9w90oki7yqvwyzpfcw1"); // return nbp;
716 UNSUPPORTED("8yd6g3a3f0g09gmu5f67vah0x"); // if (nbp.area < bp.area)
717 UNSUPPORTED("d6ac36j6lh6qspxwnn3vi0uc3"); // bp = nbp;
718 UNSUPPORTED("6t98dcecgbvbvtpycwiq2ynnj"); // }
719 UNSUPPORTED("flupwh3kosf3fkhkxllllt1"); // }
720 }
721 /*sliding from bottom right */
722 lp.getStruct().pos.setDouble("x", objp.pos.x + objp.sz.x);
723 lp.getStruct().pos.setDouble("y", objp.pos.y - lp.getStruct().sz.y);
724 if (intrsx[2]!=null || intrsx[1]!=null || intrsx[0]!=null || intrsx[5]!=null || intrsx[8]!=null) { /* have to move */
725 if (N(intrsx[1]) && N(intrsx[0])) { /* some room left? */
726 /* slide along lower edge */
727 for (lp.getStruct().pos.setDouble("x", objp.pos.x + objp.sz.x),
728 lp.getStruct().pos.setDouble("y", objp.pos.y - lp.getStruct().sz.y);
729 lp.getStruct().pos.x >= (objp.pos.x - lp.getStruct().sz.x);
730 lp.getStruct().pos.setDouble("x", lp.getStruct().pos.x - xincr)) {
731 nbp.___(xlintersections(xlp, objp, intrsx));
732 if (nbp.n == 0)
733 return nbp;
734 if (nbp.area < bp.area)
735 bp.___(nbp);
736 }
737 }
738 if (N(intrsx[5]) && N(intrsx[8])) { /* some room up? */
739 UNSUPPORTED("4bcpk3ixfwrlr0yzrjv2efigj"); // /* slide up right edge */
740 UNSUPPORTED("7natp0873pfsvymhhhvki1sev"); // for (lp->pos.x = objp->pos.x + objp->sz.x,
741 UNSUPPORTED("56ycmo0ljb7e86mnezdx3regh"); // lp->pos.y = objp->pos.y - lp->sz.y;
742 UNSUPPORTED("9cepfi69gtzy7muk9d27es8oc"); // lp->pos.y <= (objp->pos.y + objp->sz.y);
743 UNSUPPORTED("az41g895dhl39ckrigxl1c5jl"); // lp->pos.y += yincr) {
744 UNSUPPORTED("8pbum2o0fs86ceaiuxv4efbb6"); // nbp = xlintersections(xlp, objp, intrsx);
745 UNSUPPORTED("5xx7o143ftoj0rhyhg1hqgioa"); // if (nbp.n == 0)
746 UNSUPPORTED("eqanxe9w90oki7yqvwyzpfcw1"); // return nbp;
747 UNSUPPORTED("8yd6g3a3f0g09gmu5f67vah0x"); // if (nbp.area < bp.area)
748 UNSUPPORTED("d6ac36j6lh6qspxwnn3vi0uc3"); // bp = nbp;
749 UNSUPPORTED("6t98dcecgbvbvtpycwiq2ynnj"); // }
750 }
751 }
752 return bp;
753 }
754
755
756
757
758 //3 e29g2hwlogx0zchsnvi464c7t
759 // static int xlhdxload(XLabels_t * xlp)
760 public static int xlhdxload(ST_XLabels_t xlp) {
761 ENTERING("e29g2hwlogx0zchsnvi464c7t","xlhdxload");
762 try {
763 int i;
764 int order = xlhorder(xlp);
765 for (i = 0; i < xlp.n_objs; i++) {
766 ST_HDict_t hp;
767 final ST_point pi = new ST_point();
768 hp = new ST_HDict_t();
769 hp.d.child = xlp.objs.get(i);
770 hp.d.setStruct("rect", objplpmks(xlp, (ST_object_t) xlp.objs.plus(i).getStruct()));
771 /* center of the labeling area */
772 pi.setInt("x", hp.d.rect.boundary[0] +
773 (hp.d.rect.boundary[2] - hp.d.rect.boundary[0]) / 2);
774 pi.setInt("y", hp.d.rect.boundary[1] +
775 (hp.d.rect.boundary[3] - hp.d.rect.boundary[1]) / 2);
776 hp.setInt("key", hd_hil_s_from_xy(pi, order));
777 if (N(xlp.hdx.searchf.exe(xlp.hdx, hp, 0000001)))
778 return -1;
779 }
780 return 0;
781 } finally {
782 LEAVING("e29g2hwlogx0zchsnvi464c7t","xlhdxload");
783 }
784 }
785
786
787
788
789 //3 26qpvnyd6tmdut8i2wo4itza3
790 // static void xlhdxunload(XLabels_t * xlp)
791 public static void xlhdxunload(ST_XLabels_t xlp) {
792 ENTERING("26qpvnyd6tmdut8i2wo4itza3","xlhdxunload");
793 try {
794 //UNSUPPORTED("4bsnj74f63qe288s6be1xmrzw"); // static void xlhdxunload(XLabels_t * xlp)
795 //UNSUPPORTED("erg9i1970wdri39osu8hx2a6e"); // {
796 //UNSUPPORTED("9sqtid8yyo2ws8avf33utdebf"); // int size=dtsize(xlp->hdx), freed=0;
797 //UNSUPPORTED("dm7bmt2fwlkdskmcebdm1ctqj"); // while(dtsize(xlp->hdx) ) {
798 //UNSUPPORTED("a3jz6ykhoarsdfviidq7beb9z"); // void*vp=(((Dt_t*)(xlp->hdx))->data->here ? (((Dt_t*)((xlp->hdx)))->disc->link < 0 ? ((Dthold_t*)((((Dt_t*)(xlp->hdx))->data->here)))->obj : (void*)((char*)((((Dt_t*)(xlp->hdx))->data->here)) - ((Dt_t*)((xlp->hdx)))->disc->link) ):(void*)(0));
799 //UNSUPPORTED("2covsywkzvpkysnjf34nmr1uw"); // assert(vp);
800 //UNSUPPORTED("a9jmr8hmnwcky7f1e1qorwnjv"); // if(vp) {
801 //UNSUPPORTED("d2vfgb4tj6x8x7cq0kv0qgk23"); // (*(((Dt_t*)(xlp->hdx))->searchf))((xlp->hdx),(void*)(vp),0010000);
802 //UNSUPPORTED("7f4abg2jsf465jjlnp95d9sk6"); // free(vp);
803 //UNSUPPORTED("5hklxkrkvjgi37kkm6v9xajwc"); // freed++;
804 //UNSUPPORTED("dvgyxsnyeqqnyzq696k3vskib"); // }
805 //UNSUPPORTED("7ijd6pszsxnoopppf6xwo8wdl"); // }
806 //UNSUPPORTED("bifp41eoqo8l51crrab087z21"); // assert(size==freed);
807 //UNSUPPORTED("c24nfmv9i7o5eoqaymbibp7m7"); // }
808 } finally {
809 LEAVING("26qpvnyd6tmdut8i2wo4itza3","xlhdxunload");
810 }
811 }
812
813
814
815
816 //3 3wrxwwd3y5ts0ekr32o8vhuvv
817 // static int xlspdxload(XLabels_t * xlp)
818 public static int xlspdxload(ST_XLabels_t xlp) {
819 ENTERING("3wrxwwd3y5ts0ekr32o8vhuvv","xlspdxload");
820 try {
821 ST_HDict_t op=null;
822 for (op = (ST_HDict_t) xlp.hdx.searchf.exe(xlp.hdx, null, 0000200); op!=null;
823 op = (ST_HDict_t) xlp.hdx.searchf.exe(xlp.hdx, op, 0000010)) {
824 /* tree rectangle data node lvl */
825 // RTreeInsert(xlp->spdx, &op->d.rect, op->d.data, &xlp->spdx->root, 0);
826 // WARNING ARRAY
827 final ST_Node_t___[] tmp = new ST_Node_t___[] {(ST_Node_t___) xlp.spdx.root};
828 RTreeInsert((ST_RTree) xlp.spdx, (ST_Rect_t)op.d.rect,
829 op.d.child,
830 tmp, 0);
831 xlp.spdx.setPtr("root", tmp[0]);
832 }
833 return 0;
834 } finally {
835 LEAVING("3wrxwwd3y5ts0ekr32o8vhuvv","xlspdxload");
836 }
837 }
838
839
840
841
842 //3 6d3fqrllm55toeo3wscwvv4ty
843 // static int xlinitialize(XLabels_t * xlp)
844 public static int xlinitialize(ST_XLabels_t xlp) {
845 ENTERING("6d3fqrllm55toeo3wscwvv4ty","xlinitialize");
846 try {
847 int r=0;
848 if ((r = xlhdxload(xlp)) < 0)
849 return r;
850 if ((r = xlspdxload(xlp)) < 0)
851 return r;
852 xlhdxunload(xlp);
853 return dtclose((ST_dt_s) xlp.hdx);
854 } finally {
855 LEAVING("6d3fqrllm55toeo3wscwvv4ty","xlinitialize");
856 }
857 }
858
859
860
861
862 //3 brqgbskh3z4ah8infjompibvu
863 // int placeLabels(object_t * objs, int n_objs, xlabel_t * lbls, int n_lbls, label_params_t * params)
864 public static int placeLabels(ST_object_t.Array objs, int n_objs, ST_xlabel_t.Array lbls, int n_lbls, ST_label_params_t params) {
865 ENTERING("brqgbskh3z4ah8infjompibvu","placeLabels");
866 try {
867 int r, i;
868 final ST_BestPos_t bp = new ST_BestPos_t();
869 ST_XLabels_t xlp = xlnew(objs, n_objs, lbls, n_lbls, params);
870 if ((r = xlinitialize(xlp)) < 0)
871 return r;
872 /* Place xlabel_t* lp near lp->obj so that the rectangle whose lower-left
873 * corner is lp->pos, and size is lp->sz does not intersect any object
874 * in objs (by convention, an object consisting of a single point
875 * intersects nothing) nor any other label, if possible. On input,
876 * lp->set is 0.
877 *
878 * On output, any label with a position should have this stored in
879 * lp->pos and have lp->set non-zero.
880 *
881 * If params->force is true, all labels must be positioned, even if
882 * overlaps are necessary.
883 *
884 * Return 0 if all labels could be placed without overlap;
885 * non-zero otherwise.
886 */
887 r = 0;
888 for (i = 0; i < n_objs; i++) {
889 if (objs.get(i).lbl == null)
890 continue;
891 xladjust(xlp, (ST_object_t) objs.get(i).getStruct());
892 bp.___(xladjust(xlp, (ST_object_t) objs.get(i).getStruct()));
893 if (bp.n == 0) {
894 objs.get(i).lbl.setInt("set", 1);
895 } else if(bp.area == 0) {
896 objs.get(i).lbl.getStruct().pos.setDouble("x", bp.pos.x);
897 objs.get(i).lbl.getStruct().pos.setDouble("y", bp.pos.y);
898 objs.get(i).lbl.setInt("set", 1);
899 } else if (params.force) {
900 objs.get(i).lbl.getStruct().pos.setDouble("x", bp.pos.x);
901 objs.get(i).lbl.getStruct().pos.setDouble("y", bp.pos.y);
902 objs.get(i).lbl.setInt("set", 1);
903 } else {
904 r = 1;
905 }
906 }
907 xlfree(xlp);
908 return r;
909 } finally {
910 LEAVING("brqgbskh3z4ah8infjompibvu","placeLabels");
911 }
912 }
913
914
915 }