BGRABitmap Geometry types

From Free Pascal wiki
Jump to navigationJump to search

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

Geometry types

2D points

TPoint = BGRAClasses.TPoint;
Represents a point with X and Y integer coordinates
const EmptyPoint : TPoint = (X: -2147483648; Y: -2147483648);
A constant representing an empty point (with minimum possible integer values for X and Y) that can be used as a separator in a list of TPoint
function IsEmptyPoint(const APoint: TPoint): boolean;
Checks if the given point is equivalent to EmptyPoint
const 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 = ^BGRAClasses.TPointF;
Pointer to a TPointF structure
TPointF = BGRAClasses.TPointF;
Contains a point with single-precision floating point coordinates
const 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; overload;
Creates a new structure with values x and y
function PointF(pt: TPoint): TPointF; overload;
Creates a new structure converting integer values to single-precision floating-point coordinates
function isEmptyPointF(const 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 (deprecated): multiplies x and y components and returns the sum
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(const dx,dy: single): single; overload; inline;
Returns the length of the vector (dx, dy)
function VectLen(const v: TPointF): single; overload;
Returns the length of the vector represented by (x, y)
function VectDet(const v1,v2: TPointF): double; inline;
Computes the determinant of the two vectors (equal to the determinant of the square matrix with those vectors as columns)
TPointFHelper = record helper for TPointF
Helper for TPointF structure providing additional functionality for point manipulation
procedure Offset(const apt: TPointF); overload;
Offsets the point by another point (TPointF)
procedure Offset(const apt: TPoint); overload;
Offsets the point by another point (TPoint)
procedure Offset(dx, dy: longint); overload;
Offsets the point by specified distances in the X (dx) and Y (dy) directions (integer values)
procedure Offset(dx, dy: single); overload;
Offsets the point by specified distances in the X (dx) and Y (dy) directions (single values)
procedure Scale(AScale: single);
Scales the point as a vector from the origin) by a specified factor
procedure Normalize;
Normalizes the point (modifies it to a unit length)
function Ceiling: TPoint;
Rounds the coordinates of the point to the nearest integer towards positive infinity
function Truncate: TPoint;
Truncates the coordinates of the point, discarding fractional part
function Floor: TPoint;
Rounds the coordinates of the point to the nearest integer towards negative infinity
function Round: TPoint;
Rounds the coordinates of the point to the nearest integer
function Length: Single;
Calculates the length (magnitude) of the point from the origin
function IsEmpty: boolean;
Determines if the point is empty (has special coordinates EmptyPointF)
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; AInsertEmptyPointInBetween: boolean = false): 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
TAffineMatrix = array[1..2,1..3] of single;
An affine matrix contains three 2D vectors: the image of x, the image of y and the translation

3D points

PPoint3D = ^TPoint3D;
Pointer to a TPoint3D structure
TPoint3D = record
Point in 3D with single-precision floating point coordinates
procedure Offset(const point3D: TPoint3D);
Offsets the point by the given 3D vector
procedure Scale(AScale: single);
Scale the point (as a vector from the origin)
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
function VectLen3D(const v: TPoint3D): single;
Computes the length of the vector from the origin to the point
TFaceCulling = (
Enumerates the modes of face culling in 3D rendering. Face culling is a technique used to determine which faces of a polygon are visible and should be rendered
fcNone,
No face culling is applied. All faces of the polygon are rendered
fcKeepCW,
Keeps only the faces that are clockwise (CW) from the viewer's perspective. Typically used to remove back faces when the convention is that CW is for front faces
fcKeepCCW);
Keeps only the faces that are counter-clockwise (CCW) from the viewer's perspective. Typically used to remove back faces when the convention is that CCW is for front faces

Rectangles

TRectF = BGRAClasses.TRectF;
Represents a rectangle with single-precision floating point coordinates
const EmptyRectF : TRectF = (left:0; top:0; right:0; bottom: 0);
A constant representing an empty rectangle with all coordinates set to 0
function RectF(Left, Top, Right, Bottom: Single): TRectF;
Creates a TRectF structure with specified left, top, right, and bottom coordinates
function RectF(const ATopLeft,ABottomRight: TPointF): TRectF;
Creates a TRectF structure from two TPointF points representing the top-left and bottom-right corners
function RectF(const ARect: TRect): TRectF;
Creates a TRectF structure from a TRect structure (integer coordinates converted to single precision)
function RectWithSizeF(left,top,width,height: Single): TRectF;
Creates a TRectF structure with a specified position (left, top) and size (width, height)
function IsEmptyRectF(const ARect:TRectF): boolean;
Checks if the given TRectF structure is empty (of zero size)
const EmptyRect : TRect = (left:0; top:0; right:0; bottom: 0);
A value for an empty rectangle with integer coordinates
function PtInRect(const pt: TPoint; r: TRect): boolean; overload;
Checks if a point is in a rectangle with integer coordinates. This follows usual convention that 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 integer coordinates with the specified width and height
TRectHelper = record helper for TRect
Helper for TRect structure providing additional functionality to manipulate rectangles
function GetHeight: integer;
Gets the height of the rectangle
function GetIsEmpty: boolean;
Determines if the rectangle is empty (of zero size)
function GetWidth: integer;
Gets the width of the rectangle
procedure SetHeight(AValue: integer);
Sets the height of the rectangle
procedure SetWidth(AValue: integer);
Sets the width of the rectangle
constructor Create(Origin: TPoint; AWidth, AHeight: Longint); overload;
Creates a rectangle with specified origin, width, and height
constructor Create(ALeft, ATop, ARight, ABottom: Longint); overload;
Creates a rectangle with specified left, top, right, and bottom coordinates
procedure Intersect(R: TRect);
Modifies the rectangle to be the intersection of itself and another rectangle
class function Intersect(R1: TRect; R2: TRect): TRect; static;
Returns the intersection of two given rectangles
function IntersectsWith(R: TRect): Boolean;
Checks if the rectangle intersects with another rectangle
class function Union(R1, R2: TRect): TRect; static;
Returns the smallest rectangle that contains both of the given rectangles
procedure Union(R: TRect);
Modifies the rectangle to be the union of itself and another rectangle
procedure Offset(DX, DY: Longint);
Offsets the rectangle by the given distances in the X and Y directions
procedure Inflate(DX, DY: Longint);
Expands or contracts the rectangle by the specified amounts in both directions
function Contains(const APoint: TPoint): boolean; overload;
Checks if the rectangle contains a specified point
function Contains(const ARect: TRect): boolean; overload;
Checks if the rectangle completely contains another rectangle
property Width: integer read GetWidth write SetWidth;
Property to get or set the width of the rectangle
property Height: integer read GetHeight write SetHeight;
Property to get or set the height of the rectangle
property IsEmpty: boolean read GetIsEmpty;
Property to check if the rectangle is empty
TSize = BGRAClasses.TSize;
Constains a size with integer with and height
TSizeHelper = record helper for TSize
Helper to access a size
function GetHeight: integer;
Gets the height of the size
function GetWidth: integer;
Gets the width of the size
property Width: integer read GetWidth;
Property to get the width
property Height: integer read GetHeight;
Property to get the height
PRectF = ^TRectF;
Pointer to a TRectF structure
TRectFHelper = record helper for TRectF
Helper for TRectF structure providing additional functionality for rectangle manipulation
class function Intersect(const R1: TRectF; const R2: TRectF): TRectF; overload; static;
Returns the intersection of two given rectangles
class function Union(const R1: TRectF; const R2: TRectF): TRectF; overload; static;
Returns the union of two given rectangles
class function Union(const R1: TRectF; const R2: TRectF; ADiscardEmpty: boolean): TRectF; overload; static;
Returns the union of two given rectangles, with an option to ignore empty rectangles
function Union(const r: TRectF): TRectF; overload;
Returns the union of itself and another rectangle
function Union(const r: TRectF; ADiscardEmpty: boolean): TRectF; overload;
Returns the union of itself and another rectangle, with an option to ignore empty rectangles
procedure Include(const APoint: TPointF);
Expands the rectangle to include a specified point (empty points are ignored)
function Contains(const APoint: TPointF; AIncludeBottomRight: boolean = false): boolean;
Checks if the rectangle contains a specified point, with an option to include or exclude the bottom-right boundary
function IntersectsWith(const r: TRectF): boolean;
Checks if the rectangle intersects with another rectangle
function IsEmpty: boolean;
Determines if the rectangle is empty (of zero size)
TAffineBox = object
Object representing an affine box, defined by three corner points (top-left, top-tight, bottom-left)
function GetAsPolygon: ArrayOfTPointF;
Retrieves the affine box as an array of points (polygon representation)
function GetBottomRight: TPointF;
Gets the bottom-right corner of the affine box
function GetCenter: TPointF;
Calculates the center point of the affine box
function GetHeight: single;
Calculates the height of the affine box
function GetIsEmpty: boolean;
Determines if the affine box is empty (one of the point being empty, not just of zero size)
function GetRectBounds: TRect;
Gets the bounding rectangle of the affine box as TRect
function GetRectBoundsF: TRectF;
Gets the bounding rectangle of the affine box as TRectF
function GetSurface: single;
Calculates the surface area of the affine box
function GetWidth: single;
Calculates the width of the affine box
TopLeft,
Top-left corner of the affine box
TopRight,
Top-right corner of the affine box
BottomLeft: TPointF;
Bottom-left corner of the affine box
class function EmptyBox: TAffineBox; static;
Creates an empty affine box
class function AffineBox(ATopLeft, ATopRight, ABottomLeft: TPointF): TAffineBox; overload; static;
Creates an affine box defined by three corner points
class function AffineBox(ARectF: TRectF): TAffineBox; overload; static;
Creates an affine box from a TRectF structure
procedure Offset(AOfsX, AOfsY: single); overload;
Offsets the affine box by specified X and Y amounts
procedure Offset(AOfs: TPointF); overload;
Offsets the affine box by a specified point
procedure Inflate(AHoriz, AVert: single);
Inflates the affine box along its axes by specified horizontal and vertical amounts
function Contains(APoint: TPointF): boolean;
Checks if a point is contained within the affine box
property RectBounds: TRect read GetRectBounds;
Bounding rectangle as TRect
property RectBoundsF: TRectF read GetRectBoundsF;
Bounding rectangle as TRectF
property BottomRight: TPointF read GetBottomRight;
Bottom-right corner of the affine box
property IsEmpty: boolean read GetIsEmpty;
Check if the affine box is empty (containing empty points, not just of zero size)
property AsPolygon: ArrayOfTPointF read GetAsPolygon;
Affine box as an array of points (polygon)
property Width: single read GetWidth;
Width of the affine box along its axes
property Height: single read GetHeight;
Height of the affine box along its axes
property Surface: single read GetSurface;
Surface area of the affine box
property Center: TPointF read GetCenter;
Center point of the affine box
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

Paths

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 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)
ssEasyBezier);
The curve is rounded using Bezier curves when the angle is less than or equal to 45°
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
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; overload;
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; overload;
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 IsClockwise(const pts: array of TPointF): boolean;
Checks if the points follow a clockwise curve
function IsMostlyClockwise(const pts: array of TPointF): boolean;
Checks if the curve is clockwise on the whole but accepting some counter-clockwise points
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
TBGRAPathDrawProc = procedure(const APoints: array of TPointF; AClosed: boolean; AData: Pointer) of object;
Callback function when rendering a stroke
TBGRAPathFillProc = procedure(const APoints: array of TPointF; AData: pointer) of object;
Callback function when filling a shape
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(constref pt: TPointF);
Moves to a location, disconnected from previous points
procedure lineTo(constref 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(constref cp,pt: TPointF);
Adds a quadratic Bézier curve from the current point
procedure bezierCurveTo(constref cp1,cp2,pt: TPointF);
Adds a cubic Bézier curve from the current point
procedure arc(constref 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; overload;
Returns the content of the path as an array of points
function getPoints(AMatrix: TAffineMatrix): ArrayOfTPointF; overload;
Returns the content of the path as an array of points with the transformation specified by AMatrix
procedure stroke(ADrawProc: TBGRAPathDrawProc; AData: pointer); overload;
Calls a given draw procedure for each sub path with computed coordinates for rendering
procedure stroke(ADrawProc: TBGRAPathDrawProc; const AMatrix: TAffineMatrix; AData: pointer); overload;
Calls a given draw procedure for each sub path with computed coordinates using given AMatrix transformation
procedure fill(AFillProc: TBGRAPathFillProc; AData: pointer); overload;
Calls a given fill procedure for each sub path with computed coordinates for rendering
procedure fill(AFillProc: TBGRAPathFillProc; const AMatrix: TAffineMatrix; AData: pointer); overload;
Calls a given fill procedure for each sub path with computed coordinates using given AMatrix transformation
function getCursor: TBGRACustomPathCursor;
Returns a cursor to go through the path. The cursor must be freed by calling Free.
TBGRACustomPath = class(IBGRAPath)
Generic class representing a path, providing methods for creation, exploration and rendering
constructor Create; virtual; abstract;
Constructor to create a custom path. Must be overridden in subclasses
procedure beginPath; virtual; abstract;
Begins a new path
procedure closePath; virtual; abstract;
Closes the current path
procedure moveTo(constref pt: TPointF); virtual; abstract;
Moves the current point to a specified location, starting a new sub-path
procedure lineTo(constref pt: TPointF); virtual; abstract;
Adds a line from the current point to a specified point
procedure polylineTo(const pts: array of TPointF); virtual; abstract;
Adds a series of lines to the path based on an array of points
procedure quadraticCurveTo(constref cp, pt: TPointF); virtual; abstract;
Adds a quadratic Bézier curve to the path
procedure bezierCurveTo(constref cp1, cp2, pt: TPointF); virtual; abstract;
Adds a cubic Bézier curve to the path
procedure arc(constref arcDef: TArcDef); virtual; abstract;
Adds an arc to the path based on an arc definition
procedure openedSpline(const pts: array of TPointF; style: TSplineStyle); virtual; abstract;
Adds an open spline to the path based on a series of points and a spline style
procedure closedSpline(const pts: array of TPointF; style: TSplineStyle); virtual; abstract;
Adds a closed spline to the path based on a series of points and a spline style
procedure copyTo(dest: IBGRAPath); virtual; abstract;
Copies the path to another path object
function getPoints: ArrayOfTPointF; overload; virtual; abstract;
Retrieves the points of the path
function getPoints(AMatrix: TAffineMatrix): ArrayOfTPointF; overload; virtual; abstract;
Retrieves the points of the path, transformed by a specified matrix
procedure stroke(ADrawProc: TBGRAPathDrawProc; AData: pointer); overload; virtual; abstract;
Strokes the path with a specified drawing procedure
procedure stroke(ADrawProc: TBGRAPathDrawProc; const AMatrix: TAffineMatrix; AData: pointer); overload; virtual; abstract;
Strokes the path with a specified drawing procedure and transformation matrix
procedure fill(AFillProc: TBGRAPathFillProc; AData: pointer); overload; virtual; abstract;
Fills the path with a specified filling procedure
procedure fill(AFillProc: TBGRAPathFillProc; const AMatrix: TAffineMatrix; AData: pointer); overload; virtual; abstract;
Fills the path with a specified filling procedure and transformation matrix
function getLength: single; virtual; abstract;
Retrieves the length of the path
function getCursor: TBGRACustomPathCursor; virtual; abstract;
Retrieves a cursor for navigating the path
TBGRAPathAny = class of TBGRACustomPath;
Type for specifying any derived class of TBGRACustomPath
TBGRACustomPathCursor = class
Class that contains a cursor to browse an existing path
function GetArcPos: single; virtual; abstract;
Retrieves the current position from the start
function GetCurrentCoord: TPointF; virtual; abstract;
Returns the current coordinate in the path
function GetCurrentTangent: TPointF; virtual; abstract;
Returns the tangent vector to the current position
function GetLoopClosedShapes: boolean; virtual; abstract;
Retrieves if the cursor loops when there is a closed shape
function GetLoopPath: boolean; virtual; abstract;
Retrieves if the cursor loops at the end of the whole path
function GetPathLength: single; virtual; abstract;
Retreive the full arc length of the path
function GetBounds: TRectF; virtual; abstract;
Compute the bounds of the path
function GetStartCoordinate: TPointF; virtual; abstract;
Starting coordinate of the path
procedure SetArcPos(AValue: single); virtual; abstract;
Sets the current position from the start
procedure SetLoopClosedShapes(AValue: boolean); virtual; abstract;
Sets if the cursor loops when there is a closed shape
procedure SetLoopPath(AValue: boolean); virtual; abstract;
Sets if the cursor loops at the end of the whole 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 GetCurrentCoord;
Returns the current coordinate in the path
property CurrentTangent: TPointF read GetCurrentTangent;
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 GetArcPos write SetArcPos;
Current position in the path, as a distance along the arc from the starting point of the path
property PathLength: single read GetPathLength;
Full arc length of the path
property StartCoordinate: TPointF read GetStartCoordinate;
Starting coordinate of the path
property LoopClosedShapes: boolean read GetLoopClosedShapes write SetLoopClosedShapes;
Specifies if the cursor loops when there is a closed shape
property LoopPath: boolean read GetLoopPath write SetLoopPath;
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
BGRAPathFactory: TBGRAPathAny;
Factory provided to create a TBGRAPath object

Polygon filling

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
interX: single;
Horizontal position of the intersection
winding: integer;
Winding count
numSegment: integer;
Number identifying the current segment where the intersection was found
procedure SetValues(AInterX: Single; AWinding, ANumSegment: integer);
Sets the position and other information about the intersection
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
function GetSliceIndex: integer; virtual; abstract;
Returns the index of the current slice (horizontal stripe)

Arrows

TBGRAArrowStyle = (
Enumerates different styles of arrows that can be used in graphic rendering. Each style represents a unique visual appearance for arrowheads or tails
asNone,
No arrow style. This option indicates that no arrowhead or tail is to be rendered
asNormal,
A normal arrow style, representing a standard arrowhead with an angle
asCut,
A cut arrow style, where the edge of the arrow are cut instead of using the pen end cap
asTriangle,
A triangle arrow style, forming a simple triangular arrowhead
asHollowTriangle,
A hollow triangle arrow style, similar to asTriangle but with an unfilled center
asFlipped,
A flipped arrow style, where the arrowhead points in the opposite direction to the normal style
asFlippedCut,
A flipped cut arrow style, combining the aspects of asFlipped and asCut
asTail,
A small tail, typically used to depict the starting point of an arrow
asTailRepeat);
A tail repeat arrow style, depicting a series of repeated patterns typically used for the starting point of an arrow
TBGRACustomArrow = class
Generic class configuring and rendering an arrow
function GetEndOffsetX: single; virtual; abstract;
Retrieves the X-offset for the end of the arrow
function GetEndRepeatCount: integer; virtual; abstract;
Retrieves the repeat count for the end symbol
function GetEndSizeFactor: TPointF; virtual; abstract;
Retrieves the size factor for the end of the arrow
function GetIsEndDefined: boolean; virtual; abstract;
Determines if the end of the arrow is defined
function GetIsStartDefined: boolean; virtual; abstract;
Determines if the start of the arrow is defined
function GetStartOffsetX: single; virtual; abstract;
Retrieves the X-offset for the start of the arrow
function GetStartRepeatCount: integer; virtual; abstract;
Retrieves the repeat count for the start symbol
function GetStartSizeFactor: TPointF; virtual; abstract;
Retrieves the size factor for the start of the arrow
procedure SetEndOffsetX(AValue: single); virtual; abstract;
Sets the X-offset for the end of the arrow
procedure SetEndRepeatCount(AValue: integer); virtual; abstract;
Sets the repeat count for the end symbol
procedure SetEndSizeFactor(AValue: TPointF); virtual; abstract;
Sets the size factor for the end of the arrow
procedure SetStartOffsetX(AValue: single); virtual; abstract;
Sets the X-offset for the start of the arrow
procedure SetStartRepeatCount(AValue: integer); virtual; abstract;
Sets the repeat count for the start symbol
procedure SetStartSizeFactor(AValue: TPointF); virtual; abstract;
Sets the size factor for the start of the arrow
function GetLineCap: TPenEndCap; virtual; abstract;
Retrieves the line cap style for the classic arrow
procedure SetLineCap(AValue: TPenEndCap); virtual; abstract;
Sets the line cap style for the classic arrow
function ComputeStartAt(const APosition, ADirection: TPointF; const AWidth, ACurrentPos: single): ArrayOfTPointF; virtual; abstract;
Computes the start of the arrow at a given position and direction
function ComputeEndAt(const APosition, ADirection: TPointF; const AWidth, ACurrentPos: single): ArrayOfTPointF; virtual; abstract;
Computes the end of the arrow at a given position and direction
procedure StartAsNone; virtual; abstract;
Sets the start of the arrow to no style
procedure StartAsClassic(AFlipped: boolean = false; ACut: boolean = false; ARelativePenWidth: single = 1); virtual; abstract;
Sets the start of the arrow to a classic style
procedure StartAsTriangle(ABackOffset: single = 0; ARounded: boolean = false; AHollow: boolean = false; AHollowPenWidth: single = 0.5); virtual; abstract;
Sets the start of the arrow to a triangle style
procedure StartAsTail; virtual; abstract;
Sets the start of the arrow to a tail style
procedure EndAsNone; virtual; abstract;
Sets the end of the arrow to no style
procedure EndAsClassic(AFlipped: boolean = false; ACut: boolean = false; ARelativePenWidth: single = 1); virtual; abstract;
Sets the end of the arrow to a classic style
procedure EndAsTriangle(ABackOffset: single = 0; ARounded: boolean = false; AHollow: boolean = false; AHollowPenWidth: single = 0.5); virtual; abstract;
Sets the end of the arrow to a triangle style
procedure EndAsTail; virtual; abstract;
Sets the end of the arrow to a tail style
property IsStartDefined: boolean read GetIsStartDefined;
Check if the start of the arrow is defined
property IsEndDefined: boolean read GetIsEndDefined;
Check if the end of the arrow is defined
property StartOffsetX: single read GetStartOffsetX write SetStartOffsetX;
X-offset for the start of the arrow
property EndOffsetX: single read GetEndOffsetX write SetEndOffsetX;
X-offset for the end of the arrow
property LineCap: TPenEndCap read GetLineCap write SetLineCap;
Line cap style
property StartSize: TPointF read GetStartSizeFactor write SetStartSizeFactor;
Size factor for the start of the arrow
property EndSize: TPointF read GetEndSizeFactor write SetEndSizeFactor;
Size factor for the end of the arrow
property StartRepeatCount: integer read GetStartRepeatCount write SetStartRepeatCount;
Repeat count for the start symbol
property EndRepeatCount: integer read GetEndRepeatCount write SetEndRepeatCount;
Repeat count for the end symbol
TBGRACustomPenStroker = class
Generic class representing a pen stroker, used for drawing and styling lines with various attributes
function GetArrow: TBGRACustomArrow; virtual; abstract;
Retrieves the arrow style used at both ends of strokes
function GetArrowOwned: boolean; virtual; abstract;
Determines if the arrow is owned (managed) by the pen stroker
function GetCustomPenStyle: TBGRAPenStyle; virtual; abstract;
Gets the custom pen style
function GetJoinStyle: TPenJoinStyle; virtual; abstract;
Retrieves the style of line joins (e.g., bevel, miter)
function GetLineCap: TPenEndCap; virtual; abstract;
Retrieves the line cap style (e.g., butt, round)
function GetMiterLimit: single; virtual; abstract;
Gets the miter limit for line joins
function GetPenStyle: TPenStyle; virtual; abstract;
Retrieves the standard pen style
function GetStrokeMatrix: TAffineMatrix; virtual; abstract;
Gets the stroke transformation matrix (applied only to stroke and not to path points)
procedure SetArrow(AValue: TBGRACustomArrow); virtual; abstract;
Sets the arrow style used at both ends of strokes
procedure SetArrowOwned(AValue: boolean); virtual; abstract;
Sets whether the arrow is owned by the pen stroker
procedure SetCustomPenStyle(AValue: TBGRAPenStyle); virtual; abstract;
Sets the custom pen style
procedure SetJoinStyle(AValue: TPenJoinStyle); virtual; abstract;
Sets the style of line joins
procedure SetLineCap(AValue: TPenEndCap); virtual; abstract;
Sets the line cap style
procedure SetMiterLimit(AValue: single); virtual; abstract;
Sets the miter limit for line joins
procedure SetPenStyle(AValue: TPenStyle); virtual; abstract;
Sets the standard pen style
procedure SetStrokeMatrix(const AValue: TAffineMatrix); virtual; abstract;
Sets the stroke transformation matrix (applied only to stroke and not to path points)
function ComputePolyline(const APoints: array of TPointF; AWidth: single; AClosedCap: boolean = true): ArrayOfTPointF; overload; virtual; abstract;
Computes a polyline with the given points and width, optionally closing the cap
function ComputePolyline(const APoints: array of TPointF; AWidth: single; APenColor: TBGRAPixel; AClosedCap: boolean = true): ArrayOfTPointF; overload; virtual; abstract;
Computes a polyline with the given points, width, and pen color, optionally closing the cap
function ComputePolylineAutoCycle(const APoints: array of TPointF; AWidth: single): ArrayOfTPointF; virtual; abstract;
Computes a polyline with automatic cycling of points and given width
function ComputePolygon(const APoints: array of TPointF; AWidth: single): ArrayOfTPointF; virtual; abstract;
Computes a polygon with the given points and width
property Style: TPenStyle read GetPenStyle write SetPenStyle;
Standard pen style
property CustomPenStyle: TBGRAPenStyle read GetCustomPenStyle write SetCustomPenStyle;
Custom pen style (with given dash and gap lengths)
property Arrow: TBGRACustomArrow read GetArrow write SetArrow;
Arrow style at both ends of strokes
property ArrowOwned: boolean read GetArrowOwned write SetArrowOwned;
Is the arrow is owned by the pen stroker
property StrokeMatrix: TAffineMatrix read GetStrokeMatrix write SetStrokeMatrix;
Stroke transformation matrix (applied only to stroke and not to path points)
property LineCap: TPenEndCap read GetLineCap write SetLineCap;
Line cap style
property JoinStyle: TPenJoinStyle read GetJoinStyle write SetJoinStyle;
Join style of lines
property MiterLimit: single read GetMiterLimit write SetMiterLimit;
Miter limit for line joins

Gradients

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
gtAngular);
The color changes according to the angle relative to a given center
const 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
TBGRAGradientGetColorAtFunc = function(position: integer): TBGRAPixel of object;
Function type to get the the color at a given integer position
TBGRAGradientGetColorAtFloatFunc = function(position: single): TBGRAPixel of object;
Function type to get the the color at a given single-precision floating type position
TBGRAGradientGetExpandedColorAtFunc = function(position: integer): TExpandedPixel of object;
Function type to get the the expanded color at a given integer position
TBGRAGradientGetExpandedColorAtFloatFunc = function(position: single): TExpandedPixel of object;
Function type to get the the expanded color at a given single-precision floating type position
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 GetExpandedColorAt(position: integer): TExpandedPixel; virtual;
Returns the expanded 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 GetExpandedColorAtF(position: single): TExpandedPixel; virtual;
Returns the expanded 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
function GetAverageExpandedColor: TExpandedPixel; virtual;
Returns the average expanded color of the gradient
function GetMonochrome: boolean; virtual; abstract;
Returns whether the gradient has only one color
property Monochrome: boolean read GetMonochrome;
If the gradient contains only one color and thus is not really a gradient

Bézier curves

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 in general.
function SimpleComputePoints(AAcceptedDeviation: single = 0.1; AIncludeFirstPoint: boolean = true): ArrayOfTPointF;
Compute the points using the simple approach of computing for each time value
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
procedure CopyToPath(ADest: IBGRAPath);
Copy the curve to the given path
function GetBounds: TRectF;
Computes the rectangular bounds
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
function SimpleComputePoints(AAcceptedDeviation: single = 0.1; AIncludeFirstPoint: boolean = true): ArrayOfTPointF;
Compute the points using the simple approach of computing for each time value
function ComputeExtremumPositionOutsideSegment: single;
Computes the position where the curve has its extremum
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
procedure CopyToPath(ADest: IBGRAPath);
Copy the curve to the given path
function GetBounds: TRectF;
Computes the rectangular bounds
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
ArrayOfSingle = array of single;
Array of single-precision floating point values
TRationalQuadraticBezierCurve = object
Quasi-standard rational quadratic Bezier curve, defined by three points and a number:
  • p1: starting point
  • c: control point
  • p2: ending point
  • weight: weight for the control point

The curve is defined with the function (t in [0; 1]):

  • f: t → ((1-t)2 * p1 + 2 * t * (1-t) * weight * c + t2*p2) / (1-t)2 + 2 * t * (1-t) * weight + t2)

The curve is an arc of:

  • ellipse when weight in ]-1; 1[
  • parabola when weight = 1 (classical quadratic Bezier curve)
  • hyperbola when weight > 1

A negative weight give the complementary curve for its positive counterpart. So when weight ≤ -1 the curve is discontinuous:

  • infinite branches of parabola when weight = -1
  • infinite branches of hyperbola and symetric hyperbola when weight < -1

To transform a rational quadratic Bezier curve with an affin transformation, you only have to transform the three points and leave the weight as it is.

p1, c, p2 : TPointF;
Starting, control and ending points
weight : single;
Weight of control point
function GetIsInfinite: boolean;
Checks whether the curve is infinitely long
function InternalComputePoints(AInfiniteBounds: TRectF; AAcceptedDeviation: single = 0.1; AIncludeFirstPoint: boolean = true): ArrayOfTPointF;
Compute points in the general case
function GetBoundingPositions(AIncludeFirstAndLast: boolean; ASorted: boolean): ArrayOfSingle;
Computes the points relevant to compute bounds
function ComputePointAt(t: single): TPointF;
Compute a point at the specified time
function ComputeLength(AAcceptedDeviation: single = 0.1): single;
Compute the length
function ToPoints(AAcceptedDeviation: single = 0.1; AIncludeFirstPoint: boolean = true): ArrayOfTPointF; overload;
Computes the points of the curve
function ToPoints(AInfiniteBounds: TRectF; AAcceptedDeviation: single = 0.1; AIncludeFirstPoint: boolean = true): ArrayOfTPointF; overload;
Computes the points of the curve by providing where the infinite curve can stop
function GetBounds: TRectF;
Compute the rectangular bounds
procedure Split(out ALeft, ARight: TRationalQuadraticBezierCurve);
Split into two curves
property IsInfinite: boolean read GetIsInfinite;
Is the curve infinitely long
function BezierCurve(origin, control, destination: TPointF; Aweight:single) : TRationalQuadraticBezierCurve; overload;
Creates a rational Bézier curve
TEasyBezierCurveMode = (
Enumerates modes for handling curves in a Bezier curve sequence
cmAuto,
Automatically determines whether to curve or form an angle based on the points' positions
cmCurve,
Forces a curve at the point
cmAngle
Forces an angle at the point, meaning the point is reached and forms an angle instead of a curve
TEasyBezierPointTransformFunc = function(APoint: PPointF; AData: Pointer): TPointF of object;
Function type for transforming Bezier curve points
TEasyBezierCurve = object
Object representing an easy-to-use Bezier curve, with configurable curve modes and transformation functions
function GetCurveMode(AIndex: integer): TEasyBezierCurveMode;
Retrieves the curve mode for a specified point index
function GetCurveStartPoint: TPointF;
Gets the starting point of the curve
function GetPoint(AIndex: integer): TPointF;
Retrieves the point at a specified index
function GetPointCount: integer;
Gets the total number of points in the curve
procedure SetClosed(AValue: boolean);
Sets whether the curve is closed
procedure SetCurveMode(AIndex: integer; AValue: TEasyBezierCurveMode);
Sets the curve mode for a specified point index
procedure SetMinimumDotProduct(AValue: single);
Sets the minimum dot product to form a curve instead of an angle
procedure SetPoint(AIndex: integer; AValue: TPointF);
Sets the point at a specified index
FCurves: array of record
Computed Bézier control points
FInvalidated: boolean;
Whether the curve need to be recomputed
FPoints: array of record
Definition of the curve by the user
FMinimumDotProduct: single;
Minimum dot product to form a curve instead of an angle
FClosed: boolean;
Is the curve is closed
function MaybeCurve(start1, end1, start2, end2: integer): boolean;
Checks whether two vectors have the minimum dot product to suggest a curve. start1 and end1 are the indices for the first vector. start2 and end2 for the second vector.
procedure ComputeQuadraticCurves;
Computes the control points for the classical quadratic curve
function PointTransformNone(APoint: PPointF; AData: Pointer): TPointF;
Fonction to apply no transformation
function PointTransformOffset(APoint: PPointF; AData: Pointer): TPointF;
Fonction to apply an offset
procedure Init;
Initializes the Bezier curve object
procedure Clear;
Clears all points and resets the curve
procedure SetPoints(APoints: array of TPointF; ACurveMode: TEasyBezierCurveMode); overload;
Sets the points and curve mode for the entire curve
procedure SetPoints(APoints: array of TPointF; ACurveMode: array of TEasyBezierCurveMode); overload;
Sets the points and individual curve modes for each point
procedure SetPoints(APoints: array of TPointF; ACurveMode: TEasyBezierCurveMode; AStart, ACount: integer); overload;
Sets a subset of points and a single curve mode for these points
procedure SetPoints(APoints: array of TPointF; ACurveMode: array of TEasyBezierCurveMode; AStart, ACount: integer); overload;
Sets a subset of points and individual curve modes for each of these points
procedure CopyToPath(ADest: IBGRAPath); overload;
Copies the Bezier curve to a path object
procedure CopyToPath(ADest: IBGRAPath; AOffset: TPointF; AReverse: boolean = false); overload;
Copies the Bezier curve to a path object with an offset and optional reversal
procedure CopyToPath(ADest: IBGRAPath; ATransformFunc: TEasyBezierPointTransformFunc; ATransformData: Pointer; AReverse: boolean = false); overload;
Copies the Bezier curve to a path object with a custom transformation
property Point[AIndex: integer]: TPointF read GetPoint write SetPoint;
Coordinates of the points
property CurveMode[AIndex: integer]: TEasyBezierCurveMode read GetCurveMode write SetCurveMode;
Mode to use for each point
property PointCount: integer read GetPointCount;
Number of points
property MinimumDotProduct: single read FMinimumDotProduct write SetMinimumDotProduct;
Minimum dot product to form a curve rather than an angle when using cmAuto mode
property Closed: boolean read FClosed write SetClosed;
Gets or sets whether to close the curve
property CurveStartPoint: TPointF read GetCurveStartPoint;
Coordinates of the starting point
function ToPoints: ArrayOfTPointF;
Converts the Bezier curve into an array of points
function ComputeLength: single;
Computes the total length of the Bezier curve
const EasyBezierDefaultMinimumDotProduct = 0.707;
Minimum dot product, corresponding to approximately 45 degrees, to form a curve instead of an angle
function EasyBezierCurve(APoints: array of TPointF; AClosed: boolean; ACurveMode: TEasyBezierCurveMode;
Create a TEasyBezierCurve object with only one curve mode
function EasyBezierCurve(APoints: array of TPointF; AClosed: boolean; ACurveMode: array of TEasyBezierCurveMode;
Create a TEasyBezierCurve object with a curve mode for each point
function EasyBezierCurve(APoints: array of TPointF; AStart, ACount: integer; AClosed: boolean; ACurveMode: TEasyBezierCurveMode;
Create a TEasyBezierCurve object with a subsection of the array of points, with only one curve mode
function EasyBezierCurve(APoints: array of TPointF; AStart, ACount: integer; AClosed: boolean; ACurveMode: array of TEasyBezierCurveMode;
Create a TEasyBezierCurve object with a subsection of the array of points, with a curve mode for each point