GpPointF type
A point or two-dimensional vector with Single coordinates.
GpPointF is the point that the Single overloads of the drawing methods take. It is 8 bytes: the fields X and Y, followed by methods that read and change them. The integer counterpart is GpPoint; a size is a GpSizeF and a rectangle a GpRectF. It mirrors the PointF class of the GDI+ C++ wrapper.
A variable declared with Dim starts at (0, 0).
Creating
Syntax: GpPointF( )
Syntax: GpPointF( x, y )
Syntax: GpPointF( point )
Syntax: GpPointF( size )
The module function GpPointF returns a new point. A GpPointF has no constructor of the New form.
- x, y
- required A Single giving each coordinate.
- point
- required A GpPoint. The new point has the same coordinates.
- size
- required A GpSizeF. The new point takes X from its Width and Y from its Height.
With no arguments the point is (0, 0).
Dim user As GdiPlusUser = GdiPlusUser()
Dim p As GpPointF = GpPointF(3, 4)
Debug.Print p.X & "," & p.Y ' 3,4
Debug.Print GpPointF().Zero ' True
Dim fromInt As GpPointF = GpPointF(GpPoint(7, 8))
Debug.Print fromInt.X & "," & fromInt.Y ' 7,8
Dim fromSize As GpPointF = GpPointF(GpSizeF(1.5, 2.5))
Debug.Print fromSize.X & "," & fromSize.Y ' 1.5,2.5
Fields and properties
X, Y
The coordinates, as Single fields. Assign them directly.
Zero
Syntax: point.Zero As Boolean
Read-only. True when both coordinates are exactly 0.
Length
Syntax: point.Length [ = value ] As Single
Returns the length of the vector, the square root of X squared plus Y squared. Setting it scales the vector to the given length and keeps its direction.
Setting Length to 0 sets both coordinates to 0, and the direction is lost. Setting the length of a zero vector, or of one shorter than twice REAL_EPSILON, changes nothing.
Normalized
Syntax: point.Normalized As GpPointF
Returns the vector scaled to length 1.
Note 0.9.45.0 BETA 1005
A program that names Normalized does not link: the linker reports a code generation error in Types.Normalized. Use Normalize on a copy of the point instead.
Transposed
Syntax: point.Transposed As GpPointF
Read-only. Returns a point with X and Y exchanged.
Dim user As GdiPlusUser = GdiPlusUser()
Dim p As GpPointF = GpPointF(3, 4)
Debug.Print p.Length ' 5
p.Length = 10
Debug.Print p.X & "," & p.Y ' 6,8
p.Length = 0
Debug.Print p.Zero ' True
Debug.Print GpPointF(1, 2).Transposed.X ' 2
Conversion
AsGpPoint
Syntax: point.AsGpPoint( ) As GpPoint
Returns the point with its coordinates rounded to whole numbers. Halves go to the even number: 2.5 becomes 2 and 3.5 becomes 4.
SetFrom
Syntax: point.SetFrom( source )
Sets both coordinates from a GpPoint.
AsPOINT, SetFromPOINT
Syntax: point.AsPOINT( ) As GDIP_POINT
Syntax: point.SetFromPOINT( source As GDIP_POINT )
Convert to and from a structure of two Long fields x and y, which is the layout of the Windows POINT. The structure is declared as GDIP_POINT. AsPOINT rounds as AsGpPoint does.
Dim user As GdiPlusUser = GdiPlusUser()
Dim whole As GpPoint = GpPointF(2.5, 3.5).AsGpPoint()
Debug.Print whole.X & "," & whole.Y ' 2,4
Dim p As GpPointF
p.SetFrom GpPoint(5, 6)
Debug.Print p.X & "," & p.Y ' 5,6
Dim winPoint As GDIP_POINT = GpPointF(9.2, 1.7).AsPOINT()
Debug.Print winPoint.x & "," & winPoint.y ' 9,2
Modifying methods
These change the point they are called on.
Note 0.9.45.0
Add and Sub change the point they are called on. Before version 0.9.0.43 they returned the result and left the point alone. Use Sum and Diff to get a new point.
Note 0.9.45.0 BETA 1005
The compiler reads p.Scale(2) as the start of a Scale statement and reports a syntax error. Write p.Scale 2 or Call p.Scale(2). Scale2, InvScale and the other methods are not affected.
Add, Sub
Syntax: point.Add( other As GpPointF )
Syntax: point.Sub( other As GpPointF )
Adds other to the point, or subtracts it.
Scale, Scale2
Syntax: point.Scale factor
Syntax: point.Scale2( xFactor, yFactor )
Multiplies both coordinates by factor (Single), or X by xFactor and Y by yFactor.
InvScale, InvScale2
Syntax: point.InvScale( divisor )
Syntax: point.InvScale2( xDivisor, yDivisor )
Divides both coordinates by divisor, or X by xDivisor and Y by yDivisor.
Transpose
Syntax: point.Transpose
Exchanges X and Y.
Normalize
Syntax: point.Normalize
Sets the length to 1 and keeps the direction. A zero vector stays as it is.
Dim user As GdiPlusUser = GdiPlusUser()
Dim p As GpPointF = GpPointF(3, 4)
p.Add GpPointF(1, 1)
Debug.Print p.X & "," & p.Y ' 4,5
p.Sub GpPointF(1, 1)
p.Scale 2
Debug.Print p.X & "," & p.Y ' 6,8
p.Scale2 1, 3
Debug.Print p.X & "," & p.Y ' 6,24
p.InvScale 2
p.InvScale2 3, 12
Debug.Print p.X & "," & p.Y ' 1,1
p.Transpose
p = GpPointF(3, 4)
p.Normalize
Debug.Print p.X & "," & p.Y ' 0.6,0.8
Query methods
These return a new value and leave the point unchanged.
Sum, Diff
Syntax: point.Sum( other As GpPointF ) As GpPointF
Syntax: point.Diff( other As GpPointF ) As GpPointF
Returns the sum of the two vectors, or the point less other.
Prod, Prod2
Syntax: point.Prod( factor ) As GpPointF
Syntax: point.Prod2( xFactor, yFactor ) As GpPointF
Returns the point with its coordinates multiplied.
Quot, Quot2
Syntax: point.Quot( divisor ) As GpPointF
Syntax: point.Quot2( xDivisor, yDivisor ) As GpPointF
Returns the point with its coordinates divided.
DotProd
Syntax: point.DotProd( other As GpPointF ) As Single
Returns the dot product, X * other.X + Y * other.Y.
Equals
Syntax: point.Equals( other As GpPointF ) As Boolean
True when both coordinates are exactly equal to those of other.
Dim user As GdiPlusUser = GdiPlusUser()
Dim p As GpPointF = GpPointF(3, 4)
Dim s As GpPointF = p.Sum(GpPointF(1, 1))
Debug.Print s.X & "," & s.Y ' 4,5
Debug.Print p.X & "," & p.Y ' 3,4
Debug.Print p.Diff(GpPointF(1, 1)).X ' 2
Debug.Print p.Prod(2).Y ' 8
Debug.Print p.Quot2(2, 4).Y ' 1
Debug.Print p.DotProd(GpPointF(2, 1)) ' 10
Debug.Print p.Equals(GpPointF(3, 4)) ' True