采用ISegment进行点转线(或点转面)时容易出现的错误



           问题描述,有一系列点,想构成面,而面由ring构成,ring由Segment构成,所以先由点构成Segment。由于点变量比较多,不想再定义相同多的 tempLine变量,仅仅是把它清空了又在构成下一个线段时利用,结果出现之前的pSegment变量的值被改变:

            ILine tempLine = new LineClass();

            IPoint p1 = new PointClass();
            IPoint p2 = new PointClass();
            p1.X = 502225.693493928;
            p1.Y = 401985.666916852;
            p2.X = 502185.696188842;
            p2.Y = 401985.202822681;
            tempLine.PutCoords(p1, p2);
            ISegment pSegment1 = tempLine as ISegment;//注意这里
            Console.WriteLine(pSegment1.FromPoint.X+ " "+pSegment1.FromPoint.Y+ " "+ pSegment1.ToPoint.X+" "+ pSegment1.ToPoint.Y);


            //如果用SetEmpty()就会导致pSegment的两端点跟着改变
            tempLine.SetEmpty();
            IPoint pp1 = new PointClass();
            IPoint pp2 = new PointClass();
            pp1.X = 602225.693493928;
            pp1.Y = 701985.666916852;
            pp2.X = 602185.696188842;
            pp2.Y = 701985.202822681;
            tempLine.PutCoords(pp1, pp2);          

           ISegment pSegment2 = tempLine as ISegment;//注意这里


            Console.WriteLine(pSegment.FromPoint.X + " " + pSegment.FromPoint.Y + " " + pSegment.ToPoint.X + " " + pSegment.ToPoint.Y);//与上边打印的结果不一样


解决的办法: 为新的Segment定义新的tempLine变量。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值