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