Commit da54796f authored by Marc Coiffier's avatar Marc Coiffier
Browse files

Tweak some Logos

parent cfed7d16
......@@ -72,7 +72,7 @@ stringWords = map fromString . fromBlank
fromWChar k "" = [k ""]
data LogosBuiltin = Wait | Quit | Format | Print | OpenWindow | Texture Bool | BuildMesh | Draw | Uniform | DefUniform
| VCons | MCons | Norm | Rotation | Translation | Skew | Ejection | MCompose | Transpose | MAdd | Recip | Delay
| VCons | MCons | Norm | Rotation | Translation | Skew | Ejection | MCompose | MScalar | Transpose | MAdd | Recip | Delay
deriving Show
toFloat (StackInt n) = Just (fromIntegral n)
toFloat (StackSymbol s) = matches Just readable s
......@@ -111,6 +111,7 @@ dict = fromAList $
("rotation" , Builtin_Extra Rotation),
("translation" , Builtin_Extra Translation),
("**" , Builtin_Extra MCompose),
("<>" , Builtin_Extra MScalar),
("++" , Builtin_Extra MAdd),
("transpose" , Builtin_Extra Transpose),
("skew" , Builtin_Extra Skew),
......@@ -217,6 +218,9 @@ runLogos MCompose = runStackState $ modify $ \case
StackMat m:StackFloat f:st -> StackMat (map2 (f*) m):st
StackFloat f:StackFloat f':st -> StackExtra (Opaque $ F $ f*f'):st
st -> st
runLogos MScalar = runStackState $ modify $ \case
StackMat m:StackMat m':st -> StackMat (scalProdM m m'):st
st -> st
runLogos Transpose = runStackState $ modify $ \case
StackMat m:st -> StackMat (transpose m):st
st -> st
......
......@@ -72,6 +72,8 @@ matMult x y = map (\vm -> map (\vm' -> scalProd vm vm') (transpose y)) x
scalProd :: (Ring a,Vector (Vec n)) => Vec n a -> Vec n a -> a
scalProd u v = sum (u*v)
scalProdM :: (Ring a,Vector (Vec n)) => Mat n n a -> Mat n n a -> Mat n n a
scalProdM u v = fromLinearMap (\w -> w * pure (scalProd (w & from scalar %~ ($* u)) (w & from scalar %~ ($* v))))
normalize :: (Vector (Vec n),Invertible a, RealFloat a) => Vec n a -> Vec n a
normalize v = map (/ sqrt (scalProd v v)) v
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment