//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); }
public static ListOperations AddIntoRectangle(Rectangle old, Rectangle add, bool XOR) { ListOperations aList = new ListOperations(); int oldMinX = old.getCoord()[0]; int oldMaxX = old.getCoord()[1]; int oldMinY = old.getCoord()[2]; int oldMaxY = old.getCoord()[3]; int addMinX = add.getCoord()[0]; int addMaxX = add.getCoord()[1]; int addMinY = add.getCoord()[2]; int addMaxY = add.getCoord()[3]; if (subset(old,add)) { if (XOR) { Rectangle upper = new Rectangle(oldMinX, oldMaxX, oldMaxY + 1, addMaxY); Rectangle lower = new Rectangle(oldMinX, oldMaxX, addMinY, oldMinY - 1); Rectangle left = new Rectangle(addMinX, oldMinX - 1, addMinY, addMaxY); Rectangle right = new Rectangle(oldMaxX + 1, addMaxX, addMinY, addMaxY); aList.validAdd(upper, true); aList.validAdd(lower, true); aList.validAdd(left, true); aList.validAdd(right, true); return aList; } aList.Add(add); return aList; } if(subset(add, old)) { if (XOR) { Rectangle upper = new Rectangle(oldMinX, oldMaxX, oldMaxY + 1, addMaxY); Rectangle lower = new Rectangle(oldMinX, oldMaxX, addMinY, oldMinY - 1); Rectangle left = new Rectangle(addMinX, oldMinX - 1, addMinY, addMaxY); Rectangle right = new Rectangle(oldMaxX + 1, addMaxX, addMinY, addMaxY); aList.validAdd(upper, true); aList.validAdd(lower, true); aList.validAdd(left, true); aList.validAdd(right, true); return aList; } return aList; } if((Rectangle.intersection(old,add).getInvalid())) { aList.Add(add); return aList; } //new Rectangle between old bounds if ((oldMinX <= addMinX) && (addMaxX <= oldMaxX)) { Rectangle lower = new Rectangle(addMinX, addMaxX, addMinY, oldMinY-1); Rectangle upper = new Rectangle(addMinX, addMaxX, oldMaxY+1, addMaxY); aList.validAdd(lower, true); aList.validAdd(upper, true); return aList; } //new Rectangle exceeds old bounds if ((addMinX <= oldMinX) && (oldMaxX <= addMaxX)) { Rectangle upper = new Rectangle(oldMinX, oldMaxX, oldMaxY+1, addMaxY); Rectangle lower = new Rectangle(oldMinX, oldMaxX, addMinY, oldMinY-1); Rectangle left = new Rectangle(addMinX, oldMinX-1, addMinY, addMaxY); Rectangle right = new Rectangle(oldMaxX+1, addMaxX, addMinY, addMaxY); aList.validAdd(upper, true); aList.validAdd(lower, true); aList.validAdd(left, true); aList.validAdd(right, true); return aList; } //new Rectangle left of old bounds if ((oldMinX <= addMaxX) && (addMaxX <= oldMaxX)) { Rectangle upper = new Rectangle(oldMinX, addMaxX, oldMaxY+1, addMaxY); Rectangle lower = new Rectangle(oldMinX, addMaxX, addMinY, oldMinY-1); Rectangle left = new Rectangle(addMinX, oldMinX-1, addMinY, addMaxY); aList.validAdd(upper, true); aList.validAdd(lower, true); aList.validAdd(left, true); return aList; } //new Rectangle right of old bounds if ((addMinX <= oldMaxX) && (oldMaxX <= addMaxX)) { Rectangle upper = new Rectangle(addMinX, oldMaxX, oldMaxY+1, addMaxY); Rectangle lower = new Rectangle(addMinX, oldMaxX, addMinY, oldMinY-1); Rectangle right = new Rectangle(oldMaxX+1, addMaxX, addMinY, addMaxY); aList.validAdd(upper, true); aList.validAdd(lower, true); aList.validAdd(right, true); return aList; } return aList; }