CuneiPainter  Version 1.2
LocationCalc Class Reference

Created by timo on 14.12.18 . More...

Collaboration diagram for LocationCalc:

Static Public Member Functions

static Integer getAverageStrokeLength (StrokeType type)
 
static Boolean crosses (LineParameters one, LineParameters two)
 
static Double distance (Float x1, Float x2, Float y1, Float y2)
 
static Boolean startsDiagonallyToAndIntersects (LineParameters one, LineParameters two)
 
static String smallNormalOrBigStroke (StrokeType type, float delta)
 
static String calculateRelationBetweenTwoLines (LineParameters line, LineParameters newline)
 
static String calculateRelation (List< LineParameters > lines)
 
static void main (String[] args)
 

Static Public Attributes

static Map< StrokeType, Set
< Integer > > 
stroketypeLength =new TreeMap<>()
 

Static Package Functions

static Boolean checkIntersection (int ax, int ay, int bx, int by, int cx, int cy, int dx, int dy)
 

Detailed Description

Created by timo on 14.12.18 .

Member Function Documentation

static String calculateRelation ( List< LineParameters lines)
static

References LocationCalc.calculateRelationBetweenTwoLines(), LineParameters.deltaX, LocationCalc.smallNormalOrBigStroke(), LocationCalc.stroketypeLength, and LineParameters.type.

171  {
172  //find smallest y
173  Collections.sort(lines);
174  if(lines.isEmpty())
175  return "";
176  for(LineParameters line : lines){
177  if(!stroketypeLength.containsKey(line.type)){
178  stroketypeLength.put(line.type,new TreeSet<Integer>());
179  }
180  stroketypeLength.get(line.type).add(line.deltaX.intValue());
181  }
182  LineParameters line=lines.iterator().next();
183  Iterator<LineParameters> linit=lines.iterator();
184  LineParameters line1=linit.next();
185  LineParameters line2=null;
186  StringBuilder drawnSign=new StringBuilder();
187  drawnSign.append(smallNormalOrBigStroke(line.type,line.deltaX));
188  System.out.println("Lines: "+lines);
189  while(linit.hasNext()){
190  if(linit.hasNext()){
191  line2=linit.next();
192  }
193  drawnSign.append(calculateRelationBetweenTwoLines(line1,line2));
194  System.out.println("DrawSign: "+drawnSign.toString());
195  line1=line2;
196  }
197 
198  return drawnSign.toString();
199  }
static String calculateRelationBetweenTwoLines(LineParameters line, LineParameters newline)
Definition: LocationCalc.java:82
static String smallNormalOrBigStroke(StrokeType type, float delta)
Definition: LocationCalc.java:34
static Map< StrokeType, Set< Integer > > stroketypeLength
Definition: LocationCalc.java:10
static String calculateRelationBetweenTwoLines ( LineParameters  line,
LineParameters  newline 
)
static

References StrokeType.A, StrokeType.B, StrokeType.C, LocationCalc.crosses(), StrokeType.D, LineParameters.deltaX, LineParameters.deltaY, StrokeType.E, StrokeType.F, StrokeType.INV_A, StrokeType.INV_B, LocationCalc.smallNormalOrBigStroke(), LocationCalc.startsDiagonallyToAndIntersects(), LineParameters.startY, and LineParameters.type.

Referenced by LocationCalc.calculateRelation().

82  {
83  StringBuilder returnString=new StringBuilder();
84  switch(line.type){
85  case A:
86  System.out.println("Case A: "+crosses(newline,line));
87  if((newline.type==StrokeType.A || newline.type==StrokeType.INV_A) && !newline.startX.equals(line.startX)) {
88  returnString.append(":");
89  returnString.append(smallNormalOrBigStroke(newline.type,newline.deltaX));
90  }else if((newline.type==StrokeType.B || newline.type==StrokeType.INV_B) && crosses(newline,line)){
91  returnString.append("-");
92  returnString.append(smallNormalOrBigStroke(newline.type,newline.deltaX));
93  }else if((newline.type==StrokeType.B || newline.type==StrokeType.INV_B) && !crosses(newline,line) && newline.startX>=line.endX){
94  returnString.append("_");
95  returnString.append(smallNormalOrBigStroke(newline.type,newline.deltaX));
96  }else if((newline.type==StrokeType.C || newline.type==StrokeType.D) && !crosses(newline,line)){
97 
98  }else if((newline.type==StrokeType.C || newline.type==StrokeType.D) && crosses(newline,line)){
99 
100  }else if((newline.type==StrokeType.E || newline.type==StrokeType.F) && !crosses(newline,line)){
101 
102  }else if((newline.type==StrokeType.E || newline.type==StrokeType.F) && crosses(newline,line)){
103 
104  }
105  //lines.add(newline);
106  return returnString.toString();
107  case B:
108  System.out.println("Case B: "+crosses(newline,line));
109  if((newline.type==StrokeType.B || newline.type==StrokeType.INV_B) && !newline.startX.equals(line.startX) && !newline.startY.equals(line.startY)) {
110  //Parallel horizontal
111  //lines.add(newline);
112  returnString.append(":");
113  returnString.append(smallNormalOrBigStroke(newline.type,newline.deltaX));
114  }else if((newline.type==StrokeType.A || newline.type==StrokeType.INV_A) && crosses(newline,line)){
115  returnString.append("-");
116  returnString.append(smallNormalOrBigStroke(newline.type,newline.deltaX));
117  }else if((newline.type==StrokeType.A || newline.type==StrokeType.INV_A) && !crosses(newline,line) && newline.startX>=line.endX){
118  returnString.append("_");
119  returnString.append(smallNormalOrBigStroke(newline.type,newline.deltaX));
120  }
121  return returnString.toString();
122  case C:
123  if((newline.type==StrokeType.A || newline.type==StrokeType.INV_A) && crosses(newline,line)){
124  if(newline.deltaY==0){
125  returnString.append(smallNormalOrBigStroke(newline.type,newline.deltaX));
126  returnString.append("'");
127  }else{
128  returnString.append(smallNormalOrBigStroke(newline.type,newline.deltaX));
129  returnString.append("-");
130  }
131  }else if((newline.type==StrokeType.A || newline.type==StrokeType.INV_A) && !crosses(newline,line)){
132  if(newline.deltaY==0){
133  returnString.append(smallNormalOrBigStroke(newline.type,newline.deltaX));
134  returnString.append("-");
135  }else{
136  returnString.append(smallNormalOrBigStroke(newline.type,newline.deltaX));
137  returnString.append("_");
138  }
139  }else if(newline.type==StrokeType.C && crosses(newline,line)){
140  if(startsDiagonallyToAndIntersects(line,newline)){
141  return ".";
142  }else{
143  return ",";
144  }
145  }
146  break;
147  case D:
148  if((newline.type==StrokeType.A || newline.type==StrokeType.INV_A) && crosses(newline,line)){
149  if(newline.deltaY==0){
150  returnString.append(smallNormalOrBigStroke(newline.type,newline.deltaX));
151  returnString.append("'");
152  }else{
153  returnString.append(smallNormalOrBigStroke(newline.type,newline.deltaX));
154  returnString.append("-");
155  }
156  }else if((newline.type==StrokeType.A || newline.type==StrokeType.INV_A) && !crosses(newline,line)){
157 
158  }
159  returnString.append(smallNormalOrBigStroke(newline.type,newline.deltaX));
160  break;
161  case E:
162  returnString.append(smallNormalOrBigStroke(newline.type,newline.deltaX));
163  break;
164  case F:
165  returnString.append(smallNormalOrBigStroke(newline.type,newline.deltaX));
166  break;
167  }
168  return returnString.toString();
169  }
static Boolean crosses(LineParameters one, LineParameters two)
Definition: LocationCalc.java:22
static String smallNormalOrBigStroke(StrokeType type, float delta)
Definition: LocationCalc.java:34
static Boolean startsDiagonallyToAndIntersects(LineParameters one, LineParameters two)
Definition: LocationCalc.java:30
static Boolean checkIntersection ( int  ax,
int  ay,
int  bx,
int  by,
int  cx,
int  cy,
int  dx,
int  dy 
)
staticpackage

Referenced by LocationCalc.crosses().

52  {
53  int det = (bx - ax)*(dy - cy) - (by - ay)*(dx - cx);
54  if (det != 0) {
55  /*
56  * Lines intersect. Check if intersection point is on both segments:
57  */
58  int detu = (cx - ax)*(dy - cy) - (cy - ay)*(dx - cx);
59  int detv = (cx - ax)*(by - ay) - (cy - ay)*(bx - ax);
60  if (det < 0) {
61  // Normalise to det>0 to simplify the following check.
62  det = -det;
63  detu = -detu;
64  detv = -detv;
65  }
66  if (detu >= 0 && detu <= det && detv >= 0 && detv <= det) {
67  System.out.println("INTERSECT");
68  return true;
69  } else {
70  System.out.println("NO NOT INTERSECT");
71  return false;
72  }
73  } else {
74  /*
75  * Lines are parallel (or identical):
76  */
77  System.out.println("PARALLEL");
78  }
79  return false;
80  }
static Boolean crosses ( LineParameters  one,
LineParameters  two 
)
static

References LocationCalc.checkIntersection(), LineParameters.endX, and LineParameters.startX.

Referenced by LocationCalc.calculateRelationBetweenTwoLines().

22  {
23  return checkIntersection(one.startX.intValue(),one.startY.intValue(),one.endX.intValue(),one.endY.intValue(),two.startX.intValue(),two.startY.intValue(),two.endX.intValue(),two.endY.intValue());
24  }
static Boolean checkIntersection(int ax, int ay, int bx, int by, int cx, int cy, int dx, int dy)
Definition: LocationCalc.java:52
static Double distance ( Float  x1,
Float  x2,
Float  y1,
Float  y2 
)
static

Referenced by LocationCalc.startsDiagonallyToAndIntersects().

26  {
27  return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
28  }
static Integer getAverageStrokeLength ( StrokeType  type)
static

References LocationCalc.stroketypeLength.

Referenced by LocationCalc.smallNormalOrBigStroke().

12  {
13  Integer sum=0;
14  for(Integer len:stroketypeLength.get(type)) {
15  sum+=len;
16  }
17  System.out.println("Sum: "+sum+" - "+sum/stroketypeLength.get(type).size());
18  return sum/stroketypeLength.get(type).size();
19  }
static Map< StrokeType, Set< Integer > > stroketypeLength
Definition: LocationCalc.java:10
static void main ( String[]  args)
static

References StrokeType.A, and StrokeType.B.

201  {
202  List<LineParameters> lines=new LinkedList<>();
203  lines.add(new LineParameters((float)0.,(float)0.,(float)5.,(float)0.,(float)5.,(float)0.,StrokeType.A));
204  lines.add(new LineParameters((float)0.,(float)0.,(float)0.,(float)5.,(float)0.,(float)5.,StrokeType.B));
205  String res=LocationCalc.calculateRelation(lines);
206  System.out.println(lines);
207  System.out.println(lines.get(0).type+res);
208  lines=new LinkedList<>();
209  lines.add(new LineParameters((float)0.,(float)0.,(float)0.,(float)5.,(float)0.,(float)5.,StrokeType.B));
210  res=LocationCalc.calculateRelation(lines);
211  System.out.println(lines);
212  System.out.println(lines.get(0).type+res);
213  }
static String smallNormalOrBigStroke ( StrokeType  type,
float  delta 
)
static

References LocationCalc.getAverageStrokeLength(), and LocationCalc.stroketypeLength.

Referenced by LocationCalc.calculateRelation(), and LocationCalc.calculateRelationBetweenTwoLines().

34  {
35  if(delta<0)
36  delta*=-1;
37  if(stroketypeLength.get(type).size()==1){
38  return type.toString();
39  }
40  int avglength=getAverageStrokeLength(type);
41  System.out.println("Average length: "+avglength+" - Big: "+1.5*avglength+" Small: "+avglength/1.5+" Delta: "+delta);
42  System.out.println(delta+">="+1.5*avglength+" Big? "+(delta>=(1.5*avglength)));
43  System.out.println(delta+"<="+avglength/1.5+" Small? "+(delta<=avglength/2));
44  if(delta>=(1.5*avglength)){
45  return type.toString().toUpperCase();
46  }else if(delta<=avglength/2){
47  return "s"+type.toString();
48  }
49  return type.toString();
50  }
static Integer getAverageStrokeLength(StrokeType type)
Definition: LocationCalc.java:12
static Map< StrokeType, Set< Integer > > stroketypeLength
Definition: LocationCalc.java:10
static Boolean startsDiagonallyToAndIntersects ( LineParameters  one,
LineParameters  two 
)
static

References LocationCalc.distance(), LineParameters.endX, LineParameters.endY, LineParameters.startX, and LineParameters.startY.

Referenced by LocationCalc.calculateRelationBetweenTwoLines().

30  {
31  return distance(one.startX,two.startX, one.startY,two.startY) + distance(one.endX,two.startX,one.endY, two.startY) == distance(one.startX,one.endX,one.startY,one.endY);
32  }
static Double distance(Float x1, Float x2, Float y1, Float y2)
Definition: LocationCalc.java:26

Member Data Documentation

Map<StrokeType,Set<Integer> > stroketypeLength =new TreeMap<>()
static