module Bound where import Geometry import Control.Lens import Streaming import qualified Streaming.Prelude as S import qualified Control.Foldl as L boundPoints :: Stream (Of Point2) Identity () -> Maybe (Float,Float,Float,Float) {-# INLINE boundPoints #-} boundPoints = f . runIdentity . L.purely S.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