metaobj 点作为对象

metaobj 点作为对象

我首先查看了 metaobj 包,并尝试定义一个三角形(几乎与手册中一样)。所以这是编辑(fpast 请求)代码:

input metaobj;

vardef newTriangle@# text options=
  ExecuteOptions(@#)(options);
  assignObj(@#,"Triangle");
  StandardInterface;
  %%
  forsuffixes $ = suba,subb,subc :
    save $;
    string $;
    $ = newobjstring_;
    ObjPoint $;
    SubObject($,obj($));
  endfor;
  %
  ObjCode StandardEquations,
    "obj(@#subb) - obj(@#suba) = (5cm,0)",
    "obj(@#subc) - obj(@#subb) = (0,3cm)",
    "obj(@#subc)  = (obj(@#suba)+obj(@#subb)+obj(@#subc)) / 3",
    "@#ne = obj(@#subc)";
  StandardTies;
enddef;  

vardef drawTriangle (suffix n) =
  draw obj(n.suba)--obj(n.subb)--obj(n.subc)--cycle;
enddef;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

vardef newTrianglee@# text options =
  ExecuteOptions(@#)(options);
  assignObj(@#,"Trianglee");
  StandardInterface;
  ObjPoint c,sa,sb,sc;
  ObjCode StandardEquations,
    "@#sb - @#sa = (5cm,0)",
    "@#sc - @#sb = (0,3cm)",
    "@#c  = (@#sa+@#sb+@#sc) / 3",
    "@#ne = @#sc";
  StandardTies;
enddef;  

vardef drawTrianglee (suffix s) =
  draw s.sa--s.sb--s.sc--cycle;
enddef;

%%% error ... or not
test = 0;

beginfig(1);
  if test=1 :
    newTriangle.u
  else :
    newTrianglee.u
  fi;
  u.c = origin;
  drawObj(u)
endfig;
end

但编译结果返回:

******* metaobj 0.93 (c) D. Roegel (2006/12/03) *******
)
>> -_______a+_______b
>> (141.73225,0)
! Equation cannot be performed (numeric=pair).
<to be read again> 
                   ;
code_function_->...bb)-obj((SUFFIX2)suba)=(5cm,0);
                                              obj((SUFFIX2)subc)-obj((SU...
<to be read again> 

ETC。

如果我不使用 ObjPoint 作为子对象,代码实际上可以工作,所以我猜这是问题所在。但我不明白为什么?

谢谢您的帮助

编辑我注意到我忘记了StandardEquations命令ObjCode,但事实就在那里......

编辑2编辑代码(fpast 请求):选择test=0使用对象 Trianglee 进行成功编译,并test=1选择失败编译

相关内容