module HGeometry.Ball.Class
( Ball_(..)
, ConstructableBall_(..)
, pattern Ball_
, HasCenter(..)
, radius
, Disk_
, pattern Disk_
, HasInBall(..)
, inDisk
) where
import Control.Arrow ((&&&))
import Control.Lens
import HGeometry.Boundary
import qualified HGeometry.Number.Radical as Radical
import HGeometry.Point
import HGeometry.Properties
class HasCenter geom point | geom -> point where
center :: Lens' geom point
class ( HasCenter ball point
, NumType ball ~ NumType point
, Point_ point (Dimension ball) (NumType ball)
) => Ball_ ball point | ball -> point where
{-# MINIMAL squaredRadius #-}
squaredRadius :: Getter ball (NumType ball)
radius :: (Radical.Radical r, Ball_ ball point, NumType ball ~ r) => ball -> r
radius :: forall r ball point.
(Radical r, Ball_ ball point, NumType ball ~ r) =>
ball -> r
radius = r -> r
forall r. Radical r => r -> r
Radical.sqrt (r -> r) -> (ball -> r) -> ball -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting r ball r -> ball -> r
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting r ball r
(NumType ball -> Const r (NumType ball)) -> ball -> Const r ball
forall ball point. Ball_ ball point => Getter ball (NumType ball)
Getter ball (NumType ball)
squaredRadius
class ( Ball_ ball point
) => ConstructableBall_ ball point where
{-# MINIMAL fromCenterAndSquaredRadius #-}
fromCenterAndSquaredRadius :: point -> NumType ball -> ball
unitBall :: (r ~ NumType ball, d ~ Dimension ball
, Num r, ConstructablePoint_ point d r) => ball
unitBall = point -> NumType ball -> ball
forall ball point.
ConstructableBall_ ball point =>
point -> NumType ball -> ball
fromCenterAndSquaredRadius point
forall point (d :: Nat) r.
(Num r, ConstructablePoint_ point d r) =>
point
origin r
NumType ball
1
pattern Ball_ :: ConstructableBall_ ball point => point -> NumType ball -> ball
pattern $mBall_ :: forall {r} {ball} {point}.
ConstructableBall_ ball point =>
ball -> (point -> NumType ball -> r) -> ((# #) -> r) -> r
$bBall_ :: forall ball point.
ConstructableBall_ ball point =>
point -> NumType ball -> ball
Ball_ c r <- ((view center &&& view squaredRadius) -> (c,r))
where
Ball_ point
c NumType ball
r = point -> NumType ball -> ball
forall ball point.
ConstructableBall_ ball point =>
point -> NumType ball -> ball
fromCenterAndSquaredRadius point
c NumType ball
r
{-# COMPLETE Ball_ #-}
class HasInBall ball where
inBall :: ( Point_ point d r, Ord r, Num r
, NumType ball ~ r, Dimension ball ~ d
) => point -> ball -> PointLocationResult
inDisk :: ( Point_ point 2 r, HasInBall disk, Ord r, Num r
, Dimension disk ~ 2, NumType disk ~ r
)
=> point -> disk -> PointLocationResult
inDisk :: forall point r disk.
(Point_ point 2 r, HasInBall disk, Ord r, Num r,
Dimension disk ~ 2, NumType disk ~ r) =>
point -> disk -> PointLocationResult
inDisk = point -> disk -> PointLocationResult
forall ball point (d :: Nat) r.
(HasInBall ball, Point_ point d r, Ord r, Num r, NumType ball ~ r,
Dimension ball ~ d) =>
point -> ball -> PointLocationResult
forall point (d :: Nat) r.
(Point_ point d r, Ord r, Num r, NumType disk ~ r,
Dimension disk ~ d) =>
point -> disk -> PointLocationResult
inBall
class (Ball_ disk point, Dimension disk ~ 2) => Disk_ disk point where
pattern Disk_ :: (Disk_ ball point, ConstructableBall_ ball point)
=> point -> NumType ball -> ball
pattern $mDisk_ :: forall {r} {ball} {point}.
(Disk_ ball point, ConstructableBall_ ball point) =>
ball -> (point -> NumType ball -> r) -> ((# #) -> r) -> r
$bDisk_ :: forall ball point.
(Disk_ ball point, ConstructableBall_ ball point) =>
point -> NumType ball -> ball
Disk_ c r = Ball_ c r
{-# COMPLETE Disk_ #-}