Beispiel #1
0
        public void JsonSerializeVertexStorage()
        {
            var test1Control = new VertexStorage();

            test1Control.MoveTo(10, 11);
            test1Control.LineTo(100, 11);
            test1Control.LineTo(100, 110);
            test1Control.ClosePolygon();
            string jsonData    = JsonConvert.SerializeObject(test1Control);
            var    test1Result = JsonConvert.DeserializeObject <VertexStorage>(jsonData);

            Assert.AreEqual(test1Control.Count, test1Result.Count);

            var control = test1Control.Vertices().GetEnumerator();
            var result  = test1Result.Vertices().GetEnumerator();

            for (int i = 0; i < test1Control.Count; i++)
            {
                control.MoveNext();
                result.MoveNext();
                var controlVertex = control.Current;
                var resultVertex  = result.Current;
                Assert.AreEqual(controlVertex.command, resultVertex.command);
                Assert.AreEqual(controlVertex.position, resultVertex.position);
            }
        }
Beispiel #2
0
            public ClosedLoopGlyphData(VertexStorage source)
            {
                storage = new VertexStorage();

                var vertexData = source.Vertices().Where(v => v.command != ShapePath.FlagsAndCommand.FlagNone).ToArray();

                VertexData previous = default(VertexData);

                for (var i = 0; i < vertexData.Length; i++)
                {
                    var current = vertexData[i];

                    // All MoveTo operations should be preceded by ClosePolygon
                    if (i > 0 &&
                        current.IsMoveTo &&
                        ShapePath.is_vertex(previous.command))
                    {
                        storage.ClosePolygon();
                    }

                    // Add original VertexData
                    storage.Add(current.position.X, current.position.Y, current.command);

                    // Hold prior item
                    previous = current;
                }

                // Ensure closed
                storage.ClosePolygon();
            }
        public VertexStorageObject3D(VertexStorage vertexStorage)
        {
            this.vertexStorage = vertexStorage;

            this.Children.Modify(children =>
            {
                int i = 0;
                foreach (var v in vertexStorage.Vertices())
                {
                    if (!v.IsMoveTo && !v.IsLineTo)
                    {
                        continue;
                    }

                    var localVertex = v;

                    var localIndex = i++;

                    var item = new Object3D()
                    {
                        Mesh   = CreateCylinder(1, 1),
                        Matrix = Matrix4X4.CreateTranslation(v.position.X, v.position.Y, 0),
                        Color  = Color.Green
                    };

                    item.Invalidated += (s, e) =>
                    {
                        System.Diagnostics.Debugger.Break();
                        //vertexStorage.modify_vertex(localIndex, item.Matrix.Position.X, localVertex.position.Y = item.Matrix.Position.Y);
                    };

                    children.Add(item);
                }

                children.Add(generatedMesh = new Object3D()
                {
                    Mesh  = VertexSourceToMesh.Extrude(vertexStorage, 0.5),
                    Color = new Color("#93CEFF99")
                });
            });

            this.Invalidated += (s, e) =>
            {
                // Recompute path from content
                generatedMesh.Mesh = VertexSourceToMesh.Extrude(vertexStorage, 0.5);
                //VertexSourceToMesh.Revolve(vertexStorage));
            };
        }
Beispiel #4
0
 public IEnumerable <VertexData> Vertices()
 {
     return(storage.Vertices());
 }