{-# 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.Geometry
-- 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.Rekognition.Types.Geometry 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
import Amazonka.Rekognition.Types.BoundingBox
import Amazonka.Rekognition.Types.Point

-- | Information about where an object (DetectCustomLabels) or text
-- (DetectText) is located on an image.
--
-- /See:/ 'newGeometry' smart constructor.
data Geometry = Geometry'
  { -- | An axis-aligned coarse representation of the detected item\'s location
    -- on the image.
    Geometry -> Maybe BoundingBox
boundingBox :: Prelude.Maybe BoundingBox,
    -- | Within the bounding box, a fine-grained polygon around the detected
    -- item.
    Geometry -> Maybe [Point]
polygon :: Prelude.Maybe [Point]
  }
  deriving (Geometry -> Geometry -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Geometry -> Geometry -> Bool
$c/= :: Geometry -> Geometry -> Bool
== :: Geometry -> Geometry -> Bool
$c== :: Geometry -> Geometry -> Bool
Prelude.Eq, ReadPrec [Geometry]
ReadPrec Geometry
Int -> ReadS Geometry
ReadS [Geometry]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Geometry]
$creadListPrec :: ReadPrec [Geometry]
readPrec :: ReadPrec Geometry
$creadPrec :: ReadPrec Geometry
readList :: ReadS [Geometry]
$creadList :: ReadS [Geometry]
readsPrec :: Int -> ReadS Geometry
$creadsPrec :: Int -> ReadS Geometry
Prelude.Read, Int -> Geometry -> ShowS
[Geometry] -> ShowS
Geometry -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Geometry] -> ShowS
$cshowList :: [Geometry] -> ShowS
show :: Geometry -> String
$cshow :: Geometry -> String
showsPrec :: Int -> Geometry -> ShowS
$cshowsPrec :: Int -> Geometry -> ShowS
Prelude.Show, forall x. Rep Geometry x -> Geometry
forall x. Geometry -> Rep Geometry x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Geometry x -> Geometry
$cfrom :: forall x. Geometry -> Rep Geometry x
Prelude.Generic)

-- |
-- Create a value of 'Geometry' 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:
--
-- 'boundingBox', 'geometry_boundingBox' - An axis-aligned coarse representation of the detected item\'s location
-- on the image.
--
-- 'polygon', 'geometry_polygon' - Within the bounding box, a fine-grained polygon around the detected
-- item.
newGeometry ::
  Geometry
newGeometry :: Geometry
newGeometry =
  Geometry'
    { $sel:boundingBox:Geometry' :: Maybe BoundingBox
boundingBox = forall a. Maybe a
Prelude.Nothing,
      $sel:polygon:Geometry' :: Maybe [Point]
polygon = forall a. Maybe a
Prelude.Nothing
    }

-- | An axis-aligned coarse representation of the detected item\'s location
-- on the image.
geometry_boundingBox :: Lens.Lens' Geometry (Prelude.Maybe BoundingBox)
geometry_boundingBox :: Lens' Geometry (Maybe BoundingBox)
geometry_boundingBox = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Geometry' {Maybe BoundingBox
boundingBox :: Maybe BoundingBox
$sel:boundingBox:Geometry' :: Geometry -> Maybe BoundingBox
boundingBox} -> Maybe BoundingBox
boundingBox) (\s :: Geometry
s@Geometry' {} Maybe BoundingBox
a -> Geometry
s {$sel:boundingBox:Geometry' :: Maybe BoundingBox
boundingBox = Maybe BoundingBox
a} :: Geometry)

-- | Within the bounding box, a fine-grained polygon around the detected
-- item.
geometry_polygon :: Lens.Lens' Geometry (Prelude.Maybe [Point])
geometry_polygon :: Lens' Geometry (Maybe [Point])
geometry_polygon = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Geometry' {Maybe [Point]
polygon :: Maybe [Point]
$sel:polygon:Geometry' :: Geometry -> Maybe [Point]
polygon} -> Maybe [Point]
polygon) (\s :: Geometry
s@Geometry' {} Maybe [Point]
a -> Geometry
s {$sel:polygon:Geometry' :: Maybe [Point]
polygon = Maybe [Point]
a} :: Geometry) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON Geometry where
  parseJSON :: Value -> Parser Geometry
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Geometry"
      ( \Object
x ->
          Maybe BoundingBox -> Maybe [Point] -> Geometry
Geometry'
            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
"BoundingBox")
            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
"Polygon" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable Geometry where
  hashWithSalt :: Int -> Geometry -> Int
hashWithSalt Int
_salt Geometry' {Maybe [Point]
Maybe BoundingBox
polygon :: Maybe [Point]
boundingBox :: Maybe BoundingBox
$sel:polygon:Geometry' :: Geometry -> Maybe [Point]
$sel:boundingBox:Geometry' :: Geometry -> Maybe BoundingBox
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe BoundingBox
boundingBox
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Point]
polygon

instance Prelude.NFData Geometry where
  rnf :: Geometry -> ()
rnf Geometry' {Maybe [Point]
Maybe BoundingBox
polygon :: Maybe [Point]
boundingBox :: Maybe BoundingBox
$sel:polygon:Geometry' :: Geometry -> Maybe [Point]
$sel:boundingBox:Geometry' :: Geometry -> Maybe BoundingBox
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe BoundingBox
boundingBox
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Point]
polygon