| •1 |
|
| 2 |
|
| 3 |
|
| •4 |
|
| 5 |
|
| •6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| •11 |
|
| 12 |
|
| 13 |
|
| •14 |
|
| 15 |
|
| •16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
package org.stathissideris.ascii2image.text; |
| 21 |
|
| 22 |
import java.util.ArrayList; |
| 23 |
import java.util.Iterator; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public class GridPatternGroup extends ArrayList<GridPattern> { |
| 30 |
public boolean areAllMatchedBy(TextGrid grid){ |
| 31 |
Iterator<GridPattern> it = iterator(); |
| 32 |
while (it.hasNext()) { |
| 33 |
GridPattern pattern = it.next(); |
| 34 |
if(!pattern.isMatchedBy(grid)) return false; |
| 35 |
} |
| 36 |
return true; |
| 37 |
} |
| 38 |
|
| 39 |
public boolean isAnyMatchedBy(TextGrid grid){ |
| 40 |
Iterator<GridPattern> it = iterator(); |
| 41 |
while (it.hasNext()) { |
| 42 |
GridPattern pattern = it.next(); |
| 43 |
if(pattern.isMatchedBy(grid)) return true; |
| 44 |
} |
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
public void add(GridPattern... patterns) { |
| 50 |
for(GridPattern p : patterns) add(p); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public static final GridPatternGroup cornerCriteria = new GridPatternGroup(); |
| 56 |
public static final GridPatternGroup normalCornerCriteria = new GridPatternGroup(); |
| 57 |
public static final GridPatternGroup roundCornerCriteria = new GridPatternGroup(); |
| 58 |
|
| 59 |
public static final GridPatternGroup corner1Criteria = new GridPatternGroup(); |
| 60 |
public static final GridPatternGroup corner2Criteria = new GridPatternGroup(); |
| 61 |
public static final GridPatternGroup corner3Criteria = new GridPatternGroup(); |
| 62 |
public static final GridPatternGroup corner4Criteria = new GridPatternGroup(); |
| 63 |
|
| 64 |
|
| 65 |
public static final GridPatternGroup normalCorner1Criteria = new GridPatternGroup(); |
| 66 |
public static final GridPatternGroup normalCorner2Criteria = new GridPatternGroup(); |
| 67 |
public static final GridPatternGroup normalCorner3Criteria = new GridPatternGroup(); |
| 68 |
public static final GridPatternGroup normalCorner4Criteria = new GridPatternGroup(); |
| 69 |
|
| 70 |
public static final GridPatternGroup roundCorner1Criteria = new GridPatternGroup(); |
| 71 |
public static final GridPatternGroup roundCorner2Criteria = new GridPatternGroup(); |
| 72 |
public static final GridPatternGroup roundCorner3Criteria = new GridPatternGroup(); |
| 73 |
public static final GridPatternGroup roundCorner4Criteria = new GridPatternGroup(); |
| 74 |
|
| 75 |
public static final GridPatternGroup intersectionCriteria = new GridPatternGroup(); |
| 76 |
public static final GridPatternGroup TCriteria = new GridPatternGroup(); |
| 77 |
public static final GridPatternGroup inverseTCriteria = new GridPatternGroup(); |
| 78 |
public static final GridPatternGroup KCriteria = new GridPatternGroup(); |
| 79 |
public static final GridPatternGroup inverseKCriteria = new GridPatternGroup(); |
| 80 |
|
| 81 |
public static final GridPatternGroup crossCriteria = new GridPatternGroup(); |
| 82 |
|
| 83 |
public static final GridPatternGroup stubCriteria = new GridPatternGroup(); |
| 84 |
public static final GridPatternGroup verticalLinesEndCriteria = new GridPatternGroup(); |
| 85 |
public static final GridPatternGroup horizontalLinesEndCriteria = new GridPatternGroup(); |
| 86 |
public static final GridPatternGroup linesEndCriteria = new GridPatternGroup(); |
| 87 |
|
| 88 |
public static final GridPatternGroup crossOnLineCriteria = new GridPatternGroup(); |
| 89 |
public static final GridPatternGroup horizontalCrossOnLineCriteria = new GridPatternGroup(); |
| 90 |
public static final GridPatternGroup verticalCrossOnLineCriteria = new GridPatternGroup(); |
| 91 |
|
| 92 |
public static final GridPatternGroup starOnLineCriteria = new GridPatternGroup(); |
| 93 |
public static final GridPatternGroup horizontalStarOnLineCriteria = new GridPatternGroup(); |
| 94 |
public static final GridPatternGroup verticalStarOnLineCriteria = new GridPatternGroup(); |
| 95 |
|
| 96 |
public static final GridPatternGroup loneDiagonalCriteria = new GridPatternGroup(); |
| 97 |
|
| 98 |
static { |
| 99 |
GridPattern crossPattern1 = new GridPattern( |
| 100 |
".6.", |
| 101 |
"4+8", |
| 102 |
".2." |
| 103 |
); |
| 104 |
crossCriteria.add(crossPattern1); |
| 105 |
|
| 106 |
GridPattern KPattern1 = new GridPattern( |
| 107 |
".6.", |
| 108 |
"%4+8", |
| 109 |
".2." |
| 110 |
); |
| 111 |
KCriteria.add(KPattern1); |
| 112 |
|
| 113 |
GridPattern inverseKPattern1 = new GridPattern( |
| 114 |
".6.", |
| 115 |
"4+%8", |
| 116 |
".2." |
| 117 |
); |
| 118 |
inverseKCriteria.add(inverseKPattern1); |
| 119 |
|
| 120 |
GridPattern TPattern1 = new GridPattern( |
| 121 |
".%6.", |
| 122 |
"4+8", |
| 123 |
".2." |
| 124 |
); |
| 125 |
TCriteria.add(TPattern1); |
| 126 |
|
| 127 |
GridPattern inverseTPattern1 = new GridPattern( |
| 128 |
".6.", |
| 129 |
"4+8", |
| 130 |
".%2." |
| 131 |
); |
| 132 |
inverseTCriteria.add(inverseTPattern1); |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
GridPattern normalCorner1Pattern1 = new GridPattern( |
| 138 |
".[.", |
| 139 |
"~+(", |
| 140 |
".^." |
| 141 |
); |
| 142 |
normalCorner1Criteria.add(normalCorner1Pattern1); |
| 143 |
|
| 144 |
GridPattern normalCorner2Pattern1 = new GridPattern( |
| 145 |
".[.", |
| 146 |
"(+~", |
| 147 |
".^." |
| 148 |
); |
| 149 |
normalCorner2Criteria.add(normalCorner2Pattern1); |
| 150 |
|
| 151 |
GridPattern normalCorner3Pattern1 = new GridPattern( |
| 152 |
".^.", |
| 153 |
"(+~", |
| 154 |
".[." |
| 155 |
); |
| 156 |
normalCorner3Criteria.add(normalCorner3Pattern1); |
| 157 |
|
| 158 |
GridPattern normalCorner4Pattern1 = new GridPattern( |
| 159 |
".^.", |
| 160 |
"~+(", |
| 161 |
".[." |
| 162 |
); |
| 163 |
normalCorner4Criteria.add(normalCorner4Pattern1); |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
GridPattern roundCorner1Pattern1 = new GridPattern( |
| 168 |
".[.", |
| 169 |
"~/4", |
| 170 |
".2." |
| 171 |
); |
| 172 |
roundCorner1Criteria.add(roundCorner1Pattern1); |
| 173 |
|
| 174 |
GridPattern roundCorner2Pattern1 = new GridPattern( |
| 175 |
".[.", |
| 176 |
"4\\~", |
| 177 |
".2." |
| 178 |
); |
| 179 |
roundCorner2Criteria.add(roundCorner2Pattern1); |
| 180 |
|
| 181 |
GridPattern roundCorner3Pattern1 = new GridPattern( |
| 182 |
".6.", |
| 183 |
"4/~", |
| 184 |
".[." |
| 185 |
); |
| 186 |
roundCorner3Criteria.add(roundCorner3Pattern1); |
| 187 |
|
| 188 |
GridPattern roundCorner4Pattern1 = new GridPattern( |
| 189 |
".6.", |
| 190 |
"~\\8", |
| 191 |
".[." |
| 192 |
); |
| 193 |
roundCorner4Criteria.add(roundCorner4Pattern1); |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
GridPattern stubPattern1 = new GridPattern( |
| 198 |
"!^!", |
| 199 |
"!+!", |
| 200 |
".!." |
| 201 |
); |
| 202 |
stubCriteria.add(stubPattern1); |
| 203 |
|
| 204 |
GridPattern stubPattern2 = new GridPattern( |
| 205 |
"!^!", |
| 206 |
"!+!", |
| 207 |
".-." |
| 208 |
); |
| 209 |
stubCriteria.add(stubPattern2); |
| 210 |
|
| 211 |
GridPattern stubPattern3 = new GridPattern( |
| 212 |
"!!.", |
| 213 |
"(+!", |
| 214 |
"!!." |
| 215 |
); |
| 216 |
stubCriteria.add(stubPattern3); |
| 217 |
|
| 218 |
GridPattern stubPattern4 = new GridPattern( |
| 219 |
"!!.", |
| 220 |
"(+|", |
| 221 |
"!!." |
| 222 |
); |
| 223 |
stubCriteria.add(stubPattern4); |
| 224 |
|
| 225 |
GridPattern stubPattern5 = new GridPattern( |
| 226 |
".!.", |
| 227 |
"!+!", |
| 228 |
"!^!" |
| 229 |
); |
| 230 |
stubCriteria.add(stubPattern5); |
| 231 |
|
| 232 |
GridPattern stubPattern6 = new GridPattern( |
| 233 |
".-.", |
| 234 |
"!+!", |
| 235 |
"!^!" |
| 236 |
); |
| 237 |
stubCriteria.add(stubPattern6); |
| 238 |
|
| 239 |
GridPattern stubPattern7 = new GridPattern( |
| 240 |
".!!", |
| 241 |
"!+(", |
| 242 |
".!!" |
| 243 |
); |
| 244 |
stubCriteria.add(stubPattern7); |
| 245 |
|
| 246 |
GridPattern stubPattern8 = new GridPattern( |
| 247 |
".!!", |
| 248 |
"|+(", |
| 249 |
".!!" |
| 250 |
); |
| 251 |
stubCriteria.add(stubPattern8); |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
GridPattern verticalLinesEndPattern1 = new GridPattern( |
| 256 |
".^.", |
| 257 |
".|.", |
| 258 |
".!." |
| 259 |
); |
| 260 |
verticalLinesEndCriteria.add(verticalLinesEndPattern1); |
| 261 |
|
| 262 |
GridPattern verticalLinesEndPattern2 = new GridPattern( |
| 263 |
".^.", |
| 264 |
".|.", |
| 265 |
".-." |
| 266 |
); |
| 267 |
verticalLinesEndCriteria.add(verticalLinesEndPattern2); |
| 268 |
|
| 269 |
GridPattern horizontalLinesEndPattern3 = new GridPattern( |
| 270 |
"...", |
| 271 |
"(-!", |
| 272 |
"..." |
| 273 |
); |
| 274 |
horizontalLinesEndCriteria.add(horizontalLinesEndPattern3); |
| 275 |
|
| 276 |
GridPattern horizontalLinesEndPattern4 = new GridPattern( |
| 277 |
"...", |
| 278 |
"(-|", |
| 279 |
"..." |
| 280 |
); |
| 281 |
horizontalLinesEndCriteria.add(horizontalLinesEndPattern4); |
| 282 |
|
| 283 |
GridPattern verticalLinesEndPattern5 = new GridPattern( |
| 284 |
".!.", |
| 285 |
".|.", |
| 286 |
".^." |
| 287 |
); |
| 288 |
verticalLinesEndCriteria.add(verticalLinesEndPattern5); |
| 289 |
|
| 290 |
GridPattern verticalLinesEndPattern6 = new GridPattern( |
| 291 |
".-.", |
| 292 |
".|.", |
| 293 |
".^." |
| 294 |
); |
| 295 |
verticalLinesEndCriteria.add(verticalLinesEndPattern6); |
| 296 |
|
| 297 |
GridPattern horizontalLinesEndPattern7 = new GridPattern( |
| 298 |
"...", |
| 299 |
"!-(", |
| 300 |
"..." |
| 301 |
); |
| 302 |
horizontalLinesEndCriteria.add(horizontalLinesEndPattern7); |
| 303 |
|
| 304 |
GridPattern horizontalLinesEndPattern8 = new GridPattern( |
| 305 |
"...", |
| 306 |
"|-(", |
| 307 |
"..." |
| 308 |
); |
| 309 |
horizontalLinesEndCriteria.add(horizontalLinesEndPattern8); |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
GridPattern horizontalCrossOnLinePattern1 = new GridPattern( |
| 316 |
"...", |
| 317 |
"(+(", |
| 318 |
"..." |
| 319 |
); |
| 320 |
horizontalCrossOnLineCriteria.add(horizontalCrossOnLinePattern1); |
| 321 |
|
| 322 |
GridPattern verticalCrossOnLinePattern1 = new GridPattern( |
| 323 |
".^.", |
| 324 |
".+.", |
| 325 |
".^." |
| 326 |
); |
| 327 |
verticalCrossOnLineCriteria.add(verticalCrossOnLinePattern1); |
| 328 |
|
| 329 |
|
| 330 |
GridPattern horizontalStarOnLinePattern1 = new GridPattern( |
| 331 |
"...", |
| 332 |
"(*(", |
| 333 |
"..." |
| 334 |
); |
| 335 |
horizontalStarOnLineCriteria.add(horizontalStarOnLinePattern1); |
| 336 |
|
| 337 |
GridPattern horizontalStarOnLinePattern2 = new GridPattern( |
| 338 |
"...", |
| 339 |
"!*(", |
| 340 |
"..." |
| 341 |
); |
| 342 |
horizontalStarOnLineCriteria.add(horizontalStarOnLinePattern2); |
| 343 |
|
| 344 |
GridPattern horizontalStarOnLinePattern3 = new GridPattern( |
| 345 |
"...", |
| 346 |
"(*!", |
| 347 |
"..." |
| 348 |
); |
| 349 |
horizontalStarOnLineCriteria.add(horizontalStarOnLinePattern3); |
| 350 |
|
| 351 |
|
| 352 |
GridPattern verticalStarOnLinePattern1 = new GridPattern( |
| 353 |
".^.", |
| 354 |
".*.", |
| 355 |
".^." |
| 356 |
); |
| 357 |
verticalStarOnLineCriteria.add(verticalStarOnLinePattern1); |
| 358 |
|
| 359 |
GridPattern verticalStarOnLinePattern2 = new GridPattern( |
| 360 |
".!.", |
| 361 |
".*.", |
| 362 |
".^." |
| 363 |
); |
| 364 |
verticalStarOnLineCriteria.add(verticalStarOnLinePattern2); |
| 365 |
|
| 366 |
GridPattern verticalStarOnLinePattern3 = new GridPattern( |
| 367 |
".^.", |
| 368 |
".*.", |
| 369 |
".!." |
| 370 |
); |
| 371 |
verticalStarOnLineCriteria.add(verticalStarOnLinePattern3); |
| 372 |
|
| 373 |
|
| 374 |
GridPattern loneDiagonalPattern1 = new GridPattern( |
| 375 |
".%6%7", |
| 376 |
"%4/%8", |
| 377 |
"%3%2." |
| 378 |
); |
| 379 |
loneDiagonalCriteria.add(loneDiagonalPattern1); |
| 380 |
|
| 381 |
GridPattern loneDiagonalPattern2 = new GridPattern( |
| 382 |
"%1%6.", |
| 383 |
"%4\\%8", |
| 384 |
".%2%5" |
| 385 |
); |
| 386 |
loneDiagonalCriteria.add(loneDiagonalPattern2); |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
intersectionCriteria.addAll(crossCriteria); |
| 392 |
intersectionCriteria.addAll(KCriteria); |
| 393 |
intersectionCriteria.addAll(TCriteria); |
| 394 |
intersectionCriteria.addAll(inverseKCriteria); |
| 395 |
intersectionCriteria.addAll(inverseTCriteria); |
| 396 |
|
| 397 |
normalCornerCriteria.addAll(normalCorner1Criteria); |
| 398 |
normalCornerCriteria.addAll(normalCorner2Criteria); |
| 399 |
normalCornerCriteria.addAll(normalCorner3Criteria); |
| 400 |
normalCornerCriteria.addAll(normalCorner4Criteria); |
| 401 |
|
| 402 |
roundCornerCriteria.addAll(roundCorner1Criteria); |
| 403 |
roundCornerCriteria.addAll(roundCorner2Criteria); |
| 404 |
roundCornerCriteria.addAll(roundCorner3Criteria); |
| 405 |
roundCornerCriteria.addAll(roundCorner4Criteria); |
| 406 |
|
| 407 |
corner1Criteria.addAll(normalCorner1Criteria); |
| 408 |
corner1Criteria.addAll(roundCorner1Criteria); |
| 409 |
|
| 410 |
corner2Criteria.addAll(normalCorner2Criteria); |
| 411 |
corner2Criteria.addAll(roundCorner2Criteria); |
| 412 |
|
| 413 |
corner3Criteria.addAll(normalCorner3Criteria); |
| 414 |
corner3Criteria.addAll(roundCorner3Criteria); |
| 415 |
|
| 416 |
corner4Criteria.addAll(normalCorner4Criteria); |
| 417 |
corner4Criteria.addAll(roundCorner4Criteria); |
| 418 |
|
| 419 |
cornerCriteria.addAll(normalCornerCriteria); |
| 420 |
cornerCriteria.addAll(roundCornerCriteria); |
| 421 |
|
| 422 |
crossOnLineCriteria.addAll(horizontalCrossOnLineCriteria); |
| 423 |
crossOnLineCriteria.addAll(verticalCrossOnLineCriteria); |
| 424 |
|
| 425 |
starOnLineCriteria.addAll(horizontalStarOnLineCriteria); |
| 426 |
starOnLineCriteria.addAll(verticalStarOnLineCriteria); |
| 427 |
|
| 428 |
|
| 429 |
linesEndCriteria.addAll(horizontalLinesEndCriteria); |
| 430 |
linesEndCriteria.addAll(verticalLinesEndCriteria); |
| 431 |
linesEndCriteria.addAll(stubCriteria); |
| 432 |
|
| 433 |
} |
| 434 |
} |