Тесты на extensions и Deconstruct
This commit is contained in:
parent
b3d5ec894f
commit
d5e2e6004f
17
TestSuite/Deconstructs1.pas
Normal file
17
TestSuite/Deconstructs1.pas
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
type
|
||||||
|
A = class
|
||||||
|
procedure Deconstruct(var i: integer; var j: integer);
|
||||||
|
begin
|
||||||
|
i := 1;
|
||||||
|
j := 1;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
var a1 := new A;
|
||||||
|
var a2: A;
|
||||||
|
a1.Deconstruct(a2);
|
||||||
|
var i,j: integer;
|
||||||
|
a1.Deconstruct(i,j);
|
||||||
|
Assert((i,j)=(1,1));
|
||||||
|
end.
|
||||||
33
TestSuite/extensionmethods31.pas
Normal file
33
TestSuite/extensionmethods31.pas
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
var a,b,c,d: integer;
|
||||||
|
|
||||||
|
type
|
||||||
|
AA = class
|
||||||
|
procedure p(i: integer);
|
||||||
|
begin
|
||||||
|
a := 1;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure p(Self: AA; i,j: integer); extensionmethod;
|
||||||
|
begin
|
||||||
|
b := 2;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure p<T>(self: T; i,j,k: integer); extensionmethod;
|
||||||
|
begin
|
||||||
|
c := 3;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure p<T>(self: T; i: T); extensionmethod;
|
||||||
|
begin
|
||||||
|
d := 4;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
var a1 := new AA;
|
||||||
|
a1.p(1);
|
||||||
|
a1.p(1,2);
|
||||||
|
a1.p(1,2,3);
|
||||||
|
a1.p(a1);
|
||||||
|
Assert((a,b,c,d)=(1,2,3,4));
|
||||||
|
end.
|
||||||
|
|
@ -341,36 +341,31 @@ type
|
||||||
|
|
||||||
RegularPolygonWPF = class(BoundedObjectWPF)
|
RegularPolygonWPF = class(BoundedObjectWPF)
|
||||||
private
|
private
|
||||||
{x,y,}r: real;
|
|
||||||
n: integer;
|
n: integer;
|
||||||
function Element: Polygon := ob as Polygon;
|
function Element: Polygon := ob as Polygon;
|
||||||
procedure InitOb2(x,y,r: real; n: integer; c: GColor);
|
procedure InitOb2(x,y,r: real; n: integer; c: GColor);
|
||||||
begin
|
begin
|
||||||
InitOb1(x-r,y-r,2*r,2*r,c,CreateRegularPolygon(x,y,r,n),false);
|
InitOb1(x-r,y-r,2*r,2*r,c,CreatePolygon(r,n),false);
|
||||||
(Self.x,Self.y,Self.r,Self.n) := (x-r,y-r,r,n);
|
(Self.x,Self.y,Self.n) := (x-r,y-r,n);
|
||||||
end;
|
end;
|
||||||
function ChangePointCollection(r: real; n: integer): PointCollection;
|
function ChangePointCollection(r: real; n: integer): PointCollection;
|
||||||
begin
|
begin
|
||||||
var pp := Partition(0,2*Pi,n).Select(phi->Pnt(r+r*cos(phi-Pi/2),r+r*sin(phi-Pi/2))).ToArray;
|
var pp := Partition(0,2*Pi,n).Select(phi->Pnt(r+r*cos(phi-Pi/2),r+r*sin(phi-Pi/2))).ToArray;
|
||||||
Result := new PointCollection(pp);
|
Result := new PointCollection(pp);
|
||||||
end;
|
end;
|
||||||
function CreateRegularPolygon(x,y,r: real; n: integer): Polygon;
|
function CreatePolygon(r: real; n: integer): Polygon;
|
||||||
begin
|
begin
|
||||||
var pp := Partition(0,2*Pi,n).Select(phi->Pnt(r+r*cos(phi-Pi/2),r+r*sin(phi-Pi/2))).ToArray;
|
|
||||||
var p := new Polygon();
|
var p := new Polygon();
|
||||||
p.Points := new PointCollection(pp);
|
p.Points := ChangePointCollection(r,n);
|
||||||
Result := p;
|
Result := p;
|
||||||
end;
|
end;
|
||||||
procedure Rad(value: real);
|
procedure Rad(value: real);
|
||||||
begin
|
begin
|
||||||
var delta := value - gr.Width/2;
|
var delta := value - gr.Width/2;
|
||||||
//Println('in',x,y);
|
|
||||||
//Println(delta);
|
|
||||||
X -= delta;
|
X -= delta;
|
||||||
Y -= delta;
|
Y -= delta;
|
||||||
(gr.Width,gr.Height) := (value*2,value*2);
|
(gr.Width,gr.Height) := (value*2,value*2);
|
||||||
Element.Points := ChangePointCollection(value,n);
|
Element.Points := ChangePointCollection(value,n);
|
||||||
//Println('in',Self.x,Self.y);
|
|
||||||
end;
|
end;
|
||||||
procedure Cnt(value: integer);
|
procedure Cnt(value: integer);
|
||||||
begin
|
begin
|
||||||
|
|
@ -388,13 +383,68 @@ type
|
||||||
write begin end; override;
|
write begin end; override;
|
||||||
property Radius: real
|
property Radius: real
|
||||||
read InvokeReal(()->gr.Height/2)
|
read InvokeReal(()->gr.Height/2)
|
||||||
write Invoke(Rad,Value);
|
write Invoke(Rad,Value); virtual;
|
||||||
property Count: integer
|
property Count: integer
|
||||||
read InvokeInteger(()->n)
|
read InvokeInteger(()->n)
|
||||||
write Invoke(Cnt,Value);
|
write Invoke(Cnt,Value);
|
||||||
function GetInternalGeometry: Geometry; override := new EllipseGeometry(Center,Width/2,Height/2);
|
function GetInternalGeometry: Geometry; override := new EllipseGeometry(Center,Width/2,Height/2);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
StarWPF = class(RegularPolygonWPF)
|
||||||
|
private
|
||||||
|
rint: real;
|
||||||
|
procedure InitOb2(x,y,r,rint: real; n: integer; c: GColor);
|
||||||
|
begin
|
||||||
|
InitOb1(x-r,y-r,2*r,2*r,c,CreatePolygon(r,rint,n),false);
|
||||||
|
(Self.x,Self.y,Self.rint,Self.n) := (x-r,y-r,rint,n);
|
||||||
|
end;
|
||||||
|
function ChangePointCollection(r,rint: real; n: integer): PointCollection;
|
||||||
|
begin
|
||||||
|
var pp1 := Partition(0,2*Pi,n).Select(phi->Pnt(r+r*cos(phi-Pi/2),r+r*sin(phi-Pi/2)));
|
||||||
|
var pp2 := Partition(0+Pi/n,2*Pi+Pi/n,n).Select(phi->Pnt(r+rint*cos(phi-Pi/2),r+rint*sin(phi-Pi/2)));
|
||||||
|
Result := new PointCollection(pp1.Interleave(pp2).ToArray);
|
||||||
|
end;
|
||||||
|
function CreatePolygon(r,rint: real; n: integer): Polygon;
|
||||||
|
begin
|
||||||
|
var p := new Polygon();
|
||||||
|
p.Points := ChangePointCollection(r,rint,n);
|
||||||
|
Result := p;
|
||||||
|
end;
|
||||||
|
procedure Rad(value: real);
|
||||||
|
begin
|
||||||
|
var delta := value - gr.Width/2;
|
||||||
|
X -= delta;
|
||||||
|
Y -= delta;
|
||||||
|
(gr.Width,gr.Height) := (value*2,value*2);
|
||||||
|
Element.Points := ChangePointCollection(value,rint,n);
|
||||||
|
end;
|
||||||
|
procedure IntRad(value: real);
|
||||||
|
begin
|
||||||
|
if value>Radius then
|
||||||
|
value := Radius;
|
||||||
|
Element.Points := ChangePointCollection(Radius,value,n);
|
||||||
|
end;
|
||||||
|
procedure Cnt(value: integer);
|
||||||
|
begin
|
||||||
|
n := value;
|
||||||
|
Element.Points := ChangePointCollection(Radius,rint,value);
|
||||||
|
end;
|
||||||
|
public
|
||||||
|
constructor (x,y,r,rinternal: real; n: integer; c: GColor);
|
||||||
|
begin
|
||||||
|
if rinternal<r then
|
||||||
|
Invoke(InitOb2,x,y,r,rinternal,n,c)
|
||||||
|
else Invoke(InitOb2,x,y,rinternal,r,n,c)
|
||||||
|
end;
|
||||||
|
constructor (p: Point; r,rinternal: real; n: integer; c: GColor) := Create(p.X,p.Y,r,rinternal,n,c);
|
||||||
|
property Radius: real
|
||||||
|
read InvokeReal(()->gr.Height/2)
|
||||||
|
write Invoke(Rad,Value); override;
|
||||||
|
property InternalRadius: real
|
||||||
|
read rint
|
||||||
|
write Invoke(IntRad,Value);
|
||||||
|
end;
|
||||||
|
|
||||||
PolygonWPF = class(BoundedObjectWPF)
|
PolygonWPF = class(BoundedObjectWPF)
|
||||||
private
|
private
|
||||||
procedure InitOb2(pp: array of Point; c: GColor);
|
procedure InitOb2(pp: array of Point; c: GColor);
|
||||||
|
|
@ -484,11 +534,6 @@ function Pnt(x,y: real) := new Point(x,y);
|
||||||
function Rect(x,y,w,h: real) := new System.Windows.Rect(x,y,w,h);
|
function Rect(x,y,w,h: real) := new System.Windows.Rect(x,y,w,h);
|
||||||
function ColorBrush(c: Color) := new SolidColorBrush(c);
|
function ColorBrush(c: Color) := new SolidColorBrush(c);
|
||||||
|
|
||||||
procedure InvokeVisual(d: System.Delegate; params args: array of object);
|
|
||||||
begin
|
|
||||||
app.Dispatcher.Invoke(d,DispatcherPriority.Background,args);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function operator implicit(Self: (integer, integer)): Point; extensionmethod := new Point(Self[0], Self[1]);
|
function operator implicit(Self: (integer, integer)): Point; extensionmethod := new Point(Self[0], Self[1]);
|
||||||
function operator implicit(Self: (integer, real)): Point; extensionmethod := new Point(Self[0], Self[1]);
|
function operator implicit(Self: (integer, real)): Point; extensionmethod := new Point(Self[0], Self[1]);
|
||||||
function operator implicit(Self: (real, integer)): Point; extensionmethod := new Point(Self[0], Self[1]);
|
function operator implicit(Self: (real, integer)): Point; extensionmethod := new Point(Self[0], Self[1]);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue