anchor.diff:                      for p in appState.polygons do
                           let lines = 
                               Mod.custom (fun self -> 
  -                                let positions = (p :> IMod<_>).GetValue self
  -                                let lines = List.foldBack (fun (x:pmod<_>) s -> (x :> IMod<_>).GetValue self :: s) positions [] |> List.toArray
  +                                let positions = (p.UnsafeInner :> IMod<_>).GetValue self
  +                                let lines = List.foldBack (fun (x:pmod<_>) s -> (x.UnsafeInner :> IMod<_>).GetValue self :: s) positions [] |> List.toArray
                                   Helpers.lineLoopGeometry C4b.White lines
                            )
                           yield Sg.dynamic lines
                   }
   
               let scene =
  -                Mod.map2 (lineGeometry C4b.Red) (fst workingState) endPoint 
  +                Mod.map2 (lineGeometry C4b.Red) workingState.polygon endPoint 
                       |> Sg.dynamic
                       |> Sg.andAlso (polygonVis |> Sg.set)
   
  
positive.code:                 |> Sg.onOff (m |> Mod.map Option.isSome)    
  
          let pickSphere  = conditionally 0.040 C4b.Green camPick
          let hoverSphere = conditionally 0.041 C4b.Yellow (Mod.map (Option.map (fun (_,_,p) -> p)) hoverPosition)
          let groundPlane = Helpers.quad C4b.Gray
  
          let sg =
  
negative.code:         type Polygons = pset<Polygon>
  
          type Scene = { polygons : Polygons }
          type State = { polygon : pmod<list<V3f>>; unique : Scope.Unique; 
                         hoverPosition : IModRef<Option<Polygon * pmod<V3f>>>; 
                         selectedPoint : ref<Option<pmod<V3f>>>
                         dragging      : ref<bool> }
  
          type Logics = Scene * State
  
          let createScene () = { polygons = Scope.pset git "polygons" }
  
          let createWorkingState () = 
              { polygon        = Scope.pmod git "workingPolygon" []; 
                unique         = Scope.empty ()
                hoverPosition  = Mod.init None;
                selectedPoint  = ref None
                dragging       = ref false
              }
  
              
          let interact ((scene,state) : Logics) (commit : bool)  (op : Operation) =
              let changes =
                  [
                      match op with
                          | AddPoint p   -> 
                              yield state.polygon <~ p :: state.polygon.Value
                          | ClosePolygon ->
                              let closedPolygon = state.polygon.Value |> List.toArray
                              if closedPolygon.Length > 0 then
                                  let newPolygon = 
                                      Scope.uniqueScope state.unique (fun scope ->
                                          state.polygon.Value 
                                              |> List.mapi (fun i v -> Scope.pmod git (sprintf "%d" i) v) 
                                              |> List.rev
                                              |> Scope.pmod git scope
                                  )
                                  yield PSet.add scene.polygons newPolygon
                              yield state.polygon <~ []
                          | MovePoint (newPos) when !state.dragging  ->
                              yield (!state.selectedPoint).Value <~ newPos
                          | ToggleMoving when !state.dragging ->
                              state.dragging := false
                              state.selectedPoint := None
                          | ToggleMoving when not !state.dragging && state.hoverPosition.Value.IsSome ->
                              state.dragging := true
                              state.selectedPoint := Some (snd state.hoverPosition.Value.Value)
                          | ToggleMoving | MovePoint _ -> ()
                  ]
              for c in changes do git.apply c
              let action = sprintf "%A" op
  
              if commit then
                  git.commit action
                  Git2Dgml.visualizeHistory (Path.combine [ __SOURCE_DIRECTORY__; "polygons.dgml" ]) (git.Branches |> Dictionary.toList) |> ignore
  
      module Picking =
          open Logics
  
          let pick ((scene, state):Logics) =
              let polygons = (scene.polygons :> aset<_>).GetReader()
              fun (camera : Camera) (current : PixelPosition) ->
                  
                  polygons.GetDelta() |> ignore
                  let changes =
                      [
                          let pick = Camera.pickRay camera current
                          let nearbyRay = 
                              polygons.Content
                                  |> Seq.collect (fun (p : Logics.Polygon) -> 
                                      [ for px in p.Value do 
                                          let mutable hit = RayHit3d.MaxRange
                                          let hitD = 
                                              if pick.HitsSphere(V3d.op_Explicit px.Value, 0.1, 0.1, 10.0, &hit) 
                                              then hit.T
                                              else Double.MaxValue
                                          yield p, px, hitD
                                      ] )
                                  |> Seq.sortBy (fun (_,_,d) -> d)
                                  |> Seq.toList
                          match nearbyRay with
                              | [] -> ()
                              | (p,bestPosition,d)::_ when d < Double.MaxValue && not !state.dragging -> 
                                  yield fun () -> 
                                      Mod.change state.hoverPosition (Some (p, bestPosition)) 
                              | _ -> 
                                  yield fun () -> Mod.change state.hoverPosition None 
                      ]
  
                  transact (fun () -> 
                      for c in changes do c ()
                  )
  
  
      [<AutoOpen>]
      module View =
  
          let viewTrafo = viewTrafo ()
          let frustum = perspective ()
  