{-# 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.Textract.Types.Point
-- 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.Textract.Types.Point where

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

-- | The X and Y coordinates of a point on a document page. The X and Y
-- values that are returned are ratios of the overall document page size.
-- For example, if the input document is 700 x 200 and the operation
-- returns X=0.5 and Y=0.25, then the point is at the (350,50) pixel
-- coordinate on the document page.
--
-- An array of @Point@ objects, @Polygon@, is returned by
-- DetectDocumentText. @Polygon@ represents a fine-grained polygon around
-- detected text. For more information, see Geometry in the Amazon Textract
-- 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
(Point -> Point -> Bool) -> (Point -> Point -> Bool) -> Eq Point
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]
(Int -> ReadS Point)
-> ReadS [Point]
-> ReadPrec Point
-> ReadPrec [Point]
-> Read 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
(Int -> Point -> ShowS)
-> (Point -> String) -> ([Point] -> ShowS) -> Show Point
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. Point -> Rep Point x)
-> (forall x. Rep Point x -> Point) -> Generic Point
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' :: Maybe Double -> Maybe Double -> Point
Point' {$sel:x:Point' :: Maybe Double
x = Maybe Double
forall a. Maybe a
Prelude.Nothing, $sel:y:Point' :: Maybe Double
y = Maybe Double
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 :: (Maybe Double -> f (Maybe Double)) -> Point -> f Point
point_x = (Point -> Maybe Double)
-> (Point -> Maybe Double -> Point)
-> Lens Point Point (Maybe Double) (Maybe Double)
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 :: (Maybe Double -> f (Maybe Double)) -> Point -> f Point
point_y = (Point -> Maybe Double)
-> (Point -> Maybe Double -> Point)
-> Lens Point Point (Maybe Double) (Maybe Double)
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 Core.FromJSON Point where
  parseJSON :: Value -> Parser Point
parseJSON =
    String -> (Object -> Parser Point) -> Value -> Parser Point
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Point"
      ( \Object
x ->
          Maybe Double -> Maybe Double -> Point
Point'
            (Maybe Double -> Maybe Double -> Point)
-> Parser (Maybe Double) -> Parser (Maybe Double -> Point)
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
"X") Parser (Maybe Double -> Point)
-> Parser (Maybe Double) -> Parser Point
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
"Y")
      )

instance Prelude.Hashable Point

instance Prelude.NFData Point