-- Assemble all of the mathematical expressions here, to promote re-use
--
-- This is supposed to always be imported qualified, since we're purposefully
-- overloading the names.
module Drasil.Projectile.Expressions where

import Prelude hiding (cos, sin)

import Language.Drasil
import qualified Data.Drasil.Quantities.Physics as QP (iSpeed,
  constAccel, xConstAccel, yConstAccel, ixPos, iyPos)
import Data.Drasil.Quantities.Physics (gravitationalAccel, gravitationalAccelConst,
  ixVel, iyVel, xPos, yPos, time, iPos, scalarPos, xVel, yVel, xAccel, yAccel, position, 
  velocity, acceleration, constAccelV, speed)
import Drasil.Projectile.Unitals (launAngle, launSpeed, targPos, tol, landPos, offset)

flightDur', iyPos, yConstAccel, iSpeed :: PExpr
flightDur' :: PExpr
flightDur' = forall r. LiteralC r => Integer -> r
exactDbl Integer
2 forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrConcept
launSpeed forall r. ExprC r => r -> r -> r
`mulRe` forall r. ExprC r => r -> r
sin (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrConcept
launAngle) forall r. ExprC r => r -> r -> r
$/ forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstQDef
gravitationalAccelConst
iyPos :: PExpr
iyPos = forall r. LiteralC r => Integer -> r
exactDbl Integer
0                              -- launchOrigin
yConstAccel :: PExpr
yConstAccel = forall r. ExprC r => r -> r
neg forall a b. (a -> b) -> a -> b
$ forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstQDef
gravitationalAccelConst  -- accelYGravity
iSpeed :: PExpr
iSpeed = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrConcept
launSpeed

offset' :: PExpr
offset' :: PExpr
offset' = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrConcept
landPos forall r. ExprC r => r -> r -> r
$- forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrConcept
targPos

message :: PExpr
message :: PExpr
message = forall r. ExprC r => [(r, r)] -> r
completeCase [(r, r)
case1, (r, r)
case2, (r, r)
case3]
  where case1 :: (r, r)
case1 = (forall r. LiteralC r => String -> r
str String
"The target was hit.",        forall r. ExprC r => r -> r
abs_ (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrConcept
offset forall r. ExprC r => r -> r -> r
$/ forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrConcept
targPos) forall r. ExprC r => r -> r -> r
$< forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstQDef
tol)
        case2 :: (r, r)
case2 = (forall r. LiteralC r => String -> r
str String
"The projectile fell short.", forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrConcept
offset forall r. ExprC r => r -> r -> r
$< forall r. LiteralC r => Integer -> r
exactDbl Integer
0)
        case3 :: (r, r)
case3 = (forall r. LiteralC r => String -> r
str String
"The projectile went long.",  forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrConcept
offset forall r. ExprC r => r -> r -> r
$> forall r. LiteralC r => Integer -> r
exactDbl Integer
0)

--
speed' :: PExpr
speed' :: PExpr
speed' = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.iSpeed forall r. ExprC r => r -> r -> r
`addRe` (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.constAccel forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
time)

scalarPos' :: PExpr
scalarPos' :: PExpr
scalarPos' = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
iPos forall r. ExprC r => r -> r -> r
`addRe` (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.iSpeed forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
time forall r. ExprC r => r -> r -> r
`addRe` forall r. (ExprC r, LiteralC r) => r -> r
half (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.constAccel forall r. ExprC r => r -> r -> r
`mulRe` forall r. (ExprC r, LiteralC r) => r -> r
square (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
time)))

rectNoTime :: PExpr
rectNoTime :: PExpr
rectNoTime = forall r. (ExprC r, LiteralC r) => r -> r
square (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
speed) forall r. ExprC r => r -> r -> r
$= forall r. (ExprC r, LiteralC r) => r -> r
square (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.iSpeed) forall r. ExprC r => r -> r -> r
`addRe` (forall r. LiteralC r => Integer -> r
exactDbl Integer
2 forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.constAccel forall r. ExprC r => r -> r -> r
`mulRe` (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
scalarPos forall r. ExprC r => r -> r -> r
$- forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
iPos))

--
velVecExpr :: PExpr
velVecExpr :: PExpr
velVecExpr = forall r. ExprC r => r -> r -> r
vec2D (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
ixVel forall r. ExprC r => r -> r -> r
`addRe` (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.xConstAccel forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
time)) (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
iyVel forall r. ExprC r => r -> r -> r
`addRe` (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.yConstAccel forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
time))

--
posVecExpr :: PExpr
posVecExpr :: PExpr
posVecExpr = forall r. ExprC r => r -> r -> r
vec2D
              (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.ixPos forall r. ExprC r => r -> r -> r
`addRe` (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
ixVel forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
time) forall r. ExprC r => r -> r -> r
`addRe` forall r. (ExprC r, LiteralC r) => r -> r
half (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.xConstAccel forall r. ExprC r => r -> r -> r
`mulRe` forall r. (ExprC r, LiteralC r) => r -> r
square (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
time)))
              (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.iyPos forall r. ExprC r => r -> r -> r
`addRe` (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
iyVel forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
time) forall r. ExprC r => r -> r -> r
`addRe` forall r. (ExprC r, LiteralC r) => r -> r
half (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.yConstAccel forall r. ExprC r => r -> r -> r
`mulRe` forall r. (ExprC r, LiteralC r) => r -> r
square (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
time)))

--
landPosExpr :: PExpr
landPosExpr :: PExpr
landPosExpr = forall r. LiteralC r => Integer -> r
exactDbl Integer
2 forall r. ExprC r => r -> r -> r
`mulRe` forall r. (ExprC r, LiteralC r) => r -> r
square (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrConcept
launSpeed) forall r. ExprC r => r -> r -> r
`mulRe` forall r. ExprC r => r -> r
sin (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrConcept
launAngle) forall r. ExprC r => r -> r -> r
`mulRe` forall r. ExprC r => r -> r
cos (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrConcept
launAngle) forall r. ExprC r => r -> r -> r
$/ forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstQDef
gravitationalAccelConst

-- Helper expressions that represent the vectors of quantities as components
positionXY, velocityXY, accelerationXY, constAccelXY :: PExpr
positionXY :: PExpr
positionXY     = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
position     forall r. ExprC r => r -> r -> r
$= forall r. ExprC r => r -> r -> r
vec2D (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
xPos)           (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
yPos)
velocityXY :: PExpr
velocityXY     = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
velocity     forall r. ExprC r => r -> r -> r
$= forall r. ExprC r => r -> r -> r
vec2D (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
xVel)           (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
yVel)
accelerationXY :: PExpr
accelerationXY = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
acceleration forall r. ExprC r => r -> r -> r
$= forall r. ExprC r => r -> r -> r
vec2D (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
xAccel)         (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
yAccel)
constAccelXY :: PExpr
constAccelXY   = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
constAccelV  forall r. ExprC r => r -> r -> r
$= forall r. ExprC r => r -> r -> r
vec2D (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.xConstAccel) (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.yConstAccel)

-- Expressions for Lesson
horizVel, horizPos :: PExpr
horizVel :: PExpr
horizVel = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
xVel forall r. ExprC r => r -> r -> r
$= forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
ixVel
horizPos :: PExpr
horizPos = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
xPos forall r. ExprC r => r -> r -> r
$= forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.ixPos forall r. ExprC r => r -> r -> r
`addRe` (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
ixVel forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
time)

vertVel, vertPos, vertNoTime :: PExpr
vertVel :: PExpr
vertVel = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
yVel forall r. ExprC r => r -> r -> r
$= forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
iyVel forall r. ExprC r => r -> r -> r
$- (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
gravitationalAccel forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
time)
vertPos :: PExpr
vertPos = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
yPos forall r. ExprC r => r -> r -> r
$= forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.iyPos forall r. ExprC r => r -> r -> r
`addRe` (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
iyVel forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
time) forall r. ExprC r => r -> r -> r
$- (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
gravitationalAccel forall r. ExprC r => r -> r -> r
`mulRe` forall r. (ExprC r, LiteralC r) => r -> r
square (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
time) forall r. ExprC r => r -> r -> r
$/ forall r. LiteralC r => Integer -> r
exactDbl Integer
2)
vertNoTime :: PExpr
vertNoTime = forall r. (ExprC r, LiteralC r) => r -> r
square (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
yVel) forall r. ExprC r => r -> r -> r
$= forall r. (ExprC r, LiteralC r) => r -> r
square (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
iyVel) forall r. ExprC r => r -> r -> r
$- (forall r. LiteralC r => Integer -> r
exactDbl Integer
2 forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
gravitationalAccel forall r. ExprC r => r -> r -> r
`mulRe` (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
yPos forall r. ExprC r => r -> r -> r
$- forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.iyPos)) 

lcrectVel, lcrectPos, lcrectNoTime, lchorizVel, lchorizPos, lcvertVel, lcvertPos, lcvertNoTime :: LabelledContent
lcrectVel :: LabelledContent
lcrectVel = ModelExpr -> Reference -> LabelledContent
lbldExpr (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
speed forall r. ExprC r => r -> r -> r
$= PExpr
speed') (String -> Reference
makeEqnRef String
"rectVel")
lcrectPos :: LabelledContent
lcrectPos = ModelExpr -> Reference -> LabelledContent
lbldExpr (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
scalarPos forall r. ExprC r => r -> r -> r
$= PExpr
scalarPos') (String -> Reference
makeEqnRef String
"rectPos")
lcrectNoTime :: LabelledContent
lcrectNoTime = ModelExpr -> Reference -> LabelledContent
lbldExpr PExpr
rectNoTime (String -> Reference
makeEqnRef String
"rectNoTime")
lchorizVel :: LabelledContent
lchorizVel = ModelExpr -> Reference -> LabelledContent
lbldExpr PExpr
horizVel (String -> Reference
makeEqnRef String
"horizVel")
lchorizPos :: LabelledContent
lchorizPos = ModelExpr -> Reference -> LabelledContent
lbldExpr PExpr
horizPos (String -> Reference
makeEqnRef String
"horizPos")
lcvertVel :: LabelledContent
lcvertVel = ModelExpr -> Reference -> LabelledContent
lbldExpr PExpr
vertVel (String -> Reference
makeEqnRef String
"vertVel")
lcvertPos :: LabelledContent
lcvertPos = ModelExpr -> Reference -> LabelledContent
lbldExpr PExpr
vertPos (String -> Reference
makeEqnRef String
"vertPos")
lcvertNoTime :: LabelledContent
lcvertNoTime = ModelExpr -> Reference -> LabelledContent
lbldExpr PExpr
vertNoTime (String -> Reference
makeEqnRef String
"vertNoTime")

-- References --
eqnRefs :: [Reference]
eqnRefs :: [Reference]
eqnRefs = forall a b. (a -> b) -> [a] -> [b]
map forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Reference
ref [LabelledContent
lcrectVel, LabelledContent
lcrectPos, LabelledContent
lcrectNoTime, LabelledContent
lchorizVel, LabelledContent
lchorizPos, LabelledContent
lcvertVel, LabelledContent
lcvertPos, LabelledContent
lcvertNoTime]