-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLIC.java
More file actions
284 lines (238 loc) · 9.98 KB
/
LIC.java
File metadata and controls
284 lines (238 loc) · 9.98 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
import java.util.stream.IntStream;
public class LIC {
public static boolean LIC0(int numPoints, Point[] points, Parameters p) throws IllegalArgumentException {
if (p.LENGTH1 < 0 || numPoints < 2) {
throw new IllegalArgumentException();
}
for (int i = 0; i < numPoints - 1; i++) {
if (Point.distance(points[i], points[i + 1]) > p.LENGTH1)
return true;
}
return false;
}
public static boolean LIC1(int numPoints, Point[] points, Parameters p) throws IllegalArgumentException {
if (p.RADIUS1 < 0) {
throw new IllegalArgumentException();
}
if (numPoints < 3) return false;
for (int i = 0; i < numPoints - 2; i++) {
if (Point.circleRadius(points[i], points[i + 1], points[i + 2]) > p.RADIUS1)
return true;
}
return false;
}
public static boolean LIC2(int numPoints, Point[] points, Parameters p) {
double PI = 3.14159;
if (!(0 <= p.EPSILON && p.EPSILON < PI)) {
throw new IllegalArgumentException();
}
if (numPoints < 3) {
throw new IllegalArgumentException();
}
for (int i = 0; i < numPoints - 2; i++) {
Point p1 = points[i];
Point p2 = points[i + 1];
Point p3 = points[i + 2];
if (!((p1.x == p2.x && p1.y == p2.y) || (p3.x == p2.x && p3.y == p2.y))) {
double angle = Point.angle(p1, p2, p3);
if (angle < PI - p.EPSILON || angle > PI + p.EPSILON) {
return true;
}
}
}
return false;
}
public static boolean LIC3(int numPoints, Point[] points, Parameters p) {
if (p.AREA1 < 0) return false;
if(numPoints == 2) return false;
for (int i = 0; i < numPoints - 2; i++){
if(Point.triangleArea(points[i], points[i+1], points[i+2]) > p.AREA1){
return true;
}
}
return false;
}
public static boolean LIC4(int numPoints, Point[] points, Parameters p) {
if (p.Q_PTS > numPoints || p.Q_PTS < 2) {
throw new IllegalArgumentException();
}
if (p.QUADS < 1 || p.QUADS > 3) {
throw new IllegalArgumentException();
}
for (int i = 0; i <= numPoints - p.Q_PTS; i++) {
// i in range [0,numPoints-p.Q_PTS]
int[] quadsVisited = new int[]{0, 0, 0, 0};
for (int j = i; j < i + p.Q_PTS; j++) {
// j in range [i, i+p.Q_PTS), so we evaluate precisely Q_PTS
quadsVisited[Point.pointQuadrant(points[j])-1] = 1;
}
if (IntStream.of(quadsVisited).sum() > p.QUADS) {
return true;
}
}
return false;
}
public static boolean LIC5(int numPoints, Point[] points, Parameters p) {
if (numPoints < 2) {
throw new IllegalArgumentException();
}
for (int i = 0; i < numPoints - 1; i++) {
if(points[i+1].x - points[i].x < 0) {
return true;
}
}
return false;
}
public static boolean LIC6(int numPoints, Point[] points, Parameters p) throws IllegalArgumentException {
if (numPoints < 3) return false;
if (p.N_PTS < 3 || p.DIST < 0 || numPoints < p.N_PTS) {
throw new IllegalArgumentException();
}
for (int i = 0; i <= numPoints - p.N_PTS; i++) {
Point p_start = points[i];
Point p_end = points[i + p.N_PTS - 1];
for (int j = i + 1; j <= i + p.N_PTS - 2; j++) {
Point p_mid = points[j];
if (Point.distancePointToLine(p_start, p_end, p_mid) > p.DIST) {
return true;
}
}
}
return false;
}
public static boolean LIC7(int numPoints, Point[] points, Parameters p) throws IllegalArgumentException {
if (p.K_PTS < 1 || p.K_PTS > numPoints - 2) {
throw new IllegalArgumentException();
}
if (p.LENGTH1 < 0) {
throw new IllegalArgumentException();
}
if (numPoints < 3) return false;
for (int i = 0; i < numPoints - p.K_PTS - 1; i++) {
if (Point.distance(points[i], points[i + p.K_PTS + 1]) > p.LENGTH1)
return true;
}
return false;
}
public static boolean LIC8(int numPoints, Point[] points, Parameters p) {
if (p.A_PTS < 1 || p.B_PTS < 1 || p.A_PTS+p.B_PTS > (numPoints-3) || 0>p.RADIUS1){
throw new IllegalArgumentException();
}
if (numPoints < 5){
return false;
}
for (int i = 0; i + p.A_PTS+p.B_PTS < numPoints-2; i++){
Point p1 = points[i];
Point p2 = points[i+p.A_PTS+1];
Point p3 = points[i+p.A_PTS+p.B_PTS+2];
if (Point.circleRadius(p1, p2, p3) > p.RADIUS1){
return true;
}
}
return false;
}
public static boolean LIC9(int numPoints, Point[] points, Parameters p){
if(numPoints < 5) return false;
if(p.C_PTS < 1 || p.D_PTS < 1) return false;
if(p.C_PTS + p.D_PTS > numPoints - 3) return false;
if(p.EPSILON < 0 || p.EPSILON >= Math.PI) return false;
for(int i = 0; i + p.C_PTS + p.D_PTS + 2 < numPoints; i++){
Point a = points[i];
Point b = points[i + p.C_PTS + 1];
Point c = points[i + p.C_PTS + p.D_PTS + 2];
/* If either the first point or the last point (or both) coincide with the vertex,
the angle is undefined and the LIC is not satisfied by those three points. */
if((a.x == b.x && a.y == b.y) || (c.x == b.x && c.y == b.y)) continue;
double ang = Point.directedAngle(a, b, c);
if((ang < Math.PI - p.EPSILON) || (ang > Math.PI + p.EPSILON)) return true;
}
return false;
}
public static boolean LIC10(int numPoints, Point[] points, Parameters p) throws IllegalArgumentException {
if (numPoints < 5) return false;
if (p.E_PTS < 1 ||p.F_PTS < 1 || p.E_PTS + p.F_PTS > numPoints - 3 || p.AREA1 < 0) {
throw new IllegalArgumentException();
}
for (int i = 0; i < numPoints - p.F_PTS - p.E_PTS - 2; i ++) {
Point p1 = points[i];
Point p2 = points[i + p.E_PTS + 1];
Point p3 = points[i + p.E_PTS + p.F_PTS + 2];
if (Point.triangleArea(p1, p2, p3) > p.AREA1) {
return true;
}
}
return false;
}
public static boolean LIC11(int numPoints, Point[] points , Parameters p){
if ( 1 > p.G_PTS || p.G_PTS > numPoints-2){
throw new IllegalArgumentException();
}
for (int i = 0; i + p.G_PTS < numPoints-1; i++){
Point p1 = points[i];
Point p2 = points[i+p.G_PTS+1];
if (p2.x - p1.x < 0){
return true;
}
}
return false;
}
public static boolean LIC12(int numPoints, Point[] points , Parameters p){
if(numPoints < 3) return false;
if(p.LENGTH2 < 0) return false;
if(p.LENGTH1 < 0) return false;
if(p.K_PTS < 1 || p.K_PTS > numPoints -2) return false;
boolean condA = false; /* Exists pair with distance > LENGTH1 */
boolean condB = false; /* Exists pair with distance < LENGTH2 */
for(int i = 0; i + p.K_PTS + 1 < numPoints; i++){
double dist = Point.distance(points[i], points[i + p.K_PTS + 1]);
if(dist > p.LENGTH1) condA = true;
if(dist < p.LENGTH2) condB = true;
if(condA && condB) return true;
}
return false;
}
public static boolean LIC13(int numPoints, Point[] points, Parameters p) throws IllegalArgumentException {
if (p.RADIUS2 < 0) {
throw new IllegalArgumentException();
}
if (p.RADIUS1 < 0) {
throw new IllegalArgumentException();
}
if (p.A_PTS < 1 || p.B_PTS < 1 || p.A_PTS + p.B_PTS > numPoints - 3) {
throw new IllegalArgumentException();
}
if (numPoints < 5) return false;
boolean not_contained_flag = false, contained_flag = false;
for (int i = 0; i < numPoints - p.A_PTS - p.B_PTS - 2; i++) {
double radius = Point.circleRadius(points[i], points[i + p.A_PTS + 1], points[i + p.A_PTS + p.B_PTS + 2]);
if (radius > p.RADIUS1) not_contained_flag = true;
if (radius <= p.RADIUS2) contained_flag = true;
if (not_contained_flag && contained_flag) return true;
}
return false;
}
public static boolean LIC14(int numPoints, Point[] points, Parameters p) {
if (numPoints < 5) {
return false;
}
if (p.AREA1 < 0 || p.AREA2 < 0 || p.E_PTS < 1 || p.F_PTS < 1) {
throw new IllegalArgumentException();
}
if (p.E_PTS + p.F_PTS + 3 > numPoints) {
throw new IllegalArgumentException();
}
boolean moreThanArea1 = false;
boolean lessThanArea2 = false;
for (int i = 0; i < numPoints - p.E_PTS - p.F_PTS - 2; i++) {
// i in range [0, numPoints - p.E_PTS - p.F_PTS - 2 - 1]
double triangleArea = Point.triangleArea(points[i], points[i+p.E_PTS+1], points[i+p.E_PTS+1+p.F_PTS+1]);
if (triangleArea > p.AREA1){
moreThanArea1 = true;
}
if (triangleArea < p.AREA2){
lessThanArea2 = true;
}
}
return moreThanArea1 && lessThanArea2;
}
}