0 | module Geom.Gen2D.Generate
2 | import Data.Graph.Indexed.Subgraph
3 | import Data.Linear.Traverse1
6 | import Geom.Gen2D.Rings
7 | import Geom.Gen2D.State
8 | import Geom.Gen2D.Place
9 | import Geom.Gen2D.Types
13 | VECT_INI : MolVector
14 | VECT_INI = rotate (fromDegree 30) (V BOND_LEN 0)
18 | {auto dg : DebugFlag}
19 | {auto ce : Cast n Elem}
20 | {auto ch : Cast n Hybridization}
23 | pchain : PlaceST s k => AttachPoint k -> List (Fin k) -> F1' s
24 | pchain _ [] = pure ()
25 | pchain None (x::xs) = place x origin >> placeChain g x xs VECT_INI
26 | pchain (Attach p _) (x::xs) = bondVector p x >>= placeChain g p (x::xs)
28 | placeComp : PlaceST s k => Component k e n -> F1' s
29 | placeComp (C a ns False _) = pchain a ns >> for1_ ns (ignore1 . placeNeighbours g)
30 | placeComp (C a ns True sg) = placeRing g a ns sg
32 | coords : IGraph k e (MolPoint, n)
36 | for1_ (components g) placeComp
38 | pure $
{graph $= mapWithIndex $
\x => map (ps `at` x,)} g
40 | 0 CGraph : Nat -> Type -> Type -> Type
41 | CGraph k e n = Graph e (MolPoint,Fin k, n)
43 | coordArray : {k : _} -> List (CGraph k e n) -> IArray k MolPoint
45 | alloc k origin $
\m => T1.do
46 | for1_ (gs >>= \(G _ h) => labels h) $
\(p,x,_) => set m x p
49 | adjust : {k : _} -> IGraph k e n -> List (CGraph k e n) -> IGraph k e (MolPoint,n)
51 | let cs := coordArray gs
52 | in mapWithCtxt (\x => (at cs x,) . label) g
54 | Cast n e => Cast (a,n) e where cast = cast . snd
56 | ModPoint (MolPoint,a) where
58 | modPoint f (p,v) = (modPoint f p, v)
60 | GetPoint (MolPoint,a) where
68 | -> {auto dg : DebugFlag}
69 | -> {auto ce : Cast n Elem}
70 | -> {auto ch : Cast n Hybridization}
71 | -> (g : IGraph k e n)
72 | -> IGraph k e (MolPoint, n)
74 | connectedComponents g
75 | |> map (\(G _ y) => G _ $
coords y)