packages feed

balkon-1.2.0.0: src/Data/Text/ParagraphLayout/Internal/ParagraphExtents.hs

module Data.Text.ParagraphLayout.Internal.ParagraphExtents
    ( paragraphOriginX
    , paragraphOriginY
    , containRects
    , emptyRect
    )
where

import Data.Maybe (fromMaybe)

import Data.Text.ParagraphLayout.Internal.Rect

-- | X coordinate used as the left edge of every paragraph.
paragraphOriginX :: (Num a) => a
paragraphOriginX = 0

-- | Y coordinate used as the top edge of every paragraph.
paragraphOriginY :: (Num a) => a
paragraphOriginY = 0

-- | A `Rect` located at the top left corner of a paragraph,
-- with zero size in each dimension.
emptyRect :: (Num a) => Rect a
emptyRect = Rect
    { x_origin = paragraphOriginX
    , y_origin = paragraphOriginY
    , x_size = 0
    , y_size = 0
    }

-- | Smallest rectangle containing the given rectangles,
-- or `emptyRect` if none are given.
containRects :: (Num a, Ord a) => [Rect a] -> Rect a
containRects rects = fromMaybe emptyRect $ unionMany LH rects