Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

31
LINES

< > BotCompany Repo | #1009521 // calFromCoordinates

JavaX fragment (include)

1  
static CirclesAndLines calFromCoordinates(Map<S, Pt> coordinates, SS withImage, Collection<Relation> relations) {
2  
  Rect r = mergeRects(map(f ptToRect, values(coordinates)));
3  
  BufferedImage img = newBufferedImage(20, 20, Color.white);
4  
5  
  new CirclesAndLines cal;
6  
  Map<S, Circle> circles = caseInsensitiveMap();
7  
  for (S node : keys(coordinates)) {
8  
    Pt p = coordinates.get(node);
9  
    double x = ((p.x-r.x)/(double) r.w)*0.6+0.2;
10  
    double y = ((p.y-r.y)/(double) r.h)*0.5+0.2;
11  
    Circle c;
12  
    S imgText = mapGet(withImage, node);
13  
    if (nempty(imgText))
14  
      c = cal.circle_autoVis(node, imgText, x, y);
15  
    else
16  
      c = cal.circle(img, x, y, node);
17  
    circles.put(node, c);
18  
  }
19  
  
20  
  for (Relation rel : relations) {
21  
    if (rel.is("An arrow from * to *")) {
22  
      Circle a = circles.get(rel.a()), b = circles.get(rel.b());
23  
      if (a != null && b != null) cal.addArrow(a, b);
24  
    } else if (rel.is("An arrow * from * to *")) {
25  
      Circle a = circles.get(rel.b()), b = circles.get(rel.c());
26  
      if (a != null && b != null) cal.addArrow(a, b, rel.a());
27  
    }
28  
  }
29  
  
30  
  ret cal;
31  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009521
Snippet name: calFromCoordinates
Eternal ID of this version: #1009521/10
Text MD5: ad85c44165cb7a744c677590e77b1cb1
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-06 20:51:43
Source code size: 1124 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 429 / 510
Version history: 9 change(s)
Referenced in: [show references]