1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package org.ximtec.igesture.algorithm.siger;
30
31 import java.util.ArrayList;
32 import java.util.List;
33
34 import org.sigtec.ink.Note;
35 import org.sigtec.ink.Point;
36 import org.sigtec.util.Constant;
37 import org.ximtec.igesture.util.GestureTool;
38
39
40
41
42
43
44
45
46
47 public class StrokeInfo {
48
49 private static final int ANGLE_E0 = 0;
50
51 private static final double ANGLE_N_NE = 292.5;
52
53 private static final double ANGLE_NW_N = 247.5;
54
55 private static final double ANGLE_W_NW = 202.5;
56
57 private static final double ANGLE_SW_W = 157.5;
58
59 private static final double ANGLE_S_SW = 112.5;
60
61 private static final double ANGLE_SE_S = 67.5;
62
63 private static final double ANGLE_E_SE = 22.5;
64
65 private static final int ANGLE_E = 360;
66
67 private static final double ANGLE_NE_E = 337.5;
68
69 private List<Direction> directions;
70
71 private Note note;
72
73 private Statistics statistics;
74
75
76 public StrokeInfo(Note note) {
77 this.note = GestureTool.getCharacteristicNote((Note)note.clone(), 3, 10);
78 directions = new ArrayList<Direction>();
79 final List<Point> points = this.note.getPoints();
80
81 for (int i = 1; i < points.size(); i++) {
82 final double angle = GestureTool.getAngle(points.get(i - 1), points
83 .get(i));
84
85 if (!Double.isNaN(angle)) {
86 directions.add(getDirection(angle));
87 }
88
89 }
90
91 this.statistics = new Statistics(directions, this.note);
92 }
93
94
95
96
97
98
99
100 public String getString() {
101 final StringBuilder sb = new StringBuilder();
102
103 for (final Direction d : directions) {
104 sb.append(d.name() + Constant.COMMA);
105 }
106
107 return sb.toString();
108 }
109
110
111
112
113
114
115
116
117 private Direction getDirection(double angle) {
118 if ((angle >= ANGLE_NE_E && angle < ANGLE_E)
119 || (angle >= ANGLE_E0 && angle < ANGLE_E_SE)) {
120 return Direction.E;
121 }
122 else if (angle >= ANGLE_E_SE && angle < ANGLE_SE_S) {
123 return Direction.SE;
124 }
125 else if (angle >= ANGLE_SE_S && angle < ANGLE_S_SW) {
126 return Direction.S;
127 }
128 else if (angle >= ANGLE_S_SW && angle < ANGLE_SW_W) {
129 return Direction.SW;
130 }
131 else if (angle >= ANGLE_SW_W && angle < ANGLE_W_NW) {
132 return Direction.W;
133 }
134 else if (angle >= ANGLE_W_NW && angle < ANGLE_NW_N) {
135 return Direction.NW;
136 }
137 else if (angle >= ANGLE_NW_N && angle < ANGLE_N_NE) {
138 return Direction.N;
139 }
140 else if (angle >= ANGLE_N_NE && angle < ANGLE_NE_E) {
141 return Direction.NE;
142 }
143 throw new IllegalStateException();
144 }
145
146
147
148
149
150
151
152 public Statistics getStatistics() {
153 return statistics;
154 }
155
156
157 @Override
158 public String toString() {
159 final StringBuilder sb = new StringBuilder();
160 sb.append(Constant.OPEN_ANGULAR_BRACKET);
161
162 for (final Direction d : directions) {
163 sb.append(d.name() + Constant.COMMA);
164 }
165
166 sb.append(Constant.CLOSE_ANGULAR_BRACKET);
167 return sb.toString();
168 }
169
170 }