public string GetMaxNumberOfCylindersTrianglePattern(int length, int width, int radius, int minDistC2C, int minDistC2Edge)
        {
            Tape      tape      = new Tape(length, width);
            Rondelica rondelica = new Rondelica(radius, minDistC2C, minDistC2Edge, new Point());

            return(tape.MaxNumberOfCylindersTriangularPattern(rondelica).ToString());
        }
        public string GetPositionsOfCylindersTriangularPattern(int length, int width, int radius, int minDistC2C, int minDistC2Edge)
        {
            Tape      tape      = new Tape(length, width);
            Rondelica rondelica = new Rondelica(radius, minDistC2C, minDistC2Edge, new Point());

            return(JsonConvert.SerializeObject(tape.GetPositionsOfCylindersTriangularPattern(rondelica)));
        }
Esempio n. 3
0
        public void TrianglePatternRandomInputMultipleTests()
        {
            int numberOfTests = 10000;

            for (int i = 0; i < numberOfTests; i++)
            {
                Random rnd = new Random();

                int radius        = rnd.Next(1000);
                int minDistC2C    = rnd.Next(200);
                int minDistC2Edge = rnd.Next(200);
                int length        = rnd.Next(10000);
                int width         = rnd.Next(10000);

                Tape tape = new Tape(length, width);

                Rondelica rondelica = new Rondelica(radius, minDistC2C, minDistC2Edge, new Point());
                int       actual    = tape.GetPositionsOfCylindersTriangularPattern(rondelica).Count;
                int       expected  = tape.MaxNumberOfCylindersTriangularPattern(rondelica);

                string output = "radius: " + radius + ", minDistC2C: " + minDistC2C
                                + ", minDistC2Edge: " + minDistC2Edge + ", length: " + length + ", width: " + width;

                Assert.AreEqual(expected, actual, output);
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            int radius        = 1;
            int minDistC2C    = 0;
            int minDistC2Edge = 0;
            int length        = 13;
            int width         = 13;

            /*int radius = 100;
            *  int minDistC2C = 0;
            *  int minDistC2Edge = 0;
            *  int length = 2000;
            *  int width = 1000;*/

            Tape tape = new Tape(length, width);

            Rondelica rondelica = new Rondelica(radius, minDistC2C, minDistC2Edge, new Point());
            int       a         = tape.GetPositionsOfCylindersRecPattern(rondelica).Count;

            Console.WriteLine(a);

            int b = tape.MaxNumberOfCylindersRecPattern(rondelica);

            Console.WriteLine(b);

            Console.WriteLine("----------------");

            int c = tape.GetPositionsOfCylindersTriangularPattern(rondelica).Count;
            int d = tape.MaxNumberOfCylindersTriangularPattern(rondelica);

            Console.WriteLine(c + " " + d);

            Console.Read();
        }
Esempio n. 5
0
        /// <summary>
        /// Draw cylinders on tape with canvas element
        /// </summary>
        /// <param name="tape"></param>
        /// <param name="rondelica"></param>
        /// <param name="selectedPattern"></param>
        private void Draw(Tape tape, Rondelica rondelica, string selectedPattern)
        {
            log.Info("Draw(Tape tape, Rondelica rondelica, bool recPattern) called");

            Canvas1.Children.Clear();

            int maxNumber = 0;

            if (selectedPattern == "Rectangle")
            {
                maxNumber = tape.GetPositionsOfCylindersRecPattern(rondelica).Count;
            }
            else if (selectedPattern == "Triangle")
            {
                maxNumber = tape.GetPositionsOfCylindersTriangularPattern(rondelica).Count;
            }
            // check which pattern is better
            else
            {
                int recPatternNr      = tape.GetPositionsOfCylindersRecPattern(rondelica).Count;
                int trianglePatternNr = tape.GetPositionsOfCylindersTriangularPattern(rondelica).Count;

                if (recPatternNr > trianglePatternNr)
                {
                    maxNumber = tape.GetPositionsOfCylindersRecPattern(rondelica).Count;
                }
                else
                {
                    maxNumber = tape.GetPositionsOfCylindersTriangularPattern(rondelica).Count;
                }
            }

            Rectangle rectangle = new Rectangle
            {
                Width  = tape.Length,
                Height = tape.Width,
                Stroke = Brushes.Black
            };

            Canvas1.Children.Add(rectangle);

            for (int i = 0; i < tape.ListOfCylinders.Count; i++)
            {
                Ellipse ellipse = new Ellipse
                {
                    Height = tape.ListOfCylinders[i].Radius * 2,
                    Width  = tape.ListOfCylinders[i].Radius * 2,
                    Stroke = Brushes.Black
                };

                Canvas.SetLeft(ellipse, tape.ListOfCylinders[i].Position.X - tape.ListOfCylinders[i].Radius);
                Canvas.SetTop(ellipse, tape.ListOfCylinders[i].Position.Y - tape.ListOfCylinders[i].Radius);

                Canvas1.Children.Add(ellipse);
            }

            Max1.Content = "Število rondelic: " + maxNumber.ToString();
        }
        public string GetMaxNumberOfCylindersRecPattern(int length, int width, int radius, int minDistC2C, int minDistC2Edge)
        {
            /*using (var db = new DatabaseLogger())
             * {
             *  var requestInfo = new RequestInfo { Url = "http://sample.com", Time = DateTime.Now.ToString() };
             *  db.RequestsInfo.Add(requestInfo);
             *  db.SaveChanges();
             * }*/

            Tape      tape      = new Tape(length, width);
            Rondelica rondelica = new Rondelica(radius, minDistC2C, minDistC2Edge, new Point());

            return(tape.MaxNumberOfCylindersRecPattern(rondelica).ToString());
        }
Esempio n. 7
0
        private void ButtonCalculate_Click(object sender, RoutedEventArgs e)
        {
            log.Info("ButtonCalculate_Click(object sender, RoutedEventArgs e) called");

            // parse input data from textboxes
            int.TryParse(TextBoxRadius.Text, out int radius);
            int.TryParse(TextBoxDistanceC2C.Text, out int minDistC2C);
            int.TryParse(TextBoxDistanceC2E.Text, out int minDistC2Edge);
            int.TryParse(TextBoxLength.Text, out int length);
            int.TryParse(TextBoxWidth.Text, out int width);
            bool   recPattern      = RadioButtonRecPattern.IsChecked.Value;
            bool   trianglePattern = RadioButtonTrianglePattern.IsChecked.Value;
            string selectedPattern = "";

            if (recPattern)
            {
                selectedPattern = "Rectangle";
            }
            else if (trianglePattern)
            {
                selectedPattern = "Triangle";
            }
            else
            {
                selectedPattern = "Optimal";
            }

            // check if the parameters are ok
            bool isOk = IsInputOK(radius, minDistC2C, minDistC2Edge, length, width);

            if (isOk)
            {
                Tape      tape      = new Tape(length, width);
                Rondelica rondelica = new Rondelica(radius, minDistC2C, minDistC2Edge, new Library.Point());
                Draw(tape, rondelica, selectedPattern);
                FillListBoxWithPositions(tape);
            }
            else
            {
                log.Warn("Wrong input values: radius = " + radius.ToString() +
                         " length = " + length.ToString() +
                         " width = " + width.ToString() +
                         " min distance between cylinders = " + minDistC2C.ToString() +
                         " min distance between cylinder and edge = " + minDistC2Edge.ToString());
                MessageBox.Show("POGOJI: Polmer > 0, dolžina <= 10000, širina <= 2000", "Napačne vrednosti",
                                MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
Esempio n. 8
0
        public void TrianglePatternNoSpacing()
        {
            int radius        = 100;
            int minDistC2C    = 0;
            int minDistC2Edge = 0;
            int length        = 2000;
            int width         = 1000;

            Tape tape = new Tape(length, width);

            Rondelica rondelica = new Rondelica(radius, minDistC2C, minDistC2Edge, new Point());
            int       actual    = tape.GetPositionsOfCylindersTriangularPattern(rondelica).Count;
            int       expected  = tape.MaxNumberOfCylindersTriangularPattern(rondelica);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 9
0
        public void RecPatternNoSpacing()
        {
            //TODO: test divide by zero exception
            int radius        = 100;
            int minDistC2C    = 0;
            int minDistC2Edge = 0;
            int length        = 2000;
            int width         = 1000;

            Tape tape = new Tape(length, width);

            Rondelica rondelica = new Rondelica(radius, minDistC2C, minDistC2Edge, new Point());
            int       actual    = tape.GetPositionsOfCylindersRecPattern(rondelica).Count;
            int       expected  = tape.MaxNumberOfCylindersRecPattern(rondelica);

            Assert.AreEqual(expected, actual);
        }