Exemplo n.º 1
0
        public static List<Point> getArrayIndiciesMarkedByLine(LineSegment line, long arrayspacesizex, long arrayspacesizey)
        {
            //columnList = new List<PixelColumn>();
            List<Point> coordinateList = new List<Point>();

            double regionone, regiontwo, regionmax, regionmin;

            regionone = line.lowerBound.x;
            regiontwo = (int)regionone + 1;

            //Console.Out.WriteLine("Starting Regions: " + regionone + ", " + regiontwo);
            bool positiveSlope = false;
            if (line.slope > 0)
            {
                positiveSlope = true;
            }
            else
            {
                positiveSlope = false;
            }

            if ((int)regionone == (int)regiontwo)
            {
                //Near verticle line

                regionmax = line.getMaxOnRegion(regionone, regiontwo);
                regionmin = line.getMinOnRegion(regionone, regiontwo);
                if (regionmax == Double.PositiveInfinity || (int)regionmax == arrayspacesizey)
                {
                    regionmax = arrayspacesizey - 1;
                }

                if ((int)regionone == arrayspacesizex)
                {
                    regionone = arrayspacesizex - 1;
                }

                addAllVerticalPointsToList(ref coordinateList, (int)regionmin, (int)regionmax, (int)regionone, positiveSlope);
            }
            else
            {
                while (regiontwo < line.upperBound.x)
                {
                    //Using this region, add all points to the list
                    regionmax = line.getMaxOnRegion(regionone, regiontwo);
                    regionmin = line.getMinOnRegion(regionone, regiontwo);

                    if (regionmax == Double.PositiveInfinity || (int)regionmax == arrayspacesizey)
                    {
                        regionmax = arrayspacesizey - 1;
                    }

                    //Console.Out.WriteLine("region: " + regionone + ", " + regiontwo + " Max: " + regionmax + ", Min: " + regionmin);

                    //addAllVerticalColumnsToList(ref columnList, (int)regionmin, (int)regionmax, (int)regionone);
                    addAllVerticalPointsToList(ref coordinateList, (int)regionmin, (int)regionmax, (int)regionone, positiveSlope);
                    regionone = regiontwo;
                    regiontwo++;
                }

                //Add last region manually

                regiontwo = line.upperBound.x;
                regionmax = line.getMaxOnRegion(regionone, regiontwo);
                regionmin = line.getMinOnRegion(regionone, regiontwo);

                if (regionmax == Double.PositiveInfinity || (int)regionmax == arrayspacesizey)
                {
                    regionmax = arrayspacesizey - 1;
                }

                if ((int)regionone == arrayspacesizex)
                {
                    regionone = arrayspacesizex - 1;
                }
                //Console.Out.WriteLine("last region: " + regionone + ", " + regiontwo + " Max: " + regionmax + ", Min: " + regionmin);
                //addAllVerticalColumnsToList(ref columnList, (int)regionmin, (int)regionmax, (int)regionone);
                addAllVerticalPointsToList(ref coordinateList, (int)regionmin, (int)regionmax, (int)regionone, positiveSlope);
            }

            //Reverse the list if the points go in the opposite direction, ie if the ipad is flipped 180 degrees,
            //the two points used to find the line will be reversed, thus here we are moving left to right vs right to left
            //if (one.x > two.x)
            //{
            //    coordinateList.Reverse();
            //}

            return coordinateList;
        }
Exemplo n.º 2
0
        public void getMaxOnRegionTest()
        {
            Point one = new Point(0, 0);
            Point two = new Point(1, 1);
            LineSegment target = new LineSegment(one, two);

            double regionx1 = .5;
            double regionx2 = .75;
            double expected = .75;

            Assert.AreEqual(expected, target.getMaxOnRegion(regionx1, regionx2));
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx2, regionx1));

            regionx1 = .25;
            regionx2 = 1.0;
            expected = 1.0;
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx1, regionx2));
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx2, regionx1));

            //Test when max is outside the region, and restricted
            regionx2 = 1.5;
            regionx1 = .25;
            expected = 1.0;
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx1, regionx2));
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx2, regionx1));

            one = new Point(0, 1);
            two = new Point(1, 0);
            target = new LineSegment(one, two);
            regionx1 = -.5;
            regionx2 = .2;
            expected = 1.0;
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx1, regionx2));
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx2, regionx1));

            regionx1 = .5;
            regionx2 = .2;
            expected = .8;
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx1, regionx2));
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx2, regionx1));

            regionx1 = -.5;
            regionx2 = 1.2;
            expected = 1.0;
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx1, regionx2));
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx2, regionx1));

            regionx1 = .5;
            regionx2 = 1.2;
            expected = .5;
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx1, regionx2));
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx2, regionx1));

            //region outside
            one = new Point(0, 1);
            two = new Point(1, 0);
            target = new LineSegment(one, two);
            regionx1 = -.5;
            regionx2 = -.2;
            expected = Double.NaN;
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx1, regionx2));
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx2, regionx1));

            regionx1 = 1.5;
            regionx2 = 3.2;
            expected = Double.NaN;
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx1, regionx2));
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx2, regionx1));

            //Test vertical line segment, outside less than
            one = new Point(1, 1);
            two = new Point(1, 0);
            target = new LineSegment(one, two);
            regionx1 = -.5;
            regionx2 = .2;
            expected = Double.NaN;
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx1, regionx2));
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx2, regionx1));

            //outside greater than
            regionx1 = 1.5;
            regionx2 = 6.62;
            expected = Double.NaN;
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx1, regionx2));
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx2, regionx1));

            //Region contained
            regionx1 = -.5;
            regionx2 = 1.2;
            expected = 1.0;
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx1, regionx2));
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx2, regionx1));

            //region equal
            regionx1 = 1.0;
            regionx2 = 1.0;
            expected = 1.0;
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx1, regionx2));
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx2, regionx1));

            regionx1 = 1.5;
            regionx2 = 1.0;
            expected = 1.0;
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx1, regionx2));
            Assert.AreEqual(expected, target.getMaxOnRegion(regionx2, regionx1));
        }