aggpas: Use sincos() rather than separate sin() and cos(). Issue #40474.

This commit is contained in:
wp_xyz 2023-08-30 23:53:18 +02:00
parent 7d4a36a290
commit 3b062e3689
15 changed files with 162 additions and 99 deletions

View File

@ -1,27 +1,32 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="7"/>
<Version Value="12"/>
<General>
<Flags>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InIDEConfig"/>
<MainUnit Value="0"/>
<TargetFileExt Value=""/>
<Title Value="PangoFontsDemo1"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T &apos;Lazarus Run Output&apos; -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default">
<local>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T &apos;Lazarus Run Output&apos; -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</Mode0>
</Modes>
</RunParams>
<RequiredPackages Count="2">
<Item1>
@ -36,23 +41,27 @@
<Unit0>
<Filename Value="PangoFontsDemo1.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="PangoFontsDemo1"/>
</Unit0>
<Unit1>
<Filename Value="unit3.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit3"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="8"/>
<Version Value="11"/>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)/"/>
<LCLWidgetType Value="gtk2"/>
<IncludeFiles Value="$(ProjOutDir)"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
<UseAnsiStrings Value="False"/>
</SyntaxOptions>
</Parsing>
<Linking>
<Options>
<Win32>
@ -61,7 +70,9 @@
</Options>
</Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
<ConfigFile>
<WriteConfigFilePath Value="$(ProjOutDir)/fpclaz.cfg"/>
</ConfigFile>
</Other>
</CompilerOptions>
</CONFIG>

View File

@ -1,10 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<Version Value="12"/>
<General>
<Flags>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InIDEConfig"/>
<MainUnit Value="0"/>
<UseXPManifest Value="True"/>
</General>
<BuildModes Count="1">
@ -15,15 +17,19 @@
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T &apos;Lazarus Run Output&apos; -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default">
<local>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T &apos;Lazarus Run Output&apos; -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</Mode0>
</Modes>
</RunParams>
<RequiredPackages Count="2">
<Item1>
@ -43,6 +49,7 @@
<Filename Value="unit1.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
</Unit1>
@ -60,6 +67,11 @@
</Win32>
</Options>
</Linking>
<Other>
<ConfigFile>
<WriteConfigFilePath Value="$(ProjOutDir)/fpclaz.cfg"/>
</ConfigFile>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">

View File

@ -1,27 +1,32 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="8"/>
<Version Value="12"/>
<General>
<Flags>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InIDEConfig"/>
<MainUnit Value="0"/>
<TargetFileExt Value=""/>
<Title Value="AggPasInLCLDemo2"/>
</General>
<VersionInfo>
<StringTable Comments="" CompanyName="" FileDescription="" FileVersion="0.0.0.0" InternalName="" LegalCopyright="" LegalTrademarks="" OriginalFilename="" ProductName="" ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T &apos;Lazarus Run Output&apos; -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default">
<local>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T &apos;Lazarus Run Output&apos; -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</Mode0>
</Modes>
</RunParams>
<RequiredPackages Count="2">
<Item1>
@ -36,21 +41,21 @@
<Unit0>
<Filename Value="AggPasInLCLDemo2.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="AggPasInLCLDemo2"/>
</Unit0>
<Unit1>
<Filename Value="unit2.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit2"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="9"/>
<Version Value="11"/>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)/"/>
<IncludeFiles Value="$(ProjOutDir)"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
@ -65,7 +70,9 @@
</Options>
</Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
<ConfigFile>
<WriteConfigFilePath Value="$(ProjOutDir)/fpclaz.cfg"/>
</ConfigFile>
</Other>
</CompilerOptions>
</CONFIG>

View File

@ -4,8 +4,8 @@ object Form1: TForm1
Top = 287
Width = 415
Caption = 'Form1'
LCLVersion = '3.99.0.0'
OnCreate = FormCreate
OnDestroy = FormDestroy
OnPaint = FormPaint
LCLVersion = '0.9.29'
end

View File

@ -34,10 +34,10 @@ uses LazFileUtils;
procedure TForm1.FormCreate(Sender: TObject);
var
HasFont: Boolean;
FontFilename: String;
FontFilename: String = '';
s: String;
TxtW: integer;
TxtH: integer;
TxtW: integer = 0;
TxtH: integer = 0;
TxtX: Integer;
TxtY: Integer;
begin

View File

@ -2391,6 +2391,7 @@ end;
procedure TAgg2D.Star(cx ,cy ,r1 ,r2 ,startAngle : double; numRays : integer );
var
da ,a ,x ,y : double;
sina, cosa: Double;
i : int;
@ -2404,8 +2405,9 @@ begin
while i < numRays do
begin
x:=Cos(a ) * r2 + cx;
y:=Sin(a ) * r2 + cy;
sincos(a, sina, cosa);
x:=cosa * r2 + cx;
y:=sina * r2 + cy;
if i <> 0 then
m_path.line_to(x ,y )
@ -2413,8 +2415,9 @@ begin
m_path.move_to(x ,y );
a:=a + da;
sincos(a, sina, cosa);
m_path.line_to(Cos(a ) * r1 + cx ,Sin(a ) * r1 + cy );
m_path.line_to(cosa * r1 + cx, sina * r1 + cy );
a:=a + da;

View File

@ -2010,7 +2010,7 @@ end;
procedure Agg2D.star(cx ,cy ,r1 ,r2 ,startAngle : double; numRays : int );
var
da ,a ,x ,y : double;
cosa, sina: Double;
i : int;
begin
@ -2022,9 +2022,10 @@ begin
i:=0;
while i < numRays do
begin
x:=Cos(a ) * r2 + cx;
y:=Sin(a ) * r2 + cy;
begin
sincos(a, sina, cosa);
x:=cosa * r2 + cx;
y:=sina * r2 + cy;
if i <> 0 then
m_path.line_to(x ,y )
@ -2032,8 +2033,8 @@ begin
m_path.move_to(x ,y );
a:=a + da;
m_path.line_to(Cos(a ) * r1 + cx ,Sin(a ) * r1 + cy );
sincos(a, sina, cosa);
m_path.line_to(cosa * r1 + cx, sina * r1 + cy );
a:=a + da;

View File

@ -156,6 +156,7 @@ end;
function arc.vertex;
var
pf : unsigned;
sinangle, cosangle: Double;
begin
if is_stop(m_path_cmd ) then
@ -164,8 +165,9 @@ begin
else
if (m_angle < m_end - m_da / 4 ) <> m_ccw then
begin
x^:=m_x + Cos(m_end ) * m_rx;
y^:=m_y + Sin(m_end ) * m_ry;
sincos(m_end, sinangle, cosangle);
x^:=m_x + cosangle * m_rx;
y^:=m_y + sinangle * m_ry;
m_path_cmd:=path_cmd_stop;
@ -174,8 +176,9 @@ begin
end
else
begin
x^:=m_x + Cos(m_angle ) * m_rx;
y^:=m_y + Sin(m_angle ) * m_ry;
sincos(m_angle, sinangle, cosangle);
x^:=m_x + cosangle * m_rx;
y^:=m_y + sinangle * m_ry;
m_angle:=m_angle + m_da;

View File

@ -113,8 +113,7 @@ var
px ,py : array[0..3 ] of double;
begin
x0:=Cos(sweep_angle / 2.0 );
y0:=Sin(sweep_angle / 2.0 );
sincos(sweep_angle / 2.0, y0, x0);
tx:=(1.0 - x0 ) * 4.0 / 3.0;
ty:=y0 - tx * x0 / y0;
@ -127,8 +126,7 @@ begin
px[3 ]:=x0;
py[3 ]:=y0;
sn:=Sin(start_angle + sweep_angle / 2.0 );
cs:=Cos(start_angle + sweep_angle / 2.0 );
sincos(start_angle + sweep_angle / 2.0, sn, cs);
for i:=0 to 3 do
begin
@ -166,6 +164,7 @@ var
total_sweep ,
local_sweep ,
prev_sweep : double;
sinangle, cosangle: double;
done : boolean;
@ -187,10 +186,12 @@ begin
m_cmd:=path_cmd_line_to;
m_vertices[0 ]:=x + rx * Cos(start_angle );
m_vertices[1 ]:=y + ry * Sin(start_angle );
m_vertices[2 ]:=x + rx * Cos(start_angle + sweep_angle );
m_vertices[3 ]:=y + ry * Sin(start_angle + sweep_angle );
sincos(start_angle, sinangle, cosangle);
m_vertices[0 ]:=x + rx * cosangle;
m_vertices[1 ]:=y + ry * sinangle;
sincos(start_angle + sweep_angle, sinangle, cosangle);
m_vertices[2 ]:=x + rx * cosangle;
m_vertices[3 ]:=y + ry * sinangle;
exit;
@ -358,8 +359,7 @@ begin
dy2:=(y0 - y2 ) / 2.0;
// Convert angle from degrees to radians
cos_a:=Cos(angle );
sin_a:=Sin(angle );
sincos(angle, sin_a, cos_a);
// Calculate (x1, y1)
x1:= cos_a * dx2 + sin_a * dy2;

View File

@ -150,6 +150,7 @@ end;
function ellipse.vertex;
var
angle : double;
sinangle, cosangle: double;
begin
if m_step = m_num then
@ -175,8 +176,9 @@ begin
if m_cw then
angle:=2.0 * pi - angle;
x^:=m_x + Cos(angle ) * m_rx;
y^:=m_y + Sin(angle ) * m_ry;
sincos(angle, sinangle, cosangle);
x^:=m_x + cosangle * m_rx;
y^:=m_y + sinangle * m_ry;
inc(m_step );

View File

@ -1962,6 +1962,7 @@ procedure TAggFPCanvas.AggStar(const cx, cy, r1, r2, startAngle: double;
numRays: integer);
var
da, a, x, y: double;
sina, cosa: Double;
i : int;
begin
Path.m_path.remove_all;
@ -1972,8 +1973,9 @@ begin
i:=0;
while i < numRays do begin
x:=Cos(a) * r2 + cx;
y:=Sin(a) * r2 + cy;
sincos(a, sina, cosa);
x:=cosa * r2 + cx;
y:=sina * r2 + cy;
if i <> 0 then
Path.m_path.line_to(x ,y)
@ -1981,8 +1983,8 @@ begin
Path.m_path.move_to(x ,y);
a:=a + da;
Path.m_path.line_to(Cos(a ) * r1 + cx ,Sin(a ) * r1 + cy);
sincos(a, sina, cosa);
Path.m_path.line_to(cosa * r1 + cx, sina * r1 + cy);
a:=a + da;

View File

@ -15,7 +15,7 @@ uses
{$IFDEF LCLGtk2}
pango, LCLType, Gtk2Proc, Gtk2Def, gtk2,
{$ENDIF}
agg_arc, GraphMath, agg_fpimage, agg_basics;
agg_arc, Math, GraphMath, agg_fpimage, agg_basics;
type
@ -503,7 +503,7 @@ procedure TAggLCLCanvas.RadialPie(x1, y1, x2, y2, StartAngle16Deg,
}
var
cx, cy, rx, ry: double;
a, da, startangle, endangle: Double;
a, da, startangle, endangle, sina, cosa: Double;
begin
if Angle16DegLength=0 then exit;
Path.m_path.remove_all;
@ -523,10 +523,12 @@ begin
Path.m_path.move_to(cx,cy);
a:=startangle;
while a<endangle do begin
Path.m_path.line_to(cx+rx*cos(a),cy+ry*sin(a));
sincos(a, sina, cosa);
Path.m_path.line_to(cx+rx*cosa,cy+ry*sina);
a:=a+da;
end;
Path.m_path.line_to(cx+rx*cos(endangle),cy+ry*sin(endangle));
sincos(endangle, sina, cosa);
Path.m_path.line_to(cx+rx*cosa,cy+ry*sina);
AggClosePolygon;
AggDrawPath(AGG_FillAndStroke);
@ -542,7 +544,7 @@ procedure TAggLCLCanvas.Pie(EllipseX1, EllipseY1, EllipseX2, EllipseY2, StartX,
var
cx, cy, rx, ry: double;
StartAngle16deg, AngleLength16deg: extended;
a, da, startangle, endangle: Double;
a, da, startangle, endangle, sina, cosa: Double;
begin
Coords2Angles(EllipseX1, EllipseY1, EllipseX2-EllipseX1, EllipseY2-EllipseY1,
StartX, StartY, EndX, EndY,
@ -566,10 +568,12 @@ begin
Path.m_path.move_to(cx,cy);
a:=startangle;
while a<endangle do begin
Path.m_path.line_to(cx+rx*cos(a),cy+ry*sin(a));
sincos(a, sina, cosa);
Path.m_path.line_to(cx+rx*cosa,cy+ry*sina);
a:=a+da;
end;
Path.m_path.line_to(cx+rx*cos(endangle),cy+ry*sin(endangle));
sincos(endangle, sina, cosa);
Path.m_path.line_to(cx+rx*cosa,cy+ry*sina);
AggClosePolygon;
AggDrawPath(AGG_FillAndStroke);
@ -695,11 +699,12 @@ var
procedure AddArc(cx, cy, startangle, endangle: double);
var
a: Double;
a, sina, cosa: Double;
begin
a:=startangle;
while a<endangle do begin
Path.m_path.line_to(cx+rx*cos(a),cy+ry*sin(a));
sincos(a, sina, cosa);
Path.m_path.line_to(cx+rx*cosa,cy+ry*sina);
a:=a+da;
end;
end;

View File

@ -306,6 +306,7 @@ procedure math_stroke.calc_cap(
len : double );
var
dx1 ,dy1 ,dx2 ,dy2 ,da ,a1 : double;
sina1, cosa1: Double;
i ,n : int;
@ -349,10 +350,11 @@ begin
while i < n do
begin
sincos(a1, sina1, cosa1);
add_vertex(
vc ,
v0.x + Cos(a1 ) * m_width ,
v0.y + Sin(a1 ) * m_width );
v0.x + cosa1 * m_width ,
v0.y + sina1 * m_width );
a1:=a1 + da;
@ -369,10 +371,11 @@ begin
while i < n do
begin
sincos(a1, sina1, cosa1);
add_vertex(
vc ,
v0.x + Cos(a1 ) * m_width ,
v0.y + Sin(a1 ) * m_width );
v0.x + cosa1 * m_width ,
v0.y + sina1 * m_width );
a1:=a1 - da;
@ -551,6 +554,7 @@ procedure math_stroke.calc_arc(
x ,y ,dx1 ,dy1 ,dx2 ,dy2 : double );
var
a1 ,a2 ,da : double;
sina1, cosa1: double;
i ,n : int;
@ -574,7 +578,8 @@ begin
while i < n do
begin
add_vertex(vc ,x + Cos(a1 ) * m_width ,y + Sin(a1 ) * m_width );
sincos(a1, sina1, cosa1);
add_vertex(vc ,x + cosa1 * m_width, y + sina1 * m_width );
a1:=a1 + da;
@ -741,6 +746,7 @@ var
pt : point_type;
a1 ,a2 ,da : double;
sina1, cosa1: double;
ccw : boolean;
@ -784,8 +790,9 @@ begin
while a1 < a2 do
begin
pt.x:=x + Cos(a1 ) * width;
pt.y:=y + Sin(a1 ) * width;
sincos(a1, sina1, cosa1);
pt.x:=x + cosa1 * width;
pt.y:=y + sina1 * width;
out_vertices.add(@pt );
@ -804,8 +811,9 @@ begin
while a1 > a2 do
begin
pt.x:=x + Cos(a1 ) * width;
pt.y:=y + Sin(a1 ) * width;
sincos(a1, sina1, cosa1);
pt.x:=x + cosa1 * width;
pt.y:=y + sina1 * width;
out_vertices.add(@pt );
@ -950,6 +958,7 @@ var
dx2 ,dy2 ,
a1 ,a2 ,da : double;
sina1, cosa1: double;
begin
out_vertices.remove_all;
@ -1002,8 +1011,9 @@ begin
while a1 < a2 do
begin
pt.x:=v0.x + Cos(a1 ) * width;
pt.y:=v0.y + Sin(a1 ) * width;
sincos(a1, sina1, cosa1);
pt.x:=v0.x + cosa1 * width;
pt.y:=v0.y + sina1 * width;
out_vertices.add(@pt );

View File

@ -560,6 +560,7 @@ end;
procedure gradient_radial_focus.update_values;
var
dist ,r ,a : double;
sina, cosa: Double;
begin
// For use in the quadratic equation
@ -577,9 +578,10 @@ begin
// clamp focus to radius
// x = r cos theta, y = r sin theta
a:=ArcTan2(m_focus_y ,m_focus_x );
sincos(a, sina, cosa);
m_focus_x:=trunc(r * Cos(a ) );
m_focus_y:=trunc(r * Sin(a ) );
m_focus_x:=trunc(r * cosa);
m_focus_y:=trunc(r * sina);
end;

View File

@ -768,8 +768,7 @@ var
ca ,sa ,t0 ,t2 ,t4 : double;
begin
ca:=Cos(a);
sa:=Sin(a);
sincos(a, sa, ca);
t0:=m0 * ca - m1 * sa;
t2:=m2 * ca - m3 * sa;
t4:=m4 * ca - m5 * sa;
@ -815,8 +814,11 @@ end;
{ CONSTRUCT }
constructor trans_affine_rotation.Construct;
var
sina, cosa: Double;
begin
inherited Construct(Cos(a ) ,Sin(a ) ,-Sin(a ) ,Cos(a ) ,0 ,0 );
sincos(a, sina, cosa);
inherited Construct(cosa, sina, -sina, cosa ,0 ,0 );
end;
@ -893,8 +895,11 @@ end;
{ CONSTRUCT }
constructor trans_affine_reflection.Construct(a : double );
var
sina, cosa: Double;
begin
inherited Construct(Cos(a ) ,Sin(a ) );
sincos(a, sina, cosa);
inherited Construct(cosa, sina);
end;