# BGRABitmap Geometry types

From Free Pascal wiki

Here are all the basic geometry types used in BGRABitmap library. They are provided by *BGRABitmapTypes* unit.

### Geometry types

EmptySingle: single = -3.402823e38; | ||

Value indicating that there is nothing in the single-precision floating point value. It is also used as a separator in lists | ||

PPointF = ^TPointF; | ||

Pointer to a TPointF structure | ||

TPointF = packed record x, y: single; | ||

Contains a point with single-precision floating point coordinates | ||

EmptyPointF: TPointF = (x: -3.402823e38; y: -3.402823e38); | ||

Value indicating that there is an empty TPointF structure. It is also used as a separator in lists of points | ||

function PointF(x, y: single): TPointF; | ||

Creates a new structure with values x and y | ||

function isEmptyPointF(pt: TPointF): boolean; | ||

Checks if the structure is empty (equal to EmptyPointF) | ||

operator = (const pt1, pt2: TPointF): boolean; inline; | ||

Checks if both x and y are equal | ||

operator + (const pt1, pt2: TPointF): TPointF; inline; | ||

Adds x and y components separately. It is like adding vectors | ||

operator - (const pt1, pt2: TPointF): TPointF; inline; | ||

Subtract x and y components separately. It is like subtracting vectors | ||

operator - (const pt2: TPointF): TPointF; inline; | ||

Returns a point with opposite values for x and y components | ||

operator * (const pt1, pt2: TPointF): single; inline; | ||

Scalar product: multiplies x and y components and returns the sum | ||

operator * (const pt1: TPointF; factor: single): TPointF; inline; | ||

Multiplies both x and y by factor. It scales the vector represented by (x,y) | ||

operator * (factor: single; const pt1: TPointF): TPointF; inline; | ||

Multiplies both x and y by factor. It scales the vector represented by (x,y) | ||

function VectLen(dx,dy: single): single; overload; | ||

Returns the length of the vector (dx,dy) | ||

function VectLen(v: TPointF): single; overload; | ||

Returns the length of the vector represented by (x,y) | ||

ArrayOfTPointF = array of TPointF; | ||

Contains an array of points with single-precision floating point coordinates | ||

function PointsF(const pts: array of TPointF): ArrayOfTPointF; | ||

Creates an array of TPointF | ||

function ConcatPointsF(const APolylines: array of ArrayOfTPointF): ArrayOfTPointF; | ||

Concatenates arrays of TPointF | ||

function PolylineLen(const pts: array of TPointF; AClosed: boolean = false): single; | ||

Compute the length of the polyline contained in the array. AClosed specifies if the last point is to be joined to the first one | ||

TBGRAPenStyle = array of Single; | ||

A pen style can be dashed, dotted, etc. It is defined as a list of floating point number. The first number is the length of the first dash, the second number is the length of the first gap, the third number is the length of the second dash... It must have an even number of values. This is used as a complement to TPenStyle | ||

function BGRAPenStyle(dash1, space1: single; dash2: single=0; space2: single = 0; dash3: single=0; space3: single = 0; dash4 : single = 0; space4 : single = 0): TBGRAPenStyle; | ||

Creates a pen style with the specified length for the dashes and the spaces | ||

TSplineStyle = ( | ||

Different types of spline. A spline is a series of points that are used as control points to draw a curve. The first point and last point may or may not be the starting and ending point | ||

ssInside, | ||

The curve is drawn inside the polygonal envelope without reaching the starting and ending points | ||

ssInsideWithEnds, | ||

The curve is drawn inside the polygonal envelope and the starting and ending points are reached | ||

ssCrossing, | ||

The curve crosses the polygonal envelope without reaching the starting and ending points | ||

ssCrossingWithEnds, | ||

The curve crosses the polygonal envelope and the starting and ending points are reached | ||

ssOutside, | ||

The curve is outside the polygonal envelope (starting and ending points are reached) | ||

ssRoundOutside, | ||

The curve expands outside the polygonal envelope (starting and ending points are reached) | ||

ssVertexToSide); | ||

The curve is outside the polygonal envelope and there is a tangeant at vertices (starting and ending points are reached) | ||

TCubicBezierCurve = object | ||

Definition of a Bézier curve of order 3. It has two control points c1 and c2. Those are not reached by the curve | ||

p1: TPointF; | ||

Starting point (reached) | ||

c1: TPointF; | ||

First control point (not reached by the curve) | ||

c2: TPointF; | ||

Second control point (not reached by the curve) | ||

p2: TPointF; | ||

Ending point (reached) | ||

function ComputePointAt(t: single): TPointF; | ||

Computes the point at time t, varying from 0 to 1 | ||

procedure Split(out ALeft, ARight: TCubicBezierCurve); | ||

Split the curve in two such that ALeft.p2 = ARight.p1 | ||

function ComputeLength(AAcceptedDeviation: single = 0.1): single; | ||

Compute an approximation of the length of the curve. AAcceptedDeviation indicates the maximum orthogonal distance that is ignored and approximated by a straight line. | ||

function ToPoints(AAcceptedDeviation: single = 0.1; AIncludeFirstPoint: boolean = true): ArrayOfTPointF; | ||

Computes a polygonal approximation of the curve. AAcceptedDeviation indicates the maximum orthogonal distance that is ignored and approximated by a straight line. AIncludeFirstPoint indicates if the first point must be included in the array | ||

function BezierCurve(origin, control1, control2, destination: TPointF) : TCubicBezierCurve; overload; | ||

Creates a structure for a cubic Bézier curve | ||

TQuadraticBezierCurve = object | ||

Definition of a Bézier curve of order 2. It has one control point | ||

p1: TPointF; | ||

Starting point (reached) | ||

c: TPointF; | ||

Control point (not reached by the curve) | ||

p2: TPointF; | ||

Ending point (reached) | ||

function ComputePointAt(t: single): TPointF; | ||

Computes the point at time t, varying from 0 to 1 | ||

procedure Split(out ALeft, ARight: TQuadraticBezierCurve); | ||

Split the curve in two such that ALeft.p2 = ARight.p1 | ||

function ComputeLength: single; | ||

Compute the exact length of the curve | ||

function ToPoints(AAcceptedDeviation: single = 0.1; AIncludeFirstPoint: boolean = true): ArrayOfTPointF; | ||

Computes a polygonal approximation of the curve. AAcceptedDeviation indicates the maximum orthogonal distance that is ignored and approximated by a straight line. AIncludeFirstPoint indicates if the first point must be included in the array | ||

function BezierCurve(origin, control, destination: TPointF) : TQuadraticBezierCurve; overload; | ||

Creates a structure for a quadratic Bézier curve | ||

function BezierCurve(origin, destination: TPointF) : TQuadraticBezierCurve; overload; | ||

Creates a structure for a quadratic Bézier curve without curvature | ||

PArcDef = ^TArcDef; | ||

Pointer to an arc definition | ||

TArcDef = record | ||

Definition of an arc of an ellipse | ||

center: TPointF; | ||

Center of the ellipse | ||

radius: TPointF; | ||

Horizontal and vertical of the ellipse before rotation | ||

xAngleRadCW: single; | ||

Rotation of the ellipse | ||

startAngleRadCW, endAngleRadCW: single; | ||

Start and end angle, in radian and clockwise. See angle convention in BGRAPath | ||

anticlockwise: boolean | ||

Specifies if the arc goes anticlockwise | ||

function ArcDef(cx, cy, rx,ry, xAngleRadCW, startAngleRadCW, endAngleRadCW: single; anticlockwise: boolean) : TArcDef; | ||

Creates a structure for an arc definition | ||

TArcOption = ( | ||

Possible options for drawing an arc of an ellipse (used in BGRACanvas) | ||

aoClosePath, | ||

Close the path by joining the ending and starting point together | ||

aoPie, | ||

Draw a pie shape by joining the ending and starting point to the center of the ellipse | ||

aoFillPath); | ||

Fills the shape | ||

TArcOptions = set of TArcOption; | ||

Set of options for drawing an arc | ||

TPoint3D = record x,y,z: single; | ||

Point in 3D with single-precision floating point coordinates | ||

function Point3D(x,y,z: single): TPoint3D; | ||

Creates a new structure with values (x,y,z) | ||

operator = (const v1,v2: TPoint3D): boolean; inline; | ||

Checks if all components x, y and z are equal | ||

operator + (const v1,v2: TPoint3D): TPoint3D; inline; | ||

Adds components separately. It is like adding vectors | ||

operator - (const v1,v2: TPoint3D): TPoint3D; inline; | ||

Subtract components separately. It is like subtracting vectors | ||

operator - (const v: TPoint3D): TPoint3D; inline; | ||

Returns a point with opposite values for all components | ||

operator * (const v1,v2: TPoint3D): single; inline; | ||

Scalar product: multiplies components and returns the sum | ||

operator * (const v1: TPoint3D; const factor: single): TPoint3D; inline; | ||

Multiplies components by factor. It scales the vector represented by (x,y,z) | ||

operator * (const factor: single; const v1: TPoint3D): TPoint3D; inline; | ||

Multiplies components by factor. It scales the vector represented by (x,y,z) | ||

procedure VectProduct3D(u,v: TPoint3D; out w: TPoint3D); | ||

Computes the vectorial product w. It is perpendicular to both u and v | ||

procedure Normalize3D(var v: TPoint3D); inline; | ||

Normalize the vector, i.e. scale it so that its length be 1 | ||

TLineDef = record | ||

Defition of a line in the euclidian plane | ||

origin: TPointF; | ||

Some point in the line | ||

dir: TPointF; | ||

Vector indicating the direction | ||

function IntersectLine(line1, line2: TLineDef): TPointF; | ||

Computes the intersection of two lines. If they are parallel, returns the middle of the segment between the two origins | ||

function IntersectLine(line1, line2: TLineDef; out parallel: boolean): TPointF; | ||

Computes the intersection of two lines. If they are parallel, returns the middle of the segment between the two origins. The value parallel is set to indicate if the lines were parallel | ||

function IsConvex(const pts: array of TPointF; IgnoreAlign: boolean = true): boolean; | ||

Checks if the polygon formed by the given points is convex. IgnoreAlign specifies that if the points are aligned, it should still be considered as convex | ||

function DoesQuadIntersect(pt1,pt2,pt3,pt4: TPointF): boolean; | ||

Checks if the quad formed by the 4 given points intersects itself | ||

function DoesSegmentIntersect(pt1,pt2,pt3,pt4: TPointF): boolean; | ||

Checks if two segment intersect | ||

IBGRAPath = interface | ||

A path is the ability to define a contour with moveTo, lineTo... Even if it is an interface, it must not implement reference counting. | ||

procedure closePath; | ||

Closes the current path with a line to the starting point | ||

procedure moveTo(const pt: TPointF); | ||

Moves to a location, disconnected from previous points | ||

procedure lineTo(const pt: TPointF); | ||

Adds a line from the current point | ||

procedure polylineTo(const pts: array of TPointF); | ||

Adds a polyline from the current point | ||

procedure quadraticCurveTo(const cp,pt: TPointF); | ||

Adds a quadratic Bézier curve from the current point | ||

procedure bezierCurveTo(const cp1,cp2,pt: TPointF); | ||

Adds a cubic Bézier curve from the current point | ||

procedure arc(const arcDef: TArcDef); | ||

Adds an arc. If there is a current point, it is connected to the beginning of the arc | ||

procedure openedSpline(const pts: array of TPointF; style: TSplineStyle); | ||

Adds an opened spline. If there is a current point, it is connected to the beginning of the spline | ||

procedure closedSpline(const pts: array of TPointF; style: TSplineStyle); | ||

Adds an closed spline. If there is a current point, it is connected to the beginning of the spline | ||

procedure copyTo(dest: IBGRAPath); | ||

Copy the content of this path to the specified destination | ||

function getPoints: ArrayOfTPointF; | ||

Returns the content of the path as an array of points | ||

function getCursor: TBGRACustomPathCursor; | ||

Returns a cursor to go through the path. The cursor must be freed by calling Free. | ||

TBGRACustomPathCursor = class | ||

Class that contains a cursor to browse an existing path | ||

function MoveForward(ADistance: single; ACanJump: boolean = true): single; virtual; abstract; | ||

Go forward in the path, increasing the value of Position. If ADistance is negative, then it goes backward instead. ACanJump specifies if the cursor can jump from one shape to another without a line or an arc. Otherwise, the cursor is stuck, and the return value is less than the value ADistance provided. If all the way has been travelled, the return value is equal to ADistance | ||

function MoveBackward(ADistance: single; ACanJump: boolean = true): single; virtual; abstract; | ||

Go backward, decreasing the value of Position. If ADistance is negative, then it goes forward instead. ACanJump specifies if the cursor can jump from one shape to another without a line or an arc. Otherwise, the cursor is stuck, and the return value is less than the value ADistance provided. If all the way has been travelled, the return value is equal to ADistance | ||

property CurrentCoordinate: TPointF read; | ||

Returns the current coordinate in the path | ||

property CurrentTangent: TPointF read; | ||

Returns the tangent vector. It is a vector of length one that is parallel to the curve at the current point. A normal vector is easily deduced as PointF(y,-x) | ||

property Position: single read write; | ||

Current position in the path, as a distance along the arc from the starting point of the path | ||

property PathLength: single read; | ||

Full arc length of the path | ||

property StartCoordinate: TPointF read; | ||

Starting coordinate of the path | ||

property LoopClosedShapes: boolean read write; | ||

Specifies if the cursor loops when there is a closed shape | ||

property LoopPath: boolean read write; | ||

Specifies if the cursor loops at the end of the path. Note that if it needs to jump to go to the beginning, it will be only possible if the parameter ACanJump is set to True when moving along the path | ||

EmptyRect : TRect = (left:0; top:0; right:0; bottom: 0); | ||

A value for an empty rectangle | ||

function PtInRect(const pt: TPoint; r: TRect): boolean; overload; | ||

Checks if a point is in a rectangle. This follows usual convention: r.Right and r.Bottom are not considered to be included in the rectangle. | ||

function RectWithSize(left,top,width,height: integer): TRect; | ||

Creates a rectangle with the specified width and height | ||

TRoundRectangleOption = ( | ||

Possible options for a round rectangle | ||

rrTopLeftSquare,rrTopRightSquare,rrBottomRightSquare,rrBottomLeftSquare, | ||

specify that a corner is a square (not rounded) | ||

rrTopLeftBevel,rrTopRightBevel,rrBottomRightBevel,rrBottomLeftBevel, | ||

specify that a corner is a bevel (cut) | ||

rrDefault); | ||

default option, does nothing particular | ||

TRoundRectangleOptions = set of TRoundRectangleOption; | ||

A set of options for a round rectangle | ||

TPolygonOrder = ( | ||

Order of polygons when rendered using TBGRAMultiShapeFiller (in unit BGRAPolygon) | ||

poNone, | ||

No order, colors are mixed together | ||

poFirstOnTop, | ||

First polygon is on top | ||

poLastOnTop); | ||

Last polygon is on top | ||

TIntersectionInfo = class | ||

Contains an intersection between an horizontal line and any shape. It is used when filling shapes | ||

ArrayOfTIntersectionInfo = array of TIntersectionInfo; | ||

An array of intersections between an horizontal line and any shape | ||

TBGRACustomFillInfo = class | ||

Abstract class defining any shape that can be filled | ||

function SegmentsCurved: boolean; virtual; abstract; | ||

Returns true if one segment number can represent a curve and thus cannot be considered exactly straight | ||

function GetBounds: TRect; virtual; abstract; | ||

Returns integer bounds for the shape | ||

function IsPointInside(x,y: single; windingMode: boolean): boolean; virtual; abstract; | ||

Check if the point is inside the shape | ||

function CreateIntersectionArray: ArrayOfTIntersectionInfo; virtual; abstract; | ||

Create an array that will contain computed intersections. To augment that array, use CreateIntersectionInfo for new items | ||

function CreateIntersectionInfo: TIntersectionInfo; virtual; abstract; | ||

Create a structure to define one single intersection | ||

procedure FreeIntersectionArray(var inter: ArrayOfTIntersectionInfo); virtual; abstract; | ||

Free an array of intersections | ||

procedure ComputeAndSort(cury: single; var inter: ArrayOfTIntersectionInfo; out nbInter: integer; windingMode: boolean); virtual; abstract; | ||

Fill an array inter with actual intersections with the shape at the y coordinate cury. nbInter receives the number of computed intersections. windingMode specifies if the winding method must be used to determine what is inside of the shape | ||

TGradientType = ( | ||

Shape of a gradient | ||

gtLinear, | ||

The color changes along a certain vector and does not change along its perpendicular direction | ||

gtReflected, | ||

The color changes like in gtLinear however it is symmetrical to a specified direction | ||

gtDiamond, | ||

The color changes along a diamond shape | ||

gtRadial); | ||

The color changes in a radial way from a given center | ||

GradientTypeStr : array[TGradientType] of string | ||

List of string to represent gradient types | ||

function StrToGradientType(str: string): TGradientType; | ||

Returns the gradient type represented by the given string | ||

TBGRACustomGradient = class | ||

Defines a gradient of color, not specifying its shape but only the series of colors | ||

function GetColorAt(position: integer): TBGRAPixel; virtual; abstract; | ||

Returns the color at a given position. The reference range is from 0 to 65535, however values beyond are possible as well | ||

function GetColorAtF(position: single): TBGRAPixel; virtual; | ||

Returns the color at a given position. The reference range is from 0 to 1, however values beyond are possible as well | ||

function GetAverageColor: TBGRAPixel; virtual; abstract; | ||

Returns the average color of the gradient | ||

property Monochrome: boolean read; | ||

This property is True if the gradient contains only one color, and thus is not really a gradient | ||