A Possible bug with Apath.AddArc ....method

Hello
I have spent many many hours to find the problem. I give up!
I believe there is some thing wrong with the method Apath.AddArc of TDgrGraphicsPath class.
I have added an image to illustate my problem....
The problem occures only when the ellipse is not a circle!!
It seems that when trying to draw an arc as a part of an ellipse
the two points that represent the two sides of this arc are located wrongly compared to what an accurate math calulation gives ... I also added the necessary code that prodced the Shape.
Please help!!

Actually we just leverage the AddArc call to the underlying graphic library. Have you tried, for example, to change the graphic lib of the diagram to see if it behaves differently depending on the lib used?

atDiagram1.GraphicLib := dglGdiPlus; // you can also try dglGdi or dglDirect2D

If you have the full sample project reproducing the issue, please send it to us.

You are right!!
When I used atDiagram1.GraphicLib := dglGdiPlus the problem is solved. There is a bug with dglDirect2D.. It is a pity since as I understand dglDirect2D library is the newest one!!
I believe some thing should be corrected inside then following function from Direct2d:

function TD2DGraphicsPath.AddArc(x, y, width, height, startAngle, sweepAngle: number): integer;
var
startRad, sweepRad: number;
sweepDir: D2D1_SWEEP_DIRECTION;
arcSize: D2D1_ARC_SIZE;
dotSize: TDot;
arcRect: TSquare;
begin
if not FFigureOpen then
SinkBeginFigure(Dot(x, y), D2D1_FIGURE_BEGIN_FILLED);

startRad := DegToRad(startAngle);
if (Frac(sweepAngle) = 0) and (Trunc(sweepAngle) mod 360 = 0) then
sweepAngle := sweepAngle - 1e-3;
sweepRad := DegToRad(sweepAngle);

if sweepRad < 0 then
sweepDir := D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE
else
sweepDir := D2D1_SWEEP_DIRECTION_CLOCKWISE;
if Abs(sweepRad) > Pi then
arcSize := D2D1_ARC_SIZE_LARGE
else
arcSize := D2D1_ARC_SIZE_SMALL;

dotSize := Dot(width / 2, height / 2);
arcRect := Square(x + dotSize.x + (Cos(startRad) * dotSize.x), y + dotSize.y + (Sin(startRad) * dotSize.y),
x + dotSize.x + (Cos(startRad + sweepRad) * dotSize.x), y + dotSize.y + (Sin(startRad + sweepRad) * dotSize.y));

if (FPosition.x = -1) and (FPosition.y = -1) then
begin
D2DSink.EndFigure(D2D1_FIGURE_END_OPEN);
D2DSink.BeginFigure(D2D1PointF(arcRect.Left, arcRect.Top), D2D1_FIGURE_BEGIN_FILLED);
FPosition := Dot(arcRect.Left, arcRect.Top);
end
else // set draw position
D2DSink.AddLine(D2D1PointF(arcRect.Left, arcRect.Top));

D2DSink.AddArc(D2D1ArcSegment(D2D1PointF(arcRect.Right, arcRect.Bottom), D2D1SizeF(dotSize.x, dotSize.y), 0,
sweepDir, arcSize));

result := 0;
end;

Can you please send us the project reproducing the issue, so we can investigate better a fix for Direct2D.

yes. I will do that very soon>
Than kyou

Hello
I coudn't send my test.rar file here. so I sent it to you by Email. Hope you will get it
Thank you very much for effort you make for me.

We didn't receive it yet. RAR files are forbidden, please send it in ZIP format.

Hello
My test project is attached as as zip File
Test.zip (5.9 KB)

This link to the whole project in case the above file is not downloaded I
I used TDatabaseBlock from TFlowChartblocks...
Before you lanch the test you should make some changes to the routine GetBlockPath as follownig:

procedure TDatabaseBlock.GetBlockPath(APath: TDgrGraphicsPath; ADrawer: TDgrBlockDrawer);
begin
APath.SetFillMode(TFillMode.fmAlternate);
APath.StartFigure;
// APath.AddArc(0, 0, 100, 20, 180, 360);
// APath.AddArc(0, 0, 100, 20, 180, 180);
// APath.AddArc(0, 80, 100, 20, 0, 180);
// ADrawer.Canvas.Brush.Color:=clgreen;
APath.AddArc(0,0,50,100,-45, 90);
APath.CloseFigure;
end;

you will notice that when switches between 2 libraries the shape is drawn differently
the correct one is which is obtained with dglGdiPlus not with direct2D!!!!
Important to say that the problem occurs only when requiring to draw an arc as a part of an ellipse(not circle)
I am quite sure that some minor modifications inside APath.AddArc from direct2d suffice to solve the problem!!
Thank you very much for the
effort you make for me.
Please inform me when you receive the mail

We have fixed this issue. A patch was sent via private message.

Yes it works now. this correction was vital for the project I am working on.
Soon, hundreds of pupils in my country will begin learning physics thanks to many dynamic shapes built with Diagram Studio. I never could imagine enough the real power of this software.
You assistance is remarkable my friend!!
Thank you very much.

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.