生成した図形のハンドルを返す描画関数です。図形が生成されないときはNilを返します。その判定は、実際に描画して図形の生成を確認するのではなく、エラーになる条件を満たすパラメータのときにNilを返しています。例えば図形の長さ、幅、高さ、円弧角がゼロの図形は生成されないのでNilを返します。

 座標値の型により、関数名の末尾にR、P、Vの文字を付けています。


 まずは指定した位置に図形を生成する関数です。基準点、円、シンボルを指定した位置に生成します。


(* 指定した位置に図形を配置する関数です。 *)


function Locus_R(x, y :real): handle; { 基準点を配置する(real型) }

Begin

Locus(x, y);

Locus_R:= LNewObj;

end;


function Locus_P(pt :point): handle; { 基準点を配置する(point型) }

Begin

Locus(pt.x, pt.y);

Locus_P:= LNewObj;

end;


function Locus_V(pt :vector): handle; { 基準点を配置する(vector型) }

Begin

Locus(pt.x, pt.y);

Locus_V:= LNewObj;

end;



function CircleByCenter_R(x, y, rad :real): handle;

{ 中心と半径を指定して正円を描く(real型) }

var

result :handle;

begin

if rad > 0 then begin

Oval(-rad, rad, rad, -rad);

result:= LNewObj;

hMove(result, x, y);

end

else

result:= Nil;

CircleByCenter_R:= result;

end;


function CircleByCenter_P(cnt :point; rad :real): handle;

{ 中心と半径を指定して正円を描く(point型) }

begin

CircleByCenter_P:= CircleByCenter_R(cnt.x, cnt.y, rad);

end;


function CircleByCenter_V(cnt :vector; rad :real): handle;

{ 中心と半径を指定して正円を描く(vector型) }

begin

CircleByCenter_V:= CircleByCenter_R(cnt.x, cnt.y, rad);

end;



function Symbol_R(nm :string; x, y, rot :real): handle; { シンボルを配置する(real型) }

const

SymbolDef = 16;

var

h, result :handle;

begin

h:= GetObject(nm);

if (h <> Nil) & (GetTypeN(h) = SymbolDef) then begin

Symbol(nm, x, y, rot);

result:= LNewObj;

end

else

result:= Nil;

Symbol_R:= result;

end;


function Symbol_P(nm :string; pt :point; rot :real): handle; { シンボルを配置する(point型) }

Begin

Symbol_P:= Symbol_R(nm, pt.x, pt.y, rot);

end;


function Symbol_V(nm :string; pt :vector; rot :real): handle; { シンボルを配置する(vector型) }

Begin

Symbol_V:= Symbol_R(nm, pt.x, pt.y, rot);

end;




続いては始点と終点を指定して作図する関数です。直線と壁(直線壁)を描きます。


(* 始点と終点を指定して作図する関数です。 *)


function Line_R(x1, y1, x2, y2 :real): handle; { 2点を指定して直線を描く(real型) }

var

result :handle;

begin

if (x1 <> x2) | (y1 <> y2) then begin { 2022/09/22 : & を | に修正 }

MoveTo(x1, y1);

LineTo(x2, y2);

result:= LNewObj;

end

else

result:= Nil;

Line_R:= result;

end;


function Line_P(pt1, pt2: point): handle; { 2点を指定して直線を描く(point型) }

begin

Line_P:= Line_R(pt1.x, pt1.y, pt2.x, pt2.y);

end;


function Line_V(pt1, pt2: vector): handle; { 2点を指定して直線を描く(vector型) }

begin

Line_V:= Line_R(pt1.x, pt1.y, pt2.x, pt2.y);

end;



function Wall_R(x1, y1, x2, y2 :real): handle; { 2点を指定して壁を描く(real型) }

var

result :handle;

begin

if (x1 <> x2) | (y1 <> y2) then begin { 2022/09/22 : & を | に修正 }

MoveTo(x1, y1);

WallTo(x2, y2);

result:= LNewObj;

end

else

result:= Nil;

Wall_R:= result;

end;


function Wall_P(pt1, pt2 :point): handle; { 2点を指定して壁を描く(point型) }

begin

Wall_P:= Wall_R(pt1.x, pt1.y, pt2.x, pt2.y);

end;


function Wall_V(pt1, pt2 :vector): handle; { 2点を指定して壁を描く(vector型) }

begin

Wall_V:= Wall_R(pt1.x, pt1.y, pt2.x, pt2.y);

end;