-- | Normalize coords of given vectors to fit [0 .. 1] range and return info
-- how to denormalize them back.
normVecs :: Vector (V2 Float) -> (V2 Float -> V2 Float, Vector (V2 Float))
normVecs vs = (\v -> v * dv + minv, (\v -> (v - minv) / dv) <$> vs)
  where
  minx = minimum . fmap (^. _x) $ vs
  miny = minimum . fmap (^. _y) $ vs
  minv = V2 minx miny

  maxx = maximum . fmap (^. _x) $ vs
  maxy = maximum . fmap (^. _y) $ vs
  maxv = V2 maxx maxy

  dv = fmap (\v -> if v `approxEq` 0 then 1.0 else v) $ maxv - minv
normVecs :: Vector (V2 Float) -> (V2 Float -> V2 Float, Vector (V2 Float))
normVecs vs = (\v -> v * dv + minv, (\v -> (v - minv) / dv) <$> vs)
  where
  minx = minimum . fmap (^. _x) $ vs
  miny = minimum . fmap (^. _y) $ vs
  minv = V2 minx miny

  maxx = maximum . fmap (^. _x) $ vs
  maxy = maximum . fmap (^. _y) $ vs
  maxv = V2 maxx maxy

  dv = fmap (\v -> if v `approxEq` 0 then 1.0 else v) $ maxv - minv
normVecs vs = (\v -> v * dv + minv, (\v -> (v - minv) / dv) <$> vs)
  where
  minx = minimum . fmap (^. _x) $ vs
  miny = minimum . fmap (^. _y) $ vs
  minv = V2 minx miny

  maxx = maximum . fmap (^. _x) $ vs
  maxy = maximum . fmap (^. _y) $ vs
  maxv = V2 maxx maxy

  dv = fmap (\v -> if v `approxEq` 0 then 1.0 else v) $ maxv - minv