Files
loop/src/Bound.hs
T

27 lines
695 B
Haskell

module Bound (boundPoints
,boundPointsRect) where
import qualified Control.Foldl as L
import Control.Lens
import Geometry
---- NSEW
boundPoints :: [Point2] -> Maybe (Float, Float, Float, Float)
{-# INLINE boundPoints #-}
boundPoints =
f
. L.fold
( (,,,)
<$> L.premap (^?! _2) L.maximum
<*> L.premap (^?! _2) L.minimum
<*> L.premap (^?! _1) L.maximum
<*> L.premap (^?! _1) L.minimum
)
where
f (mn, ms, me, mw) = (,,,) <$> mn <*> ms <*> me <*> mw
boundPointsRect :: [Point2] -> Maybe (Point2,Point2)
boundPointsRect ps = do
(n,s,e,w) <- boundPoints ps
return (V2 w s, V2 e n)