TAChart: Add and use TAGeometry.TEllipse instead of BoundingBoxToCenterAndHalfRadius

git-svn-id: trunk@38538 -
This commit is contained in:
ask 2012-09-06 14:54:02 +00:00
parent 80283e5a89
commit b9c2d8fc91
3 changed files with 25 additions and 18 deletions

View File

@ -120,10 +120,10 @@ end;
procedure TFPVectorialDrawer.Ellipse(AX1, AY1, AX2, AY2: Integer);
var
cx, cy, rx, ry: Integer;
e: TEllipse;
begin
BoundingBoxToCenterAndHalfRadius(AX1, AY1, AX2, AY2, cx, cy, rx, ry);
FCanvas.AddEllipse(cx, InvertY(cy), rx, ry, 0.0);
e.InitBoundingBox(AX1, AY1, AX2, AY2);
FCanvas.AddEllipse(e.FC.X, InvertY(Round(e.FC.Y)), e.FR.x, e.FR.Y, 0.0);
end;
procedure TFPVectorialDrawer.FillRect(AX1, AY1, AX2, AY2: Integer);

View File

@ -174,12 +174,12 @@ end;
procedure TSVGDrawer.Ellipse(AX1, AY1, AX2, AY2: Integer);
var
cx, cy, rx, ry: Integer;
e: TEllipse;
begin
BoundingBoxToCenterAndHalfRadius(AX1, AY1, AX2, AY2, cx, cy, rx, ry);
e.InitBoundingBox(AX1, AY1, AX2, AY2);
WriteFmt(
'<ellipse cx="%d" cy="%d" rx="%d" ry="%d" style="%s"/>',
[cx, cy, rx, ry, StyleFill + StyleStroke]);
'<ellipse cx="%g" cy="%g" rx="%g" ry="%g" style="%s"/>',
[e.FC.X, e.FC.Y, e.FR.X, e.FR.Y, StyleFill + StyleStroke]);
end;
procedure TSVGDrawer.FillRect(AX1, AY1, AX2, AY2: Integer);

View File

@ -23,8 +23,14 @@ interface
uses
TAChartUtils, Types;
procedure BoundingBoxToCenterAndHalfRadius(
AX1, AY1, AX2, AY2: Integer; out ACX, ACY, ARX, ARY: Integer);
type
TEllipse = object
public
FC: TDoublePoint;
FR: TDoublePoint;
constructor InitBoundingBox(AX1, AY1, AX2, AY2: Integer);
end;
function CopyPoints(
APoints: array of TPoint; AStartIndex, ANumPts: Integer): TPointArray;
function DoublePoint(AX, AY: Double): TDoublePoint; inline;
@ -85,15 +91,6 @@ uses
function PointLineSide(AP, A1, A2: TPoint): TValueSign; forward;
procedure BoundingBoxToCenterAndHalfRadius(
AX1, AY1, AX2, AY2: Integer; out ACX, ACY, ARX, ARY: Integer);
begin
ACX := (AX1 + AX2) div 2;
ACY := (AY1 + AY2) div 2;
ARX := Abs(AX1 - AX2) div 2;
ARY := Abs(AY1 - AY2) div 2;
end;
function CopyPoints(
APoints: array of TPoint; AStartIndex, ANumPts: Integer): TPointArray;
var
@ -521,5 +518,15 @@ begin
Result.Y := ASize.cy;
end;
{ TEllipse }
constructor TEllipse.InitBoundingBox(AX1, AY1, AX2, AY2: Integer);
begin
FC.X := (AX1 + AX2) / 2;
FC.Y := (AY1 + AY2) / 2;
FR.X := Abs(AX1 - AX2) / 2;
FR.Y := Abs(AY1 - AY2) / 2;
end;
end.