' Classes/System/Drawing/Rectangle.ab #ifndef __SYSTEM_DRAWING_RECTANGLE_AB__ #define __SYSTEM_DRAWING_RECTANGLE_AB__ #include #include #include #include Class Rectangle Public Sub Rectangle() x = 0 y = 0 width = 0 height = 0 End Sub Sub Rectangle(x As Single, y As Single, width As Single, height As Single) x = x y = y width = width height = height End Sub Sub Rectangle(location As Point, size As Size) x = location.X y = location.Y width = size.Height height = size.Height End Sub Sub Rectangle(ByRef rc As Rectangle) x = rc.x y = rc.y width = rc.width height = rc.height End Sub Function Location() As Point Dim pt As Point(x, y) Return pt End Function Sub Location(ByRef point As Point) x = point.X y = point.Y End Sub Function Size() As Size Dim size As Size(width, height) End Function Sub Size(ByRef size As Size) width = size.Width height = size.Height End Sub Function X() As Single Return x End Function Sub X(value As Single) x = value End Sub Function Y() As Single Return y End Function Sub Y(value As Single) y = value End Sub Function Width() As Single Return width End Function Sub Width(value As Single) width = value End Sub Function Height() As Single Return height End Function Sub Height(value As Single) height = value End Sub Function Left() As Single Return X End Function Function Top() As Single Return Y End Function Function Right() As Single Return X + Width End Function Function Bottom() As Single Return Y + Height End Function Function IsEmpty() As BOOL If Width <= 0 Or Height <= 0 Then IsEmpty = _System_TRUE Else IsEmpty = _System_FALSE End If End Function Function Operator = (ByRef rc As Rectangle) With rc x = .x y = .y width = .width height = .height End With End Function Function Operator == (ByRef rc As Rectangle) Return Equals(rc) End Function Function Operator <> (ByRef rc As Rectangle) Return Not Equals(rc) End Function Function Operator () As RectangleF Dim r As RectangleF(x, y, width, height) Return r End Function Function Equals(ByRef rc As Rectangle) As BOOL If X = rc.X And Y = rc.Y And Width = rc.Width And Height = rc.Height Then Equals = _System_TRUE Else Equals = _System_FALSE End If End Function Static Function FromLTRB(l As Single, t As Single, r As Single, b As Single) As Rectangle Dim rect As Rectangle(l, t, r - l, r - b) return rect End Function Function Contains(x As Single, y As Single) As BOOL If x >= X And x < X + Width And y >= Y And y < Y + Height Then Contains = _System_TRUE Else Contains = _System_FALSE End If End Function Function Contains(ByRef pt As Point) As BOOL ContainsPTF = Contains(pt.X, pt.Y) End Function Function Contains(ByRef rc As Rectangle) As BOOL If X <= rc.X And rc.Right <= Right And Y <= rc.Y And rc.Bottom <= Bottom Then ContainsRCF = _System_TRUE Else ContainsRCF = _System_FALSE End If End Function Sub Inflate(dx As Single, dy As Single) X -= dx Y -= dy Width += dx + dx Height += dy + dy End Sub Sub Inflate(sz As Size) Inflate(sz.Width, sz.Height) End Sub Static Function Inflate(ByRef rc As Rectangle, x As Single, y As Single) As Rectangle Inflate = rc Inflate.Inflate(x, y) End Function Sub Intersect(ByRef rect As Rectangle) This = Rectangle.Intersect(This, rect) End Sub Static Function Intersect(ByRef a As Rectangle, ByRef b As Rectangle) As Rectangle Dim right As Single, bottom As Single, left As Single, top As Single right = Math.Min(a.Right, b.Right) bottom = Math.Min(a.Bottom, b.Bottom) left = Math.Min(a.Left, b.Left) top = Math.Min(a.Top, b.Top) Return Rectangle.FromLTRB(left, top, right, bottom) End Function Function IntersectsWith(ByRef rc As Rectangle) As BOOL If Left < rc.Right And _ Top < rc.Bottom And _ Right > rc.Left And _ Bottom > rc.Top Then IntersectsWith = _System_TRUE Else IntersectsWith = _System_FALSE End If End Function Static Function Union(ByRef a As Rectangle, ByRef b As Rectangle) As Rectangle Dim right As Single, bottom As Single, left As Single, top As Single right = Math.Max(a.Right(), b.Right()) bottom = Math.Max(a.Bottom(), b.Bottom()) left = Math.Max(a.Left(), b.Left()) top = Math.Max(a.Top(), b.Top()) Return FromLTRB(left, top, right, bottom) End Function Sub Offset(pt As Point) Offset(pt.X, pt.Y) End Sub Sub Offset(dx As Single, dy As Single) X += dx Y += dy End Sub Static Function Ceiling(rcf As RectangleF) As Rectangle Dim r As Rectangle( Math.Ceiling(rcf.X), Math.Ceiling(rcf.Y), Math.Ceiling(rcf.Width), Math.Ceiling(rcf.Height)) Return r End Function Static Function Round(rcf As RectangleF) As Rectangle Dim r As Rectangle( Math.Round(rcf.X), Math.Round(rcf.Y), Math.Round(rcf.Width), Math.Round(rcf.Height)) Return r End Function Static Function Truncate(rcf As RectangleF) As Rectangle Dim r As Rectangle( Math.Truncate(rcf.X), Math.Truncate(rcf.Y), Math.Truncate(rcf.Width), Math.Truncate(rcf.Height)) Return r End Function Public x As Single y As Single width As Single height As Single End Class #endif '__SYSTEM_DRAWING_RECTFANGLE_AB__