0 | module Geom.Gen2D.State
2 | import Data.Array.Mutable
3 | import public Data.Graph.Indexed
4 | import public Data.Linear.List
5 | import public Data.Linear.Ref1
6 | import public Data.Linear.Traverse1
7 | import public Data.Refined
9 | import public Syntax.T1
23 | record PlaceST (s : Type) (k : Nat) where
26 | pos : MArray s k (Maybe $
Point Mol)
27 | psum : Ref s MolPoint
34 | placeST : (k : Nat) -> F1 s (PlaceST s k)
36 | m <- marray1 k Nothing
46 | place : PlaceST s k => Fin k -> Point Mol -> F1' s
48 | Core.get st.pos x >>= \case
50 | set st.pos x (Just p)
51 | mod1 st.psum $
\(P x y) => P (x + p.x - q.x) (y + p.y - q.y)
53 | set st.pos x (Just p)
55 | mod1 st.psum $
\(P x y) => P (x + p.x) (y + p.y)
63 | unplace : PlaceST s k => Fin k -> F1' s
65 | Core.get st.pos x >>= \case
68 | set st.pos x Nothing
70 | mod1 st.psum $
\(P x y) => P (x - p.x) (y - p.y)
76 | nodePosition : PlaceST s k => Fin k -> F1 s MolPoint
77 | nodePosition @{st} x t =
78 | case Core.get st.pos x t of
80 | Nothing # t => origin # t
85 | bondVector : PlaceST s k => (x,y : Fin k) -> F1 s MolVector
86 | bondVector x y = T1.do
87 | px <- nodePosition x
88 | py <- nodePosition y
93 | isPlaced : PlaceST s k => Fin k -> F1 s Bool
94 | isPlaced @{st} x t =
95 | case Core.get st.pos x t of
96 | Just p # t => True # t
97 | Nothing # t => False # t
101 | center : PlaceST s k => F1 s MolPoint
103 | case read1 st.placed t of
106 | let P x y # t := read1 st.psum t
107 | d := cast {to = Double} n
108 | in P (x/d) (y/d) # t
115 | centerOf : PlaceST s k => List (Fin k) -> F1 s MolPoint
116 | centerOf vs = center2d <$> traverse1 nodePosition vs
122 | getPoints : {k : _} -> PlaceST s k -> F1 s (IArray k $
Point Mol)
124 | let m # t := mmap (fromMaybe origin) st.pos t
125 | in unsafeFreeze m t
130 | adjPoint : PlaceST s k => (Point Mol -> Point Mol) -> Fin k -> F1' s
131 | adjPoint @{st} f i = nodePosition i >>= place i . f