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 package org.ximtec.igesture.algorithm.feature;
28
29 import org.sigtec.ink.Note;
30 import org.sigtec.ink.Point;
31 import org.sigtec.ink.Trace;
32
33
34
35
36
37
38
39
40 public class F26 implements Feature {
41
42 private static final int MINIMAL_NUMBER_OF_POINTS = 5;
43
44 public double compute(Note note) throws FeatureException {
45 if (note.getPoints().size() < MINIMAL_NUMBER_OF_POINTS) {
46 throw new FeatureException(FeatureException.NOT_ENOUGH_POINTS);
47 }
48
49 Trace trace = FeatureTool.createTrace(note);
50
51 double m = (trace.getEndPoint().getY() - trace.getStartPoint().getY())
52 / (trace.getEndPoint().getX() - trace.getStartPoint().getX());
53
54 double b = trace.getStartPoint().getY() - trace.getStartPoint().getX()
55 * m;
56
57 int below = 1;
58 int above = 1;
59
60 for (Point point : trace.getPoints()) {
61 if (m * point.getX() + b > point.getY()) {
62 below++;
63 } else {
64 above++;
65 }
66 }
67
68
69 return (double) above / (double) below;
70 }
71
72 public int getMinimalNumberOfPoints() {
73 return MINIMAL_NUMBER_OF_POINTS;
74 }
75
76 }