' Classes/System/Drawing/Size.ab

#ifndef __SYSTEM_DRAWING_SIZE_AB__
#define __SYSTEM_DRAWING_SIZE_AB__

'#include <Classes/System/Math.ab>
#include <Classes/System/Drawing/SizeF.ab>

Class Size
Public
	Sub Size()
		width = 0
		height = 0
	End Sub

	Sub Size(initWidth As Long, initHeight As Long)
		width = initWidth
		height = initHeight
	End Sub

	Sub Size(sz As Size)
		width = sz.width
		height = sz.height
	End Sub

	Function Width() As Long
		Return width
	End Function

	Sub Width(w As Long)
		width = w
	End Sub

	Function Height() As Long
		Return height
	End Function

	Sub Height(h As Long)
		height = h
	End Sub

	Function Operator +(sz As Size) As Size
		Dim ret As Size(width + sz.width, height + sz.height)
		Return ret
	End Function

	Function Operator -(sz As Size) As Size
		Dim ret As Size(width - sz.width, height - sz.height)
		Return ret
	End Function

	Function Operator () As SizeF
		Dim szf As SizeF(width, height)
		Return szf
	End Function

	Function Operator ==(sz As Size) As Boolean
		Return Equals(sz)
	End Function

	Function Operator <>(sz As Size) As Boolean
		Return Not Equals(sz)
	End Function
/*
	Sub Operator =(ByRef sz As Size)
		width = sz.width
		height = sz.height
	End Sub
*/
	Function Equals(sz As Size) As Boolean
		If width = sz.width And height = sz.height Then
			Equals = True
		Else
			Equals = False
		End If
	End Function

	Override Function GetHashCode() As Long
		Return width As DWord Xor _System_BSwap(height As DWord)
	End Function

	Function IsEmpty() As Boolean
		Return width = 0 And height = 0
	End Function

	Function Add(sz As Size) As Size
		Return This + sz
	End Function

	Function Subtract(sz As Size) As Size
		Return This - sz
	End Function

	Static Function Ceiling(szf As SizeF) As Size
		Dim sz As Size(System.Math.Ceiling(szf.Width) As Long, System.Math.Ceiling(szf.Height) As Long)
		Return sz
	End Function

	Static Function Round(szf As SizeF) As Size
		Dim sz As Size(System.Math.Round(szf.Width) As Long, System.Math.Round(szf.Height) As Long)
		Return sz
	End Function

	Static Function Truncate(szf As SizeF) As Size
		Dim sz As Size(System.Math.Truncate(szf.Width) As Long, System.Math.Truncate(szf.Height) As Long)
		Return sz
	End Function

Private
	width As Long
	height As Long
End Class

#endif '__SYSTEM_DRAWING_SIZE_AB__
