コード例 #1
0
ファイル: ProjectObserver.cs プロジェクト: nagyistge/Core2D
        private void Remove(XOptions options)
        {
            if (options == null)
            {
                return;
            }

            if (options.PointShape != null)
            {
                Remove(options.PointShape);
            }

            if (options.PointStyle != null)
            {
                Remove(options.PointStyle);
            }

            if (options.SelectionStyle != null)
            {
                Remove(options.SelectionStyle);
            }

            if (options.HelperStyle != null)
            {
                Remove(options.HelperStyle);
            }
        }
コード例 #2
0
        public (IGenotype, IGenotype) Crossover(IGenotype partner, XOptions options = default)
        {
            if (!Equals(partner))
            {
                throw new ArgumentException();
            }

            EvoNet offspringX = new EvoNet(layers);
            EvoNet offspringY = new EvoNet(layers);

            offspringX.Build();
            offspringY.Build();

            (float[] offspringX, float[] offspringY)offsprings = (new float[0], new float[0]);
            switch (options.xType)
            {
            case XType.OnePointX:
                offsprings = Reproduction.OnePointX(ToRowMajorArray(), ((EvoNet)partner).ToRowMajorArray());
                break;

            case XType.KPointX:
                offsprings = Reproduction.KPointX(ToRowMajorArray(), ((EvoNet)partner).ToRowMajorArray(), options.kPoints);
                break;
            }

            int gene = 0;

            for (int w = 0; w < weights.Length; w++)
            {
                for (int y = 0; y < weights[w].RowCount; y++)
                {
                    for (int x = 0; x < weights[w].ColumnCount; x++)
                    {
                        offspringX.weights[w][y, x] = offsprings.offspringX[gene];
                        offspringY.weights[w][y, x] = offsprings.offspringY[gene];
                        gene++;
                    }
                }
                for (int x = 0; x < b_weights[w].ColumnCount; x++)
                {
                    offspringX.b_weights[w][0, x] = offsprings.offspringX[gene];
                    offspringY.b_weights[w][0, x] = offsprings.offspringY[gene];
                    gene++;
                }
            }

            return(offspringX, offspringY);
        }
コード例 #3
0
        public void Inherits_From_ObservableObject()
        {
            var target = new XOptions();

            Assert.True(target is ObservableObject);
        }
コード例 #4
0
ファイル: DesignerContext.cs プロジェクト: nagyistge/Core2D
        /// <summary>
        /// Initializes static designer context.
        /// </summary>
        /// <param name="renderer">The design time renderer instance.</param>
        /// <param name="clipboard">The design time clipboard instance.</param>
        /// <param name="jsonSerializer">The design time Json serializer instance.</param>
        /// <param name="xamlSerializer">The design time Xaml serializer instance.</param>
        /// <returns>The new instance of the <see cref="DesignerContext"/> class.</returns>
        public static void InitializeContext(ShapeRenderer renderer, ITextClipboard clipboard, ITextSerializer jsonSerializer, ITextSerializer xamlSerializer)
        {
            // Editor

            Editor = new ProjectEditor()
            {
                CurrentTool     = Tool.Selection,
                CurrentPathTool = PathTool.Line,
                CommandManager  = new DesignerCommandManager(),
                Renderers       = new ShapeRenderer[] { renderer },
                ProjectFactory  = new ProjectFactory(),
                TextClipboard   = clipboard,
                JsonSerializer  = jsonSerializer,
                XamlSerializer  = xamlSerializer
            }.Defaults();

            // Recent Projects
            Editor.RecentProjects = Editor.RecentProjects.Add(RecentFile.Create("Test1", "Test1.project"));
            Editor.RecentProjects = Editor.RecentProjects.Add(RecentFile.Create("Test2", "Test2.project"));

            // Commands

            Editor.InitializeCommands();
            InitializeCommands(Editor);
            Editor.CommandManager.RegisterCommands();

            // New Project

            Editor.OnNew(null);

            // Data

            var db      = XDatabase.Create("Db");
            var fields  = new string[] { "Column0", "Column1" };
            var columns = ImmutableArray.CreateRange(fields.Select(c => XColumn.Create(db, c)));

            db.Columns = columns;
            var values = Enumerable.Repeat("<empty>", db.Columns.Length).Select(c => XValue.Create(c));
            var record = XRecord.Create(
                db,
                db.Columns,
                ImmutableArray.CreateRange(values));

            db.Records       = db.Records.Add(record);
            db.CurrentRecord = record;

            Database = db;
            Data     = XContext.Create(record);
            Record   = record;

            // Project

            IProjectFactory factory = new ProjectFactory();

            Project = factory.GetProject();

            Template = XContainer.CreateTemplate();

            Page = XContainer.CreatePage();
            var layer = Page.Layers.FirstOrDefault();

            layer.Shapes      = layer.Shapes.Add(XLine.Create(0, 0, null, null));
            Page.CurrentLayer = layer;
            Page.CurrentShape = layer.Shapes.FirstOrDefault();
            Page.Template     = Template;

            Document = XDocument.Create();
            Layer    = XLayer.Create();
            Options  = XOptions.Create();

            // State

            State = ShapeState.Create();

            // Style

            ArgbColor       = ArgbColor.Create();
            ArrowStyle      = ArrowStyle.Create();
            FontStyle       = FontStyle.Create();
            LineFixedLength = LineFixedLength.Create();
            LineStyle       = LineStyle.Create();
            Style           = ShapeStyle.Create("Default");
            TextStyle       = TextStyle.Create();

            // Shapes

            Arc             = XArc.Create(0, 0, Style, null);
            CubicBezier     = XCubicBezier.Create(0, 0, Style, null);
            Ellipse         = XEllipse.Create(0, 0, Style, null);
            Group           = XGroup.Create(Constants.DefaulGroupName);
            Image           = XImage.Create(0, 0, Style, null, "key");
            Line            = XLine.Create(0, 0, Style, null);
            Path            = XPath.Create("Path", Style, null);
            Point           = XPoint.Create();
            QuadraticBezier = XQuadraticBezier.Create(0, 0, Style, null);
            Rectangle       = XRectangle.Create(0, 0, Style, null);
            Text            = XText.Create(0, 0, Style, null, "Text");

            // Path

            ArcSegment                 = XArcSegment.Create(XPoint.Create(), XPathSize.Create(), 180, true, XSweepDirection.Clockwise, true, true);
            CubicBezierSegment         = XCubicBezierSegment.Create(XPoint.Create(), XPoint.Create(), XPoint.Create(), true, true);
            LineSegment                = XLineSegment.Create(XPoint.Create(), true, true);
            PathFigure                 = XPathFigure.Create(XPoint.Create(), false, true);
            PathGeometry               = XPathGeometry.Create(ImmutableArray.Create <XPathFigure>(), XFillRule.EvenOdd);
            PathSize                   = XPathSize.Create();
            PolyCubicBezierSegment     = XPolyCubicBezierSegment.Create(ImmutableArray.Create <XPoint>(), true, true);
            PolyLineSegment            = XPolyLineSegment.Create(ImmutableArray.Create <XPoint>(), true, true);
            PolyQuadraticBezierSegment = XPolyQuadraticBezierSegment.Create(ImmutableArray.Create <XPoint>(), true, true);
            QuadraticBezierSegment     = XQuadraticBezierSegment.Create(XPoint.Create(), XPoint.Create(), true, true);
        }