关于逻辑判断

//====================================获取延长类型==================================== 
    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。有时候做很多判断,其实没有必要,只要列出事实就可以了。让程序自己去判断,岂不省了很多功夫吗。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值