/// <summary>
        /// Visualize the palette
        /// </summary>
        /// <param name="height">height of the palette to be drawn in pixels</param>
        /// <param name="width">width of the palette to be drawn in pixels</param>
        /// <returns>a bitmap visualizing the palette</returns>
        public Bitmap VisualizePallet(int height, int width)
        {
            if (!imageStore.QuantizerReady)
            {
                throw new Exception("Quantizer not ready!");
            }

            Bitmap bmp = new Bitmap(width, height);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                var palette    = imageStore.Quantizer.GetPalette();
                var pallet     = Cloner.DeepClone(palette);
                int maxRows    = System.Math.Max(pallet.Count / 16, 1);
                int maxColumns = System.Math.Min(pallet.Count, 16);
                int xDelta     = width / maxColumns;
                int yDelta     = height / maxRows;

                for (int row = 0; row < maxRows; row++)
                {
                    for (int column = 0; column < maxColumns; column++)
                    {
                        Models.Color         c     = pallet[row * 16 + column];
                        System.Drawing.Color color = System.Drawing.Color.FromArgb(255, (int)c.Channel1, (int)c.Channel2, (int)c.Channel3);
                        g.FillRectangle(new SolidBrush(color), column * xDelta, row * yDelta, (column + 1) * xDelta, (row + 1) * yDelta);
                    }
                }
            }

            return(bmp);
        }
        /// <summary>
        /// Create a single polygon from a list where the first index is a polygon and all other polygons in the list are holes of the first polygon
        /// </summary>
        /// <param name="polygon">the polygon and it's holes</param>
        /// <param name="topVertices">the top vertices for the polygon and it's holes</param>
        /// <returns>a list of points representing a single polygon where the holes have been incorporated</returns>
        private static List <PointF> CreateSimplePolygon(List <List <PointF> > polygon, List <PointF> topVertices)
        {
            var mainPolygon = Cloner.DeepClone(polygon[0]);

            if (IsPolygonClockwise(mainPolygon))
            {
                mainPolygon.Reverse();
            }
            int insertionIndex = 0;

            for (int i = 1; i < polygon.Count; i++)
            {
                // Find the closest vertex to the highest vertex of the hole
                var distances          = mainPolygon.Select((point) => CalculateDistance(point, topVertices[i])).ToList();
                var closestVertexIndex = distances.IndexOf(distances.Min());


                // Rotate the polygon so the highest vertex is the starting vertex
                var rotatedPolygon = polygon[i].Skip(polygon[i].IndexOf(topVertices[i])).ToList();
                rotatedPolygon.AddRange(polygon[i].Take(polygon[i].IndexOf(topVertices[i])));

                rotatedPolygon.Add(rotatedPolygon[0]);
                // If there's a hole that intersects our polygon, just inserting it will not help,
                // if we just insert it the polygon will self intersect and triangulation is not currently equipped for that.
                if (PolygonIntersections(mainPolygon, rotatedPolygon) > 0)
                {
                    continue;
                }

                mainPolygon.Insert(closestVertexIndex, mainPolygon[closestVertexIndex]);
                insertionIndex = closestVertexIndex + 1;
                mainPolygon.InsertRange(insertionIndex, rotatedPolygon);
            }
            return(mainPolygon);
        }
Пример #3
0
        public void Cloner_DeepClone_AsExpected()
        {
            Cloner       cloner       = new Cloner();
            ClassToClone classToClone = new ClassToClone();

            ClassToClone clone = cloner.DeepClone(classToClone);

            CollectionAssert.AreEqual(classToClone.Children, clone.Children);
            Assert.AreEqual(classToClone.Body, clone.Body);
        }
Пример #4
0
        public void Clone_Array()
        {
            var cloner = new Cloner();

            var items = new string[] { "A", "B" };

            var result = cloner.DeepClone(items);

            Assert.AreEqual("A", result.GetValue(0));
            Assert.AreEqual("B", result.GetValue(1));
        }
Пример #5
0
        private static void Version6()
        {
            RegisterEventProcessors();

            var tom  = v6.StaffMember.Register("Tom");
            var jack = v6.StaffMember.Register("Jack");

            Repository <v6.StaffMember>().Add(tom);
            Repository <v6.StaffMember>().Add(jack);
            var customer = v6.Customer.Register("John", "Smith", "*****@*****.**");

            PrintStep("Creating Job ...");

            var job = v6.Job.Create(customer, "1 George Street");

            Repository <v6.Customer>().Add(customer);
            EventStore <v6.Job>().Add(job);

            PrintStep("Scheduling Appointment ...");

            var appointment = v6.Appointment.Schedule(job, DateTime.Now, DateTime.Now.AddHours(2), tom.Id);

            EventStore <v6.Appointment>().Add(appointment);

            PrintStep("Assigning staff member ...");

            var concurrentAppointment = Cloner.DeepClone(appointment);

            concurrentAppointment.AssignStaffMember(jack.Id);
            EventStore <v6.Appointment>().Add(concurrentAppointment);

            PrintStep("Scheduling Another Appointment ...");

            var appointment2 = v6.Appointment.Schedule(job, DateTime.Now.AddDays(1), DateTime.Now.AddDays(1).AddHours(2), tom.Id);

            EventStore <v6.Appointment>().Add(appointment2);

            PrintStep("Rescheduling Appointment using stale appointment with merge ...");

            appointment.Reschedule(DateTime.Now.AddDays(1), DateTime.Now.AddDays(1).AddHours(2));
            EventStore <v6.Appointment>().Add(appointment);

            PrintStep("Start and Complete Appointment using stale appointment with conflict ...");

            appointment.Start();
            appointment.Complete("Some comments");
            EventStore <v6.Appointment>().Add(appointment);

            PrintStep("Showing JobView ...");

            var jobView = Repository <v6.JobView>().Fetch(job.Id);

            Printer.Print(JsonConvert.SerializeObject(jobView, Newtonsoft.Json.Formatting.Indented), ConsoleColor.Yellow);
        }
        /// <summary>
        /// Copy the palette generated in the quantizer to a bitmap
        /// </summary>
        /// <param name="b"></param>
        public void CopyPalette(Bitmap b)
        {
            List <Models.Color> palette    = Cloner.DeepClone(imageStore.Quantizer.GetPalette());
            ColorPalette        newPalette = b.Palette;

            for (int i = 0; i < palette.Count; i++)
            {
                System.Diagnostics.Debug.WriteLine($"Adding {palette[i]} to the palette as color {i}");
                newPalette.Entries[i] = System.Drawing.Color.FromArgb(255, (int)palette[i].Channel1, (int)palette[i].Channel2, (int)palette[i].Channel3);
            }
            b.Palette = newPalette;
        }
Пример #7
0
 /// <summary>
 /// Draws the current state to the screen
 /// </summary>
 private void Draw()
 {
     // Unlike what is expected, lock does not lock the object.
     // Lock just ensures that whatever is inside it's body does not execute while the object between the brackets is in use somewhere else.
     lock (gameBoard)
     {
         PrepareSendData(gameBoard, CurrentBlock);
         lock (CurrentBlock)
         {
             tetrisDrawer.Draw(Cloner.DeepClone(gameBoard), new Block(CurrentBlock), new Block(NextBlock), Score);
         }
     }
 }
Пример #8
0
        public void Clone_List()
        {
            var cloner = new Cloner();

            var items = new ArrayList {
                "A", "B"
            };

            var result = cloner.DeepClone(items);

            Assert.AreEqual("A", result[0]);
            Assert.AreEqual("B", result[1]);
        }
Пример #9
0
        public void Clone_Generic_Collection()
        {
            var cloner = new Cloner();

            var items = new MyCollectionOfString {
                "A", "B"
            };

            var result = cloner.DeepClone(items);

            Assert.AreEqual("A", result[0]);
            Assert.AreEqual("B", result[1]);
        }
Пример #10
0
        public void Clone_Generic_List()
        {
            var cloner = new Cloner();

            var items = new List <string> {
                "A", "B"
            };

            var result = cloner.DeepClone(items);

            Assert.AreEqual("A", result[0]);
            Assert.AreEqual("B", result[1]);
        }
 /// <summary>
 /// This is the central method, this should be called in the main game loop
 /// </summary>
 /// <param name="gameBoard">the game board</param>
 /// <param name="block">the block that is currently falling</param>
 /// <param name="nextBlock">the next block that will fall</param>
 /// <param name="score">the score of the player</param>
 public void Draw(bool[,] gameBoard, Block block, Block nextBlock, int score)
 {
     // Clear previous block by painting over it with the background color
     DrawBlock(previousBlock, ConsoleColor.Black);
     DrawBoard(gameBoard);
     DrawBlock(block);
     DrawNextBlock(nextBlock);
     DrawScore(score);
     // Make a deepcopy of the gameboard otherwise it changes whenever the game changes it
     previousGameBoard = Cloner.DeepClone(gameBoard);
     // Make a copy of the block using it's copy constructor
     previousBlock = new Block(block);
 }
Пример #12
0
    /// <summary>
    /// Create one array containing the falling block and the gameboard
    /// </summary>
    /// <param name="gameBoard"></param>
    /// <param name="currentBlock"></param>
    private void PrepareSendData(bool[,] gameBoard, Block currentBlock)
    {
        var gameBoardCopy = Cloner.DeepClone(gameBoard);

        for (int r = 0; r < currentBlock.Shape.GetLength(0); r++)
        {
            for (int c = 0; c < currentBlock.Shape.GetLength(1); c++)
            {
                gameBoardCopy[r + currentBlock.Row, c + currentBlock.Column] |= currentBlock.Shape[r, c];
            }
        }

        SendData("gameboard", gameBoardCopy);
    }
Пример #13
0
        public void Clones_With_Class_That_Inherits_From_IList()
        {
            var item = new MyItemWithClassIList();

            item.MyItems.Add("A");
            item.MyItems.Add("B");

            var cloner = new Cloner();
            var clone  = cloner.DeepClone(item);

            Assert.AreEqual(2, clone.MyItems.Count);
            Assert.AreEqual("A", clone.MyItems[0]);
            Assert.AreEqual("B", clone.MyItems[1]);
        }
Пример #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="odm"></param>
        /// <param name="useSuffix"></param>
        /// <returns></returns>
        public List <OutputDataElement> GetOutputs(OutputDataModel odm, bool useSuffix = true)
        {
            List <OutputDataElement> OutputDataElements = new List <OutputDataElement>();

            string suffix = "";

            if (useSuffix == true)
            {
                suffix = odm.Suffix;
            }

            foreach (OutputDataElement v in odm.OutputDataElements)
            {
                if (v.IsSelected)
                {
                    if (v.PropertyInfo.PropertyType.IsGenericType)
                    {
                        int layerCount = 1;

                        foreach (double d in (IEnumerable <double>)v.PropertyInfo.GetValue(odm.HLController))
                        {
                            OutputDataElement o = Cloner.DeepClone(v);

                            o.Index        = layerCount - 1;
                            o.Name         = v.PropertyInfo.Name + "Layer" + layerCount.ToString() + (suffix == "" ? "" : ("-" + suffix));
                            o.HLController = odm.HLController;
                            o.PropertyInfo = v.PropertyInfo;

                            OutputDataElements.Add(o);
                            layerCount++;
                        }
                    }
                    else
                    {
                        OutputDataElements.Add(v);
                        v.Name         = v.PropertyInfo.Name + (suffix == "" ? "" : ("-" + suffix));
                        v.HLController = odm.HLController;
                    }
                }
            }
            return(OutputDataElements);
        }
Пример #15
0
 public List <GameObject> Clone()
 {
     return((List <GameObject>)Cloner.DeepClone(_internalList));
 }
Пример #16
0
 public object Clone()
 {
     return(Cloner.DeepClone(this));
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="image">the image this class is storing</param>
 /// <param name="quantizer">the quantizer that will be used</param>
 /// <param name="ditherer">the ditherer that will be used</param>
 public ImageStore(Bitmap image, IQuantizer quantizer, IDitherer ditherer)
 {
     Image     = Cloner.DeepClone(image);
     Quantizer = quantizer;
     Ditherer  = ditherer;
 }
 private void Start()
 {
     currentUnitCredits = Cloner.DeepClone(GameController.instance.GetUnitCredits());
     currentGold        = GameController.instance.GetCurrentGold();
     RefreshUI();
 }
Пример #19
0
        public static Simulation GenerateSimulationXML(Project Project, XElement simElement, List <InputModel> allModels)
        {
            List <InputModel> simModels = new List <InputModel>();

            int startYear = 0;
            int endYear   = 0;

            //Get the models from the filenames of the simualtion pointers
            foreach (XElement element in simElement.Elements())
            {
                if (element.Name.ToString() == "StartYear")
                {
                    startYear = element.Value.ToString() == "default" ? 0 : int.Parse(element.Value.ToString());
                }
                else if (element.Name.ToString() == "EndYear")
                {
                    endYear = element.Value.ToString() == "default" ? 0 : int.Parse(element.Value.ToString());
                }
                else
                {
                    try
                    {
                        string fileName = element.Attribute("href").Value.ToString().Replace("\\", "/");

                        if (fileName.Contains("./"))
                        {
                            fileName = Path.GetDirectoryName(Project.FileName).Replace("\\", "/") + "/" + fileName;
                        }

                        InputModel model = allModels.Where(im => im.FileName == fileName).FirstOrDefault();

                        InputModel model2 = Cloner.DeepClone <InputModel>(model);

                        string modelDescription = model.GetType().Name;

                        modelDescription += (":" + model.Name);

                        //Check for child nodes
                        foreach (XElement childElement in element.Elements())
                        {
                            if (childElement.Name == "OverrideParameter")
                            {
                                if (childElement.Attribute("Keyword").Value.ToString() == "" && childElement.Attribute("Active").Value.ToString() != "false")
                                {
                                    //Add the override to the model
                                    model2.Overrides.Add(childElement.Attribute("Keyword").Value, childElement.Element("Value").Value);
                                    modelDescription += (";" + childElement.Attribute("Keyword").Value + "=" + childElement.Element("Value").Value);
                                }
                            }
                            else
                            {
                                //Probably a climate file override
                                if (element.Name == "ptrStation")
                                {
                                    if (childElement.Attribute("index") != null)
                                    {
                                        model2.Overrides.Add(childElement.Name.ToString(), childElement.Attribute("index").Value);
                                        modelDescription += (";" + childElement.Name.ToString() + "=" + childElement.Attribute("index").Value);
                                    }
                                    else
                                    {
                                        model2.Overrides.Add(childElement.Name.ToString(), childElement.Value);
                                        modelDescription += (";" + childElement.Name.ToString() + "=" + childElement.Value);
                                    }
                                }
                            }
                        }
                        if (element.Name == "ptrStation")
                        {
                            //Map the data to the original model
                            ClimateInputModel cimNew  = (ClimateInputModel)model2;
                            ClimateInputModel cimOrig = (ClimateInputModel)model;

                            cimNew.Rain      = cimOrig.Rain;
                            cimNew.MaxT      = cimOrig.MaxT;
                            cimNew.MinT      = cimOrig.MinT;
                            cimNew.PanEvap   = cimOrig.PanEvap;
                            cimNew.Radiation = cimOrig.Radiation;
                            cimNew.VP        = cimOrig.VP;

                            //cimNew.StartDate = cimOrig.StartDate;
                            //cimNew.EndDate = cimOrig.EndDate;
                        }
                        model2.ApplyOverrides();

                        model2.LongName = modelDescription;

                        simModels.Add(model2);
                    }
                    catch (Exception e)
                    {
                    }
                }
            }

            return(new Simulation(Project, simModels, startYear, endYear));
        }
Пример #20
0
 public static T DeepClone <T>(this IObjectInfo <T> source, AssetsFile toFile = null, List <CloneExclusion> exclusions = null, List <AssetsObject> addedObjects = null) where T : AssetsObject
 {
     return(Cloner.DeepClone <T>((T)source.Object, toFile, addedObjects, null, exclusions));
 }
Пример #21
0
        public IList <Person> GetPeople()
        {
            var result = cloner.DeepClone(FakeData.People);

            return(result);
        }