User Tools

Site Tools


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. Properties

The Point class has these two properties

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 : Properties of the Point class Methods

The two methods for the Point class are described here.

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 : Selected methods of the Point class 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
Public Sub ScriptPointCloud()
  Dim i As Integer
  Dim PointP As Point '-- Class 'Point' in gb.clipper
    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)))
     Paint.AntiAlias = True

If you count exactly, you should get about 20000 points - I have counted all the points:


Figure 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 Mutual position of point and rectangle 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