The Point class (gb.clipper) describes a point with integer coordinates. This chapter presents the properties and methods of the Point class as well as some examples for using the class.
The Point class has these two properties
Property | Description |
---|---|
X As Integer | Sets the x-coordinate of the point or returns the value. |
Y As Integer | Sets the y-coordinate of the point or returns the value. |
Table 25.2.3.1.1 : Properties of the Point class
The two methods for the Point class are described here.
Method | Description |
---|---|
Copy( ) As Point | Returns a copy of the current point. |
InRect( Rectangle As Rect ) As Boolean | Returns True if the point is in the specified rectangle. |
Table 25.2.3.2.1 : Selected methods of the Point class
The Point class can be created. You can use the class like a (static) function:
Dim PointP, PointQ As Point PointP = New Point() ' P(0|0) PointQ = New Point(44,-22)
In the following example, points with random coordinates (from a restricted area) and a random colour are created and drawn on a picture, which is then displayed in a DrawArea:
Public Sub SetPoint(X As Integer, Y As Integer, cColor As Integer) Paint.AntiAlias = False Paint.FillRect(X, Y, 1, 1, cColor) Paint.AntiAlias = True End Public Sub ScriptPointCloud() Dim i As Integer Dim PointP As Point '-- Class 'Point' in gb.clipper GenerateNewPicture() SetPictureBorder() Paint.Begin(hPicture) Paint.Translate(xTranslate, yTranslate) Paint.Scale(xScale, yScale) ' +y ▲ Paint.AntiAlias = False DrawCoordinateSystem() ' +y ▲ For i = 1 To 20000 '-- Points with random coordinates and a random colour PointP = New Point(Rnd(10, 550 - 5), Rnd(10, 260)) SetPoint(PointP.X, PointP.Y, Color.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))) Next Paint.AntiAlias = True Paint.End() End
If you count exactly, you should get about 20000 points - I have counted all the points:
Figure 25.2.3.3.1: Point cloud
The final example demonstrates how you can determine whether a given point lies within a specific rectangle.
Dim PointP As Point Dim RectRed As Rect PointP = New Point(260, 150) RectRed = New Rect(60, 60, 400, 180) Print "P in RectRed? --> "; PointP.InRect(RectRed) '-- Result: TRUE
Figure 25.2.3.3.2: Mutual position of point and rectangle
While only integers are permitted as coordinates for the Point class, you can use real numbers for the coordinates of a point for the PointF class.