Example #1
0
        public Form1()
        {
            InitializeComponent();

            int areaWidth  = 20;
            int areaHeight = 15;

            userLines = new List<ILine>();
            shapeMaker = new ShapeMaker(areaWidth, areaHeight, new Trans { XScale = 20, YScale = 20, Origin = new Point(10, 16) });

            // set up x y selector controls (spin boxes)
            this.point1X.Maximum = new decimal(new int[] { areaWidth,  0, 0, 0 });
            this.point2X.Maximum = new decimal(new int[] { areaWidth,  0, 0, 0 });
            this.point1Y.Maximum = new decimal(new int[] { areaHeight, 0, 0, 0 });
            this.point2Y.Maximum = new decimal(new int[] { areaHeight, 0, 0, 0 });
        }
Example #2
0
        public static void Draw(ShapeMaker a, DrawParams dParams, SelectShapeEnum fillMode, List<ILine> lines)
        {
            if (a.Shapes.Count == 0)
            {
                foreach (ILine line in lines)
                {
                    Draw(line, dParams);
                }
            }
            else
            {
                List<Shape> flatList = a.GetFlatListOfShapes();

                int [] fill = {-1, -1};

                switch (fillMode)
                {
                    case SelectShapeEnum.Largest:
                        fill[0] = a.FindLargestShape(flatList);
                        break;
                    case SelectShapeEnum.Smallest:
                        fill[0] = a.FindSmallestShape(flatList);
                        break;
                    case SelectShapeEnum.LargestAdjacentPair:
                        fill = a.FindLargestAdjacentPair(flatList);
                        break;
                }

                int nShape = flatList.Count;

                for (int i = 0; i < nShape; i++)
                {
                    Draw(flatList[i], dParams, fill[0] == i || fill[1] == i);
                }
            }
        }
Example #3
0
        public void TestShapeMaker()
        {
            int areaWidth = 20;
            int areaHeight = 15;
            ShapeMaker shapeMaker = new ShapeMaker(areaWidth, areaHeight, new Trans { XScale = 20, YScale = 20, Origin = new Point(10, 16) });
            string dirPath = @"C:\Projects\Rooms\WindowsFormsApplication1\UnitTests\TestFiles\";

            int[,] expectRes = new int[,]
            {
                {14,2,91,125},
                {9,2,28,40},
                {4,12,135,233},
                {5,2,135,233},
                {5,3,135,233},
                {2,70,230,300},
                {2,10,70,0},
                {3,65,130,235},
                {1,300,300,0},
                {29,1,49,91},
                {1,300,300,0},
                {2,15,35,0},
                {12,2,18,24}
            };

            for (int i  = 0; i  < expectRes.Length/4; i ++)
            {
                shapeMaker.Reset();
                string fileName = @"Lines" + (i + 1).ToString() + @".txt";
                System.Collections.Generic.List<ILine> lines = LineReader.GetLines(dirPath + fileName);
                shapeMaker.MakeShapes(lines);
                System.Collections.Generic.List<Shape> flatList = shapeMaker.GetFlatListOfShapes();

                Assert.AreEqual(expectRes[i,0], flatList.Count, "Error in ShapeMaker, number of shapes, file: " + fileName);
                Assert.AreEqual(expectRes[i, 1], shapeMaker.CalculateSmallestArea(flatList), "Error in ShapeMaker, number of shapes, file: " + fileName);
                Assert.AreEqual(expectRes[i, 2], shapeMaker.CalculateLargestArea(flatList), "Error in ShapeMaker, number of shapes, file: " + fileName);
                Assert.AreEqual(expectRes[i, 3], shapeMaker.CalculateLargestAdjacentArea(flatList), "Error in ShapeMaker, number of shapes, file: " + fileName);
            }
        }