Beispiel #1
0
 public void OrRectRegion(Rectangle newRectangle)
 {
     //1) Prüfe auf Kollisionen mit bisherigen Rectangles
     for (int c = In.Count() - 1; c >= 0; c--)
     {
         if (Rectangle.subset(In[c], newRectangle))
         {
             In.RemoveAt(c);
         }
     }
     this.CutOrIn(In, newRectangle, true);
     this.region.RegionRect(In);
 }
Beispiel #2
0
        //returns \cup_{rectangle in list}(rectanlge \cap intersect)
        public static ListOperations regionListIntersect(ListOperations rectList, Rectangle intersect)
        {
            ListOperations result = new ListOperations();

            foreach (Rectangle item in rectList)
            {
                result.Add(Rectangle.intersection(item, intersect));
                if (result[result.Count() - 1].getInvalid())
                {
                    result.RemoveAt(result.Count() - 1);
                }
            }
            return(result);
        }
Beispiel #3
0
        //See how index can be simplified with other rectangles
        public ListOperations simplifyByY(ListOperations List, int index)
        {
            for (int i = List.Count() - 1; i >= 0; i--)
            {
                if (i != index) //Wir können nicht ein Rectangle mit sich selber zusammenfassen
                {
                    if ((List[i].getCoord()[2] == List[index].getCoord()[2]) && (List[i].getCoord()[3] == List[index].getCoord()[3]))
                    {
                        if ((Math.Abs(List[i].getCoord()[0] - List[index].getCoord()[1]) == 1) || (Math.Abs(List[i].getCoord()[1] - List[index].getCoord()[0]) == 1))
                        {
                            int minY = List[i].getCoord()[2];
                            int maxY = List[i].getCoord()[3];

                            int minXList  = List[i].getCoord()[0];
                            int minXIndex = List[index].getCoord()[0];
                            int minX      = Math.Min(minXList, minXIndex);

                            int maxXList  = List[i].getCoord()[1];
                            int maxXIndex = List[index].getCoord()[1];
                            int maxX      = Math.Max(maxXList, maxXIndex);

                            Rectangle simplified = new Rectangle(minX, maxX, minY, maxY);

                            if (i > index)
                            {
                                List.RemoveAt(i);
                                List.RemoveAt(index);
                            }
                            else
                            {
                                List.RemoveAt(index);
                                List.RemoveAt(i);
                            }

                            List.Insert(Math.Max(0, List.Count()), simplified);
                            index = Math.Max(0, List.Count() - 1);
                        }
                    }
                }
            }

            return(List);
        }
Beispiel #4
0
 public static bool boolListIntersect(ListOperations list, Rectangle intersect)
 {
     for (int c = list.Count() - 1; c >= 0; c--)
     {
         if (!(Rectangle.intersection(list[c], intersect).getInvalid()))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #5
0
        private ListOperations addNotInIntersect(ListOperations intersect, Rectangle newRectangle)
        {
            ListOperations result = new ListOperations();
            bool           added  = false;

            // Step 1) Add In. All rectangles inside In are disjoint.
            foreach (Rectangle item in this.In)
            {
                added = false;
                for (int c = intersect.Count() - 1; c >= 0; c--)
                {
                    //letztes Argument ist das XOR=true (die vereinigungsart);
                    if (!Rectangle.intersection(intersect[c], item).getInvalid() && !added)
                    {
                        result.AddRange(Rectangle.AddIntoRectangle(intersect[c], item, true));
                        added = true;
                    }
                    if ((c == 0) && (!added))
                    {
                        result.AddRange(Rectangle.AddIntoRectangle(intersect[c], item, true));
                    }
                }
            }

            // Step 2 add XOR to everywhere except for the intersections
            Window w = new Window();

            w.In = intersect;
            int length = w.In.Count();

            w.CutOrIn(intersect, newRectangle, false);
            w.In.RemoveRange(0, length);

            for (int i = w.In.Count() - 1; i >= 0; i--)
            {
                if (i > w.In.Count() - 1)
                {
                    i = w.In.Count() - 1;
                }
                w.In = w.In.simplifyByX(w.In, i);
                if (i > w.In.Count() - 1)
                {
                    i = w.In.Count() - 1;
                }
                w.In = w.In.simplifyByY(w.In, i);
            }
            result.AddRange(w.In);
            return(result);
        }