--------------------------------------------------------------------------------
-- |
-- Module      :  HGeometry.Line.NonVertical.Class
-- Copyright   :  (C) Frank Staals
-- License     :  see the LICENSE file
-- Maintainer  :  Frank Staals
--
-- A class representing non-vertical lines.
--
--------------------------------------------------------------------------------
module HGeometry.Line.NonVertical.Class
  ( NVLine2_
  , pattern NVLine2_
  , slope, intercept
  ) where

import Control.Lens
import HGeometry.HyperPlane.Class
import HGeometry.Line.Class
import HGeometry.Vector

--------------------------------------------------------------------------------

-- $setup
-- >>> import HGeometry.Line.LineEQ


-- | Typeclass modelling Non-vertical lines
type NVLine2_ line r = (Line_ line 2 r, NonVerticalHyperPlane_ line 2 r)

-- | Match on a non-vertical line
pattern NVLine2_     :: NonVerticalHyperPlane_ line 2 r => r -> r -> line
pattern $mNVLine2_ :: forall {r} {line} {r}.
NonVerticalHyperPlane_ line 2 r =>
line -> (r -> r -> r) -> ((# #) -> r) -> r
NVLine2_ a b <- (view hyperPlaneCoefficients -> Vector2 a b)
{-# COMPLETE NVLine2_ #-}

-- | Lens to access the slope of a line
--
-- >>> (LineEQ 10 20) ^. slope
-- 10
slope :: NonVerticalHyperPlane_ line 2 r => Lens' line r
slope :: forall line r. NonVerticalHyperPlane_ line 2 r => Lens' line r
slope = (Vector 2 r -> f (Vector 2 r)) -> line -> f line
forall hyperPlane (d :: Nat) r.
NonVerticalHyperPlane_ hyperPlane d r =>
Lens' hyperPlane (Vector d r)
Lens' line (Vector 2 r)
hyperPlaneCoefficients ((Vector 2 r -> f (Vector 2 r)) -> line -> f line)
-> ((r -> f r) -> Vector 2 r -> f (Vector 2 r))
-> (r -> f r)
-> line
-> f line
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r -> f r) -> Vector 2 r -> f (Vector 2 r)
forall vector (d :: Nat) r.
(Vector_ vector d r, 0 <= (d - 1)) =>
IndexedLens' Int vector r
IndexedLens' Int (Vector 2 r) r
xComponent

-- | Lens to access the intercept (i.e. the value at which it
-- intersects the y-axis) of a line.
--
-- >>> (LineEQ 10 20) ^. intercept
-- 20
intercept :: NonVerticalHyperPlane_ line 2 r => Lens' line r
intercept :: forall line r. NonVerticalHyperPlane_ line 2 r => Lens' line r
intercept = (Vector 2 r -> f (Vector 2 r)) -> line -> f line
forall hyperPlane (d :: Nat) r.
NonVerticalHyperPlane_ hyperPlane d r =>
Lens' hyperPlane (Vector d r)
Lens' line (Vector 2 r)
hyperPlaneCoefficients ((Vector 2 r -> f (Vector 2 r)) -> line -> f line)
-> ((r -> f r) -> Vector 2 r -> f (Vector 2 r))
-> (r -> f r)
-> line
-> f line
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r -> f r) -> Vector 2 r -> f (Vector 2 r)
forall vector (d :: Nat) r.
(Vector_ vector d r, 1 <= (d - 1)) =>
IndexedLens' Int vector r
IndexedLens' Int (Vector 2 r) r
yComponent