public VertexEdgesSet(
     TVertex vertex,
     IEnumerable <Edge <TVertex> > edges)
 {
     Vertex = vertex;
     Edges  = edges;
 }
            private void ReadVertex([NotNull] IDictionary <string, TVertex> vertices)
            {
                Debug.Assert(vertices != null);
                Debug.Assert(
                    _reader.NodeType == XmlNodeType.Element &&
                    _reader.Name == NodeTag &&
                    _reader.NamespaceURI == _graphMLNamespace);

                // Get subtree
                using (XmlReader subReader = _reader.ReadSubtree())
                {
                    // Read id
                    string id = ReadAttributeValue(_reader, IdAttribute);
                    // Create new vertex
                    TVertex vertex = _vertexFactory(id);
                    // Apply defaults
                    ReadDelegateCompiler.SetVertexDefault(vertex);
                    // Read data
                    while (subReader.Read())
                    {
                        if (_reader.NodeType == XmlNodeType.Element &&
                            _reader.Name == DataTag &&
                            _reader.NamespaceURI == _graphMLNamespace)
                        {
                            ReadDelegateCompiler.VertexAttributesReader(subReader, _graphMLNamespace, vertex);
                        }
                    }

                    // Add to graph
                    _graph.AddVertex(vertex);
                    vertices.Add(id, vertex);
                }
            }
Beispiel #3
0
 public TarjanVertexInfo(TVertex vertex)
 {
     Vertex  = vertex;
     Index   = null;
     LowLink = 0;
     OnStack = false;
 }
Beispiel #4
0
 public VertexEdgesSet(
     [NotNull] TVertex vertex,
     [NotNull, ItemNotNull] IEnumerable <Edge <TVertex> > edges)
 {
     Vertex = vertex;
     Edges  = edges;
 }
Beispiel #5
0
 public VertexData(double distance, TEdge _edge)
 {
     this.Distance     = distance;
     this._predecessor = default(TVertex);
     this._edge        = _edge;
     this.edgeStored   = true;
 }
Beispiel #6
0
            /// <summary>
            /// Adds a vertex to the builder.
            /// </summary>
            /// <returns>The index of the vertex for triangle creation.</returns>
            public int AddVertex(TVertex v)
            {
                var i = this.vertices.Count;

                this.vertices.Add(v);
                return(i);
            }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SugiVertex"/> class.
 /// </summary>
 /// <param name="originalVertex">Wrapped vertex.</param>
 /// <param name="type">Vertex type.</param>
 /// <param name="size">Vertex size.</param>
 public SugiVertex(TVertex originalVertex, VertexTypes type, Size size)
 {
     OriginalVertex = originalVertex;
     Type           = type;
     Size           = size;
     Segment        = null;
 }
 // Null edge for self edge data
 public VertexData(double distance, [CanBeNull] TEdge edge)
 {
     Distance     = distance;
     _predecessor = default(TVertex);
     _edge        = edge;
     _edgeStored  = true;
 }
 public SugiVertex(TVertex originalVertex, SKSize size)
 {
     Size           = size;
     OriginalVertex = originalVertex;
     Type           = VertexTypes.Original;
     Segment        = null;
 }
            private void ReadVertex(Dictionary <string, TVertex> vertices)
            {
                Contract.Requires(vertices != null);
                Contract.Assert(
                    this.Reader.NodeType == XmlNodeType.Element &&
                    this.Reader.Name == "node" &&
                    this.Reader.NamespaceURI == this.graphMLNamespace);

                // get subtree
                using (var subReader = this.Reader.ReadSubtree())
                {
                    // read id
                    string id = ReadAttributeValue(this.Reader, "id");
                    // create new vertex
                    TVertex vertex = vertexFactory(id);
                    // apply defaults
                    ReadDelegateCompiler.SetVertexDefault(vertex);
                    // read data
                    while (subReader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element &&
                            reader.Name == "data" &&
                            reader.NamespaceURI == this.graphMLNamespace)
                        {
                            ReadDelegateCompiler.VertexAttributesReader(subReader, this.graphMLNamespace, vertex);
                        }
                    }
                    // add to graph
                    this.VisitedGraph.AddVertex(vertex);
                    vertices.Add(id, vertex);
                }
            }
 public IEnumerable <TEdge> GetAdjacentEdges(TVertex item)
 {
     if (Data.TryGetValue(item, out var value))
     {
         return(value.AsEnumerable());
     }
     return(Enumerable.Empty <TEdge>());
 }
            public SwapPair(TVertex vertex1, TVertex vertex2)
            {
                Debug.Assert(vertex1 != null);
                Debug.Assert(vertex2 != null);

                Vertex1 = vertex1;
                Vertex2 = vertex2;
            }
 protected VertexData(TVertex vertex, VertexData movableParent, bool isFixedToParent, Point position)
 {
     Vertex          = vertex;
     MovableParent   = movableParent;
     IsFixedToParent = isFixedToParent;
     Parent          = null;
     Position        = position;
 }
Beispiel #14
0
            /// <summary>
            /// Adds a vertex to the builder.
            /// </summary>
            /// <returns>The index of the first vertex for triangle creation.
            /// Indices for following vertices incrent by 1 each.</returns>
            public int AddVertices(TVertex v0, TVertex v1)
            {
                var i = this.vertices.Count;

                this.vertices.Add(v0);
                this.vertices.Add(v1);
                return(i);
            }
Beispiel #15
0
            public SwapPair([NotNull] TVertex vertex1, [NotNull] TVertex vertex2)
            {
                Debug.Assert(vertex1 != null);
                Debug.Assert(vertex2 != null);

                Vertex1 = vertex1;
                Vertex2 = vertex2;
            }
Beispiel #16
0
        /// <summary>
        /// Finds the convex hull and creates the TFace objects.
        /// </summary>
        /// <typeparam name="TVertex"></typeparam>
        /// <typeparam name="TFace"></typeparam>
        /// <returns></returns>
        private IEnumerable <TFace> GetConvexFacesInternal <TVertex, TFace>()
            where TFace : ConvexFace <TVertex, TFace>, new()
            where TVertex : IVertex
        {
            if (!Computed)
            {
                GetConvexHullInternal <TVertex>(true);
            }

            var faces     = ConvexFaces;
            int cellCount = faces.Count;
            var cells     = new TFace[cellCount];

            for (int i = 0; i < cellCount; i++)
            {
                var face     = faces[i];
                var vertices = new TVertex[Dimension];
                for (int j = 0; j < Dimension; j++)
                {
                    vertices[j] = (TVertex)face.Vertices[j].Vertex;
                }
                cells[i] = new TFace
                {
                    Vertices  = vertices,
                    Adjacency = new TFace[Dimension],
                    Normal    = face.Normal
                };
                face.Tag = i;
            }

            for (int i = 0; i < cellCount; i++)
            {
                var face = faces[i];
                var cell = cells[i];
                for (int j = 0; j < Dimension; j++)
                {
                    if (face.AdjacentFaces[j] == null)
                    {
                        continue;
                    }
                    cell.Adjacency[j] = cells[face.AdjacentFaces[j].Tag];
                }

                // Fix the vertex orientation.
                if (face.IsNormalFlipped)
                {
                    var tempVert = cell.Vertices[0];
                    cell.Vertices[0]             = cell.Vertices[Dimension - 1];
                    cell.Vertices[Dimension - 1] = tempVert;

                    var tempAdj = cell.Adjacency[0];
                    cell.Adjacency[0]             = cell.Adjacency[Dimension - 1];
                    cell.Adjacency[Dimension - 1] = tempAdj;
                }
            }

            return(cells);
        }
            public VertexData(double distance, [NotNull] TVertex predecessor)
            {
                Debug.Assert(predecessor != null);

                Distance     = distance;
                _predecessor = predecessor;
                _edge        = default(TEdge);
                _edgeStored  = false;
            }
 public LinLogVertex(
     int index,
     [NotNull] TVertex vertex,
     [NotNull, ItemNotNull] LinLogEdge[] attractions)
 {
     Index          = index;
     OriginalVertex = vertex;
     Attractions    = attractions;
 }
 public SearchFrame(TVertex vertex, IEnumerator <TEdge> edges, int depth)
 {
     Contract.Requires(vertex != null);
     Contract.Requires(edges != null);
     Contract.Requires(depth >= 0);
     this.Vertex = vertex;
     this.Edges  = edges;
     this.Depth  = depth;
 }
Beispiel #20
0
 public VertexData(double distance, TEdge edge)
 {
     //Contract.Requires(edge != null);
     this.Distance          = distance;
     this._predecessor      = default(TVertex);
     this.predecessorStored = false;
     this._edge             = edge;
     this.edgeStored        = true;
 }
Beispiel #21
0
            public VertexData(double distance, TVertex predecessor)
            {
                Contract.Requires(predecessor != null);

                this.Distance     = distance;
                this._predecessor = predecessor;
                this._edge        = default(TEdge);
                this.edgeStored   = false;
            }
Beispiel #22
0
            public void RemoveAllTargetingVertex(TVertex target)
            {
                var edges = heap.Where(e => e.Target.Equals(target));

                foreach (var e in edges)
                {
                    Remove(heap.IndexOf(e));
                }
            }
Beispiel #23
0
 public SimpleVertexData(
     [NotNull] TVertex vertex,
     VertexData movableParent,
     bool isFixedToParent,
     Point position,
     Size size)
     : base(vertex, movableParent, isFixedToParent, position)
 {
     Size = size;
 }
Beispiel #24
0
            public SearchFrame(TVertex vertex, IEnumerator <TEdge> edges, int depth)
            {
                Debug.Assert(vertex != null);
                Debug.Assert(edges != null);
                Debug.Assert(depth >= 0);

                Vertex = vertex;
                Edges  = edges;
                Depth  = depth;
            }
Beispiel #25
0
            public SearchFrame([NotNull] TVertex vertex, [NotNull] IEnumerator <TEdge> edges, int depth)
            {
                Debug.Assert(vertex != null);
                Debug.Assert(edges != null);
                Debug.Assert(depth >= 0, "Must be positive.");

                Vertex = vertex;
                Edges  = edges;
                Depth  = depth;
            }
Beispiel #26
0
            private void ReadElements()
            {
                this.Reader.ReadStartElement("graph");

                Dictionary <string, TVertex> vertices = new Dictionary <string, TVertex>();

                // read vertices or edges
                while (this.Reader.Read())
                {
                    if (this.Reader.NodeType == XmlNodeType.Element)
                    {
                        if (this.Reader.Name == "node")
                        {
                            // get subtree
                            XmlReader subReader = this.Reader.ReadSubtree();
                            // read id
                            string id = this.ReadAttributeValue("id");
                            // create new vertex
                            TVertex vertex = vertexFactory.CreateVertex(id);
                            // read data
                            GraphMLSerializer <TVertex, TEdge> .DelegateCompiler.VertexAttributesReader(subReader, vertex);

                            // add to graph
                            this.VisitedGraph.AddVertex(vertex);
                            vertices.Add(vertex.ID, vertex);
                        }
                        else if (this.Reader.Name == "edge")
                        {
                            // get subtree
                            XmlReader subReader = reader.ReadSubtree();
                            // read id
                            string  id       = this.ReadAttributeValue("id");
                            string  sourceid = this.ReadAttributeValue("source");
                            TVertex source;
                            if (!vertices.TryGetValue(sourceid, out source))
                            {
                                throw new ArgumentException("Could not find vertex " + sourceid);
                            }
                            string  targetid = this.ReadAttributeValue("target");
                            TVertex target;
                            if (!vertices.TryGetValue(targetid, out target))
                            {
                                throw new ArgumentException("Could not find vertex " + targetid);
                            }

                            TEdge edge = this.edgeFactory.CreateEdge(id, source, target);

                            // read data
                            GraphMLSerializer <TVertex, TEdge> .DelegateCompiler.EdgeAttributesReader(subReader, edge);

                            this.VisitedGraph.AddEdge(edge);
                        }
                    }
                }
            }
Beispiel #27
0
        /// <summary>
        /// Finds the convex hull and creates the TFace objects.
        /// </summary>
        /// <typeparam name="TFace">The type of the t face.</typeparam>
        /// <typeparam name="TVertex">The type of the t vertex.</typeparam>
        /// <returns>TFace[].</returns>
        private TFace[] GetConvexFaces <TVertex, TFace>()
            where TFace : ConvexFace <TVertex, TFace>, new()
            where TVertex : IVertex
        {
            var faces     = ConvexFaces;
            var cellCount = faces.Count;
            var cells     = new TFace[cellCount];

            for (var i = 0; i < cellCount; i++)
            {
                var face     = FacePool[faces[i]];
                var vertices = new TVertex[NumOfDimensions];
                for (var j = 0; j < NumOfDimensions; j++)
                {
                    vertices[j] = (TVertex)Vertices[face.Vertices[j]];
                }

                cells[i] = new TFace
                {
                    Vertices  = vertices,
                    Adjacency = new TFace[NumOfDimensions],
                    Normal    = IsLifted ? null : face.Normal
                };
                face.Tag = i;
            }

            for (var i = 0; i < cellCount; i++)
            {
                var face = FacePool[faces[i]];
                var cell = cells[i];
                for (var j = 0; j < NumOfDimensions; j++)
                {
                    if (face.AdjacentFaces[j] < 0)
                    {
                        continue;
                    }
                    cell.Adjacency[j] = cells[FacePool[face.AdjacentFaces[j]].Tag];
                }

                // Fix the vertex orientation.
                if (face.IsNormalFlipped)
                {
                    var tempVert = cell.Vertices[0];
                    cell.Vertices[0] = cell.Vertices[NumOfDimensions - 1];
                    cell.Vertices[NumOfDimensions - 1] = tempVert;

                    var tempAdj = cell.Adjacency[0];
                    cell.Adjacency[0] = cell.Adjacency[NumOfDimensions - 1];
                    cell.Adjacency[NumOfDimensions - 1] = tempAdj;
                }
            }

            return(cells);
        }
        /// <summary>
        /// Поиск выпуклой оболочки и создание объекта Face
        /// </summary>
        TFace[] GetConvexFaces <TVertex, TFace>()
            where TFace : ConvexFace <TVertex, TFace>, new()
            where TVertex : IVertex
        {
            var faces     = ConvexFaces;
            int cellCount = faces.Count;
            var cells     = new TFace[cellCount];

            for (int i = 0; i < cellCount; i++)
            {
                var face     = FacePool[faces[i]];
                var vertices = new TVertex[Dimension];
                for (int j = 0; j < Dimension; j++)
                {
                    vertices[j] = (TVertex)this.Vertices[face.Vertices[j]];
                }

                cells[i] = new TFace
                {
                    Vertices  = vertices,
                    Adjacency = new TFace[Dimension],
                    Normal    = IsLifted ? null : face.Normal
                };
                face.Tag = i;
            }

            for (int i = 0; i < cellCount; i++)
            {
                var face = FacePool[faces[i]];
                var cell = cells[i];
                for (int j = 0; j < Dimension; j++)
                {
                    if (face.AdjacentFaces[j] < 0)
                    {
                        continue;
                    }
                    cell.Adjacency[j] = cells[FacePool[face.AdjacentFaces[j]].Tag];
                }

                // Закрепление ориентации вершин
                if (face.IsNormalFlipped)
                {
                    var tempVert = cell.Vertices[0];
                    cell.Vertices[0]             = cell.Vertices[Dimension - 1];
                    cell.Vertices[Dimension - 1] = tempVert;

                    var tempAdj = cell.Adjacency[0];
                    cell.Adjacency[0]             = cell.Adjacency[Dimension - 1];
                    cell.Adjacency[Dimension - 1] = tempAdj;
                }
            }

            return(cells);
        }
 public bool RemoveVertex(TVertex item)
 {
     if (Data.TryGetValue(item, out var value))
     {
         if (Data.Remove(item))
         {
             Count -= value.Count;
             return(true);
         }
     }
     return(false);
 }
Beispiel #30
0
        private void BallToNextStair()
        {
            int CurrentStairBallOn = IndexCurrentStairBallOn;

            IndexCurrentStairBallOn = ChangeCurrentStairBallOn();

            if (IndexCurrentStairBallOn > CurrentStairBallOn)
            {
                TVertex ballPos = new TVertex(Ball.GetXPos(), Ball.GetYPos(), Ball.GetZPos());
                ballPos.Y  = Stairs[IndexCurrentStairBallOn].GetYPos() + STAIR_HEIGHT + BALL_RADIUS;
                ballPos.Z += 12;

                Ball.SetPos(ballPos.X, ballPos.Y, ballPos.Z);
            }
        }
Beispiel #31
0
 void AddVertex(int id)
 {
     TVertex vertex = new TVertex(id);
     vertexes.Add(vertex);
 }
Beispiel #32
0
            public bool Load(BinaryReader br, byte majorVersion, byte minorVersion, bool main)
            {
                Name = br.ReadCString(40);
                ParentName = br.ReadCString(40);

                IsMain = main;

                int textureCount = br.ReadInt32();
                Textures = new int[textureCount];

                for (int i = 0; i < textureCount; i++)
                {
                    Textures[i] = br.ReadInt32();
                }

                OffsetMT = new float[12];
                for (int i = 0; i < 12; i++)
                {
                    OffsetMT[i] = br.ReadSingle();
                }

                Position.Read(br);
                RotAngle = br.ReadSingle();
                RotAxis.Read(br);
                Scale.Read(br);

                int vertexCount = br.ReadInt32();
                Vertices = new Vertex[vertexCount];

                for (int i = 0; i < vertexCount; i++)
                {
                    Vertices[i].Read(br);
                }

                int tvertexCount = br.ReadInt32();
                TVertices = new TVertex[tvertexCount];

                for (int i = 0; i < tvertexCount; i++)
                {
                    TVertices[i].Read(br, majorVersion, minorVersion);
                }

                int faceCount = br.ReadInt32();
                Faces = new Face[faceCount];

                for (int i = 0; i < faceCount; i++)
                {
                    Face f = new Face();

                    f.VertexID = new ushort[3];
                    f.TVertexID = new ushort[3];

                    for (int n = 0; n < 3; n++)
                        f.VertexID[n] = br.ReadUInt16();

                    for (int n = 0; n < 3; n++)
                        f.TVertexID[n] = br.ReadUInt16();

                    f.TexID = br.ReadUInt16();
                    f.Padding = br.ReadUInt16();
                    f.TwoSide = br.ReadInt32();

                    if (majorVersion >= 1 && minorVersion >= 2)
                    {
                        f.SmoothGroup = br.ReadInt32();
                    }
                    else
                    {
                        f.SmoothGroup = 0;
                    }

                    Faces[i] = f;
                }

                if (majorVersion >= 1 && minorVersion >= 5)
                {
                    int frameCount = br.ReadInt32();
                    PosKeyFrames = new PosKeyFrame[frameCount];

                    for (int i = 0; i < frameCount; i++)
                    {
                        PosKeyFrame pfk = new PosKeyFrame();

                        pfk.Read(br);

                        PosKeyFrames[i] = pfk;
                    }
                }

                int rotFrameCount = br.ReadInt32();
                RotKeyFrames = new RotKeyFrame[rotFrameCount];

                for (int i = 0; i < rotFrameCount; i++)
                {
                    RotKeyFrame rfk = new RotKeyFrame();

                    rfk.Read(br);

                    RotKeyFrames[i] = rfk;
                }

                return true;
            }