Difference between revisions of "BGRABitmap Geometry types"

From Lazarus wiki
Jump to navigationJump to search
(update)
(update TBGRACustomPathCursor)
Line 283: Line 283:
 
<tr><td width="10%"></td><td colspan="2" style="background: #f0f0ff;">'''function''' getCursor: TBGRACustomPathCursor;</td></tr>
 
<tr><td width="10%"></td><td colspan="2" style="background: #f0f0ff;">'''function''' getCursor: TBGRACustomPathCursor;</td></tr>
 
<tr><td width="10%"></td><td width="10%" style="background: #f0f0ff;"></td><td style="border: 1px solid #e0e0a0; background: #ffffe4;">Returns a cursor to go through the path. The cursor must be freed by calling ''Free''.</td></tr>
 
<tr><td width="10%"></td><td width="10%" style="background: #f0f0ff;"></td><td style="border: 1px solid #e0e0a0; background: #ffffe4;">Returns a cursor to go through the path. The cursor must be freed by calling ''Free''.</td></tr>
 +
<tr style="height: 8px;"><td colspan="3"></td></tr>
 +
<tr style="background: white;"><td colspan="3">''TBGRACustomPathCursor'' = '''class'''</td></tr>
 +
<tr style="background: white;"><td width="10%"></td><td style="border: 1px solid #e0e0a0; background: #ffffe4;" colspan="2">Class that contains a cursor to browse an existing path</td></tr>
 +
<tr style="height: 8px;"><td colspan="3"></td></tr>
 +
<tr><td width="10%"></td><td colspan="2" style="background: #f0f0ff;">'''function''' MoveForward(ADistance: single; ACanJump: boolean = true): single; virtual; abstract;</td></tr>
 +
<tr><td width="10%"></td><td width="10%" style="background: #f0f0ff;"></td><td style="border: 1px solid #e0e0a0; background: #ffffe4;">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''</td></tr>
 +
<tr style="height: 8px;"><td colspan="3"></td></tr>
 +
<tr><td width="10%"></td><td colspan="2" style="background: white;">'''function''' MoveBackward(ADistance: single; ACanJump: boolean = true): single; virtual; abstract;</td></tr>
 +
<tr><td width="10%"></td><td width="10%" style="background: white;"></td><td style="border: 1px solid #e0e0a0; background: #ffffe4;">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''</td></tr>
 +
<tr style="height: 8px;"><td colspan="3"></td></tr>
 +
<tr><td width="10%"></td><td colspan="2" style="background: #f0f0ff;">'''property''' CurrentCoordinate: TPointF '''read''' GetCurrentCoord;</td></tr>
 +
<tr><td width="10%"></td><td width="10%" style="background: #f0f0ff;"></td><td style="border: 1px solid #e0e0a0; background: #ffffe4;">Returns the current coordinate in the path</td></tr>
 +
<tr style="height: 8px;"><td colspan="3"></td></tr>
 +
<tr><td width="10%"></td><td colspan="2" style="background: white;">'''property''' CurrentTangent: TPointF '''read''' GetCurrentTangent;</td></tr>
 +
<tr><td width="10%"></td><td width="10%" style="background: white;"></td><td style="border: 1px solid #e0e0a0; background: #ffffe4;">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)</td></tr>
 +
<tr style="height: 8px;"><td colspan="3"></td></tr>
 +
<tr><td width="10%"></td><td colspan="2" style="background: #f0f0ff;">'''property''' Position: single '''read''' GetArcPos '''write''' SetArcPos;</td></tr>
 +
<tr><td width="10%"></td><td width="10%" style="background: #f0f0ff;"></td><td style="border: 1px solid #e0e0a0; background: #ffffe4;">Current position in the path, as a distance along the arc from the starting point of the path</td></tr>
 +
<tr style="height: 8px;"><td colspan="3"></td></tr>
 +
<tr><td width="10%"></td><td colspan="2" style="background: white;">'''property''' PathLength: single '''read''' GetPathLength;</td></tr>
 +
<tr><td width="10%"></td><td width="10%" style="background: white;"></td><td style="border: 1px solid #e0e0a0; background: #ffffe4;">Full arc length of the path</td></tr>
 +
<tr style="height: 8px;"><td colspan="3"></td></tr>
 +
<tr><td width="10%"></td><td colspan="2" style="background: #f0f0ff;">'''property''' StartCoordinate: TPointF '''read''' GetStartCoordinate;</td></tr>
 +
<tr><td width="10%"></td><td width="10%" style="background: #f0f0ff;"></td><td style="border: 1px solid #e0e0a0; background: #ffffe4;">Starting coordinate of the path</td></tr>
 +
<tr style="height: 8px;"><td colspan="3"></td></tr>
 +
<tr><td width="10%"></td><td colspan="2" style="background: white;">'''property''' LoopClosedShapes: boolean '''read''' GetLoopClosedShapes '''write''' SetLoopClosedShapes;</td></tr>
 +
<tr><td width="10%"></td><td width="10%" style="background: white;"></td><td style="border: 1px solid #e0e0a0; background: #ffffe4;">Specifies if the cursor loops when there is a closed shape</td></tr>
 +
<tr style="height: 8px;"><td colspan="3"></td></tr>
 +
<tr><td width="10%"></td><td colspan="2" style="background: #f0f0ff;">'''property''' LoopPath: boolean '''read''' GetLoopPath '''write''' SetLoopPath;</td></tr>
 +
<tr><td width="10%"></td><td width="10%" style="background: #f0f0ff;"></td><td style="border: 1px solid #e0e0a0; background: #ffffe4;">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</td></tr>
 
<tr style="height: 8px;"><td colspan="3"></td></tr>
 
<tr style="height: 8px;"><td colspan="3"></td></tr>
 
<tr style="background: white;"><td colspan="3">''EmptyRect'' : TRect = (left:0; top:0; right:0; bottom: 0);</td></tr>
 
<tr style="background: white;"><td colspan="3">''EmptyRect'' : TRect = (left:0; top:0; right:0; bottom: 0);</td></tr>

Revision as of 20:37, 29 April 2015

Here are all the basic geometry types used in BGRABitmap library.

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