' Classes/System/Drawing/Point.ab

#ifndef __SYSTEM_DRAWING_POINT_AB__
#define __SYSTEM_DRAWING_POINT_AB__

#require <Classes/System/Drawing/PointF.ab>
#require <Classes/System/Drawing/Size.ab>
#require <Classes/System/Drawing/SizeF.ab>

Class Point
Public
	Sub Point()
		x = 0
		y = 0
	End Sub

	Sub Point(initX As Long, initY As Long)
		x = initX
		y = initY
	End Sub

	Sub Point(sz As Size)
		x = sz.Width
		y = sz.Height
	End Sub

	Sub Point(dw As DWord)
		x = LOWORD(dw)
		y = HIWORD(dw)
	End Sub

	Function X() As Long
		Return x
	End Function

	Sub X(newX As Long)
		x = newX
	End Sub

	Function Y() As Long
		Return y
	End Function

	Sub Y(newY As Long)
		y = newY
	End Sub

	Function IsEmpty() As Boolean
		Return x = 0 And y = 0
	End Function

	Function Operator + (pt As Point) As Point
		Return Add(This, pt)
	End Function

	Function Operator + (sz As Size) As Point
		Return Add(This, sz)
	End Function

	Function Operator - (pt As Point) As Point
		Return Substract(This, pt)
	End Function

	Function Operator - (sz As Size) As Point
		Return Substract(This, sz)
	End Function

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

	Function Operator <> (sz As Point) As Boolean
		Return Not Equals(sz)
	End Function

	Static Function Add(pt1 As Point, pt2 As Point) As Point
		Return New Point(pt1.x + pt2.x, pt1.y + pt2.y)
	End Function

	Static Function Add(pt As Point, sz As Size) As Point
		Return New Point(pt.x + sz.Width, pt.y + sz.Height)
	End Function

	Function Offset(pt As Point) As Point
		Return New Point(x + pt.x, y + pt.y)
	End Function

	Sub Offset(dx As Long, dy As Long)
		x += dx
		y += dy
	End Sub

	Static Function Substract(pt1 As Point, pt2 As Point) As Point
		Return New Point(pt1.x - pt2.x, pt1.y - pt2.y)
	End Function

	Static Function Substract(pt As Point, sz As Size) As Point
		Return New Point(pt.x - sz.Width, pt.y - sz.Height)
	End Function

	Function Equals(pt As Point) As Boolean
		Return x = pt.x And y = pt.y
	End Function

	Override Function GetHashCode() As Long
		Return x Xor _System_BSwap(y As DWord)
	End Function

	Static Function Ceiling(ptf As PointF) As Point
		Return New Point(System.Math.Ceiling(ptf.X) As Long, System.Math.Ceiling(ptf.Y) As Long)
	End Function

	Static Function Round(ptf As PointF) As Point
		Return New Point(System.Math.Round(ptf.X) As Long, System.Math.Round(ptf.Y) As Long)
	End Function

	Static Function Truncate(ptf As PointF) As Point
		Return New Point(System.Math.Truncate(ptf.X) As Long, System.Math.Truncate(ptf.Y) As Long)
	End Function

	Function Operator () As PointF
		Return New PointF(X, Y)
	End Function

Private
	x As Long
	y As Long
End Class

#endif '__SYSTEM_DRAWING_POINT_AB__
