Example #1
0
 public EdgeStates(EdgeState U, EdgeState R, EdgeState D, EdgeState L)
 {
     this.U = U;
     this.R = R;
     this.D = D;
     this.L = L;
 }
Example #2
0
 // Runs only once at the start of the game loop
 public void Start()
 {
     State  = EdgeState.Empty;
     coll2D = GetComponent <Collider2D>();
     rend   = GetComponent <SpriteRenderer>();
     rend.material.SetColor(App.SpriteRenderer.MainColorProperty, App.ColorPalette.White);
 }
Example #3
0
 private EdgeState Toggle(EdgeState loopLinkState, bool mouseButtons)
 {
     if (!mouseButtons)
     {
         if (loopLinkState == EdgeState.Filled)
         {
             return(EdgeState.Excluded);
         }
         else if (loopLinkState == EdgeState.Excluded)
         {
             return(EdgeState.Empty);
         }
         else
         {
             return(EdgeState.Filled);
         }
     }
     else
     {
         if (loopLinkState == EdgeState.Excluded)
         {
             return(EdgeState.Filled);
         }
         else if (loopLinkState == EdgeState.Filled)
         {
             return(EdgeState.Empty);
         }
         else
         {
             return(EdgeState.Excluded);
         }
     }
 }
Example #4
0
 public Edge(Node nodeA, Node nodeB, EdgeState state = EdgeState.Normal, Color?color = null)
 {
     Id     = GetEdgeId(nodeA, nodeB);
     _nodes = new List <Node>(2)
     {
         nodeA, nodeB
     };
     Nodes = _nodes.AsReadOnly();
     State = state;
     Color = color;
 }
Example #5
0
        internal Edge(Node node1, Node node2, EdgeState state)
        {
            this.Node1 = node1;
            this.Node2 = node2;
            this.State = state;

            this.vector = new double[node1.p.Length];
            calcVector();

            double check0 = Math.Sqrt(Math.Pow(node1.p[0] - node2.p[0], 2) + Math.Pow(node1.p[1] - node2.p[1], 2));
            double check = Math.Sqrt(Math.Pow(vector[0], 2) + Math.Pow(vector[1], 2));
        }
Example #6
0
        public bool Perform()
        {
            successful = true;
            // mesh.ConsiderIntersectCellInteractsAsSimple = useICInAuto;
            mesh.ConsiderMultipleLoops = considerMultipleLoopsInAuto;
            mesh.UseColoring           = useColoringInAuto;
            mesh.UseCellColoring       = useCellColoringInAuto;
            // TODO: add settings for use derived/merge in auto.
            mesh.UseDerivedColoring = false;
            mesh.UseMerging         = false;
            mesh.ColoringCheats     = false;
            Edge      closest = mesh.Edges[edgeIndex];
            EdgeState toggled = Toggle(closest.State, buttons);

            actionsPerformed = new List <IAction>();
            if (closest.State != EdgeState.Empty)
            {
                IAction unsetAction = new UnsetAction(mesh, edgeIndex);
                bool    res         = unsetAction.Perform();
                if ((!res || !unsetAction.Successful) && disallowFalseMove)
                {
                    if (res && !unsetAction.Successful)
                    {
                        actionsPerformed.Add(unsetAction);
                    }
                    Unperform();
                    return(false);
                }
                else if (!res || !unsetAction.Successful)
                {
                    successful = false;
                }
                actionsPerformed.Add(unsetAction);
            }
            if (toggled != EdgeState.Empty)
            {
                bool res = mesh.Perform(edgeIndex, toggled, actionsPerformed, autoMove);
                if (!res && disallowFalseMove)
                {
                    Unperform();
                    return(false);
                }
                else if (!res)
                {
                    successful = false;
                }
            }
            return(true);
        }
    public void SetEdgeState(EdgeState edgeState)
    {
        switch (edgeState)
        {
        case EdgeState.Face:
            faceLine.SetActive(true);
            noFaceLine.SetActive(false);
            break;

        case EdgeState.NoFace:
            faceLine.SetActive(false);
            noFaceLine.SetActive(true);
            break;
        }
    }
Example #8
0
        /// <summary>
        /// Connect two nodes with an edge
        /// </summary>
        /// <param name="other">Node, to which current node is being connected</param>
        /// <param name="edgeState">State of the edge: Normal, Broken or Marked</param>
        /// <param name="edgeColor">Color of edge if Marked</param>
        /// <returns>Created edge or existing edge, if nodes were already linked</returns>
        public Edge LinkToNode(Node other, EdgeState edgeState = EdgeState.Normal, Color?edgeColor = null)
        {
            // If nodes are already linked => return existing edge
            if (_edges.SelectMany(x => x.Nodes).Contains(other))
            {
                return(_edges.Find(x => x.Nodes.Contains(other)));
            }

            Edge edge = new Edge(this, other, edgeState, edgeColor);

            // Add created edge to edges list of this and other node
            _edges.Add(edge);
            other._edges.Add(edge);

            return(edge);
        }
Example #9
0
 public EdgeStates(bool open)
 {
     if (open)
     {
         U = EdgeState.Open;
         R = EdgeState.Open;
         D = EdgeState.Open;
         L = EdgeState.Open;
     }
     else
     {
         U = EdgeState.Closed;
         R = EdgeState.Closed;
         D = EdgeState.Closed;
         L = EdgeState.Closed;
     }
 }
        //g.addV(T.label, 'person', T.id, '9', 'name', 'Brian', 'age', 42).as('a').properties('name').hasValue('Brian').property('acl','public').property('createdOn','12/01/2016').select('a').properties('age').hasValue(42).property('acl','private').select('a')
        internal async Task ClearEdgeStateAsync(GrainReference grainReference, EdgeState edgeState)
        {
            var graphElementGrain = grainReference.AsReference <IGraphElementGrain>();

            var feedOptions = new FeedOptions
            {
                PartitionKey = new PartitionKey(graphElementGrain.GetGraphPartition())
            };

            var dropCommand = $"g.E('{graphElementGrain.ToKeyString()}')";
            var writeQuery  = client.CreateGremlinQuery <CosmosDbEdge>(graph, dropCommand, feedOptions);
            var response    = await writeQuery.ExecuteNextAsync <CosmosDbEdge>();

            edgeState.Persisted = false;

            log.Info($"CosmosDB: Drop Vertex State: Request Charge: {response.RequestCharge}");
        }
        internal async Task ReadEdgeStateAsync(GrainReference grainReference, EdgeState edgeState)
        {
            var graphElementGrain = grainReference.AsReference <IGraphElementGrain>();

            var readExpression = $"g.E('{grainReference.ToKeyString()}')";

            var feedOptions = new FeedOptions
            {
                MaxItemCount = 1,
                PartitionKey = new PartitionKey(graphElementGrain.GetGraphPartition())
            };

            var readQuery = client.CreateGremlinQuery <CosmosDbEdge>(graph, readExpression, feedOptions, GraphSONMode.Normal);
            var response  = await readQuery.ExecuteNextAsync <CosmosDbEdge>();

            log.Info($"CosmosDB: Read Edge State: Request Charge: {response.RequestCharge}");

            var edge = response.FirstOrDefault();

            if (edge == null)
            {
                return;
            }

            edgeState.Persisted = true;

            var inV  = grainReferenceConverter.GetGrainFromKeyString(edge.InVertexId.ToString());
            var outV = grainReferenceConverter.GetGrainFromKeyString(edge.OutVertexId.ToString());

            inV.BindGrainReference(grainFactory);
            outV.BindGrainReference(grainFactory);

            edgeState.SetInVertex(inV.AsReference <IVertex>());
            edgeState.SetOutVertex(outV.AsReference <IVertex>());

            foreach (var property in edge.GetProperties())
            {
                if (property.Key[0] == '@' || property.Key == "partition")
                {
                    continue;
                }

                edgeState[property.Key] = property.Value.ToString();
            }
        }
Example #12
0
 public void ApplyState(GraphState state)
 {
     if (state == null)
     {
         return;
     }
     nodes.ForEach(delegate(Node n) {
         NodeState thisState = state.Nodes.Find(delegate(NodeState s) {
             return(n.Id == s.Id);
         });
         n.Colour = thisState.Colour;
     });
     edges.ForEach(delegate(Edge e) {
         EdgeState thisState = state.Edges.Find(delegate(EdgeState s) {
             return(e.Id == s.Id);
         });
         e.Colour = thisState.Colour;
         e.Flow   = thisState.Flow;
     });
 }
Example #13
0
    // Runs whenever the game loop updates
    public void Update()
    {
        if (OnClickEvent == null || State == EdgeState.Filled)
        {
            return;
        }

        foreach (Touch touch in Input.touches)
        {
            if (touch.phase == TouchPhase.Began)
            {
                Vector3 worldPos = Camera.main.ScreenToWorldPoint(touch.position);
                Vector2 touchPos = new Vector2(worldPos.x, worldPos.y);

                if (coll2D == Physics2D.OverlapPoint(touchPos))
                {
                    State = EdgeState.Filled;
                    rend.material.SetColor(App.SpriteRenderer.MainColorProperty, App.ColorPalette.Gray);
                    OnClickEvent();
                }
            }
        }
    }
        internal async Task WriteEdgeStateAsync(GrainReference grainReference, EdgeState edgeState)
        {
            var graphElementGrain = grainReference.AsReference <IGraphElementGrain>();

            var upsertExpression = (edgeState.Persisted ?
                                    CreateUpdateExpression(grainReference, edgeState, graphElementGrain) :
                                    CreateInsertExpression(grainReference, edgeState, graphElementGrain))
                                   .ToString();

            var feedOptions = new FeedOptions
            {
                MaxItemCount = 1,
                PartitionKey = new PartitionKey(graphElementGrain.GetGraphPartition())
            };

            var writeQuery = client.CreateGremlinQuery <CosmosDbEdge>(graph, upsertExpression, feedOptions, GraphSONMode.Normal);

            log.Info($"CosmosDB: Writing EdgeState for grain Id '{graphElementGrain.ToKeyString()}'");
            var response = await writeQuery.ExecuteNextAsync <CosmosDbEdge>();

            log.Info($"CosmosDB: Writing EdgeState complete: Request Charge: {response.RequestCharge}");

            edgeState.Persisted = true;
        }
Example #15
0
 // Runs whenever this edge needs to be reset
 public void Reset()
 {
     State = EdgeState.Empty;
     rend.material.SetColor(App.SpriteRenderer.MainColorProperty, App.ColorPalette.White);
 }
Example #16
0
 public void SetState(EdgeState state) => State = state;
        private static IEdgeResult CreateInsertExpression(GrainReference grainReference, EdgeState edgeState, IGraphElementGrain graphElementGrain)
        {
            var inVertex  = edgeState.GetInVertex();
            var outVertex = edgeState.GetOutVertex();

            var inVertexKeyString  = inVertex.ToKeyString();
            var outVertexKeyString = outVertex.ToKeyString();

            var insertExpression = g.V(inVertexKeyString)
                                   .addE(graphElementGrain.GetGraphLabel())
                                   .to(g.V(outVertexKeyString))
                                   .property("id", grainReference.ToKeyString());

            var partition = graphElementGrain.GetGraphPartition();

            if (!string.IsNullOrEmpty(partition))
            {
                insertExpression = insertExpression.property("partition", partition);
            }

            return(insertExpression.property(edgeState, p => (p.Key, p.Value)));
        }
 private static IEdgeResult CreateUpdateExpression(GrainReference grainReference, EdgeState edgeState, IGraphElementGrain graphElementGrain)
 {
     return(g.E()
            .has(graphElementGrain.GetGraphLabel(), "id", grainReference.ToKeyString())
            .property(edgeState, p => (p.Key, p.Value)));
 }
        public void GetAggregateRegionResults()
        {
            var          geminiOptions = new GeminiOptions();
            ChrReference chrReference  = null;
            var          refIdMapping  = new Dictionary <int, string>()
            {
                { 1, "chr1" }
            };
            var bamRealignmentFactory = new BamRealignmentFactory(new GeminiOptions(),
                                                                  new RealignmentAssessmentOptions(), new StitcherOptions(), new RealignmentOptions(), "out");

            var geminiFactory         = new GeminiFactory(geminiOptions, new IndelFilteringOptions());
            var dataSourceFactoryMock = new Mock <IGeminiDataSourceFactory>();
            var chromIndelSource      = new Mock <IChromosomeIndelSource>();

            //var indel = new KeyValuePair<HashableIndel, GenomeSnippet>();
            chromIndelSource
            .Setup(x => x.GetRelevantIndels(It.IsAny <int>(), It.IsAny <List <PreIndel> >(),
                                            It.IsAny <List <HashableIndel> >(), It.IsAny <List <PreIndel> >(), It.IsAny <List <PreIndel> >())).Returns(new List <KeyValuePair <HashableIndel, GenomeSnippet> >()
            {
                //indel
            });
            dataSourceFactoryMock
            .Setup(x => x.GetChromosomeIndelSource(It.IsAny <List <HashableIndel> >(),
                                                   It.IsAny <IGenomeSnippetSource>())).Returns(chromIndelSource.Object);
            var dataSourceFactory        = dataSourceFactoryMock.Object;
            var masterIndelLookup        = new ConcurrentDictionary <string, IndelEvidence>();
            var masterOutcomesLookup     = new ConcurrentDictionary <HashableIndel, int[]>();
            var masterFinalIndels        = new ConcurrentDictionary <HashableIndel, int>();
            var categoriesForRealignment = new List <PairClassification>();
            var progressTracker          = new ConcurrentDictionary <string, int>();

            var processor = new AggregateRegionProcessor(chrReference, refIdMapping, bamRealignmentFactory,
                                                         geminiOptions, geminiFactory, "chr1", dataSourceFactory, new RealignmentOptions()
            {
                CategoriesForSnowballing = new List <PairClassification>()
                {
                    PairClassification.Disagree
                }
            },
                                                         masterIndelLookup, masterOutcomesLookup, masterFinalIndels, categoriesForRealignment, progressTracker);

            var indelLookup     = new ConcurrentDictionary <string, IndelEvidence>();
            var binEvidence     = new BinEvidence(1, true, 20, false, 500, 1000);
            var edgeBinEvidence = new BinEvidence(1, true, 20, false, 500, 1000);
            var edgeState       = new EdgeState()
            {
                Name                 = "0-1000",
                EdgeAlignments       = new Dictionary <PairClassification, List <PairResult> >(),
                BinEvidence          = edgeBinEvidence,
                EdgeIndels           = new List <HashableIndel>(),
                EffectiveMinPosition = 0
            };

            var pairResultLookup =
                new ConcurrentDictionary <PairClassification, List <PairResult> >();

            pairResultLookup.TryAdd(PairClassification.Disagree, new List <PairResult>()
            {
                TestHelpers.GetPairResult(10000),
                TestHelpers.GetPairResult(10001),
                TestHelpers.GetPairResult(10002),
                TestHelpers.GetPairResult(19995)
            });
            pairResultLookup.TryAdd(PairClassification.SingleMismatchStitched, new List <PairResult>()
            {
                TestHelpers.GetPairResult(19995),
                TestHelpers.GetPairResult(19995)
            });

            // Borderline case: the max position in the pair is >= EffectiveMaxPosition - 5000, even if one of the reads in the pair is not
            var effectiveMax    = 19999;
            var r2BorderlinePos = effectiveMax - 5000 + 1;
            var offset          = 1;
            var r1BorderlinePos = r2BorderlinePos - offset;

            pairResultLookup.TryAdd(PairClassification.UnstitchForwardMessy, new List <PairResult>()
            {
                TestHelpers.GetPairResult(r1BorderlinePos, offset), // One is just over border
                TestHelpers.GetPairResult(r1BorderlinePos, 0),      // Both are within safe range
            });

            var regionData = new RegionDataForAggregation()
            {
                BinEvidence          = binEvidence,
                EdgeState            = edgeState,
                EffectiveMaxPosition = effectiveMax,
                EffectiveMinPosition = 10000,
                PairResultLookup     = pairResultLookup
            };
            var regionResults = processor.GetAggregateRegionResults(indelLookup,
                                                                    10000, 20000, false, regionData);

            // New edge state should have the correct items carrying over
            Assert.Equal("10000-20000", regionResults.EdgeState.Name);
            Assert.Equal(14999, regionResults.EdgeState.EffectiveMinPosition);
            Assert.Equal(4, regionResults.AlignmentsReadyToBeFlushed.Count); // The four that are solidly in-bounds should be flushable immediately

            var edgeAlignmentsLookup = regionResults.EdgeState.EdgeAlignments;

            Assert.Equal(1, edgeAlignmentsLookup[PairClassification.Disagree].Count);
            Assert.Equal(2, edgeAlignmentsLookup[PairClassification.SingleMismatchStitched].Count);
            Assert.Equal(1, edgeAlignmentsLookup[PairClassification.UnstitchForwardMessy].Count);
        }
Example #20
0
        private void PerformAction(bool?right, int closestEdge, int closestCell)
        {
            if (closestEdge != -1)
            {
                if (markedEdges.Contains(closestEdge))
                {
                    return;
                }
                if (noToggle && Mesh.Edges[closestEdge].State != EdgeState.Empty)
                {
                    return;
                }

                /*if (shiftPressed || controlPressed)
                 * {
                 *  if (shiftPressed)
                 *  {
                 *      if (lastShift == -1)
                 *          lastShift = closestEdge;
                 *      else
                 *      {
                 *          ColorJoinAction colorAction = new ColorJoinAction(Mesh, lastShift, closestEdge, true);
                 *          if (lastShift != closestEdge)
                 *              undoTree.Do(colorAction);
                 *          lastShift = -1;
                 *      }
                 *  }
                 *  else if (controlPressed)
                 *  {
                 *      if (lastControl == -1)
                 *          lastControl = closestEdge;
                 *      else
                 *      {
                 *          ColorJoinAction colorAction = new ColorJoinAction(Mesh, lastControl, closestEdge, false);
                 *          if (lastControl != closestEdge)
                 *              undoTree.Do(colorAction);
                 *          lastControl = -1;
                 *      }
                 *  }
                 *  UpdateChildControls();
                 *  return;
                 * }*/
                LoopClickAction action;
                if (right.HasValue)
                {
                    action = new LoopClickAction(Mesh, closestEdge, right.Value, autoMove, disallowFalseMove, useICInAuto, considerMultipleLoopsInAuto, useColoringInAuto, useCellColoringInAuto);
                }
                else
                {
                    if (Mesh.Edges[closestEdge].State == lastState)
                    {
                        return;
                    }
                    bool pretendRight = false;
                    switch (lastState)
                    {
                    case EdgeState.Filled:
                        if (Mesh.Edges[closestEdge].State == EdgeState.Excluded)
                        {
                            pretendRight = true;
                        }
                        break;

                    case EdgeState.Excluded:
                        if (Mesh.Edges[closestEdge].State == EdgeState.Empty)
                        {
                            pretendRight = true;
                        }
                        break;

                    case EdgeState.Empty:
                        if (Mesh.Edges[closestEdge].State == EdgeState.Filled)
                        {
                            pretendRight = true;
                        }
                        break;
                    }
                    action = new LoopClickAction(Mesh, closestEdge, pretendRight, autoMove, disallowFalseMove, useICInAuto, considerMultipleLoopsInAuto, useColoringInAuto, useCellColoringInAuto);
                }
                if (!undoTree.Do(action))
                {
                    /*
                     * redEdge = closestEdge;
                     * Thread thread = new Thread(new ThreadStart(ClearRed));
                     * thread.IsBackground = true;
                     * thread.Start();
                     */
                }
                else if (noToggle)
                {
                    /*
                     * if (MovePerformed != null)
                     *  MovePerformed(this, new MoveEventArgs(closestEdge, e.Button == MouseButtons.Left));
                     * */
                }
                else
                {
                    if (right.HasValue)
                    {
                        lastState = Mesh.Edges[closestEdge].State;
                    }
                    bool satisified = true;
                    bool nonempty   = false;
                    for (int i = 0; i < Mesh.Intersections.Count; i++)
                    {
                        if (Mesh.Intersections[i].FilledCount != 2 && Mesh.Intersections[i].FilledCount != 0)
                        {
                            satisified = false;
                            break;
                        }
                        if (Mesh.Intersections[i].Type != IntersType.Unknown)
                        {
                            nonempty = true;
                            if (!Mesh.TypeSatisfied(i))
                            {
                                satisified = false;
                                break;
                            }
                        }
                    }
                    if (satisified && nonempty)
                    {
                        Mesh copy = new Mesh(Mesh);
                        try
                        {
                            copy.Clear();
                            bool failed = false;
                            if (copy.TrySolve() != SolveState.Solved)
                            {
                                copy.SolverMethod = SolverMethod.Recursive;
                                //copy.UseIntersectCellInteractsInSolver = false;
                                copy.UseCellColoringTrials = false;
                                copy.UseCellColoring       = true;
                                copy.UseCellPairs          = false;
                                copy.UseCellPairsTopLevel  = true;
                                copy.UseColoring           = true;
                                copy.UseDerivedColoring    = true;
                                copy.UseEdgeRestricts      = true;
                                copy.UseMerging            = true;
                                copy.ConsiderMultipleLoops = true;
                                copy.ColoringCheats        = true;
                                if (copy.TrySolve() != SolveState.Solved)
                                {
                                    failed = true;
                                }
                            }
                            if (!failed)
                            {
                                bool done = true;
                                for (int i = 0; i < Mesh.Edges.Count; i++)
                                {
                                    if (copy.SolutionFound.Edges[i].State == EdgeState.Filled)
                                    {
                                        if (Mesh.Edges[i].State != EdgeState.Filled)
                                        {
                                            done = false;
                                        }
                                    }
                                    else if (Mesh.Edges[i].State == EdgeState.Filled)
                                    {
                                        done = false;
                                    }
                                }
                                if (done)
                                {
                                    FixPosition();
                                    copy.FullClear();
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                UpdateChildControls();
            }
            else if (closestCell != -1)
            {
                if (noToggle && Mesh.Cells[closestCell].Color != 0)
                {
                    return;
                }
                CellClickAction action = new CellClickAction(Mesh, closestCell, right.Value);
                undoTree.Do(action);
                UpdateChildControls();
            }
        }
Example #21
0
        private bool TestEdge()
        {
            int assertFailCount = 0;

            // test constructors
            // arrange
            INode     termNode1 = new Node <NodeState>("node1");
            EdgeState state2    = new EdgeState();
            INode     termNode2 = new Node <NodeState>("node1");

            // act
            IEdge edge1 = new Edge <EdgeState>("edge1", termNode1);
            IEdge edge2 = new Edge <EdgeState>("edge2", state2, termNode2, true);

            // assert
            if (edge1 == null)
            {
                assertFailCount++;
            }
            if (edge2 == null)
            {
                assertFailCount++;
            }
            EdgeState state11 = (EdgeState)edge1.GetState();

            if (!string.IsNullOrWhiteSpace(state11.ItemString))
            {
                assertFailCount++;
            }
            EdgeState state21 = (EdgeState)edge2.GetState();

            if (!string.IsNullOrWhiteSpace(state21.ItemString))
            {
                assertFailCount++;
            }
            if (!edge1.IsTerminalNode(termNode1.Name))
            {
                assertFailCount++;
            }
            if (!edge2.IsTerminalNode(termNode2.Name))
            {
                assertFailCount++;
            }

            // test methods
            // arrange
            state2.ItemString = "1234";

            // act
            edge2.Forward(termNode1);

            // assert
            if (state2.ItemString != "forward")
            {
                assertFailCount++;
            }

            // arrange
            state2.ItemString = "4321";

            // act
            try
            {
                edge2.Reverse(termNode1);
                assertFailCount++;
            }
            catch (InvalidOperationException ioex)
            {
                // good state
            }
            catch (Exception ex)
            {
                assertFailCount++;
            }

            // assert
            if (state2.ItemString != "4321")
            {
                assertFailCount++;
            }

            // arrange

            // act

            // assert

            // pass testing into the object
            //if (!((IInternalUnitTestable)edge2).ExecuteTest()) assertFailCount++;

            // cleanup
            edge1.Dispose();
            edge2.Dispose();

            // report results
            return(assertFailCount == 0);
        }
Example #22
0
 public void SetStateAndColor(EdgeState state, Color color)
 {
     SetState(state);
     Color = color;
 }
 private EdgeState Toggle(EdgeState loopLinkState, bool mouseButtons)
 {
     if (!mouseButtons)
     {
         if (loopLinkState == EdgeState.Filled)
             return EdgeState.Excluded;
         else if (loopLinkState == EdgeState.Excluded)
             return EdgeState.Empty;
         else
             return EdgeState.Filled;
     }
     else
     {
         if (loopLinkState == EdgeState.Excluded)
             return EdgeState.Filled;
         else if (loopLinkState == EdgeState.Filled)
             return EdgeState.Empty;
         else
             return EdgeState.Excluded;
     }
 }
Example #24
0
 private EdgeState Toggle(EdgeState loopLinkState, MouseButtons mouseButtons)
 {
     if (mouseButtons == MouseButtons.Left)
     {
         if (loopLinkState == EdgeState.Filled)
             return EdgeState.Empty;
         else
             return EdgeState.Filled;
     }
     else if (mouseButtons == MouseButtons.Right)
     {
         if (loopLinkState == EdgeState.Excluded)
             return EdgeState.Empty;
         else
             return EdgeState.Excluded;
     }
     return loopLinkState;
 }
 private void PerformAction(bool? right, int closestEdge, int closestCell)
 {
     if (closestEdge != -1)
     {
         if (markedEdges.Contains(closestEdge))
             return;
         if (noToggle && Mesh.Edges[closestEdge].State != EdgeState.Empty)
             return;
         /*if (shiftPressed || controlPressed)
         {
             if (shiftPressed)
             {
                 if (lastShift == -1)
                     lastShift = closestEdge;
                 else
                 {
                     ColorJoinAction colorAction = new ColorJoinAction(Mesh, lastShift, closestEdge, true);
                     if (lastShift != closestEdge)
                         undoTree.Do(colorAction);
                     lastShift = -1;
                 }
             }
             else if (controlPressed)
             {
                 if (lastControl == -1)
                     lastControl = closestEdge;
                 else
                 {
                     ColorJoinAction colorAction = new ColorJoinAction(Mesh, lastControl, closestEdge, false);
                     if (lastControl != closestEdge)
                         undoTree.Do(colorAction);
                     lastControl = -1;
                 }
             }
             UpdateChildControls();
             return;
         }*/
         LoopClickAction action;
         if (right.HasValue)
         {
             action = new LoopClickAction(Mesh, closestEdge, right.Value, autoMove, disallowFalseMove, useICInAuto, considerMultipleLoopsInAuto, useColoringInAuto, useCellColoringInAuto);
         }
         else
         {
             if (Mesh.Edges[closestEdge].State == lastState)
                 return;
             bool pretendRight = false;
             switch (lastState)
             {
                 case EdgeState.Filled:
                     if (Mesh.Edges[closestEdge].State == EdgeState.Excluded)
                         pretendRight = true;
                     break;
                 case EdgeState.Excluded:
                     if (Mesh.Edges[closestEdge].State == EdgeState.Empty)
                         pretendRight = true;
                     break;
                 case EdgeState.Empty:
                     if (Mesh.Edges[closestEdge].State == EdgeState.Filled)
                         pretendRight = true;
                     break;
             }
             action = new LoopClickAction(Mesh, closestEdge, pretendRight, autoMove, disallowFalseMove, useICInAuto, considerMultipleLoopsInAuto, useColoringInAuto, useCellColoringInAuto);
         }
         if (!undoTree.Do(action))
         {
             /*
             redEdge = closestEdge;
             Thread thread = new Thread(new ThreadStart(ClearRed));
             thread.IsBackground = true;
             thread.Start();
              */
         }
         else if (noToggle)
         {
             /*
             if (MovePerformed != null)
                 MovePerformed(this, new MoveEventArgs(closestEdge, e.Button == MouseButtons.Left));
              * */
         }
         else
         {
             if (right.HasValue)
             {
                 lastState = Mesh.Edges[closestEdge].State;
             }
             bool satisified = true;
             for (int i = 0; i < Mesh.Cells.Count; i++)
             {
                 if (Mesh.Cells[i].TargetCount >= 0 && Mesh.Cells[i].FilledCount != Mesh.Cells[i].TargetCount)
                     satisified = false;
             }
             if (satisified)
             {
                 Mesh copy = new Mesh(Mesh);
                 try
                 {
                     copy.Clear();
                     bool failed = false;
                     if (copy.TrySolve() != SolveState.Solved)
                     {
                         copy.SolverMethod = SolverMethod.Recursive;
                         copy.UseIntersectCellInteractsInSolver = false;
                         copy.UseCellColoringTrials = false;
                         copy.UseCellColoring = true;
                         copy.UseCellPairs = false;
                         copy.UseCellPairsTopLevel = true;
                         copy.UseColoring = true;
                         copy.UseDerivedColoring = true;
                         copy.UseEdgeRestricts = true;
                         copy.UseMerging = true;
                         copy.ConsiderMultipleLoops = true;
                         copy.ColoringCheats = true;
                         if (copy.TrySolve() != SolveState.Solved)
                         {
                             failed = true;
                         }
                     }
                     if (!failed)
                     {
                         bool done = true;
                         for (int i = 0; i < Mesh.Edges.Count; i++)
                         {
                             if (copy.SolutionFound.Edges[i].State == EdgeState.Filled)
                             {
                                 if (Mesh.Edges[i].State != EdgeState.Filled)
                                     done = false;
                             }
                             else if (Mesh.Edges[i].State == EdgeState.Filled)
                                 done = false;
                         }
                         if (done)
                         {
                             FixPosition();
                             copy.FullClear();
                             ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object o) { GenerateNew(copy); }));
                         }
                     }
                 }
                 catch
                 {
                 }
             }
         }
         UpdateChildControls();
     }
     else if (closestCell != -1)
     {
         if (noToggle && Mesh.Cells[closestCell].Color != 0)
             return;
         CellClickAction action = new CellClickAction(Mesh, closestCell, right.Value);
         undoTree.Do(action);
         UpdateChildControls();
     }
 }