1const BASE: u32 = 0xF0000;
6
7#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
8pub enum Icon {
9 Files = 0,
10 Search = 1,
11 Git = 2,
12 Settings = 3,
13 Folder = 4,
14 FolderOpen = 5,
15 File = 6,
16 ChevronRight = 7,
17 ChevronDown = 8,
18 Close = 9,
19 ReplaceAll = 10,
20 Globe = 11,
21 Check = 12,
22 Agents = 13,
23 Outline = 14,
24 Layers = 15,
26 ListBullet = 30,
28 ListNumber = 53,
29 ListTask = 16,
30 Quote = 17,
31 Code = 18,
32 Link = 19,
33 Table = 20,
34 Picture = 21,
35 Sigma = 22,
36 Rule = 23,
37 Comment = 24,
38 Export = 25,
39 Play = 26,
40 Cite = 27,
41 More = 28,
42 Diagram = 29,
43 Track = 31,
44 PlayAll = 32,
45 Stop = 33,
46 Restart = 34,
47 AddCell = 35,
48 AddText = 36,
49 Terminal = 37,
50 Diff = 38,
51 Replace = 39,
52 ArrowUp = 40,
53 ArrowDown = 41,
54 Maximize = 42,
56 Minimize = 43,
57 Panel = 44,
59 SymbolFunction = 45,
62 SymbolType = 46,
63 SymbolField = 47,
64 SymbolValue = 48,
65 Bell = 49,
67 Question = 50,
69 CircleCheck = 51,
70 CircleX = 52,
71 HidePane = 54,
74 HidePanel = 55,
77 ShowPane = 56,
79 Smile = 57,
81}
82
83#[derive(Clone, Copy, Debug, PartialEq, Eq)]
85pub struct Piece {
86 pub icon: Icon,
87 pub width: u8,
88 pub height: u8,
89 pub column: u8,
90 pub row: u8,
91}
92
93impl Piece {
94 pub fn symbol(self) -> char {
95 let code = (self.icon as u32) << 8
96 | u32::from(self.width) << 6
97 | u32::from(self.height) << 4
98 | u32::from(self.column) << 2
99 | u32::from(self.row);
100 char::from_u32(BASE + code).expect("the private plane holds every code")
101 }
102
103 pub fn decode(symbol: &str) -> Option<Self> {
104 let mut chars = symbol.chars();
105 let code = (chars.next()? as u32).checked_sub(BASE)?;
106 if chars.next().is_some() || code >= 1 << 12 {
107 return None;
108 }
109 let icon = match code >> 8 {
110 0 => Icon::Files,
111 1 => Icon::Search,
112 2 => Icon::Git,
113 13 => Icon::Agents,
114 14 => Icon::Outline,
115 15 => Icon::Layers,
116 _ => Icon::Settings,
117 };
118 Some(Self {
119 icon,
120 width: (code >> 6 & 3) as u8,
121 height: (code >> 4 & 3) as u8,
122 column: (code >> 2 & 3) as u8,
123 row: (code & 3) as u8,
124 })
125 }
126
127 pub fn fallback(self) -> &'static str {
129 const ART: [[[&str; 3]; 2]; 7] = [
130 [["▛", "▀", "▜"], ["▙", "▄", "▟"]],
131 [["▞", "▀", "▚"], ["▚", "▄", "▟"]],
132 [["●", "─", "●"], ["●", "─", "╯"]],
133 [["▚", "▀", "▞"], ["▞", "▄", "▚"]],
134 [["▗", "▄", "▖"], ["▐", "█", "▌"]],
135 [["▪", "─", "─"], [" ", "▪", "─"]],
136 [["▗", "▀", "▖"], ["▝", "▀", "▘"]],
137 ];
138 let art = match self.icon {
139 Icon::Agents => 4,
140 Icon::Outline => 5,
141 Icon::Layers => 6,
142 other => (other as usize).min(3),
143 };
144 if self.width == 1 || self.height == 1 {
145 if self.column > 0 {
146 return " ";
147 }
148 return match self.icon {
149 Icon::Files => "▤",
150 Icon::Search => "⌕",
151 Icon::Git => "⎇",
152 Icon::Agents => "◉",
153 Icon::Outline => "≡",
154 Icon::Layers => "≋",
155 _ => "⚙",
156 };
157 }
158 ART[art][self.row.min(1) as usize][self.column.min(2) as usize]
159 }
160}
161
162type Point = (f32, f32);
163
164fn segment(p: Point, a: Point, b: Point) -> f32 {
165 let (dx, dy) = (b.0 - a.0, b.1 - a.1);
166 let t = (((p.0 - a.0) * dx + (p.1 - a.1) * dy) / (dx * dx + dy * dy)).clamp(0.0, 1.0);
167 ((p.0 - a.0 - t * dx).powi(2) + (p.1 - a.1 - t * dy).powi(2)).sqrt()
168}
169
170fn path(p: Point, points: &[Point]) -> f32 {
172 points
173 .windows(2)
174 .map(|pair| segment(p, pair[0], pair[1]))
175 .fold(f32::MAX, f32::min)
176}
177
178fn circle(p: Point, c: Point) -> f32 {
179 ((p.0 - c.0).powi(2) + (p.1 - c.1).powi(2)).sqrt()
180}
181
182fn ring(p: Point, c: Point, radius: f32) -> f32 {
184 (circle(p, c) - radius).abs()
185}
186
187fn rounded(p: Point, min: Point, max: Point, radius: f32) -> f32 {
189 let (cx, cy) = ((min.0 + max.0) / 2.0, (min.1 + max.1) / 2.0);
190 let (qx, qy) = (
191 (p.0 - cx).abs() - (max.0 - min.0) / 2.0 + radius,
192 (p.1 - cy).abs() - (max.1 - min.1) / 2.0 + radius,
193 );
194 let outside = (qx.max(0.0).powi(2) + qy.max(0.0).powi(2)).sqrt();
195 (outside + qx.max(qy).min(0.0) - radius).abs()
196}
197
198fn solid(p: Point, min: Point, max: Point, radius: f32) -> f32 {
200 let (cx, cy) = ((min.0 + max.0) / 2.0, (min.1 + max.1) / 2.0);
201 let (qx, qy) = (
202 (p.0 - cx).abs() - (max.0 - min.0) / 2.0 + radius,
203 (p.1 - cy).abs() - (max.1 - min.1) / 2.0 + radius,
204 );
205 let outside = (qx.max(0.0).powi(2) + qy.max(0.0).powi(2)).sqrt();
206 (outside + qx.max(qy).min(0.0) - radius).max(0.0)
207}
208
209fn replace(p: Point) -> f32 {
212 rounded(p, (2.0, 14.0), (10.0, 22.0), 2.0)
213 .min(path(
214 p,
215 &[(6.0, 10.0), (6.0, 5.0), (6.9, 2.9), (9.0, 2.0), (10.0, 2.0)],
216 ))
217 .min(path(p, &[(3.0, 7.0), (6.0, 10.0), (9.0, 7.0)]))
218 .min(path(p, &[(14.0, 4.0), (14.6, 2.6), (16.0, 2.0)]))
219 .min(path(p, &[(16.0, 10.0), (14.6, 9.4), (14.0, 8.0)]))
220 .min(path(p, &[(20.0, 2.0), (21.4, 2.6), (22.0, 4.0)]))
221 .min(path(p, &[(22.0, 8.0), (21.4, 9.4), (20.0, 10.0)]))
222}
223
224fn half_stroke(icon: Icon) -> f32 {
227 match icon {
228 Icon::Files
229 | Icon::Search
230 | Icon::Git
231 | Icon::Settings
232 | Icon::Outline
233 | Icon::Layers
234 | Icon::File
235 | Icon::Folder
236 | Icon::FolderOpen
237 | Icon::ChevronRight
238 | Icon::ChevronDown
239 | Icon::Close
240 | Icon::ArrowUp
241 | Icon::ArrowDown
242 | Icon::Replace
243 | Icon::Maximize
244 | Icon::Minimize
245 | Icon::SymbolFunction
246 | Icon::SymbolType
247 | Icon::SymbolField
248 | Icon::SymbolValue
249 | Icon::HidePane
250 | Icon::HidePanel
251 | Icon::ShowPane
252 | Icon::ReplaceAll => 0.9,
253 Icon::Agents => 0.8,
254 Icon::Check => 1.7,
255 _ => 1.15,
256 }
257}
258
259pub fn inked(icon: Icon, u: f32, v: f32) -> bool {
262 let p = (u * 24.0, v * 24.0);
263 let distance = match icon {
264 Icon::Files => path(
266 p,
267 &[
268 (9.0, 18.0),
269 (7.6, 17.4),
270 (7.0, 16.0),
271 (7.0, 4.0),
272 (7.6, 2.6),
273 (9.0, 2.0),
274 (16.0, 2.0),
275 (20.0, 6.0),
276 (20.0, 16.0),
277 (19.4, 17.4),
278 (18.0, 18.0),
279 (9.0, 18.0),
280 ],
281 )
282 .min(path(
283 p,
284 &[
285 (20.0, 7.0),
286 (17.0, 7.0),
287 (15.6, 6.4),
288 (15.0, 5.0),
289 (15.0, 2.0),
290 ],
291 ))
292 .min(path(
293 p,
294 &[
295 (3.0, 7.6),
296 (3.0, 20.4),
297 (3.5, 21.5),
298 (4.6, 22.0),
299 (14.4, 22.0),
300 ],
301 )),
302 Icon::Search => ring(p, (11.0, 11.0), 7.0).min(segment(p, (16.65, 16.65), (20.0, 20.0))),
303 Icon::Git => {
304 let joint = (9.0, 9.0);
305 let quarter = p.0 >= joint.0 && p.1 >= joint.1;
306 let curve = if quarter {
307 ring(p, joint, 9.0)
308 } else {
309 f32::MAX
310 };
311 ring(p, (6.0, 18.0), 3.0)
312 .min(ring(p, (18.0, 6.0), 3.0))
313 .min(segment(p, (6.0, 3.0), (6.0, 15.0)))
314 .min(curve)
315 }
316 Icon::Settings => segment(p, (20.0, 7.0), (11.0, 7.0))
318 .min(segment(p, (14.0, 17.0), (5.0, 17.0)))
319 .min(ring(p, (17.0, 17.0), 3.0))
320 .min(ring(p, (7.0, 7.0), 3.0)),
321 Icon::Agents => rounded(p, (4.0, 8.5), (20.0, 20.5), 3.0)
322 .min(path(p, &[(12.0, 8.5), (12.0, 3.5), (8.5, 3.5)]))
323 .min(segment(p, (9.0, 13.0), (9.0, 15.5)))
324 .min(segment(p, (15.0, 13.0), (15.0, 15.5)))
325 .min(segment(p, (1.5, 14.5), (4.0, 14.5)))
326 .min(segment(p, (20.0, 14.5), (22.5, 14.5))),
327 Icon::File => path(
329 p,
330 &[
331 (15.0, 2.0),
332 (6.0, 2.0),
333 (4.6, 2.6),
334 (4.0, 4.0),
335 (4.0, 20.0),
336 (4.6, 21.4),
337 (6.0, 22.0),
338 (18.0, 22.0),
339 (19.4, 21.4),
340 (20.0, 20.0),
341 (20.0, 7.0),
342 (15.0, 2.0),
343 ],
344 )
345 .min(path(
346 p,
347 &[
348 (14.0, 2.0),
349 (14.0, 6.0),
350 (14.6, 7.4),
351 (16.0, 8.0),
352 (20.0, 8.0),
353 ],
354 )),
355 Icon::Folder => path(
356 p,
357 &[
358 (20.0, 20.0),
359 (21.4, 19.4),
360 (22.0, 18.0),
361 (22.0, 8.0),
362 (21.4, 6.6),
363 (20.0, 6.0),
364 (12.1, 6.0),
365 (10.4, 5.1),
366 (9.6, 3.9),
367 (7.9, 3.0),
368 (4.0, 3.0),
369 (2.6, 3.6),
370 (2.0, 5.0),
371 (2.0, 18.0),
372 (2.6, 19.4),
373 (4.0, 20.0),
374 (20.0, 20.0),
375 ],
376 ),
377 Icon::FolderOpen => path(
378 p,
379 &[
380 (6.0, 14.0),
381 (7.5, 11.1),
382 (9.2, 10.0),
383 (20.0, 10.0),
384 (21.9, 12.5),
385 (20.4, 18.5),
386 (18.5, 20.0),
387 (4.0, 20.0),
388 (2.6, 19.4),
389 (2.0, 18.0),
390 (2.0, 5.0),
391 (2.6, 3.6),
392 (4.0, 3.0),
393 (7.9, 3.0),
394 (9.6, 3.9),
395 (10.4, 5.1),
396 (12.1, 6.0),
397 (18.0, 6.0),
398 (19.4, 6.6),
399 (20.0, 8.0),
400 (20.0, 10.0),
401 ],
402 ),
403 Icon::Layers => path(
405 p,
406 &[
407 (12.0, 2.5),
408 (21.5, 7.5),
409 (12.0, 12.5),
410 (2.5, 7.5),
411 (12.0, 2.5),
412 ],
413 )
414 .min(path(p, &[(2.5, 12.5), (12.0, 17.5), (21.5, 12.5)]))
415 .min(path(p, &[(2.5, 17.0), (12.0, 22.0), (21.5, 17.0)])),
416 Icon::Outline => segment(p, (21.0, 6.0), (8.0, 6.0))
418 .min(segment(p, (21.0, 12.0), (13.0, 12.0)))
419 .min(segment(p, (21.0, 18.0), (13.0, 18.0)))
420 .min(path(
421 p,
422 &[
423 (3.0, 6.0),
424 (3.0, 10.0),
425 (3.6, 11.4),
426 (5.0, 12.0),
427 (8.0, 12.0),
428 ],
429 ))
430 .min(path(
431 p,
432 &[
433 (3.0, 10.0),
434 (3.0, 16.0),
435 (3.6, 17.4),
436 (5.0, 18.0),
437 (8.0, 18.0),
438 ],
439 )),
440 Icon::ListBullet => (circle(p, (5.0, 6.5)) - 0.4)
441 .min(circle(p, (5.0, 12.0)) - 0.4)
442 .min(circle(p, (5.0, 17.5)) - 0.4)
443 .min(segment(p, (9.5, 6.5), (20.5, 6.5)))
444 .min(segment(p, (9.5, 12.0), (20.5, 12.0)))
445 .min(segment(p, (9.5, 17.5), (20.5, 17.5))),
446 Icon::ListNumber => path(p, &[(3.8, 5.2), (5.4, 4.0), (5.4, 9.5)])
447 .min(path(
448 p,
449 &[
450 (3.6, 15.0),
451 (5.0, 13.8),
452 (6.8, 14.8),
453 (3.6, 19.8),
454 (7.2, 19.8),
455 ],
456 ))
457 .min(segment(p, (10.5, 6.8), (20.5, 6.8)))
458 .min(segment(p, (10.5, 16.8), (20.5, 16.8))),
459 Icon::ListTask => rounded(p, (4.0, 4.0), (20.0, 20.0), 3.5)
460 .min(path(p, &[(8.0, 12.2), (11.0, 15.2), (16.2, 9.0)])),
461 Icon::Quote => segment(p, (4.5, 5.0), (4.5, 19.0))
462 .min(segment(p, (9.5, 7.0), (20.5, 7.0)))
463 .min(segment(p, (9.5, 12.0), (20.5, 12.0)))
464 .min(segment(p, (9.5, 17.0), (16.5, 17.0))),
465 Icon::Code => path(p, &[(8.5, 6.5), (3.0, 12.0), (8.5, 17.5)])
466 .min(path(p, &[(15.5, 6.5), (21.0, 12.0), (15.5, 17.5)])),
467 Icon::Link => rounded(p, (2.5, 8.0), (13.5, 16.0), 4.0).min(rounded(
468 p,
469 (10.5, 8.0),
470 (21.5, 16.0),
471 4.0,
472 )),
473 Icon::Table => rounded(p, (3.0, 4.5), (21.0, 19.5), 2.5)
474 .min(segment(p, (3.0, 9.5), (21.0, 9.5)))
475 .min(segment(p, (3.0, 14.5), (21.0, 14.5)))
476 .min(segment(p, (12.0, 4.5), (12.0, 19.5))),
477 Icon::Track => path(
479 p,
480 &[
481 (4.0, 16.5),
482 (15.5, 5.0),
483 (19.0, 8.5),
484 (7.5, 20.0),
485 (4.0, 20.0),
486 (4.0, 16.5),
487 ],
488 )
489 .min(path(p, &[(13.0, 20.5), (21.0, 20.5)])),
490 Icon::Diagram => rounded(p, (2.5, 3.5), (10.0, 9.5), 1.5)
491 .min(rounded(p, (14.0, 3.5), (21.5, 9.5), 1.5))
492 .min(rounded(p, (14.0, 14.5), (21.5, 20.5), 1.5))
493 .min(path(p, &[(10.0, 6.5), (14.0, 6.5)]))
494 .min(path(p, &[(6.2, 9.5), (6.2, 17.5), (14.0, 17.5)])),
495 Icon::Picture => rounded(p, (3.0, 4.5), (21.0, 19.5), 2.5)
496 .min(ring(p, (8.5, 9.8), 1.5))
497 .min(path(
498 p,
499 &[
500 (3.5, 18.0),
501 (9.5, 12.8),
502 (13.5, 16.2),
503 (16.2, 13.8),
504 (20.5, 17.5),
505 ],
506 )),
507 Icon::Sigma => path(
508 p,
509 &[
510 (18.0, 7.5),
511 (18.0, 4.5),
512 (5.5, 4.5),
513 (12.5, 12.0),
514 (5.5, 19.5),
515 (18.0, 19.5),
516 (18.0, 16.5),
517 ],
518 ),
519 Icon::Rule => segment(p, (3.0, 12.0), (21.0, 12.0))
520 .min(segment(p, (8.0, 6.5), (16.0, 6.5)))
521 .min(segment(p, (8.0, 17.5), (16.0, 17.5))),
522 Icon::Comment => rounded(p, (3.0, 4.0), (21.0, 16.5), 3.5)
523 .min(path(p, &[(8.0, 16.5), (8.0, 20.5), (12.5, 16.5)])),
524 Icon::Export => path(p, &[(12.0, 3.5), (12.0, 15.0)])
525 .min(path(p, &[(7.0, 10.5), (12.0, 15.5), (17.0, 10.5)]))
526 .min(segment(p, (4.0, 20.0), (20.0, 20.0))),
527 Icon::Play => path(p, &[(7.0, 4.5), (19.5, 12.0), (7.0, 19.5), (7.0, 4.5)]),
528 Icon::PlayAll => path(p, &[(3.0, 5.5), (12.0, 12.0), (3.0, 18.5), (3.0, 5.5)]).min(path(
529 p,
530 &[(12.0, 5.5), (21.0, 12.0), (12.0, 18.5), (12.0, 5.5)],
531 )),
532 Icon::Stop => rounded(p, (6.0, 6.0), (18.0, 18.0), 1.5),
533 Icon::Restart => {
534 let angle = (p.1 - 12.0).atan2(p.0 - 12.0);
536 let gap = angle > -1.1 && angle < 0.1;
537 let arc = if gap {
538 f32::MAX
539 } else {
540 ring(p, (12.0, 12.0), 7.5)
541 };
542 arc.min(path(p, &[(19.5, 4.0), (19.5, 10.0), (13.8, 10.0)]))
543 }
544 Icon::AddCell => rounded(p, (3.0, 6.0), (21.0, 18.0), 2.0)
545 .min(segment(p, (12.0, 9.0), (12.0, 15.0)))
546 .min(segment(p, (9.0, 12.0), (15.0, 12.0))),
547 Icon::AddText => segment(p, (3.0, 6.0), (21.0, 6.0))
548 .min(segment(p, (3.0, 11.0), (13.0, 11.0)))
549 .min(segment(p, (3.0, 16.0), (10.0, 16.0)))
550 .min(segment(p, (18.0, 13.0), (18.0, 21.0)))
551 .min(segment(p, (14.0, 17.0), (22.0, 17.0))),
552 Icon::Cite => path(p, &[(9.0, 4.5), (5.5, 4.5), (5.5, 19.5), (9.0, 19.5)])
553 .min(path(
554 p,
555 &[(15.0, 4.5), (18.5, 4.5), (18.5, 19.5), (15.0, 19.5)],
556 ))
557 .min(segment(p, (12.0, 9.0), (12.0, 15.0))),
558 Icon::More => (circle(p, (5.0, 12.0)) - 0.5)
559 .min(circle(p, (12.0, 12.0)) - 0.5)
560 .min(circle(p, (19.0, 12.0)) - 0.5),
561 Icon::ChevronRight => path(p, &[(9.5, 6.5), (15.0, 12.0), (9.5, 17.5)]),
562 Icon::ChevronDown => path(p, &[(6.5, 9.5), (12.0, 15.0), (17.5, 9.5)]),
563 Icon::Close => {
564 segment(p, (6.5, 6.5), (17.5, 17.5)).min(segment(p, (17.5, 6.5), (6.5, 17.5)))
565 }
566 Icon::Replace => replace(p),
567 Icon::ArrowUp => path(p, &[(5.0, 12.0), (12.0, 5.0), (19.0, 12.0)]).min(segment(
568 p,
569 (12.0, 5.0),
570 (12.0, 19.0),
571 )),
572 Icon::ArrowDown => path(p, &[(19.0, 12.0), (12.0, 19.0), (5.0, 12.0)]).min(segment(
573 p,
574 (12.0, 5.0),
575 (12.0, 19.0),
576 )),
577 Icon::ReplaceAll => replace(p)
578 .min(path(
579 p,
580 &[
581 (14.0, 14.0),
582 (15.4, 14.6),
583 (16.0, 16.0),
584 (16.0, 20.0),
585 (15.4, 21.4),
586 (14.0, 22.0),
587 ],
588 ))
589 .min(path(
590 p,
591 &[
592 (20.0, 14.0),
593 (21.4, 14.6),
594 (22.0, 16.0),
595 (22.0, 20.0),
596 (21.4, 21.4),
597 (20.0, 22.0),
598 ],
599 )),
600 Icon::Check => path(p, &[(4.5, 12.5), (9.5, 17.5), (19.5, 6.5)]),
601 Icon::HidePane => rounded(p, (3.0, 3.0), (21.0, 21.0), 2.0)
603 .min(segment(p, (15.0, 3.0), (15.0, 21.0)))
604 .min(solid(p, (15.0, 3.0), (21.0, 21.0), 2.0)),
605 Icon::HidePanel => rounded(p, (3.0, 3.0), (21.0, 21.0), 2.0)
606 .min(segment(p, (3.0, 15.0), (21.0, 15.0)))
607 .min(solid(p, (3.0, 15.0), (21.0, 21.0), 2.0)),
608 Icon::ShowPane => {
609 rounded(p, (3.0, 3.0), (21.0, 21.0), 2.0).min(segment(p, (15.0, 3.0), (15.0, 21.0)))
610 }
611 Icon::Maximize => path(p, &[(15.0, 3.0), (21.0, 3.0), (21.0, 9.0)])
612 .min(path(p, &[(9.0, 21.0), (3.0, 21.0), (3.0, 15.0)]))
613 .min(segment(p, (21.0, 3.0), (14.0, 10.0)))
614 .min(segment(p, (3.0, 21.0), (10.0, 14.0))),
615 Icon::Minimize => path(p, &[(4.0, 14.0), (10.0, 14.0), (10.0, 20.0)])
616 .min(path(p, &[(20.0, 10.0), (14.0, 10.0), (14.0, 4.0)]))
617 .min(segment(p, (14.0, 10.0), (21.0, 3.0)))
618 .min(segment(p, (3.0, 21.0), (10.0, 14.0))),
619 Icon::SymbolFunction => path(
621 p,
622 &[
623 (12.0, 2.5),
624 (20.5, 7.2),
625 (20.5, 16.8),
626 (12.0, 21.5),
627 (3.5, 16.8),
628 (3.5, 7.2),
629 (12.0, 2.5),
630 ],
631 )
632 .min(path(p, &[(3.8, 7.3), (12.0, 12.0), (20.2, 7.3)]))
633 .min(segment(p, (12.0, 12.0), (12.0, 21.5))),
634 Icon::SymbolType => path(
635 p,
636 &[
637 (8.5, 3.0),
638 (7.0, 3.0),
639 (5.5, 4.5),
640 (5.5, 10.0),
641 (3.5, 12.0),
642 (5.5, 14.0),
643 (5.5, 19.5),
644 (7.0, 21.0),
645 (8.5, 21.0),
646 ],
647 )
648 .min(path(
649 p,
650 &[
651 (15.5, 3.0),
652 (17.0, 3.0),
653 (18.5, 4.5),
654 (18.5, 10.0),
655 (20.5, 12.0),
656 (18.5, 14.0),
657 (18.5, 19.5),
658 (17.0, 21.0),
659 (15.5, 21.0),
660 ],
661 )),
662 Icon::SymbolField => {
663 rounded(p, (3.0, 7.5), (21.0, 16.5), 2.5).min(segment(p, (7.0, 12.0), (12.0, 12.0)))
664 }
665 Icon::SymbolValue => {
666 segment(p, (4.5, 9.0), (19.5, 9.0)).min(segment(p, (4.5, 15.0), (19.5, 15.0)))
667 }
668 Icon::Terminal => path(p, &[(3.5, 6.0), (10.0, 12.0), (3.5, 18.0)]).min(segment(
669 p,
670 (12.5, 18.0),
671 (20.5, 18.0),
672 )),
673 Icon::Panel => {
674 rounded(p, (3.0, 3.0), (21.0, 21.0), 4.0).min(segment(p, (3.0, 15.0), (21.0, 15.0)))
675 }
676 Icon::Diff => rounded(p, (3.0, 3.0), (21.0, 21.0), 4.0)
677 .min(segment(p, (12.0, 6.5), (12.0, 12.5)))
678 .min(segment(p, (9.0, 9.5), (15.0, 9.5)))
679 .min(segment(p, (9.0, 16.5), (15.0, 16.5))),
680 Icon::Bell => {
682 let dome = if p.1 <= 9.0 {
683 ring(p, (12.0, 9.0), 6.0)
684 } else {
685 f32::MAX
686 };
687 dome.min(path(
688 p,
689 &[(6.0, 9.0), (6.0, 12.5), (5.2, 15.4), (3.2, 17.5)],
690 ))
691 .min(path(
692 p,
693 &[(18.0, 9.0), (18.0, 12.5), (18.8, 15.4), (20.8, 17.5)],
694 ))
695 .min(segment(p, (3.2, 17.5), (20.8, 17.5)))
696 .min(path(p, &[(10.2, 20.8), (12.0, 21.8), (13.8, 20.8)]))
697 }
698 Icon::Question => ring(p, (12.0, 12.0), 9.5)
699 .min(path(
700 p,
701 &[
702 (9.3, 9.2),
703 (10.1, 7.6),
704 (12.0, 7.0),
705 (14.0, 7.7),
706 (14.8, 9.4),
707 (14.0, 11.0),
708 (12.0, 12.2),
709 (12.0, 13.6),
710 ],
711 ))
712 .min(circle(p, (12.0, 17.0)) - 0.4),
713 Icon::CircleCheck => {
714 ring(p, (12.0, 12.0), 9.5).min(path(p, &[(8.0, 12.3), (10.8, 15.0), (16.0, 9.5)]))
715 }
716 Icon::Smile => ring(p, (12.0, 12.0), 9.5)
717 .min(circle(p, (9.0, 9.6)) - 0.35)
718 .min(circle(p, (15.0, 9.6)) - 0.35)
719 .min(path(
720 p,
721 &[
722 (8.0, 14.0),
723 (9.6, 15.5),
724 (12.0, 16.1),
725 (14.4, 15.5),
726 (16.0, 14.0),
727 ],
728 )),
729 Icon::CircleX => ring(p, (12.0, 12.0), 9.5)
730 .min(segment(p, (8.8, 8.8), (15.2, 15.2)))
731 .min(segment(p, (15.2, 8.8), (8.8, 15.2))),
732 Icon::Globe => {
733 let (x, y) = ((p.0 - 12.0) / 4.5, (p.1 - 12.0) / 9.5);
734 let meridian = ((x * x + y * y).sqrt() - 1.0).abs() * 4.5;
735 ring(p, (12.0, 12.0), 9.5)
736 .min(meridian)
737 .min(segment(p, (2.5, 12.0), (21.5, 12.0)))
738 }
739 };
740 distance < half_stroke(icon)
741}
742
743#[cfg(test)]
744mod tests {
745 use super::*;
746
747 #[test]
748 fn pieces_survive_the_grid() {
749 for icon in [
750 Icon::Files,
751 Icon::Search,
752 Icon::Git,
753 Icon::Settings,
754 Icon::Layers,
755 ] {
756 let piece = Piece {
757 icon,
758 width: 3,
759 height: 2,
760 column: 2,
761 row: 1,
762 };
763 let text = piece.symbol().to_string();
764 assert_eq!(Piece::decode(&text), Some(piece));
765 }
766 assert_eq!(Piece::decode("a"), None);
767 }
768
769 #[test]
770 fn every_icon_has_ink() {
771 for icon in [
772 Icon::Files,
773 Icon::Search,
774 Icon::Git,
775 Icon::Settings,
776 Icon::Agents,
777 Icon::Layers,
778 Icon::Folder,
779 Icon::File,
780 Icon::Maximize,
781 Icon::Minimize,
782 Icon::Panel,
783 Icon::SymbolFunction,
784 Icon::SymbolType,
785 Icon::SymbolField,
786 Icon::SymbolValue,
787 Icon::Bell,
788 Icon::Question,
789 Icon::CircleCheck,
790 Icon::CircleX,
791 Icon::HidePane,
792 Icon::HidePanel,
793 Icon::ShowPane,
794 Icon::Smile,
795 ] {
796 let dots = (0..50)
797 .flat_map(|y| (0..50).map(move |x| (x, y)))
798 .filter(|(x, y)| inked(icon, *x as f32 / 50.0, *y as f32 / 50.0))
799 .count();
800 assert!(dots > 150, "{icon:?} has {dots}");
801 }
802 }
803}