Esempio n. 1
0
        public static int ColumnOverlap(Oblong o1, Oblong o2)
        {
            if (o1.ColumnRight < o2.ColumnLeft)
            {
                return(0);
            }

            if (o2.ColumnRight < o1.ColumnLeft)
            {
                return(0);
            }

            // at this point the two events overlap
            int overlap = 0;

            if (o1.IncludesColumn(o2.ColumnLeft))
            {
                overlap = o1.ColumnRight - o2.ColumnLeft + 1;
            }
            else if (o2.IncludesColumn(o1.ColumnLeft))
            {
                overlap = o2.ColumnRight - o1.ColumnLeft + 1;
            }

            return(overlap);
        }
Esempio n. 2
0
        /// <summary>
        /// MAIN METHOD FOR UNIT TESTING
        /// </summary>
        private static void Main()
        {
            LoggedConsole.WriteLine("TESTING METHODS IN CLASS DataTools");

            // string testDir = @"D:\SensorNetworks\Software\TowseyLib\TestResources\";
            bool doit1 = false;

            if (doit1)
            {
                // test1 method AREA, CENTROID and CENTROID-DISTANCE()
                LoggedConsole.WriteLine("Test Method Name()");
                int r1 = 10;
                int c1 = 10;
                int r2 = 20;
                int c2 = 20;
                var s1 = new Oblong(r1, c1, r2, c2);
                s1.WriteBounds();
                int[] centroid1 = s1.Centroid();
                LoggedConsole.WriteLine("Centroid1: r=" + centroid1[0] + "  c=" + centroid1[1]);
                LoggedConsole.WriteLine("Area 1=" + s1.Area());
                LoggedConsole.WriteLine();

                r1 = 17;
                c1 = 16;
                r2 = 23;
                c2 = 24;
                var s2 = new Oblong(r1, c1, r2, c2);
                s2.WriteBounds();
                int[] centroid2 = s2.Centroid();
                LoggedConsole.WriteLine("Centroid2: r=" + centroid2[0] + "  c=" + centroid2[1]);
                LoggedConsole.WriteLine("Area 2=" + s2.Area());
                double dist = s1.CentroidDistance(s2);
                LoggedConsole.WriteLine("Distance=" + dist);
            }

            // end test1

            bool doit2 = false;

            if (doit2)
            {
                // test2 method IncludesRow(), IncludesColumn(), PointInside()
                LoggedConsole.WriteLine("Test Method Name()");
                int r1 = 10;
                int c1 = 10;
                int r2 = 20;
                int c2 = 20;
                var s1 = new Oblong(r1, c1, r2, c2);
                s1.WriteBounds();
                r1 = 17;
                c1 = 16;
                r2 = 23;
                c2 = 24;
                var s2 = new Oblong(r1, c1, r2, c2);
                s2.WriteBounds();
                r1 = 20;
                c1 = 20;
                r2 = 30;
                c2 = 30;
                var s3 = new Oblong(r1, c1, r2, c2);
                s3.WriteBounds();

                LoggedConsole.WriteLine();
                LoggedConsole.WriteLine("Row10 in s1=" + s1.IncludesRow(10));
                LoggedConsole.WriteLine("Row15 in s1=" + s1.IncludesRow(15));
                LoggedConsole.WriteLine("Row20 in s1=" + s1.IncludesRow(20));
                LoggedConsole.WriteLine("Row25 in s1=" + s1.IncludesRow(25));
                LoggedConsole.WriteLine("Col05 in s1=" + s1.IncludesColumn(5));
                LoggedConsole.WriteLine("Col10 in s1=" + s1.IncludesColumn(10));
                LoggedConsole.WriteLine("Col15 in s1=" + s1.IncludesColumn(15));
                LoggedConsole.WriteLine("Col20 in s1=" + s1.IncludesColumn(20));

                int  py     = 23;
                int  px     = 25;
                bool inside = s1.PointInside(py, px);
                LoggedConsole.WriteLine("\nPoint (" + py + "," + px + ") inside s1 =" + inside);
                inside = s2.PointInside(py, px);
                LoggedConsole.WriteLine("Point (" + py + "," + px + ") inside s2 =" + inside);
                inside = s3.PointInside(py, px);
                LoggedConsole.WriteLine("Point (" + py + "," + px + ") inside s3 =" + inside);

                bool overlapped = s1.Overlaps(s3);
                LoggedConsole.WriteLine("\ns1 and s3 overlap =" + overlapped);
                overlapped = s1.Overlaps(s2);
                LoggedConsole.WriteLine("s1 and s2 overlap =" + overlapped);
            }

            // end test2

            if (true)
            {
                // test Method MergeShapes()
                LoggedConsole.WriteLine("Test MergeShapes()");
                var list = new ArrayList();
                int r1   = 10;
                int c1   = 10;
                int r2   = 20;
                int c2   = 20;
                var s1   = new Oblong(r1, c1, r2, c2);
                s1.WriteBounds();
                list.Add(s1);
                r1 = 17;
                c1 = 16;
                r2 = 23;
                c2 = 24;
                var s2 = new Oblong(r1, c1, r2, c2);
                s2.WriteBounds();
                list.Add(s2);
                r1 = 20;
                c1 = 20;
                r2 = 30;
                c2 = 30;
                var s3 = new Oblong(r1, c1, r2, c2);
                s3.WriteBounds();
                list.Add(s3);

                LoggedConsole.WriteLine(" dy(s2-s1)= " + s1.RowShift(s2));
                LoggedConsole.WriteLine(" dy(s3-s2)= " + s2.RowShift(s3));

                int dyThreshold = 6;
                list = MergeShapesWhoseEndsOverlap(list, dyThreshold);
                LoggedConsole.WriteLine("List size=" + list.Count);
                foreach (Oblong s in list)
                {
                    s.WriteBounds();
                }
            }

            // end test3

            // if (false) //test Method()
            // {
            // LoggedConsole.WriteLine("Test Method Name()");
            // } //end test4
            LoggedConsole.WriteLine("\nFINISHED!!");
            Console.ReadLine();
        }