//====================================获取延长类型====================================
double[] temp=new double[3];
int upType=1;//判断线还是弧在上,默认是线
double[] maxLP=new double[3];
double[] maxCP=new double[3];
Drawing.Instance.GetLineBoundingBox(_PrcEqpAcadLines[_PrcEqpAcadLines.Length-1],out temp,out maxLP);
if (_PrcEqAcadArcs.Length>0)
{
Drawing.Instance.GetArcBoundingBox(_PrcEqAcadArcs[_PrcEqAcadArcs.Length-1],out temp,out maxCP);
if (maxCP[1]>maxLP[1])
{
upType=2;
}
}
int downType=1;//判断线还是弧在下,默认是线
double[] minLP=new double[3];
double[] minCP=new double[3];
Drawing.Instance.GetLineBoundingBox(_PrcEqpAcadLines[0],out minLP,out temp);
if (_PrcEqAcadArcs.Length>0)
{
Drawing.Instance.GetArcBoundingBox(_PrcEqAcadArcs[0],out minCP,out temp);
if (minCP[1]<minLP[1])
{
downType=2;
}
}
//====================================延长====================================
if(upType==1) //如果上是线
{
_AcadLine=_PrcEqpAcadLines[_PrcEqpAcadLines.Length-1];
p1=_AcadLine.StartPoint as double[];
p2=_AcadLine.EndPoint as double[];
if (p1[1]>p2[1])
{
Drawing.Instance.ExtendLine(_AcadLine,0,-1);
pPrcEqpUpPoint=_AcadLine.StartPoint as double[]; //取延长后上线的最高点
}
else
{
Drawing.Instance.ExtendLine(_AcadLine,1,-1);
pPrcEqpUpPoint=_AcadLine.EndPoint as double[];
}
}
//-------------------------------------------------------------------------------------//
if(upType==2) //如果上是弧
{
_AcadArc=_PrcEqAcadArcs[_PrcEqAcadArcs.Length-1];
p1=_AcadArc.StartPoint as double[];
p2=_AcadArc.EndPoint as double[];
if (p1[1]>p2[1])
{
Drawing.Instance.ExtendArc(_AcadArc,0,-1);
pPrcEqpUpPoint=_AcadArc.StartPoint as double[]; //取延长后上弧的最高点
}
else
{
Drawing.Instance.ExtendArc(_AcadArc,1,-1);
pPrcEqpUpPoint=_AcadArc.EndPoint as double[];
}
}
//-------------------------------------------------------------------------------------//
if(downType==1) //如果下是线
{
_AcadLine=_PrcEqpAcadLines[0];
p1=_AcadLine.StartPoint as double[];
p2=_AcadLine.EndPoint as double[];
if (p1[1]<p2[1])
{
Drawing.Instance.ExtendLine(_AcadLine,0,-1);
pPrcEqpDownPoint=_AcadLine.StartPoint as double[]; //取延长后下线的最低点
}
else
{
Drawing.Instance.ExtendLine(_AcadLine,1,-1);
pPrcEqpDownPoint=_AcadLine.EndPoint as double[];
}
}
//-------------------------------------------------------------------------------------//
if(downType==2) //如果下是弧
{
_AcadArc=_PrcEqAcadArcs[0];
p1=_AcadArc.StartPoint as double[];
p2=_AcadArc.EndPoint as double[];
if (p1[1]<p2[1])
{
Drawing.Instance.ExtendArc(_AcadArc,0,-1);
pPrcEqpDownPoint=_AcadArc.StartPoint as double[]; //取延长后下弧的最低点
}
else
{
Drawing.Instance.ExtendArc(_AcadArc,1,-1);
pPrcEqpDownPoint=_AcadArc.EndPoint as double[];
}
}
通过这段代码你都了解了什么呢?
1.在逻辑不好判断的时候,可以设定一个变量来确定值,根据这个变量进行判断。会很清爽。
而且还可以设定默认值。这样就可以只用if而不用else了。凡是走不到if的值都是默认值。
2。有时候做很多判断,其实没有必要,只要列出事实就可以了。让程序自己去判断,岂不省了很多功夫吗。