0 | module Geom.Interpolate
 1 |
 2 | import Geom
 3 | import Data.Fin
 4 |
 5 | %default total
 6 |
 7 | export
 8 | round : Nat -> Double -> Double
 9 | round n d =
10 |  let f := pow 10 (cast n)
11 |      dd := f*d
12 |      df := floor dd
13 |      dc := ceiling dd
14 |   in if dd - df < dc - dd then df/f else dc/f
15 |
16 | export
17 | Interpolation Angle where
18 |   interpolate a = "\{show $ round 1 $ toDegree a}°"
19 |
20 | export
21 | Interpolation Double where
22 |   interpolate = show . round 3
23 |
24 | export
25 | Interpolation (Point t) where
26 |   interpolate (P x y) = "x: \{x}, y: \{y}"
27 |
28 | export
29 | Interpolation (Vector t) where
30 |   interpolate (V x y) = "vx: \{x}, vy: \{y}"
31 |
32 | export
33 | Interpolation (Fin k) where
34 |   interpolate = show
35 |
36 | export
37 | Interpolation (List $ Fin k) where
38 |   interpolate = show
39 |
40 | export
41 | Interpolation Bounds where
42 |   interpolate = maybe "[]" (\p => "[\{fst p}, \{snd p}]") . getBounds
43 |
44 | export
45 | Interpolation (Bounds2D t) where
46 |   interpolate (BS x y) = "x: \{x}, y: \{y}"
47 |