{-# 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.Rekognition.Types.BoundingBox
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Rekognition.Types.BoundingBox where

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

-- | Identifies the bounding box around the label, face, text or personal
-- protective equipment. The @left@ (x-coordinate) and @top@ (y-coordinate)
-- are coordinates representing the top and left sides of the bounding box.
-- Note that the upper-left corner of the image is the origin (0,0).
--
-- The @top@ and @left@ values returned are ratios of the overall image
-- size. For example, if the input image is 700x200 pixels, and the
-- top-left coordinate of the bounding box is 350x50 pixels, the API
-- returns a @left@ value of 0.5 (350\/700) and a @top@ value of 0.25
-- (50\/200).
--
-- The @width@ and @height@ values represent the dimensions of the bounding
-- box as a ratio of the overall image dimension. For example, if the input
-- image is 700x200 pixels, and the bounding box width is 70 pixels, the
-- width returned is 0.1.
--
-- The bounding box coordinates can have negative values. For example, if
-- Amazon Rekognition is able to detect a face that is at the image edge
-- and is only partially visible, the service can return coordinates that
-- are outside the image bounds and, depending on the image edge, you might
-- get negative values or values greater than 1 for the @left@ or @top@
-- values.
--
-- /See:/ 'newBoundingBox' smart constructor.
data BoundingBox = BoundingBox'
  { -- | Height of the bounding box as a ratio of the overall image height.
    BoundingBox -> Maybe Double
height :: Prelude.Maybe Prelude.Double,
    -- | Left coordinate of the bounding box as a ratio of overall image width.
    BoundingBox -> Maybe Double
left :: Prelude.Maybe Prelude.Double,
    -- | Width of the bounding box as a ratio of the overall image width.
    BoundingBox -> Maybe Double
width :: Prelude.Maybe Prelude.Double,
    -- | Top coordinate of the bounding box as a ratio of overall image height.
    BoundingBox -> Maybe Double
top :: Prelude.Maybe Prelude.Double
  }
  deriving (BoundingBox -> BoundingBox -> Bool
(BoundingBox -> BoundingBox -> Bool)
-> (BoundingBox -> BoundingBox -> Bool) -> Eq BoundingBox
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]
(Int -> ReadS BoundingBox)
-> ReadS [BoundingBox]
-> ReadPrec BoundingBox
-> ReadPrec [BoundingBox]
-> Read 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
(Int -> BoundingBox -> ShowS)
-> (BoundingBox -> String)
-> ([BoundingBox] -> ShowS)
-> Show BoundingBox
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. BoundingBox -> Rep BoundingBox x)
-> (forall x. Rep BoundingBox x -> BoundingBox)
-> Generic BoundingBox
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' - Height of the bounding box as a ratio of the overall image height.
--
-- 'left', 'boundingBox_left' - Left coordinate of the bounding box as a ratio of overall image width.
--
-- 'width', 'boundingBox_width' - Width of the bounding box as a ratio of the overall image width.
--
-- 'top', 'boundingBox_top' - Top coordinate of the bounding box as a ratio of overall image height.
newBoundingBox ::
  BoundingBox
newBoundingBox :: BoundingBox
newBoundingBox =
  BoundingBox' :: Maybe Double
-> Maybe Double -> Maybe Double -> Maybe Double -> BoundingBox
BoundingBox'
    { $sel:height:BoundingBox' :: Maybe Double
height = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:left:BoundingBox' :: Maybe Double
left = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:width:BoundingBox' :: Maybe Double
width = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:top:BoundingBox' :: Maybe Double
top = Maybe Double
forall a. Maybe a
Prelude.Nothing
    }

-- | Height of the bounding box as a ratio of the overall image height.
boundingBox_height :: Lens.Lens' BoundingBox (Prelude.Maybe Prelude.Double)
boundingBox_height :: (Maybe Double -> f (Maybe Double)) -> BoundingBox -> f BoundingBox
boundingBox_height = (BoundingBox -> Maybe Double)
-> (BoundingBox -> Maybe Double -> BoundingBox)
-> Lens BoundingBox BoundingBox (Maybe Double) (Maybe Double)
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)

-- | Left coordinate of the bounding box as a ratio of overall image width.
boundingBox_left :: Lens.Lens' BoundingBox (Prelude.Maybe Prelude.Double)
boundingBox_left :: (Maybe Double -> f (Maybe Double)) -> BoundingBox -> f BoundingBox
boundingBox_left = (BoundingBox -> Maybe Double)
-> (BoundingBox -> Maybe Double -> BoundingBox)
-> Lens BoundingBox BoundingBox (Maybe Double) (Maybe Double)
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)

-- | Width of the bounding box as a ratio of the overall image width.
boundingBox_width :: Lens.Lens' BoundingBox (Prelude.Maybe Prelude.Double)
boundingBox_width :: (Maybe Double -> f (Maybe Double)) -> BoundingBox -> f BoundingBox
boundingBox_width = (BoundingBox -> Maybe Double)
-> (BoundingBox -> Maybe Double -> BoundingBox)
-> Lens BoundingBox BoundingBox (Maybe Double) (Maybe Double)
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)

-- | Top coordinate of the bounding box as a ratio of overall image height.
boundingBox_top :: Lens.Lens' BoundingBox (Prelude.Maybe Prelude.Double)
boundingBox_top :: (Maybe Double -> f (Maybe Double)) -> BoundingBox -> f BoundingBox
boundingBox_top = (BoundingBox -> Maybe Double)
-> (BoundingBox -> Maybe Double -> BoundingBox)
-> Lens BoundingBox BoundingBox (Maybe Double) (Maybe Double)
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)

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

instance Prelude.Hashable BoundingBox

instance Prelude.NFData BoundingBox

instance Core.ToJSON BoundingBox where
  toJSON :: BoundingBox -> Value
toJSON BoundingBox' {Maybe Double
top :: Maybe Double
width :: Maybe Double
left :: Maybe Double
height :: Maybe Double
$sel:top:BoundingBox' :: BoundingBox -> Maybe Double
$sel:width:BoundingBox' :: BoundingBox -> Maybe Double
$sel:left:BoundingBox' :: BoundingBox -> Maybe Double
$sel:height:BoundingBox' :: BoundingBox -> Maybe Double
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Height" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
height,
            (Text
"Left" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
left,
            (Text
"Width" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
width,
            (Text
"Top" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
top
          ]
      )