Draw2dTest: Commander.CommandProc ~ {
viewer: ViewerClasses.Viewer ← ViewerOps.CreateViewer[
flavor: $Lines,
paint: FALSE,
info: [
name: "Draw2d Tests",
openHeight: 330,
scrollable: FALSE,
column: left,
iconic: TRUE]
];
ViewerOps.OpenIcon[viewer];
};
Paint: ViewerClasses.PaintProc ~ {
p, q: ARRAY [0..100) OF Imager.VEC;
ImagerTestLine:
PROC ~ {
FOR i: NAT IN [0..100) DO Imager.MaskVector[context, p[i], [150.0, 145.0]]; ENDLOOP;
};
Draw2dTestLine:
PROC ~ {
FOR i: NAT IN [0..100) DO Draw2d.Line[context, q[i], [450.0, 145.0]]; ENDLOOP;
};
ImagerTestCircle: PROC ~ {
ImagerCircle: PROC [context: Imager.Context, vec: Imager.VEC, radius: REAL] ~ {
t: Imager.Trajectory ← ImagerPath.MoveTo[[vec.x+radius, vec.y]];
t ← ImagerPath.ArcTo[t, [vec.x, vec.y+radius], [vec.x-radius, vec.y]];
t ← ImagerPath.ArcTo[t, [vec.x, vec.y-radius], [vec.x+radius, vec.y]];
Imager.MaskStrokeTrajectory[context, t, TRUE];
};
FOR radius: REAL ← 122.0, radius-5.0 WHILE radius > 1.0 DO
ImagerCircle[context, [150.0, 445.0], radius];
ENDLOOP;
};
Draw2dTestCircle: PROC ~ {
FOR radius: REAL ← 122.0, radius-5.0 WHILE radius > 1.0 DO
Draw2d.Circle[context, [450.0, 445.0], radius];
ENDLOOP;
};
Time:
PROC [proc:
PROC, name: Rope.
ROPE, label: Imager.
VEC]
RETURNS [
REAL] ~ {
time: REAL ← BasicTime.PulsesToSeconds[BasicTime.GetClockPulses[]];
proc[];
time ← BasicTime.PulsesToSeconds[BasicTime.GetClockPulses[]]-time;
Draw2d.Label[context, label, IO.PutFR[Rope.Concat[name, ": %6.4f seconds"], IO.real[time]]];
RETURN[time];
};
FOR i:
NAT
IN[0..100)
DO
t: REAL ← REAL[i]*2.0*3.1415926535/100.0;
p[i] ← [150.0+120.0*RealFns.Cos[t], 135.0+120.0*RealFns.Sin[t]];
q[i] ← [p[i].x+300.0, p[i].y];
ENDLOOP;
Draw2d.Label[context, [200, 295],
IO.PutFR["Line/MaskVector Factor: %6.4f",
IO.real[
Time[ImagerTestLine, "Imager.MaskVector", [65, 270]]/
Time[Draw2dTestLine, "Draw2d.Line", [345, 270]]]]];
Draw2d.Label[context, [200, 595], IO.PutFR["Circle/MaskTrajectory Factor: %6.4f", IO.real[
Time[ImagerTestCircle, "Imager.Trajectory", [65, 580]]/
Time[Draw2dTestCircle, "Draw2d.Circle", [345, 580]]]]];
};
ViewerOps.RegisterViewerClass[$Lines,
NEW[ViewerClasses.ViewerClassRec ← [paint: Paint]]];
Commander.Register["Draw2dTest", Draw2dTest, "\nTest Draw2d.Line and Draw2d.Circle."];