-
Notifications
You must be signed in to change notification settings - Fork 5
/
Diagram.elm
2248 lines (2076 loc) · 56.6 KB
/
Diagram.elm
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module Diagram exposing (..)
import String
import Svg exposing (Svg,svg,path,line,marker,defs,pattern,rect)
import Svg.Attributes exposing (
x,y,x1,y1,x2,y2,height,
width,d,markerHeight,
markerWidth,orient,markerEnd,
markerUnits,refX,refY,viewBox,id,
stroke,strokeWidth,fill,strokeLinecap,
strokeLinejoin,strokeDasharray,
patternUnits
)
import Char
import Color
import Array exposing (Array)
fontSize = 14.0
lineWidth = 1.0
textWidth = 8.0
textHeight = 16.0
arcRadius = textWidth / 2
color = Color.rgb 0 0 0
optimizeSvg = False
density = Expanded
gridOn = False
type alias Model =
{rows: Int
,columns: Int
,lines: Array (Array Char)
}
init: String -> Model
init str =
let
lines = String.lines str
max =
List.map
(\line ->
String.length line
)lines
|> List.maximum
lineArr = Array.fromList lines
lineChar =
Array.map (
\line ->
(String.toList <| String.trimRight line)
|> Array.fromList
) lineArr
in
{rows = Array.length lineChar
,columns = Maybe.withDefault 0 max
,lines = lineChar
}
type Density = Compact | Medium | Expanded
measureX: Int -> Float
measureX x =
toFloat x * textWidth
measureY: Int -> Float
measureY y =
toFloat y * textHeight
type Location
= Top
| Bottom
| Left
| Right
| TopLeft
| TopRight
| BottomLeft
| BottomRight
-- plain simple elements
type Piece
{--
| :
| :
--}
= Vertical
{--
--- ===
--}
| Horizontal
{--
___ ....
--}
| LowHorizontal
{--
/
--}
| SlantRight
{--
\\
--}
| SlantLeft
type Action
= Extend
| Trim
type Outline
= Smooth -- . '
| Sharp -- + *
type Stroke
= Dashed -- : = ...
| Solid -- | - ___
type Component
= Text Char
| Piece Elevation Piece Stroke
| Arrow Location
| Corner Location Outline
| Action Elevation Piece Action Location Chunk
| Curve Location Elevation Chunk
| Junction Elevation (List Location) Outline -- + * . '
type Elevation
= Low
| Mid
| High
type Chunk
= Full
| Half
| Quarter
| Quarter3
type alias Point =
{ x : Float
, y: Float
}
type Path
= Line (Point, Point)
| ArrowLine (Point, Point)
| Arc (Point, Point, Float, Bool)
| DashedLine (Point, Point)
| TextPath (Point, String)
-- corresponding paths for each component
componentPathList: Int -> Int -> List (Component, List Path)
componentPathList x y =
let
-- block start/quarter/mid/quarter3/end x y
tw2 = textWidth / 2
tw4 = textWidth / 4
th2 = textHeight / 2
th4 = textHeight / 4
sx = measureX x
sy = measureY y
qx = measureX x + textWidth / 4
qy = measureY y + textHeight / 4
mx = measureX x + textWidth / 2
my = measureY y + textHeight / 2
q3x = measureX x + textWidth * 3 / 4
q3y = measureY y + textHeight * 3 /4
ex = measureX x + textWidth
ey = measureY y + textHeight
verticalPath = Line (Point mx sy, Point mx ey)
horizontalPath = Line (Point sx my, Point ex my)
slantLeftPath = Line (Point sx sy, Point ex ey)
slantRightPath = Line (Point sx ey, Point ex sy)
in
[
(Piece Mid Horizontal Solid
,[Line (Point sx my, Point ex my)]
)
,
(Piece Mid Horizontal Dashed
,[DashedLine (Point sx my, Point ex my)]
)
,
(Piece Low Horizontal Solid
,[Line (Point sx ey, Point ex ey)]
)
,
(Piece Low Horizontal Dashed
,[DashedLine (Point sx ey, Point ex ey)]
)
,
(Piece Mid Vertical Solid
,[Line (Point mx sy, Point mx ey)]
)
,
(Piece Mid Vertical Dashed
,[DashedLine (Point mx sy, Point mx ey)]
)
,
(Piece Mid SlantLeft Solid
,[Line (Point sx sy, Point ex ey)]
)
,
(Piece Mid SlantRight Solid
,[Line (Point sx ey, Point ex sy)]
)
,
(Arrow Top
,[ArrowLine (Point mx ey, Point mx sy)]
)
,
(Arrow Bottom
,[ArrowLine (Point mx sy, Point mx ey)]
)
,
(Arrow Left
,[ArrowLine (Point ex my, Point mx my)]
)
,
(Arrow Right
,[ArrowLine (Point sx my, Point mx my)]
)
,
(Arrow TopLeft
,[ArrowLine (Point ex ey, Point qx qy)]
)
,(Arrow TopRight
,[ArrowLine (Point sx ey, Point q3x qy)]
)
,
(Arrow BottomLeft
,[ArrowLine (Point ex sy, Point qx q3y)]
)
,
(Arrow BottomRight
,[ArrowLine (Point sx sy, Point q3x q3y)]
)
,
(Junction Mid [Bottom, Right] Sharp
,[Line (Point mx my, Point ex my)
,Line (Point mx my, Point mx ey)
]
)
,
(Junction Mid [Bottom, Left] Sharp
,[Line (Point sx my, Point mx my)
,Line (Point mx my, Point mx ey)
]
)
,
(Junction Mid [Top, Right] Sharp
,[Line (Point mx sy, Point mx my)
,Line (Point mx my, Point ex my)
]
)
,
(Junction Mid [Top, Left] Sharp
,[Line (Point sx my, Point mx my)
,Line (Point mx my, Point mx sy)
]
)
,
(Junction Mid [Top, Bottom, Right] Sharp
,[Line (Point mx sy, Point mx ey)
,Line (Point mx my, Point ex my)
]
)
,
(Junction Mid [Top, Bottom, Left] Sharp
,[Line (Point mx sy, Point mx ey)
,Line (Point sx my, Point mx my)
]
)
,
(Junction Mid [Top, Left, Right] Sharp
,[Line (Point mx sy, Point mx my)
,Line (Point sx my, Point ex my)
]
)
,
(Junction Mid [Left, Right, Bottom] Sharp
,[Line (Point sx my, Point ex my)
,Line (Point mx my, Point mx ey)
]
)
,
(Junction Mid [Right, BottomLeft] Smooth
,[Arc (Point ex my, Point qx q3y, arcRadius * 2, False)
,Line (Point sx ey, Point qx q3y)
]
)
,
(Junction Mid [Left, BottomRight] Smooth
,[Arc (Point q3x q3y, Point sx my, arcRadius * 2, False)
,Line (Point ex ey, Point q3x q3y)
]
)
,
(Junction Mid [Right, TopLeft] Smooth
,[Arc (Point qx qy, Point ex my, arcRadius * 2, False)
,Line (Point sx sy, Point qx qy)
]
)
,
{--
/
-'
--}
(Junction Mid [Left, TopRight] Smooth
,[Arc (Point sx my, Point q3x qy, arcRadius * 2, False)
,Line (Point q3x qy, Point ex sy)
]
)
,
{--
/
'-
--}
(Junction Mid [Right, TopRight] Smooth
,[Arc (Point q3x qy, Point ex my, arcRadius, False)
,Line (Point q3x qy, Point ex sy)
]
)
,
{--
-.
/
--}
(Junction Mid [Left, BottomLeft] Smooth
,[Arc (Point qx q3y, Point sx my, arcRadius, False)
,Line (Point sx ey, Point qx q3y)
]
)
,
{--
\
.
|
--}
(Junction Mid [Bottom, TopLeft] Smooth
,[Line (Point mx ey, Point mx q3y)
,Arc (Point mx q3y, Point qx qy, arcRadius * 4, False)
,Line (Point qx qy, Point sx sy)
]
)
,
{--
|
.
\
--}
(Junction Mid [Top, BottomRight] Smooth
,[Line (Point mx sy, Point mx qy)
,Arc (Point mx qy, Point q3x q3y, arcRadius * 4, False)
,Line (Point q3x q3y, Point ex ey)
]
)
,
(Junction Mid [Top, Left, Bottom, Right] Sharp
,[Line (Point sx my, Point ex my)
,Line (Point mx sy, Point mx ey)
]
)
,(Junction Mid
[Top, Left, Bottom, Right
,TopLeft, TopRight, BottomLeft, BottomRight
] Sharp
,[Line (Point sx my, Point ex my)
,Line (Point mx sy, Point mx ey)
,Line (Point sx sy, Point ex ey)
,Line (Point sx ey, Point ex sy)
]
)
{--
.-
|
--}
,
(Junction Mid [Bottom, Right] Smooth
,[ Arc (Point ex my, Point mx q3y, arcRadius, False)
,Line (Point mx q3y, Point mx ey)
]
)
{--
.-
|
--}
,(Junction Mid [Bottom, Left] Smooth
,[ Arc (Point mx q3y, Point sx my, arcRadius, False)
,Line (Point mx q3y, Point mx ey)
]
)
,
{--
|
'-
--}
(Junction Mid [Top, Right] Smooth
,[ Arc (Point mx qy, Point ex my, arcRadius, False)
,Line (Point mx sy, Point mx qy)
]
)
{--
|
-'
--}
,(Junction Mid [Top, Left] Smooth
,[ Arc (Point sx my, Point mx qy, arcRadius, False)
,Line (Point mx sy, Point mx qy)
]
)
,
{--
|
._
--}
(Junction Low [Top, Right] Smooth
, [Line (Point mx sy, Point mx q3y)
,Arc (Point mx q3y, Point ex ey, arcRadius, False)
]
)
,
{--
|
_.
--}
(Junction Low [Top, Left] Smooth
, [
Arc (Point sx ey, Point mx q3y, arcRadius, False)
,Line (Point mx q3y, Point mx sy)
]
)
,
{--
_
|
--}
(Action Low LowHorizontal Extend Left Half
,[Line (Point ex ey, Point (sx - tw2) ey)
]
)
,
{--
/_
--}
(Action Low LowHorizontal Extend Left Full
,[Line (Point ex ey, Point (sx - textWidth) ey)
]
)
,
{--
_\
--}
(Action Low LowHorizontal Extend Right Full
,[Line (Point sx ey, Point (ex + textWidth) ey)
]
)
,
{--
_
|
--}
(Action Low LowHorizontal Extend Right Half
, [Line (Point sx ey, Point (ex + tw2) ey) ]
)
,
{--
/
.-
/
--}
(Junction Mid [Right, TopRight, BottomLeft] Smooth
,[ Line (Point sx ey, Point ex sy)
,Arc (Point ex my, Point qx q3y, arcRadius * 2, False)
]
)
,
{--
\
.-
\
--}
(Junction Mid [Right, TopLeft, BottomRight] Smooth
, [Line (Point sx sy, Point ex ey)
,Line (Point ex my, Point q3x my)
,Arc (Point qx qy, Point q3x my, arcRadius * 2, False)
]
)
,
{--
|
.
/|
--}
(Junction Mid [Top, Bottom, BottomLeft] Smooth
,[Line (Point mx sy, Point mx ey)
,Line (Point sx ey, Point qx q3y)
,Arc (Point qx q3y, Point mx qy, arcRadius * 4, False)
]
)
,
{--
/
.
|
--}
(Junction Mid [Bottom, TopRight] Smooth
, [Line (Point ex sy, Point q3x qy)
,Arc (Point q3x qy, Point mx q3y, arcRadius * 4, False)
,Line (Point mx ey, Point mx q3y)
]
)
,
{--
|
.
/
--}
(Junction Mid [Top, BottomLeft] Smooth
, [
Line (Point sx ey, Point qx q3y)
,Arc (Point qx q3y, Point mx qy, arcRadius * 4, False)
,Line (Point mx sy, Point mx qy)
]
)
,
{--
\
.
/
--}
(Junction Mid [TopLeft, BottomLeft] Smooth
, [Line (Point sx sy, Point qx qy)
,Arc (Point qx q3y, Point qx qy, arcRadius * 2, False)
,Line (Point sx ey, Point qx q3y)
]
)
,
{--
/
.
\
--}
(Junction Mid [TopRight, BottomRight] Smooth
, [ Line (Point ex sy, Point q3x qy)
, Arc (Point q3x qy, Point q3x q3y, arcRadius * 2, False)
, Line (Point q3x q3y, Point ex ey)
]
)
,
{--
/
(
\
--}
(Curve Left Mid Quarter
,[Arc (Point ex sy, Point ex ey, arcRadius * 4, False)]
)
,
{--
\
)
/
--}
(Curve Right Mid Quarter
, [Arc (Point sx ey, Point sx sy, arcRadius * 4, False)]
)
,
{--
.-.
--}
(Curve Top Mid Half
, [Arc (Point ex my, Point sx my, arcRadius * 4, False)
]
)
,
{--
.
(
'
--}
(Curve Left Mid Half
, [Arc (Point q3x sy, Point q3x ey, arcRadius * 4, False)
]
)
,
{--
.
(
'
--}
(Curve Right Mid Half
, [Arc (Point qx sy, Point qx ey, arcRadius * 4, True)
]
)
,
{--
'-'
--}
(Curve Bottom Mid Half
, [Arc (Point sx my, Point ex my, arcRadius * 4, False)
]
)
,
{---
.-
(
--}
(Curve TopLeft Mid Half
,[Arc (Point ex my, Point (sx-tw4) ey, arcRadius * 4, False)]
)
,
{---
-.
)
--}
(Curve TopRight Mid Half
,[Arc (Point sx my, Point (ex+tw4) ey, arcRadius * 4, True)]
)
,
{---
(
'-
--}
(Curve BottomLeft Mid Half
, [Arc (Point (sx-tw4) sy, Point ex my, arcRadius * 4, False)
]
)
,
{---
)
-'
--}
(Curve BottomRight Mid Half
, [Arc (Point sx my, Point (ex+tw4) sy, arcRadius * 4, False)
]
)
,
{--
\|/ \|/ \|/
+ * .
/|\ /|\ /|\
--}
(Junction Mid [Top, Bottom, TopLeft, TopRight, BottomLeft, BottomRight] Sharp
,[verticalPath
,slantLeftPath
,slantRightPath
]
)
]
--check if the 3 points lie on the same line
collinear: Point -> Point -> Point -> Bool
collinear p1 p2 p3 =
let
ax = p1.x
ay = p1.y
bx = p2.x
by = p2.y
cx = p3.x
cy = p3.y
in
ax * (by - cy) + bx * (cy - ay) + cx * (ay - by) == 0
-- simply check is path1 end == path2 start
canConcat: Path -> Path -> Bool
canConcat path1 path2 =
case path1 of
Line (s, e) ->
case path2 of
Line (s2, e2) ->
e == s2
Arc (s2, e2, r2, sweep) ->
e == s2
_ ->
False
Arc (s, e, r, sweep) ->
case path2 of
Line (s2, e2) ->
e == s2
Arc (s2, e2, r2, sweep) ->
e == s2
_ ->
False
DashedLine (s, e) ->
case path2 of
DashedLine (s2, e2) ->
e == s2
_ ->
False
ArrowLine (s, e) ->
False
TextPath (s, string) ->
False
-- only lines can eat another line
-- can eat if path1 ends = path2 start and the lie on the same line
-- returns a new Path with path1 start and path2 end
eat: Path -> Path -> Maybe Path
eat path1 path2 =
case path1 of
Line (s, e) ->
case path2 of
Line (s2, e2) ->
if e == s2 && collinear s e e2 then
Just <| Line (s, e2)
else
Nothing
_ ->
Nothing
DashedLine (s, e) ->
case path2 of
DashedLine (s2, e2) ->
if e == s2 && collinear s e e2 then
Just <| DashedLine (s, e2)
else
Nothing
_ ->
Nothing
_ ->
Nothing
canReduce: (Int, Int) -> (Int, Int) -> Model -> Bool
canReduce (x1, y1) (x2, y2) model =
case tryReduce (x1, y1) (x2, y2) model of
Just can ->
True
Nothing ->
False
--arrow lines can not b reduce
isReduceable: Maybe Component -> Bool
isReduceable comp =
case comp of
Just comp ->
case comp of
Arrow _ ->
False
_ ->
True
Nothing ->
False
tryReduce: (Int, Int) -> (Int, Int) -> Model -> Maybe Path
tryReduce (x1, y1) (x2, y2) model =
let
comp1 = matchComponent x1 y1 model
comp2 = matchComponent x2 y2 model
in
-- can not reduce arrow lines
if isReduceable comp2 then
case comp1 of
Just comp1 ->
case comp2 of
Just comp2 ->
let
path1 = firstPathOnly x1 y1 comp1 model
path2 = firstPathOnly x2 y2 comp2 model
in
case path1 of
Just path1 ->
case path2 of
Just path2 ->
reduce path1 path2
Nothing ->
Nothing
Nothing ->
Nothing
Nothing ->
Nothing
Nothing ->
Nothing
else
Nothing
-- eat with trial on which arrangement
reduce: Path -> Path -> Maybe Path
reduce path1 path2 =
case eat path1 path2 of
Just path12 ->
Just path12
Nothing ->
case eat path1 (reversePath path2) of
Just path1Rev2 ->
Just path1Rev2
Nothing ->
Nothing
-- if has only 1 path return it
firstPathOnly: Int -> Int -> Component -> Model -> Maybe Path
firstPathOnly x y comp model =
let paths = getComponentPaths x y comp model
in
if List.length paths == 1 then
List.head paths
else
Nothing
-- if this component is isEdible, then don't mind plotting it
-- since it something would eat it along the way
-- if it is in between component that could eat it
-- deal only with simple elements
isEdible: Int -> Int -> Model -> Bool
isEdible x y model =
let
center = (x,y)
top = (x, y-1)
bottom = (x, y+1)
left = (x-1, y)
topLeft = (x-1, y-1)
bottomLeft = (x-1, y+1)
match =
[canReduce top center model
,canReduce left center model
,canReduce topLeft center model
,canReduce bottomLeft center model
]
in
List.any (\a -> a) match
vertical = ['|']
verticalDashed = [':']
horizontal = ['-']
horizontalDashed = ['=']
lowHorizontal = ['_']
intersection = ['+']
asterisk = ['*']
round = ['.','\'']
roundLow = ['.']
roundHigh= ['\'']
arrowRight = ['>']
arrowDown = ['V','v']
arrowLeft = ['<']
arrowUp = ['^','î']
slantRight = ['/']
slantLeft = ['\\']
openCurve = ['(']
closeCurve = [')']
get: Int -> Int -> Model -> Maybe Char
get x y model =
let
row = y
line: Maybe (Array Char)
line = Array.get y model.lines
char: Maybe Char
char =
case line of
Just l ->
Array.get x l
Nothing ->
Nothing
in
char
isOpenCurve char =
List.member char openCurve
--close parenthesis
isCloseCurve char =
List.member char closeCurve
isVertical char =
List.member char vertical
isVerticalDashed char =
List.member char verticalDashed
isHorizontalDashed char =
List.member char horizontalDashed
isAlphaNumeric char =
Char.isDigit char || Char.isUpper char || Char.isLower char
isHorizontal char =
List.member char horizontal
isLowHorizontal char =
List.member char lowHorizontal
isIntersection char =
List.member char intersection
isAsterisk char =
List.member char asterisk
isLine char =
isVertical char || isHorizontal char || isLowHorizontal char
isRound char =
List.member char round
isRoundLow char =
List.member char roundLow
isRoundHigh char =
List.member char roundHigh
isChar: Maybe Char -> (Char -> Bool) -> Bool
isChar char check =
case char of
Just char ->
check char
Nothing ->
False
isArrowRight char =
List.member char arrowRight
isArrowLeft char =
List.member char arrowLeft
isArrowDown char =
List.member char arrowDown
isArrowUp char =
List.member char arrowUp
isSlantRight char =
List.member char slantRight
isSlantLeft char =
List.member char slantLeft
leftOf x y model =
get (x-1) y model
rightOf x y model =
get (x+1) y model
topOf x y model =
get x (y-1) model
bottomOf x y model =
get x (y+1) model
topLeftOf x y model =
get (x-1) (y-1) model
topRightOf x y model =
get (x+1) (y-1) model
bottomLeftOf x y model =
get (x-1) (y+1) model
bottomRightOf x y model =
get (x+1) (y+1) model
isNeighbor neighbor check =
case neighbor of
Just neighbor ->
check neighbor
Nothing ->
False
-- conditions to match and the corresponding component
-- arrange from simple to most complex
-- low priority to higher priority, the list is reveres before using for matching
componentMatchList: Int -> Int -> Model -> List (Bool, Component)
componentMatchList x y model =
let
char = get x y model
top = topOf x y model
bottom = bottomOf x y model