{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies     #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  Diagrams.ThreeD.Size
-- Copyright   :  (c) 2014 diagrams-lib team (see LICENSE)
-- License     :  BSD-style (see LICENSE)
-- Maintainer  :  diagrams-discuss@googlegroups.com
--
-- Utilities for working with sizes of three-dimensional objects.
--
-----------------------------------------------------------------------------
module Diagrams.ThreeD.Size
       (
         -- ** Computing sizes
         extentX, extentY, extentZ

         -- ** Specifying sizes
       , mkSizeSpec3D
       , dims3D

       ) where

import           Diagrams.Core
import           Diagrams.Core.Envelope
import           Diagrams.Size
import           Diagrams.TwoD.Size
import           Diagrams.ThreeD.Types
import           Diagrams.ThreeD.Vector

------------------------------------------------------------
-- Computing diagram sizes
------------------------------------------------------------

-- | Compute the absolute z-coordinate range of an enveloped object in
--   the form @(lo,hi)@. Return @Nothing@ for objects with an empty
--   envelope.
extentZ :: (InSpace v n a, R3 v, Enveloped a) => a -> Maybe (n, n)
extentZ :: a -> Maybe (n, n)
extentZ = v n -> a -> Maybe (n, n)
forall a (v :: * -> *) n.
(V a ~ v, N a ~ n, Enveloped a) =>
v n -> a -> Maybe (n, n)
extent v n
forall (v :: * -> *) n. (R3 v, Additive v, Num n) => v n
unitZ

-- | Make a 'SizeSpec' from possibly-specified width and height.
mkSizeSpec3D :: Num n => Maybe n -> Maybe n -> Maybe n -> SizeSpec V3 n
mkSizeSpec3D :: Maybe n -> Maybe n -> Maybe n -> SizeSpec V3 n
mkSizeSpec3D Maybe n
x Maybe n
y Maybe n
z = V3 (Maybe n) -> SizeSpec V3 n
forall (v :: * -> *) n.
(Functor v, Num n) =>
v (Maybe n) -> SizeSpec v n
mkSizeSpec (Maybe n -> Maybe n -> Maybe n -> V3 (Maybe n)
forall a. a -> a -> a -> V3 a
V3 Maybe n
x Maybe n
y Maybe n
z)

-- | Make a 'SizeSpec' from a width and height.
dims3D :: n -> n -> n -> SizeSpec V3 n
dims3D :: n -> n -> n -> SizeSpec V3 n
dims3D n
x n
y n
z = V3 n -> SizeSpec V3 n
forall (v :: * -> *) n. v n -> SizeSpec v n
dims (n -> n -> n -> V3 n
forall a. a -> a -> a -> V3 a
V3 n
x n
y n
z)