puzzle-lib 1.3.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +38 -39
- package/build/src/Braille/BrailleCharacter.d.ts +15 -15
- package/build/src/Braille/BrailleCharacter.js +38 -37
- package/build/src/Braille/BrailleCharacter.js.map +1 -1
- package/build/src/Braille/BrailleData.d.ts +6 -6
- package/build/src/Braille/BrailleData.js +65 -64
- package/build/src/Braille/BrailleData.js.map +1 -1
- package/build/src/Braille/BrailleDot.d.ts +9 -9
- package/build/src/Braille/BrailleDot.js +13 -12
- package/build/src/Braille/BrailleDot.js.map +1 -1
- package/build/src/Braille/BrailleEncoding.d.ts +54 -54
- package/build/src/Braille/BrailleEncoding.js +65 -64
- package/build/src/Braille/BrailleEncoding.js.map +1 -1
- package/build/src/Braille/BrailleStream.d.ts +18 -18
- package/build/src/Braille/BrailleStream.js +75 -74
- package/build/src/Braille/BrailleStream.js.map +1 -1
- package/build/src/Cipher/AutoKeyString.d.ts +4 -4
- package/build/src/Cipher/AutoKeyString.js +34 -33
- package/build/src/Cipher/AutoKeyString.js.map +1 -1
- package/build/src/Cipher/CaesarString.d.ts +8 -8
- package/build/src/Cipher/CaesarString.js +31 -30
- package/build/src/Cipher/CaesarString.js.map +1 -1
- package/build/src/Cipher/CaesarUtils.d.ts +13 -13
- package/build/src/Cipher/CaesarUtils.js +57 -56
- package/build/src/Cipher/CaesarUtils.js.map +1 -1
- package/build/src/Cipher/KeyedCipherStringBase.d.ts +12 -12
- package/build/src/Cipher/KeyedCipherStringBase.js +28 -27
- package/build/src/Cipher/KeyedCipherStringBase.js.map +1 -1
- package/build/src/Cipher/VigenereString.d.ts +4 -4
- package/build/src/Cipher/VigenereString.js +21 -20
- package/build/src/Cipher/VigenereString.js.map +1 -1
- package/build/src/Common/CharacterImage.d.ts +6 -6
- package/build/src/Common/CharacterImage.js +10 -9
- package/build/src/Common/CharacterImage.js.map +1 -1
- package/build/src/Common/EncodingCategory.d.ts +8 -8
- package/build/src/Common/EncodingCategory.js +12 -11
- package/build/src/Common/EncodingCategory.js.map +1 -1
- package/build/src/Common/EncodingCharacterBase.d.ts +23 -23
- package/build/src/Common/EncodingCharacterBase.js +52 -51
- package/build/src/Common/EncodingCharacterBase.js.map +1 -1
- package/build/src/Common/EncodingDataBase.d.ts +7 -7
- package/build/src/Common/EncodingDataBase.js +29 -28
- package/build/src/Common/EncodingDataBase.js.map +1 -1
- package/build/src/Common/EncodingEntry.d.ts +8 -8
- package/build/src/Common/EncodingEntry.js +14 -13
- package/build/src/Common/EncodingEntry.js.map +1 -1
- package/build/src/Common/EncodingLookupResult.d.ts +6 -6
- package/build/src/Common/EncodingLookupResult.js +13 -12
- package/build/src/Common/EncodingLookupResult.js.map +1 -1
- package/build/src/Common/Helpers.d.ts +4 -4
- package/build/src/Common/Helpers.js +16 -15
- package/build/src/Common/Helpers.js.map +1 -1
- package/build/src/Common/InlineSvg.d.ts +7 -7
- package/build/src/Common/InlineSvg.js +14 -13
- package/build/src/Common/InlineSvg.js.map +1 -1
- package/build/src/Conversion/CharacterAutoConvert.d.ts +10 -7
- package/build/src/Conversion/CharacterAutoConvert.js +88 -80
- package/build/src/Conversion/CharacterAutoConvert.js.map +1 -1
- package/build/src/Conversion/CharacterConversion.d.ts +8 -8
- package/build/src/Conversion/CharacterConversion.js +50 -49
- package/build/src/Conversion/CharacterConversion.js.map +1 -1
- package/build/src/Conversion/CharacterEncoding.d.ts +9 -8
- package/build/src/Conversion/CharacterEncoding.js +13 -11
- package/build/src/Conversion/CharacterEncoding.js.map +1 -1
- package/build/src/Conversion/CharacterTableEntry.d.ts +10 -10
- package/build/src/Conversion/CharacterTableEntry.js +19 -18
- package/build/src/Conversion/CharacterTableEntry.js.map +1 -1
- package/build/src/Conversion/SignificantFigures.d.ts +7 -7
- package/build/src/Conversion/SignificantFigures.js +50 -49
- package/build/src/Conversion/SignificantFigures.js.map +1 -1
- package/build/src/Conversion/StringAutoConvert.d.ts +6 -6
- package/build/src/Conversion/StringAutoConvert.js +46 -45
- package/build/src/Conversion/StringAutoConvert.js.map +1 -1
- package/build/src/Morse/MorseCharacter.d.ts +22 -22
- package/build/src/Morse/MorseCharacter.js +96 -95
- package/build/src/Morse/MorseCharacter.js.map +1 -1
- package/build/src/Morse/MorseData.d.ts +6 -6
- package/build/src/Morse/MorseData.js +70 -69
- package/build/src/Morse/MorseData.js.map +1 -1
- package/build/src/Morse/MorseEncoding.d.ts +59 -59
- package/build/src/Morse/MorseEncoding.js +94 -93
- package/build/src/Morse/MorseEncoding.js.map +1 -1
- package/build/src/Morse/MorseString.d.ts +10 -10
- package/build/src/Morse/MorseString.js +66 -65
- package/build/src/Morse/MorseString.js.map +1 -1
- package/build/src/Nato/NatoCharacter.d.ts +5 -5
- package/build/src/Nato/NatoCharacter.js +10 -9
- package/build/src/Nato/NatoCharacter.js.map +1 -1
- package/build/src/Nato/NatoData.d.ts +7 -7
- package/build/src/Nato/NatoData.js +51 -50
- package/build/src/Nato/NatoData.js.map +1 -1
- package/build/src/NavalFlags/NavalFlags.d.ts +7 -7
- package/build/src/NavalFlags/NavalFlags.js +52 -50
- package/build/src/NavalFlags/NavalFlags.js.map +1 -1
- package/build/src/Resistor/Resistor.d.ts +24 -24
- package/build/src/Resistor/Resistor.js +86 -85
- package/build/src/Resistor/Resistor.js.map +1 -1
- package/build/src/Resistor/ResistorColorEntry.d.ts +12 -12
- package/build/src/Resistor/ResistorColorEntry.js +31 -30
- package/build/src/Resistor/ResistorColorEntry.js.map +1 -1
- package/build/src/Semaphore/SemaphoreCharacter.d.ts +20 -20
- package/build/src/Semaphore/SemaphoreCharacter.js +75 -74
- package/build/src/Semaphore/SemaphoreCharacter.js.map +1 -1
- package/build/src/Semaphore/SemaphoreData.d.ts +6 -6
- package/build/src/Semaphore/SemaphoreData.js +53 -52
- package/build/src/Semaphore/SemaphoreData.js.map +1 -1
- package/build/src/Semaphore/SemaphoreDegrees.d.ts +5 -5
- package/build/src/Semaphore/SemaphoreDegrees.js +26 -25
- package/build/src/Semaphore/SemaphoreDegrees.js.map +1 -1
- package/build/src/Semaphore/SemaphoreDirection.d.ts +11 -11
- package/build/src/Semaphore/SemaphoreDirection.js +15 -14
- package/build/src/Semaphore/SemaphoreDirection.js.map +1 -1
- package/build/src/Semaphore/SemaphoreEncoding.d.ts +40 -40
- package/build/src/Semaphore/SemaphoreEncoding.js +47 -46
- package/build/src/Semaphore/SemaphoreEncoding.js.map +1 -1
- package/build/src/Semaphore/SemaphoreStream.d.ts +17 -17
- package/build/src/Semaphore/SemaphoreStream.js +72 -71
- package/build/src/Semaphore/SemaphoreStream.js.map +1 -1
- package/build/src/WordSearch/Point.d.ts +4 -4
- package/build/src/WordSearch/Point.js +2 -2
- package/build/src/WordSearch/Result.d.ts +6 -6
- package/build/src/WordSearch/Result.js +10 -9
- package/build/src/WordSearch/Result.js.map +1 -1
- package/build/src/WordSearch/WordSearchDirection.d.ts +6 -6
- package/build/src/WordSearch/WordSearchDirection.js +10 -9
- package/build/src/WordSearch/WordSearchDirection.js.map +1 -1
- package/build/src/WordSearch/WordSearchSolver.d.ts +27 -18
- package/build/src/WordSearch/WordSearchSolver.js +222 -171
- package/build/src/WordSearch/WordSearchSolver.js.map +1 -1
- package/build/src/index.d.ts +35 -35
- package/build/src/index.js +72 -70
- package/build/src/index.js.map +1 -1
- package/package.json +40 -39
- package/src/Braille/BrailleCharacter.ts +49 -0
- package/src/Braille/BrailleData.ts +131 -0
- package/src/Braille/BrailleDot.ts +9 -0
- package/src/Braille/BrailleEncoding.ts +144 -0
- package/src/Braille/BrailleStream.ts +87 -0
- package/src/Cipher/AutoKeyString.ts +35 -0
- package/src/Cipher/CaesarString.ts +38 -0
- package/src/Cipher/CaesarUtils.ts +69 -0
- package/src/Cipher/KeyedCipherStringBase.ts +35 -0
- package/src/Cipher/VigenereString.ts +21 -0
- package/src/Common/CharacterImage.ts +11 -0
- package/src/Common/EncodingCategory.ts +10 -0
- package/src/Common/EncodingCharacterBase.ts +72 -0
- package/src/Common/EncodingDataBase.ts +31 -0
- package/src/Common/EncodingEntry.ts +17 -0
- package/src/Common/EncodingLookupResult.ts +10 -0
- package/src/Common/Helpers.ts +13 -0
- package/src/Common/InlineSvg.ts +15 -0
- package/src/Conversion/CharacterAutoConvert.ts +108 -0
- package/src/Conversion/CharacterConversion.ts +89 -0
- package/src/Conversion/CharacterEncoding.ts +9 -0
- package/src/Conversion/CharacterTableEntry.ts +23 -0
- package/src/Conversion/SignificantFigures.ts +55 -0
- package/src/Conversion/StringAutoConvert.ts +56 -0
- package/src/Morse/MorseCharacter.ts +112 -0
- package/src/Morse/MorseData.ts +143 -0
- package/src/Morse/MorseEncoding.ts +98 -0
- package/src/Morse/MorseString.ts +106 -0
- package/src/Nato/NatoCharacter.ts +9 -0
- package/src/Nato/NatoData.ts +49 -0
- package/src/NavalFlags/LICENSE +7 -0
- package/src/NavalFlags/NavalFlags.ts +293 -0
- package/src/Resistor/Resistor.ts +135 -0
- package/src/Resistor/ResistorColorEntry.ts +43 -0
- package/src/Semaphore/SemaphoreCharacter.ts +107 -0
- package/src/Semaphore/SemaphoreData.ts +58 -0
- package/src/Semaphore/SemaphoreDegrees.ts +26 -0
- package/src/Semaphore/SemaphoreDirection.ts +11 -0
- package/src/Semaphore/SemaphoreEncoding.ts +48 -0
- package/src/Semaphore/SemaphoreStream.ts +89 -0
- package/src/WordSearch/Point.ts +4 -0
- package/src/WordSearch/Result.ts +10 -0
- package/src/WordSearch/WordSearchDirection.ts +6 -0
- package/src/WordSearch/WordSearchSolver.ts +271 -0
- package/src/index.ts +38 -0
- package/src/trie-prefix-tree.d.ts +70 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import {CharacterImage} from '../Common/CharacterImage';
|
|
2
|
+
import {InlineSvg} from '../Common/InlineSvg';
|
|
3
|
+
|
|
4
|
+
export class NavalFlags {
|
|
5
|
+
static readonly instance: NavalFlags = new NavalFlags();
|
|
6
|
+
|
|
7
|
+
private readonly _entries: CharacterImage[] = [
|
|
8
|
+
// tslint:disable:max-line-length (SVG images are messy)
|
|
9
|
+
new CharacterImage(
|
|
10
|
+
'A',
|
|
11
|
+
new InlineSvg(
|
|
12
|
+
`<path d="M 18,18 H 162 L 126,90 L 162,162 H 18 z" fill="#000094"/>
|
|
13
|
+
<rect x="18" y="18" width="72" height="144" fill="#fff"/>
|
|
14
|
+
<path d="M 18,18 H 162 L 126,90 L 162,162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
15
|
+
180,
|
|
16
|
+
180
|
|
17
|
+
)
|
|
18
|
+
),
|
|
19
|
+
new CharacterImage(
|
|
20
|
+
'B',
|
|
21
|
+
new InlineSvg(
|
|
22
|
+
'<path d="M 18,18 H 162 L 126,90 L 162,162 H 18 z" fill="#f00" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>',
|
|
23
|
+
180,
|
|
24
|
+
180
|
|
25
|
+
)
|
|
26
|
+
),
|
|
27
|
+
new CharacterImage(
|
|
28
|
+
'C',
|
|
29
|
+
new InlineSvg(
|
|
30
|
+
`<rect x="18" y="18" width="144" height="144" fill="#000094"/>
|
|
31
|
+
<rect x="18" y="46.8" width="144" height="86.4" fill="#fff"/>
|
|
32
|
+
<rect x="18" y="75.6" width="144" height="28.8" fill="#f00"/>
|
|
33
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
34
|
+
180,
|
|
35
|
+
180
|
|
36
|
+
)
|
|
37
|
+
),
|
|
38
|
+
new CharacterImage(
|
|
39
|
+
'D',
|
|
40
|
+
new InlineSvg(
|
|
41
|
+
`<rect x="18" y="18" width="144" height="144" fill="#fc0"/>
|
|
42
|
+
<rect x="18" y="54" width="144" height="72" fill="#000094"/>
|
|
43
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
44
|
+
180,
|
|
45
|
+
180
|
|
46
|
+
)
|
|
47
|
+
),
|
|
48
|
+
new CharacterImage(
|
|
49
|
+
'E',
|
|
50
|
+
new InlineSvg(
|
|
51
|
+
`<rect x="18" y="18" width="144" height="144" fill="#000094"/>
|
|
52
|
+
<rect x="18" y="90" width="144" height="72" fill="#f00"/>
|
|
53
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
54
|
+
180,
|
|
55
|
+
180
|
|
56
|
+
)
|
|
57
|
+
),
|
|
58
|
+
new CharacterImage(
|
|
59
|
+
'F',
|
|
60
|
+
new InlineSvg(
|
|
61
|
+
`<rect x="18" y="18" width="144" height="144" fill="#fff"/>
|
|
62
|
+
<path d="M 90,18 l 72,72 l -72,72 l -72,-72 z" fill="#f00"/>
|
|
63
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
64
|
+
180,
|
|
65
|
+
180
|
|
66
|
+
)
|
|
67
|
+
),
|
|
68
|
+
new CharacterImage(
|
|
69
|
+
'G',
|
|
70
|
+
new InlineSvg(
|
|
71
|
+
`<path fill="#000094" d="m18,18h144v144H18"/>
|
|
72
|
+
<path stroke="#FC0" stroke-width="24" d="m30,18v144m48,0V18m48,0v144"/>
|
|
73
|
+
<path d="M18,18H162V162H18z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
74
|
+
180,
|
|
75
|
+
180
|
|
76
|
+
)
|
|
77
|
+
),
|
|
78
|
+
new CharacterImage(
|
|
79
|
+
'H',
|
|
80
|
+
new InlineSvg(
|
|
81
|
+
`<rect x="18" y="18" width="144" height="144" fill="#f00"/>
|
|
82
|
+
<rect x="18" y="18" width="72" height="144" fill="#fff"/>
|
|
83
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
84
|
+
180,
|
|
85
|
+
180
|
|
86
|
+
)
|
|
87
|
+
),
|
|
88
|
+
new CharacterImage(
|
|
89
|
+
'I',
|
|
90
|
+
new InlineSvg(
|
|
91
|
+
`<rect x="18" y="18" width="144" height="144" fill="#fc0"/>
|
|
92
|
+
<circle cx="90" cy="90" r="36" fill="#000"/>
|
|
93
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
94
|
+
180,
|
|
95
|
+
180
|
|
96
|
+
)
|
|
97
|
+
),
|
|
98
|
+
new CharacterImage(
|
|
99
|
+
'J',
|
|
100
|
+
new InlineSvg(
|
|
101
|
+
`<rect x="18" y="18" width="144" height="144" fill="#000094"/>
|
|
102
|
+
<rect x="18" y="66" width="144" height="48" fill="#fff"/>
|
|
103
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
104
|
+
180,
|
|
105
|
+
180
|
|
106
|
+
)
|
|
107
|
+
),
|
|
108
|
+
new CharacterImage(
|
|
109
|
+
'K',
|
|
110
|
+
new InlineSvg(
|
|
111
|
+
`<rect x="18" y="18" width="144" height="144" fill="#000094"/>
|
|
112
|
+
<rect x="18" y="18" width="72" height="144" fill="#fc0"/>
|
|
113
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
114
|
+
180,
|
|
115
|
+
180
|
|
116
|
+
)
|
|
117
|
+
),
|
|
118
|
+
new CharacterImage(
|
|
119
|
+
'L',
|
|
120
|
+
new InlineSvg(
|
|
121
|
+
`<rect x="16" y="16" width="148" height="148" rx="2"/>
|
|
122
|
+
<path fill="#FC0" d="m20,20h70v140h70V90H20"/>`,
|
|
123
|
+
180,
|
|
124
|
+
180
|
|
125
|
+
)
|
|
126
|
+
),
|
|
127
|
+
new CharacterImage(
|
|
128
|
+
'M',
|
|
129
|
+
new InlineSvg(
|
|
130
|
+
`<clipPath id="c">
|
|
131
|
+
<path d="M 18,18 H 162 V 162 H 18 z"/>
|
|
132
|
+
</clipPath>
|
|
133
|
+
<rect x="18" y="18" width="144" height="144" fill="#000094"/>
|
|
134
|
+
<path d="M 18,18 L 162,162 M 162,18 L 18,162" clip-path="url(#c)" stroke="#fff" stroke-width="28.8"/>
|
|
135
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
136
|
+
180,
|
|
137
|
+
180
|
|
138
|
+
)
|
|
139
|
+
),
|
|
140
|
+
new CharacterImage(
|
|
141
|
+
'N',
|
|
142
|
+
new InlineSvg(
|
|
143
|
+
`<rect x="18" y="18" width="144" height="144" fill="#fff"/>
|
|
144
|
+
<path d="M 18,18 H 54 V 162 H 90 V 18 H 126 V 162 H 162 V 126 H 18 V 90 H 162 V 54 H 18 z" fill="#000094"/>
|
|
145
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
146
|
+
180,
|
|
147
|
+
180
|
|
148
|
+
)
|
|
149
|
+
),
|
|
150
|
+
new CharacterImage(
|
|
151
|
+
'O',
|
|
152
|
+
new InlineSvg(
|
|
153
|
+
`<rect x="18" y="18" width="144" height="144" fill="#fc0"/>
|
|
154
|
+
<path d="M 18,18 H 162 V 162 z" fill="#f00"/>
|
|
155
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
156
|
+
180,
|
|
157
|
+
180
|
|
158
|
+
)
|
|
159
|
+
),
|
|
160
|
+
new CharacterImage(
|
|
161
|
+
'P',
|
|
162
|
+
new InlineSvg(
|
|
163
|
+
`<rect x="18" y="18" width="144" height="144" fill="#000094"/>
|
|
164
|
+
<rect x="54" y="54" width="72" height="72" fill="#fff"/>
|
|
165
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
166
|
+
180,
|
|
167
|
+
180
|
|
168
|
+
)
|
|
169
|
+
),
|
|
170
|
+
new CharacterImage(
|
|
171
|
+
'Q',
|
|
172
|
+
new InlineSvg(
|
|
173
|
+
`<rect x="18" y="18" width="144" height="144" fill="#fc0"/>
|
|
174
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
175
|
+
180,
|
|
176
|
+
180
|
|
177
|
+
)
|
|
178
|
+
),
|
|
179
|
+
new CharacterImage(
|
|
180
|
+
'R',
|
|
181
|
+
new InlineSvg(
|
|
182
|
+
`<rect x="18" y="18" width="144" height="144" fill="#f00"/>
|
|
183
|
+
<path d="M 90,18 V 162 M 18,90 H 162" stroke="#fc0" stroke-width="36"/>
|
|
184
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
185
|
+
180,
|
|
186
|
+
180
|
|
187
|
+
)
|
|
188
|
+
),
|
|
189
|
+
new CharacterImage(
|
|
190
|
+
'S',
|
|
191
|
+
new InlineSvg(
|
|
192
|
+
`<rect x="18" y="18" width="144" height="144" fill="#fff"/>
|
|
193
|
+
<rect x="54" y="54" width="72" height="72" fill="#000094"/>
|
|
194
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
195
|
+
180,
|
|
196
|
+
180
|
|
197
|
+
)
|
|
198
|
+
),
|
|
199
|
+
new CharacterImage(
|
|
200
|
+
'T',
|
|
201
|
+
new InlineSvg(
|
|
202
|
+
`<rect x="18" y="18" width="144" height="144" fill="#000094"/>
|
|
203
|
+
<rect x="18" y="18" width="96" height="144" fill="#fff"/>
|
|
204
|
+
<rect x="18" y="18" width="48" height="144" fill="#f00"/>
|
|
205
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
206
|
+
180,
|
|
207
|
+
180
|
|
208
|
+
)
|
|
209
|
+
),
|
|
210
|
+
new CharacterImage(
|
|
211
|
+
'U',
|
|
212
|
+
new InlineSvg(
|
|
213
|
+
`<rect x="18" y="18" width="144" height="144" fill="#ffffff"/>
|
|
214
|
+
<path d="M 18,18 H 90 V 90 H 18 z" fill="#ff0000"/>
|
|
215
|
+
<path d="M 162,91 H 91 V 162 H 162 z" fill="#ff0000"/>
|
|
216
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
217
|
+
180,
|
|
218
|
+
180
|
|
219
|
+
)
|
|
220
|
+
),
|
|
221
|
+
new CharacterImage(
|
|
222
|
+
'V',
|
|
223
|
+
new InlineSvg(
|
|
224
|
+
`<clipPath id="c">
|
|
225
|
+
<path d="M 18,18 H 162 V 162 H 18 z"/>
|
|
226
|
+
</clipPath>
|
|
227
|
+
<rect x="18" y="18" width="144" height="144" fill="#fff"/>
|
|
228
|
+
<path d="M 18,18 L 162,162 M 162,18 L 18,162" clip-path="url(#c)" stroke="#f00" stroke-width="28.8"/>
|
|
229
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
230
|
+
180,
|
|
231
|
+
180
|
|
232
|
+
)
|
|
233
|
+
),
|
|
234
|
+
new CharacterImage(
|
|
235
|
+
'W',
|
|
236
|
+
new InlineSvg(
|
|
237
|
+
`<rect x="18" y="18" width="144" height="144" fill="#000094"/>
|
|
238
|
+
<rect x="42" y="42" width="96" height="96" fill="#fff"/>
|
|
239
|
+
<rect x="66" y="66" width="48" height="48" fill="#f00"/>
|
|
240
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
241
|
+
180,
|
|
242
|
+
180
|
|
243
|
+
)
|
|
244
|
+
),
|
|
245
|
+
new CharacterImage(
|
|
246
|
+
'X',
|
|
247
|
+
new InlineSvg(
|
|
248
|
+
`<rect x="18" y="18" width="144" height="144" fill="#fff"/>
|
|
249
|
+
<path d="M 90,18 V 162 M 18,90 H 162" stroke="#000094" stroke-width="36"/>
|
|
250
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
251
|
+
180,
|
|
252
|
+
180
|
|
253
|
+
)
|
|
254
|
+
),
|
|
255
|
+
new CharacterImage(
|
|
256
|
+
'Y',
|
|
257
|
+
new InlineSvg(
|
|
258
|
+
`<clipPath id="c"><path d="m18,18h144v144H18"/></clipPath>
|
|
259
|
+
<path fill="#FC0" d="m18,18h144v144H18"/>
|
|
260
|
+
<path stroke="#F00" stroke-dasharray="18.8" stroke-width="250" clip-path="url(#c)" d="m4,4 160,160"/>
|
|
261
|
+
<path fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round" d="M18,18H162V162H18z"/>`,
|
|
262
|
+
180,
|
|
263
|
+
180
|
|
264
|
+
)
|
|
265
|
+
),
|
|
266
|
+
new CharacterImage(
|
|
267
|
+
'Z',
|
|
268
|
+
new InlineSvg(
|
|
269
|
+
`<rect x="18" y="18" width="144" height="144" fill="#fc0"/>
|
|
270
|
+
<path d="M 18,18 V 162 H 162 z" fill="#000"/>
|
|
271
|
+
<path d="M 162,18 V 162 H 18 z" fill="#000094"/>
|
|
272
|
+
<path d="M 90,90 L 162,162 H 18 z" fill="#f00"/>
|
|
273
|
+
<path d="M 18,18 H 162 V 162 H 18 z" fill="none" stroke="#000" stroke-width="3.75" stroke-linejoin="round"/>`,
|
|
274
|
+
180,
|
|
275
|
+
180
|
|
276
|
+
)
|
|
277
|
+
),
|
|
278
|
+
// tslint:enable:max-line-length
|
|
279
|
+
];
|
|
280
|
+
|
|
281
|
+
get entries(): CharacterImage[] {
|
|
282
|
+
return this._entries;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
lookup(letter: string): CharacterImage | null {
|
|
286
|
+
for (const ch of this._entries) {
|
|
287
|
+
if (ch.character.toUpperCase() === letter.toUpperCase()) {
|
|
288
|
+
return ch;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import {ResistorColorEntry} from './ResistorColorEntry';
|
|
2
|
+
|
|
3
|
+
export class Resistor {
|
|
4
|
+
// Name, Color, Multiplier, Value, Tolerance
|
|
5
|
+
static readonly BLACK = new ResistorColorEntry('Black', '#000000', 1, 0);
|
|
6
|
+
static readonly BROWN = new ResistorColorEntry('Brown', '#8B4513', 10, 1, 1);
|
|
7
|
+
static readonly RED = new ResistorColorEntry('Red', '#FF0000', 100, 2, 2);
|
|
8
|
+
static readonly ORANGE = new ResistorColorEntry('Orange', '#EE7420', 1000, 3);
|
|
9
|
+
static readonly YELLOW = new ResistorColorEntry(
|
|
10
|
+
'Yellow',
|
|
11
|
+
'#FFFF00',
|
|
12
|
+
10000,
|
|
13
|
+
4
|
|
14
|
+
);
|
|
15
|
+
static readonly GREEN = new ResistorColorEntry(
|
|
16
|
+
'Green',
|
|
17
|
+
'#008000',
|
|
18
|
+
100000,
|
|
19
|
+
5,
|
|
20
|
+
0.5
|
|
21
|
+
);
|
|
22
|
+
static readonly BLUE = new ResistorColorEntry(
|
|
23
|
+
'Blue',
|
|
24
|
+
'#0000FF',
|
|
25
|
+
1000000,
|
|
26
|
+
6,
|
|
27
|
+
0.25
|
|
28
|
+
);
|
|
29
|
+
static readonly VIOLET = new ResistorColorEntry(
|
|
30
|
+
'Violet',
|
|
31
|
+
'#800080',
|
|
32
|
+
10000000,
|
|
33
|
+
7,
|
|
34
|
+
0.1
|
|
35
|
+
);
|
|
36
|
+
static readonly GREY = new ResistorColorEntry(
|
|
37
|
+
'Grey',
|
|
38
|
+
'#808080',
|
|
39
|
+
100000000,
|
|
40
|
+
8
|
|
41
|
+
);
|
|
42
|
+
static readonly WHITE = new ResistorColorEntry(
|
|
43
|
+
'White',
|
|
44
|
+
'#FFFFFF',
|
|
45
|
+
1000000000,
|
|
46
|
+
9
|
|
47
|
+
);
|
|
48
|
+
static readonly GOLD = new ResistorColorEntry(
|
|
49
|
+
'Gold',
|
|
50
|
+
'#AB8D3F',
|
|
51
|
+
0.1,
|
|
52
|
+
undefined,
|
|
53
|
+
5
|
|
54
|
+
);
|
|
55
|
+
static readonly SILVER = new ResistorColorEntry(
|
|
56
|
+
'Silver',
|
|
57
|
+
'#C0C0C0',
|
|
58
|
+
0.01,
|
|
59
|
+
undefined,
|
|
60
|
+
10
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
static readonly colorTable: ResistorColorEntry[] = [
|
|
64
|
+
Resistor.BLACK,
|
|
65
|
+
Resistor.BROWN,
|
|
66
|
+
Resistor.RED,
|
|
67
|
+
Resistor.ORANGE,
|
|
68
|
+
Resistor.YELLOW,
|
|
69
|
+
Resistor.GREEN,
|
|
70
|
+
Resistor.BLUE,
|
|
71
|
+
Resistor.VIOLET,
|
|
72
|
+
Resistor.GREY,
|
|
73
|
+
Resistor.WHITE,
|
|
74
|
+
Resistor.GOLD,
|
|
75
|
+
Resistor.SILVER,
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
static readonly INVALID_RESISTOR = -1;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* getValue assumes there is no tolerance band, as tolerance is not part of
|
|
82
|
+
* the value calculation
|
|
83
|
+
*/
|
|
84
|
+
static getValue(colors: ResistorColorEntry[]) {
|
|
85
|
+
if (colors.length < 3 || colors.length > 4) {
|
|
86
|
+
throw new RangeError('Invalid resistor size');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Should we throw an error if the first color is black? In resistors, it's
|
|
90
|
+
// technically not allowed, but in puzzle events who knows what they'll do.
|
|
91
|
+
// The math works out fine (it's just a leading zero), so for now it's
|
|
92
|
+
// allowed.
|
|
93
|
+
|
|
94
|
+
// Iterate through all but the final band (the multipler) and extract the
|
|
95
|
+
// values
|
|
96
|
+
let value = 0;
|
|
97
|
+
for (let i = 0; i < colors.length - 1; ++i) {
|
|
98
|
+
const currentColor = colors[i];
|
|
99
|
+
if (currentColor.value === undefined) {
|
|
100
|
+
return Resistor.INVALID_RESISTOR;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
value *= 10;
|
|
104
|
+
value += currentColor.value;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return Resistor.applyMultiplier(
|
|
108
|
+
value,
|
|
109
|
+
colors[colors.length - 1].multiplier
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static getDisplayValue(value: number) {
|
|
114
|
+
if (value >= 1000000000) {
|
|
115
|
+
return `${value / 1000000000}G`;
|
|
116
|
+
} else if (value >= 1000000) {
|
|
117
|
+
return `${value / 1000000}M`;
|
|
118
|
+
} else if (value >= 1000) {
|
|
119
|
+
return `${value / 1000}k`;
|
|
120
|
+
} else {
|
|
121
|
+
return value.toString();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private static applyMultiplier(value: number, multipler: number) {
|
|
126
|
+
if (multipler >= 1) {
|
|
127
|
+
return value * multipler;
|
|
128
|
+
} else if (multipler > 0) {
|
|
129
|
+
// Avoid floating point multiplication issues
|
|
130
|
+
return value / (1 / multipler);
|
|
131
|
+
} else {
|
|
132
|
+
throw new RangeError('Invalid multiplier');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export class ResistorColorEntry {
|
|
2
|
+
readonly name: string;
|
|
3
|
+
readonly colorCode: string;
|
|
4
|
+
readonly multiplier: number;
|
|
5
|
+
readonly value?: number;
|
|
6
|
+
readonly toleranceInPercent?: number;
|
|
7
|
+
|
|
8
|
+
constructor(
|
|
9
|
+
name: string,
|
|
10
|
+
colorCode: string,
|
|
11
|
+
multiplier: number,
|
|
12
|
+
value?: number,
|
|
13
|
+
toleranceInPercent?: number
|
|
14
|
+
) {
|
|
15
|
+
this.name = name;
|
|
16
|
+
this.value = value;
|
|
17
|
+
this.colorCode = colorCode;
|
|
18
|
+
this.multiplier = multiplier;
|
|
19
|
+
this.toleranceInPercent = toleranceInPercent;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
hasValue() {
|
|
23
|
+
return this.value !== undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getDisplayValue() {
|
|
27
|
+
if (this.value === undefined) {
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
return this.value.toString();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
hasTolerance() {
|
|
34
|
+
return this.toleranceInPercent !== undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getDisplayTolerance() {
|
|
38
|
+
if (this.toleranceInPercent === undefined) {
|
|
39
|
+
return '';
|
|
40
|
+
}
|
|
41
|
+
return `${this.toleranceInPercent}%`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {EncodingCategory} from '../Common/EncodingCategory';
|
|
2
|
+
import {EncodingCharacterBase} from '../Common/EncodingCharacterBase';
|
|
3
|
+
import {EncodingEntry} from '../Common/EncodingEntry';
|
|
4
|
+
|
|
5
|
+
import {SemaphoreData} from './SemaphoreData';
|
|
6
|
+
import {SemaphoreDegrees} from './SemaphoreDegrees';
|
|
7
|
+
import {SemaphoreDirection} from './SemaphoreDirection';
|
|
8
|
+
import {SemaphoreEncoding} from './SemaphoreEncoding';
|
|
9
|
+
|
|
10
|
+
export class SemaphoreCharacter extends EncodingCharacterBase<SemaphoreEncoding> {
|
|
11
|
+
private static parseEncoding(
|
|
12
|
+
encoding: SemaphoreDirection | SemaphoreEncoding
|
|
13
|
+
) {
|
|
14
|
+
const directions: SemaphoreDirection[] = [];
|
|
15
|
+
|
|
16
|
+
for (let i = 1; i <= 8; i++) {
|
|
17
|
+
const direction = (1 << i) as SemaphoreDirection;
|
|
18
|
+
if ((encoding & direction) === direction) {
|
|
19
|
+
directions.push(direction);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return directions;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private _directions: SemaphoreDirection[] = [];
|
|
27
|
+
|
|
28
|
+
constructor(
|
|
29
|
+
encoding: SemaphoreEncoding = SemaphoreEncoding.None,
|
|
30
|
+
category: EncodingCategory = EncodingCategory.All
|
|
31
|
+
) {
|
|
32
|
+
super(SemaphoreData.instance, category);
|
|
33
|
+
|
|
34
|
+
this.addDirection(encoding);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get directions() {
|
|
38
|
+
return this._directions;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
set directions(value: SemaphoreDirection[]) {
|
|
42
|
+
this._directions = value.slice(0, 2);
|
|
43
|
+
this.invalidateLookup();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
addDirection(direction: SemaphoreDirection | SemaphoreEncoding) {
|
|
47
|
+
for (const dir of SemaphoreCharacter.parseEncoding(direction)) {
|
|
48
|
+
this._directions.push(dir);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (this._directions.length > 2) {
|
|
52
|
+
this._directions.splice(0, this._directions.length - 2);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.invalidateLookup();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
removeDirection(direction: SemaphoreDirection | SemaphoreEncoding) {
|
|
59
|
+
for (const dir of SemaphoreCharacter.parseEncoding(direction)) {
|
|
60
|
+
const index = this._directions.indexOf(dir);
|
|
61
|
+
if (index >= 0) {
|
|
62
|
+
this._directions.splice(index, 1);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this.invalidateLookup();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
hasDirection(direction: SemaphoreDirection) {
|
|
70
|
+
return this._directions.indexOf(direction) >= 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
getDegrees() {
|
|
74
|
+
return this._directions
|
|
75
|
+
.map(value => SemaphoreDegrees.ToDegrees(value))
|
|
76
|
+
.sort((a, b) => a - b);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getPotentialMatch(
|
|
80
|
+
other: SemaphoreDirection
|
|
81
|
+
): EncodingEntry<SemaphoreEncoding> | null {
|
|
82
|
+
if (this.directions.length !== 1 || this.directions[0] === other) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const potentialMatch = this.getPotentialMatches().filter(
|
|
87
|
+
value => (value.encoding & other) === other
|
|
88
|
+
)[0];
|
|
89
|
+
|
|
90
|
+
return potentialMatch || null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
protected onClear() {
|
|
94
|
+
this._directions.length = 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
protected onEmpty() {
|
|
98
|
+
return this._directions.length === 0;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
protected getEncoding() {
|
|
102
|
+
return this._directions.reduce(
|
|
103
|
+
(previousValue, currentValue) => (previousValue |= currentValue),
|
|
104
|
+
SemaphoreEncoding.None
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {EncodingCategory} from '../Common/EncodingCategory';
|
|
2
|
+
import {EncodingDataBase} from '../Common/EncodingDataBase';
|
|
3
|
+
import {SemaphoreEncoding} from './SemaphoreEncoding';
|
|
4
|
+
|
|
5
|
+
export class SemaphoreData extends EncodingDataBase<SemaphoreEncoding> {
|
|
6
|
+
static readonly instance: SemaphoreData = new SemaphoreData();
|
|
7
|
+
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
|
|
11
|
+
// Letters
|
|
12
|
+
this.addToList(SemaphoreEncoding.LetterA, EncodingCategory.Letter, 'A');
|
|
13
|
+
this.addToList(SemaphoreEncoding.LetterB, EncodingCategory.Letter, 'B');
|
|
14
|
+
this.addToList(SemaphoreEncoding.LetterC, EncodingCategory.Letter, 'C');
|
|
15
|
+
this.addToList(SemaphoreEncoding.LetterD, EncodingCategory.Letter, 'D');
|
|
16
|
+
this.addToList(SemaphoreEncoding.LetterE, EncodingCategory.Letter, 'E');
|
|
17
|
+
this.addToList(SemaphoreEncoding.LetterF, EncodingCategory.Letter, 'F');
|
|
18
|
+
this.addToList(SemaphoreEncoding.LetterG, EncodingCategory.Letter, 'G');
|
|
19
|
+
this.addToList(SemaphoreEncoding.LetterH, EncodingCategory.Letter, 'H');
|
|
20
|
+
this.addToList(SemaphoreEncoding.LetterI, EncodingCategory.Letter, 'I');
|
|
21
|
+
this.addToList(SemaphoreEncoding.LetterJ, EncodingCategory.Letter, 'J');
|
|
22
|
+
this.addToList(SemaphoreEncoding.LetterK, EncodingCategory.Letter, 'K');
|
|
23
|
+
this.addToList(SemaphoreEncoding.LetterL, EncodingCategory.Letter, 'L');
|
|
24
|
+
this.addToList(SemaphoreEncoding.LetterM, EncodingCategory.Letter, 'M');
|
|
25
|
+
this.addToList(SemaphoreEncoding.LetterN, EncodingCategory.Letter, 'N');
|
|
26
|
+
this.addToList(SemaphoreEncoding.LetterO, EncodingCategory.Letter, 'O');
|
|
27
|
+
this.addToList(SemaphoreEncoding.LetterP, EncodingCategory.Letter, 'P');
|
|
28
|
+
this.addToList(SemaphoreEncoding.LetterQ, EncodingCategory.Letter, 'Q');
|
|
29
|
+
this.addToList(SemaphoreEncoding.LetterR, EncodingCategory.Letter, 'R');
|
|
30
|
+
this.addToList(SemaphoreEncoding.LetterS, EncodingCategory.Letter, 'S');
|
|
31
|
+
this.addToList(SemaphoreEncoding.LetterT, EncodingCategory.Letter, 'T');
|
|
32
|
+
this.addToList(SemaphoreEncoding.LetterU, EncodingCategory.Letter, 'U');
|
|
33
|
+
this.addToList(SemaphoreEncoding.LetterV, EncodingCategory.Letter, 'V');
|
|
34
|
+
this.addToList(SemaphoreEncoding.LetterW, EncodingCategory.Letter, 'W');
|
|
35
|
+
this.addToList(SemaphoreEncoding.LetterX, EncodingCategory.Letter, 'X');
|
|
36
|
+
this.addToList(SemaphoreEncoding.LetterY, EncodingCategory.Letter, 'Y');
|
|
37
|
+
this.addToList(SemaphoreEncoding.LetterZ, EncodingCategory.Letter, 'Z');
|
|
38
|
+
|
|
39
|
+
// Numbers
|
|
40
|
+
this.addToList(SemaphoreEncoding.Number1, EncodingCategory.Number, '1');
|
|
41
|
+
this.addToList(SemaphoreEncoding.Number2, EncodingCategory.Number, '2');
|
|
42
|
+
this.addToList(SemaphoreEncoding.Number3, EncodingCategory.Number, '3');
|
|
43
|
+
this.addToList(SemaphoreEncoding.Number4, EncodingCategory.Number, '4');
|
|
44
|
+
this.addToList(SemaphoreEncoding.Number5, EncodingCategory.Number, '5');
|
|
45
|
+
this.addToList(SemaphoreEncoding.Number6, EncodingCategory.Number, '6');
|
|
46
|
+
this.addToList(SemaphoreEncoding.Number7, EncodingCategory.Number, '7');
|
|
47
|
+
this.addToList(SemaphoreEncoding.Number8, EncodingCategory.Number, '8');
|
|
48
|
+
this.addToList(SemaphoreEncoding.Number9, EncodingCategory.Number, '9');
|
|
49
|
+
this.addToList(SemaphoreEncoding.Number0, EncodingCategory.Number, '0');
|
|
50
|
+
|
|
51
|
+
// Formatting
|
|
52
|
+
this.addToList(
|
|
53
|
+
SemaphoreEncoding.FormattingNumber,
|
|
54
|
+
EncodingCategory.Formatting,
|
|
55
|
+
'#'
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {SemaphoreDirection} from './SemaphoreDirection';
|
|
2
|
+
|
|
3
|
+
export class SemaphoreDegrees {
|
|
4
|
+
static FromDegrees(degrees: number) {
|
|
5
|
+
if (degrees >= 360) {
|
|
6
|
+
degrees = degrees % 360;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (degrees % 45 !== 0 || degrees < 0) {
|
|
10
|
+
throw new Error('Invalid degrees');
|
|
11
|
+
}
|
|
12
|
+
const position = degrees / 45;
|
|
13
|
+
return SemaphoreDirection.North << position;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static ToDegrees(direction: SemaphoreDirection) {
|
|
17
|
+
let position = SemaphoreDirection.North;
|
|
18
|
+
let counter = 0;
|
|
19
|
+
while (counter < 9 && position !== direction) {
|
|
20
|
+
position = position << 1;
|
|
21
|
+
counter++;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return counter * 45;
|
|
25
|
+
}
|
|
26
|
+
}
|