{-# 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.Point
-- 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.Point 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 X and Y coordinates of a point on an image or video frame. The X and
-- Y values are ratios of the overall image size or video resolution. For
-- example, if an input image is 700x200 and the values are X=0.5 and
-- Y=0.25, then the point is at the (350,50) pixel coordinate on the image.
--
-- An array of @Point@ objects makes up a @Polygon@. A @Polygon@ is
-- returned by DetectText and by DetectCustomLabels @Polygon@ represents a
-- fine-grained polygon around a detected item. For more information, see
-- Geometry in the Amazon Rekognition Developer Guide.
--
-- /See:/ 'newPoint' smart constructor.
data Point = Point'
  { -- | The value of the X coordinate for a point on a @Polygon@.
    Point -> Maybe Double
x :: Prelude.Maybe Prelude.Double,
    -- | The value of the Y coordinate for a point on a @Polygon@.
    Point -> Maybe Double
y :: Prelude.Maybe Prelude.Double
  }
  deriving (Point -> Point -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Point -> Point -> Bool
$c/= :: Point -> Point -> Bool
== :: Point -> Point -> Bool
$c== :: Point -> Point -> Bool
Prelude.Eq, ReadPrec [Point]
ReadPrec Point
Int -> ReadS Point
ReadS [Point]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Point]
$creadListPrec :: ReadPrec [Point]
readPrec :: ReadPrec Point
$creadPrec :: ReadPrec Point
readList :: ReadS [Point]
$creadList :: ReadS [Point]
readsPrec :: Int -> ReadS Point
$creadsPrec :: Int -> ReadS Point
Prelude.Read, Int -> Point -> ShowS
[Point] -> ShowS
Point -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Point] -> ShowS
$cshowList :: [Point] -> ShowS
show :: Point -> String
$cshow :: Point -> String
showsPrec :: Int -> Point -> ShowS
$cshowsPrec :: Int -> Point -> ShowS
Prelude.Show, forall x. Rep Point x -> Point
forall x. Point -> Rep Point x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Point x -> Point
$cfrom :: forall x. Point -> Rep Point x
Prelude.Generic)

-- |
-- Create a value of 'Point' 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:
--
-- 'x', 'point_x' - The value of the X coordinate for a point on a @Polygon@.
--
-- 'y', 'point_y' - The value of the Y coordinate for a point on a @Polygon@.
newPoint ::
  Point
newPoint :: Point
newPoint =
  Point' {$sel:x:Point' :: Maybe Double
x = forall a. Maybe a
Prelude.Nothing, $sel:y:Point' :: Maybe Double
y = forall a. Maybe a
Prelude.Nothing}

-- | The value of the X coordinate for a point on a @Polygon@.
point_x :: Lens.Lens' Point (Prelude.Maybe Prelude.Double)
point_x :: Lens' Point (Maybe Double)
point_x = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Point' {Maybe Double
x :: Maybe Double
$sel:x:Point' :: Point -> Maybe Double
x} -> Maybe Double
x) (\s :: Point
s@Point' {} Maybe Double
a -> Point
s {$sel:x:Point' :: Maybe Double
x = Maybe Double
a} :: Point)

-- | The value of the Y coordinate for a point on a @Polygon@.
point_y :: Lens.Lens' Point (Prelude.Maybe Prelude.Double)
point_y :: Lens' Point (Maybe Double)
point_y = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Point' {Maybe Double
y :: Maybe Double
$sel:y:Point' :: Point -> Maybe Double
y} -> Maybe Double
y) (\s :: Point
s@Point' {} Maybe Double
a -> Point
s {$sel:y:Point' :: Maybe Double
y = Maybe Double
a} :: Point)

instance Data.FromJSON Point where
  parseJSON :: Value -> Parser Point
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Point"
      ( \Object
x ->
          Maybe Double -> Maybe Double -> Point
Point'
            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
"X")
            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
"Y")
      )

instance Prelude.Hashable Point where
  hashWithSalt :: Int -> Point -> Int
hashWithSalt Int
_salt Point' {Maybe Double
y :: Maybe Double
x :: Maybe Double
$sel:y:Point' :: Point -> Maybe Double
$sel:x:Point' :: Point -> Maybe Double
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
x
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
y

instance Prelude.NFData Point where
  rnf :: Point -> ()
rnf Point' {Maybe Double
y :: Maybe Double
x :: Maybe Double
$sel:y:Point' :: Point -> Maybe Double
$sel:x:Point' :: Point -> Maybe Double
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
x seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
y

instance Data.ToJSON Point where
  toJSON :: Point -> Value
toJSON Point' {Maybe Double
y :: Maybe Double
x :: Maybe Double
$sel:y:Point' :: Point -> Maybe Double
$sel:x:Point' :: Point -> Maybe Double
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"X" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
x,
            (Key
"Y" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
y
          ]
      )