/* 2D Integer Interval ItvBegin : Beginning value of the interval ItvEnd : End value of the interval */ struct Int2DInterval=[ ItvBegin:I, ItvEnd:I ] MkInt2DInterval;; struct Int2DPoint=[ iptX:I, iptY:I ] MkInt2DPoint;; struct Rectangle2D=[ RctHG:Int2DPoint, RctBD:Int2DPoint ] MkRectangle2D;; fun IsPointInRectangle(Point,Rectangle)= (Point.iptX<=Rectangle.RctBD.iptX)&&(Point.iptX>=Rectangle.RctHG.iptX)&&(Point.iptY>=Rectangle.RctHG.iptY)&&(Point.iptY<=Rectangle.RctBD.iptY) ;; fun SizeRectangle(Rec)= [Rec.RctBD.iptX-Rec.RctHG.iptX+1 Rec.RctBD.iptY-Rec.RctHG.iptY+1] ;; fun EqualityPoint(Point1,Point2)= if (Point1==nil)||(Point2==nil) then 0 else (Point1.iptX==Point2.iptX)&&(Point1.iptY==Point2.iptY);; /* Return the intersection of two intervals (nil if none) Intrv1 : First interval Intrv2 : Second interval */ fun IntervalIntersection(Intrv1,Intrv2)= if (Intrv1==nil) || (Intrv2==nil) then nil else if (Intrv2.ItvEnd ColInterval in if ColInterval==nil then nil else let IntervalIntersection MkInt2DInterval [Rect1.RctHG.iptY Rect1.RctBD.iptY] MkInt2DInterval [Rect2.RctHG.iptY Rect2.RctBD.iptY] -> LgnInterval in if LgnInterval==nil then nil else MkRectangle2D [ MkInt2DPoint [ColInterval.ItvBegin LgnInterval.ItvBegin] MkInt2DPoint [ColInterval.ItvEnd LgnInterval.ItvEnd] ] ;; /*+mb+*/ fun MoveRectangleTo (rect, point) = let SizeRectangle rect -> [rw rh] in MkRectangle2D [ MkInt2DPoint [point.iptX point.iptY] MkInt2DPoint [point.iptX+rw point.iptY+rh] ];; fun MoveRectangleBy (rect, point)= MkRectangle2D [ MkInt2DPoint [rect.RctHG.iptX+point.iptX rect.RctHG.iptY+point.iptY] MkInt2DPoint [rect.RctBD.iptX+point.iptX rect.RctBD.iptY+point.iptY] ];; /*-mb-*/