コード例 #1
0
 /// <summary>
 /// Finds edge that connects to the vertex and is not equal to given edge.
 /// </summary>
 /// <param name="a_edge"></param>
 /// <param name="a_vertex"></param>
 /// <returns></returns>
 public TriangleEdge OtherEdge(TriangleEdge a_edge, Vector2 a_vertex)
 {
     if (!Edges.Contains(a_edge) || !Vertices.Contains(a_vertex))
     {
         throw new GeomException("Edge or vertex not contained in triangle");
     }
     return(Edges.Find(e => e != a_edge && e.IsEndpoint(a_vertex)));
 }
コード例 #2
0
 /// <summary>
 /// Finds the edge that is not equal to given two.
 /// </summary>
 /// <param name="a_edge0"></param>
 /// <param name="a_edge1"></param>
 /// <returns></returns>
 public TriangleEdge OtherEdge(TriangleEdge a_edge0, TriangleEdge a_edge1)
 {
     if (!Edges.Contains(a_edge0) || !Edges.Contains(a_edge1))
     {
         throw new GeomException("One of the edges not contained in triangle");
     }
     return(Edges.Find(e => e != a_edge0 && e != a_edge1));
 }
コード例 #3
0
ファイル: Quadrangle.cs プロジェクト: damrem/ld48
        public Edge GetOppositeSide(Edge side)
        {
            if (!Edges.Contains(side))
            {
                throw new Exception("Side is not part of this quadrangle.");
            }

            return(Edges.Find(s => !s.HasVertex(side.A) && !s.HasVertex(side.B)));
        }
コード例 #4
0
        /// <summary>Gets the <see cref="Edge"/> in <see cref="Edges"/> with the specified id.</summary>
        /// <param name="id">The id of the <see cref="Edge"/>.</param>
        /// <returns>The <see cref="Edge"/>, <c>null</c> if it can't be found.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public Edge GetEdgeById(string id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }

            return(Edges.Find(e => e.Id == id));
        }
コード例 #5
0
        private Edge FindEdge(Transaction tr)
        {
            var res = Edges.Find(e => e.Start.Id == tr.StartNode.Id && e.End.Id == tr.EndNode.Id);

            if (res == null)
            {
                res = new Edge(tr.StartNode, tr.EndNode);
                Edges.Add(res);
                DbConn.Dg_InsertNewEdge(res);
            }

            return(res);
        }
コード例 #6
0
        public int GetEdgeWeight(Node start, Node end)
        {
            int weight = -1;

            try
            {
                weight = Edges.Find(n => n.Start.Equals(start) && n.End.Equals(end)).Weight;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(weight);
        }
コード例 #7
0
        public void AddEdge(int from, int to, double capacity, double f = -1)
        {
            if (from == to)
            {
                throw new InvalidConfigurationException("'from' cant equals 'to'");
            }

            if (capacity < 0)
            {
                throw new InvalidConfigurationException($"Capacity can't be less than 0");
            }

            FlowEdge sameEdge = null;

            try
            {
                sameEdge = Edges.Find((e) => (e.From == from && e.To == to) || (e.From == to && e.To == from));
            } catch (Exception e) { }

            if (sameEdge != null)
            {
                throw new InvalidConfigurationException($"Edge between {from} and {to} already exists");
            }

            var edge = f == -1 ? new FlowEdge(from, to, capacity) : new FlowEdge(from, to, capacity, f);

            edge.OnFlowChanged   += (sender) => OnEdgeFlowChanged?.Invoke(this, sender);
            edge.OnLengthChanged += (sender, length) => OnEdgeLengthChanged?.Invoke(this, sender);
            edge.OnEdgeMarked    += (sender) => OnEdgeMarked?.Invoke(this, sender);
            edge.OnEdgeUnmarked  += (sender) => OnEdgeUnmarked?.Invoke(this, sender);

            Edges.Add(edge);
            if (!Nodes.ContainsKey(edge.From))
            {
                Nodes.Add(edge.From, new FlowNode(edge.From));
            }

            if (!Nodes.ContainsKey(edge.To))
            {
                Nodes.Add(edge.To, new FlowNode(edge.To));
            }

            Nodes[edge.From].AddEdge(ref edge);
            Nodes[edge.To].AddEdge(ref edge);
        }
コード例 #8
0
        public bool IsCorrectAnswer(List <ShipmentEdge> edgeAnswers)
        {
            for (int i = 0; i < edgeAnswers.Count; i++)
            {
                edgeAnswers[i].Length = edgeAnswers[i].Length / Scale;
                ShipmentEdge edge = Edges.Find(e => e.Equals(edgeAnswers[i]));
                if (edge == null)
                {
                    return(false);
                }
            }
            bool isCorrectAnswer = edgeAnswers[edgeAnswers.Count - 1].IdNodeB == Nodes.Find(e => e.Type == ShipmentNodeType.Finish).Id;

            if (lastCorrect)
            {
                _currentLevel++;
            }
            lastCorrect = isCorrectAnswer;
            LogAnswer(isCorrectAnswer);
            return(isCorrectAnswer);
        }
コード例 #9
0
 private ShipmentEdge GetEdge(int idA, int idB)
 {
     return(Edges.Find(e => (e.IdNodeA == idA && e.IdNodeB == idB) || (e.IdNodeA == idB && e.IdNodeB == idA)));
 }
コード例 #10
0
ファイル: Face.cs プロジェクト: berkersonmez/Planar-Graph
        // Can be used to traverse the boundary edges of the
        // face in a clockwise or counter-clockwise sense.
        // Finds the edge that is connected to the given edge but not prevnode
        public Edge GetNextEdge(Edge edge, Node prevNode)
        {
            Node otherNode = edge.OtherNode(prevNode);

            return(Edges.Find(e => (e.Node1 == otherNode && e.Node2 != prevNode) || (e.Node2 == otherNode && e.Node1 != prevNode)));
        }
コード例 #11
0
 /// <summary>
 /// Finds a graph edge who has the edgeObj bound
 /// </summary>
 /// <param name="edgeObj">Object that is bound to the edge</param>
 /// <returns></returns>
 public GraphEdge <E, N> FindGraphEdge(E edgeObj)
 {
     return(Edges.Find(e => { return e == edgeObj; }));
 }