{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Comprehend.Types.BoundingBox
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Comprehend.Types.BoundingBox where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | The bounding box around the detected page or around an element on a
-- document page. The left (x-coordinate) and top (y-coordinate) are
-- coordinates that represent the top and left sides of the bounding box.
-- Note that the upper-left corner of the image is the origin (0,0).
--
-- For additional information, see
-- <https://docs.aws.amazon.com/textract/latest/dg/API_BoundingBox.html BoundingBox>
-- in the Amazon Textract API reference.
--
-- /See:/ 'newBoundingBox' smart constructor.
data BoundingBox = BoundingBox'
  { -- | The height of the bounding box as a ratio of the overall document page
    -- height.
    BoundingBox -> Maybe Double
height :: Prelude.Maybe Prelude.Double,
    -- | The left coordinate of the bounding box as a ratio of overall document
    -- page width.
    BoundingBox -> Maybe Double
left :: Prelude.Maybe Prelude.Double,
    -- | The top coordinate of the bounding box as a ratio of overall document
    -- page height.
    BoundingBox -> Maybe Double
top :: Prelude.Maybe Prelude.Double,
    -- | The width of the bounding box as a ratio of the overall document page
    -- width.
    BoundingBox -> Maybe Double
width :: Prelude.Maybe Prelude.Double
  }
  deriving (BoundingBox -> BoundingBox -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BoundingBox -> BoundingBox -> Bool
$c/= :: BoundingBox -> BoundingBox -> Bool
== :: BoundingBox -> BoundingBox -> Bool
$c== :: BoundingBox -> BoundingBox -> Bool
Prelude.Eq, ReadPrec [BoundingBox]
ReadPrec BoundingBox
Int -> ReadS BoundingBox
ReadS [BoundingBox]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BoundingBox]
$creadListPrec :: ReadPrec [BoundingBox]
readPrec :: ReadPrec BoundingBox
$creadPrec :: ReadPrec BoundingBox
readList :: ReadS [BoundingBox]
$creadList :: ReadS [BoundingBox]
readsPrec :: Int -> ReadS BoundingBox
$creadsPrec :: Int -> ReadS BoundingBox
Prelude.Read, Int -> BoundingBox -> ShowS
[BoundingBox] -> ShowS
BoundingBox -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BoundingBox] -> ShowS
$cshowList :: [BoundingBox] -> ShowS
show :: BoundingBox -> String
$cshow :: BoundingBox -> String
showsPrec :: Int -> BoundingBox -> ShowS
$cshowsPrec :: Int -> BoundingBox -> ShowS
Prelude.Show, forall x. Rep BoundingBox x -> BoundingBox
forall x. BoundingBox -> Rep BoundingBox x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BoundingBox x -> BoundingBox
$cfrom :: forall x. BoundingBox -> Rep BoundingBox x
Prelude.Generic)

-- |
-- Create a value of 'BoundingBox' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'height', 'boundingBox_height' - The height of the bounding box as a ratio of the overall document page
-- height.
--
-- 'left', 'boundingBox_left' - The left coordinate of the bounding box as a ratio of overall document
-- page width.
--
-- 'top', 'boundingBox_top' - The top coordinate of the bounding box as a ratio of overall document
-- page height.
--
-- 'width', 'boundingBox_width' - The width of the bounding box as a ratio of the overall document page
-- width.
newBoundingBox ::
  BoundingBox
newBoundingBox :: BoundingBox
newBoundingBox =
  BoundingBox'
    { $sel:height:BoundingBox' :: Maybe Double
height = forall a. Maybe a
Prelude.Nothing,
      $sel:left:BoundingBox' :: Maybe Double
left = forall a. Maybe a
Prelude.Nothing,
      $sel:top:BoundingBox' :: Maybe Double
top = forall a. Maybe a
Prelude.Nothing,
      $sel:width:BoundingBox' :: Maybe Double
width = forall a. Maybe a
Prelude.Nothing
    }

-- | The height of the bounding box as a ratio of the overall document page
-- height.
boundingBox_height :: Lens.Lens' BoundingBox (Prelude.Maybe Prelude.Double)
boundingBox_height :: Lens' BoundingBox (Maybe Double)
boundingBox_height = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BoundingBox' {Maybe Double
height :: Maybe Double
$sel:height:BoundingBox' :: BoundingBox -> Maybe Double
height} -> Maybe Double
height) (\s :: BoundingBox
s@BoundingBox' {} Maybe Double
a -> BoundingBox
s {$sel:height:BoundingBox' :: Maybe Double
height = Maybe Double
a} :: BoundingBox)

-- | The left coordinate of the bounding box as a ratio of overall document
-- page width.
boundingBox_left :: Lens.Lens' BoundingBox (Prelude.Maybe Prelude.Double)
boundingBox_left :: Lens' BoundingBox (Maybe Double)
boundingBox_left = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BoundingBox' {Maybe Double
left :: Maybe Double
$sel:left:BoundingBox' :: BoundingBox -> Maybe Double
left} -> Maybe Double
left) (\s :: BoundingBox
s@BoundingBox' {} Maybe Double
a -> BoundingBox
s {$sel:left:BoundingBox' :: Maybe Double
left = Maybe Double
a} :: BoundingBox)

-- | The top coordinate of the bounding box as a ratio of overall document
-- page height.
boundingBox_top :: Lens.Lens' BoundingBox (Prelude.Maybe Prelude.Double)
boundingBox_top :: Lens' BoundingBox (Maybe Double)
boundingBox_top = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BoundingBox' {Maybe Double
top :: Maybe Double
$sel:top:BoundingBox' :: BoundingBox -> Maybe Double
top} -> Maybe Double
top) (\s :: BoundingBox
s@BoundingBox' {} Maybe Double
a -> BoundingBox
s {$sel:top:BoundingBox' :: Maybe Double
top = Maybe Double
a} :: BoundingBox)

-- | The width of the bounding box as a ratio of the overall document page
-- width.
boundingBox_width :: Lens.Lens' BoundingBox (Prelude.Maybe Prelude.Double)
boundingBox_width :: Lens' BoundingBox (Maybe Double)
boundingBox_width = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BoundingBox' {Maybe Double
width :: Maybe Double
$sel:width:BoundingBox' :: BoundingBox -> Maybe Double
width} -> Maybe Double
width) (\s :: BoundingBox
s@BoundingBox' {} Maybe Double
a -> BoundingBox
s {$sel:width:BoundingBox' :: Maybe Double
width = Maybe Double
a} :: BoundingBox)

instance Data.FromJSON BoundingBox where
  parseJSON :: Value -> Parser BoundingBox
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"BoundingBox"
      ( \Object
x ->
          Maybe Double
-> Maybe Double -> Maybe Double -> Maybe Double -> BoundingBox
BoundingBox'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Height")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Left")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Top")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Width")
      )

instance Prelude.Hashable BoundingBox where
  hashWithSalt :: Int -> BoundingBox -> Int
hashWithSalt Int
_salt BoundingBox' {Maybe Double
width :: Maybe Double
top :: Maybe Double
left :: Maybe Double
height :: Maybe Double
$sel:width:BoundingBox' :: BoundingBox -> Maybe Double
$sel:top:BoundingBox' :: BoundingBox -> Maybe Double
$sel:left:BoundingBox' :: BoundingBox -> Maybe Double
$sel:height:BoundingBox' :: BoundingBox -> Maybe Double
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
height
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
left
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
top
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
width

instance Prelude.NFData BoundingBox where
  rnf :: BoundingBox -> ()
rnf BoundingBox' {Maybe Double
width :: Maybe Double
top :: Maybe Double
left :: Maybe Double
height :: Maybe Double
$sel:width:BoundingBox' :: BoundingBox -> Maybe Double
$sel:top:BoundingBox' :: BoundingBox -> Maybe Double
$sel:left:BoundingBox' :: BoundingBox -> Maybe Double
$sel:height:BoundingBox' :: BoundingBox -> Maybe Double
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
height
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
left
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
top
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
width