module Drasil.Projectile.Unitals where

import Language.Drasil
import Language.Drasil.Display (Symbol(..))
import Language.Drasil.ShortHands (lD, lTheta, lV, lP, lT, lS, vEpsilon)

import Data.Drasil.Quantities.Math (pi_)

import Data.Drasil.Constraints (gtZeroConstr)
import Data.Drasil.SI_Units (radian, metre, second)
import Data.Drasil.Units.Physics (velU)

import qualified Drasil.Projectile.Concepts as C (flightDur, offset,
  flightDur, landPos, launAngle, launSpeed, offset, targPos, projSpeed)

projSpeed :: UnitalChunk
projSpeed :: UnitalChunk
projSpeed  = ConceptChunk -> Symbol -> UnitDefn -> UnitalChunk
forall c u.
(Concept c, IsUnit u) =>
c -> Symbol -> u -> UnitalChunk
uc ConceptChunk
C.projSpeed ([Symbol] -> Symbol
Concat [Symbol -> Symbol
vec Symbol
lV, String -> Symbol
label "(", Symbol
lT, String -> Symbol
label ")"]) UnitDefn
velU

---
landPosUnc, launAngleUnc, launSpeedUnc, offsetUnc, targPosUnc :: UncertQ
landPosUnc :: UncertQ
landPosUnc   = ConstrConcept -> Uncertainty -> UncertQ
forall c.
(Quantity c, Constrained c, Concept c, HasReasVal c,
 MayHaveUnit c) =>
c -> Uncertainty -> UncertQ
uq ConstrConcept
landPos   Uncertainty
defaultUncrt
launAngleUnc :: UncertQ
launAngleUnc = ConstrConcept -> Uncertainty -> UncertQ
forall c.
(Quantity c, Constrained c, Concept c, HasReasVal c,
 MayHaveUnit c) =>
c -> Uncertainty -> UncertQ
uq ConstrConcept
launAngle Uncertainty
defaultUncrt
launSpeedUnc :: UncertQ
launSpeedUnc = ConstrConcept -> Uncertainty -> UncertQ
forall c.
(Quantity c, Constrained c, Concept c, HasReasVal c,
 MayHaveUnit c) =>
c -> Uncertainty -> UncertQ
uq ConstrConcept
launSpeed Uncertainty
defaultUncrt
offsetUnc :: UncertQ
offsetUnc    = ConstrConcept -> Uncertainty -> UncertQ
forall c.
(Quantity c, Constrained c, Concept c, HasReasVal c,
 MayHaveUnit c) =>
c -> Uncertainty -> UncertQ
uq ConstrConcept
offset    Uncertainty
defaultUncrt
targPosUnc :: UncertQ
targPosUnc   = ConstrConcept -> Uncertainty -> UncertQ
forall c.
(Quantity c, Constrained c, Concept c, HasReasVal c,
 MayHaveUnit c) =>
c -> Uncertainty -> UncertQ
uq ConstrConcept
targPos   Uncertainty
defaultUncrt

flightDur, landPos, launAngle, launSpeed, offset, targPos :: ConstrConcept
flightDur :: ConstrConcept
flightDur = UnitalChunk -> [ConstraintE] -> ConstrConcept
forall c.
(Concept c, MayHaveUnit c, Quantity c) =>
c -> [ConstraintE] -> ConstrConcept
constrainedNRV' (ConceptChunk -> Symbol -> Space -> UnitDefn -> UnitalChunk
forall c u.
(Concept c, IsUnit u) =>
c -> Symbol -> Space -> u -> UnitalChunk
ucs'  ConceptChunk
C.flightDur (Symbol -> String -> Symbol
subStr Symbol
lT "flight") Space
Real UnitDefn
second)  [ConstraintE
gtZeroConstr]
landPos :: ConstrConcept
landPos   = UnitalChunk -> [ConstraintE] -> ConstrConcept
forall c.
(Concept c, MayHaveUnit c, Quantity c) =>
c -> [ConstraintE] -> ConstrConcept
constrainedNRV' (ConceptChunk -> Symbol -> Space -> UnitDefn -> UnitalChunk
forall c u.
(Concept c, IsUnit u) =>
c -> Symbol -> Space -> u -> UnitalChunk
ucs'  ConceptChunk
C.landPos   (Symbol -> String -> Symbol
subStr Symbol
lP "land"  ) Space
Real UnitDefn
metre)   [ConstraintE
gtZeroConstr]
launAngle :: ConstrConcept
launAngle = DefinedQuantityDict -> [ConstraintE] -> Expr -> ConstrConcept
forall c.
(Concept c, MayHaveUnit c, Quantity c) =>
c -> [ConstraintE] -> Expr -> ConstrConcept
constrained'    (ConceptChunk
-> (Stage -> Symbol)
-> Space
-> Maybe UnitDefn
-> DefinedQuantityDict
dqd' ConceptChunk
C.launAngle (Symbol -> Stage -> Symbol
autoStage Symbol
lTheta)   Space
Real (UnitDefn -> Maybe UnitDefn
forall a. a -> Maybe a
Just UnitDefn
radian)) [RealInterval Expr Expr -> ConstraintE
physc (RealInterval Expr Expr -> ConstraintE)
-> RealInterval Expr Expr -> ConstraintE
forall a b. (a -> b) -> a -> b
$ (Inclusive, Expr) -> (Inclusive, Expr) -> RealInterval Expr Expr
forall a b. (Inclusive, a) -> (Inclusive, b) -> RealInterval a b
Bounded (Inclusive
Exc, Integer -> Expr
forall r. LiteralC r => Integer -> r
exactDbl 0) (Inclusive
Exc, Expr -> Expr
forall r. (ExprC r, LiteralC r) => r -> r
half (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ DefinedQuantityDict -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy DefinedQuantityDict
pi_)] (DefinedQuantityDict -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy DefinedQuantityDict
pi_ Expr -> Expr -> Expr
forall r. ExprC r => r -> r -> r
$/ Integer -> Expr
forall r. LiteralC r => Integer -> r
exactDbl 4)
launSpeed :: ConstrConcept
launSpeed = UnitalChunk -> [ConstraintE] -> Expr -> ConstrConcept
forall c.
(Concept c, MayHaveUnit c, Quantity c) =>
c -> [ConstraintE] -> Expr -> ConstrConcept
constrained'    (ConceptChunk -> Symbol -> Space -> UnitDefn -> UnitalChunk
forall c u.
(Concept c, IsUnit u) =>
c -> Symbol -> Space -> u -> UnitalChunk
ucs'  ConceptChunk
C.launSpeed (Symbol -> String -> Symbol
subStr Symbol
lV "launch") Space
Real UnitDefn
velU)    [ConstraintE
gtZeroConstr] (Integer -> Expr
forall r. LiteralC r => Integer -> r
exactDbl 100)
offset :: ConstrConcept
offset    = UnitalChunk -> [ConstraintE] -> ConstrConcept
forall c.
(Concept c, MayHaveUnit c, Quantity c) =>
c -> [ConstraintE] -> ConstrConcept
constrainedNRV' (ConceptChunk -> Symbol -> Space -> UnitDefn -> UnitalChunk
forall c u.
(Concept c, IsUnit u) =>
c -> Symbol -> Space -> u -> UnitalChunk
ucs'  ConceptChunk
C.offset    (Symbol -> String -> Symbol
subStr Symbol
lD "offset") Space
Real UnitDefn
metre)   [RealInterval Expr Expr -> ConstraintE
physc (RealInterval Expr Expr -> ConstraintE)
-> RealInterval Expr Expr -> ConstraintE
forall a b. (a -> b) -> a -> b
$ (Inclusive, Expr) -> RealInterval Expr Expr
forall b a. (Inclusive, b) -> RealInterval a b
UpFrom (Inclusive
Exc, Expr -> Expr
forall r. ExprC r => r -> r
neg (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ ConstrConcept -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrConcept
landPos) ]
targPos :: ConstrConcept
targPos   = UnitalChunk -> [ConstraintE] -> Expr -> ConstrConcept
forall c.
(Concept c, MayHaveUnit c, Quantity c) =>
c -> [ConstraintE] -> Expr -> ConstrConcept
constrained'    (ConceptChunk -> Symbol -> Space -> UnitDefn -> UnitalChunk
forall c u.
(Concept c, IsUnit u) =>
c -> Symbol -> Space -> u -> UnitalChunk
ucs' ConceptChunk
C.targPos   (Symbol -> String -> Symbol
subStr Symbol
lP "target") Space
Real UnitDefn
metre)   [ConstraintE
gtZeroConstr] (Integer -> Expr
forall r. LiteralC r => Integer -> r
exactDbl 1000)

---
-- The output contains a message, as a string, so it needs to be a quantity
message :: QuantityDict
message :: QuantityDict
message = String -> NP -> Symbol -> Space -> QuantityDict
vc "message" (Sentence -> NP
nounPhraseSent (String -> Sentence
S "output message as a string")) Symbol
lS Space
String

---
tol :: ConstQDef
tol :: ConstQDef
tol = QuantityDict -> Literal -> ConstQDef
forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef (String -> NP -> (Stage -> Symbol) -> Space -> QuantityDict
vcSt "tol" (String -> NP
nounPhraseSP "hit tolerance") (Symbol -> Stage -> Symbol
autoStage Symbol
vEpsilon) Space
Rational) (Integer -> Integer -> Literal
forall r. LiteralC r => Integer -> Integer -> r
perc 2 2)