1use std::ops::{Add, Div, Mul, Range, Sub};
2
3pub mod app;
4pub mod demo;
5pub mod graphics;
6
7pub fn map<T>(x: T, input_range: Range<T>, output_range: Range<T>) -> T
8where
9 T: Copy
10 + Sub<Output = T>
11 + Add<Output = T>
12 + Div<Output = T>
13 + Mul<Output = T>,
14{
15 let (u, v) = (input_range.start, input_range.end);
16 let (s, t) = (output_range.start, output_range.end);
17 let m = (s - t) / (u - v);
18 let b = (t * u - v * s) / (u - v);
19 x * m + b
20}
21
22#[macro_export]
25macro_rules! here {
26 () => {
27 $crate::app::Location {
28 file: file!(),
29 line: line!(),
30 col: column!(),
31 }
32 };
33}
34
35#[macro_export]
39macro_rules! unwrap_here {
40 ($description:expr, $operation:expr) => {{
41 use {anyhow::Context, $crate::here};
42 { $operation }
43 .with_context(|| format!("{} - {}", here!(), $description))?
44 }};
45}