User Tools

Site Tools


k25:k25.2.3:start

25.2.3 Classes Point and PointF

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.

25.2.3.1 Properties

The Point class has these two properties

PropertyDescription
X As IntegerSets the x-coordinate of the point or returns the value.
Y As IntegerSets the y-coordinate of the point or returns the value.

Table 25.2.3.1.1 : Properties of the Point class

25.2.3.2 Methods

The two methods for the Point class are described here.

MethodDescription
Copy( ) As PointReturns a copy of the current point.
InRect( Rectangle As Rect ) As BooleanReturns True if the point is in the specified rectangle.

Table 25.2.3.2.1 : Selected methods of the Point class

25.2.3.3 Examples

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:

B1

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

B2

Figure 25.2.3.3.2: Mutual position of point and rectangle

25.2.3.4 Class PointF

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.

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k25/k25.2.3/start.txt · Last modified: 21.02.2024 by emma

Page Tools