陷阱!关于AcDbPolyline的getPointAt

今天接到一个文件,图形检测出现了无法判断的错误。看了一下图形,有点特别,使用pe指令显示该对象与UCS不平行,使用li指令显示:

LWPOLYLINE  图层: 功能分区
                            空间: 模型空间
                            句柄 = 23C1F3
                            闭合
                            固定宽度         0
相对于 UCS 的拉伸方向:
                   X=        0  Y=        0  Z=       -1
        面积   109295267
        周长   42293
        。。。。。。

跟踪代码后发现,在调用getPointAt获取顶点坐标时,返回的结果非常奇怪,仔细检查后,发现我在一些地方调用getPointAt这个方法时,传入了一个AcGePoint2d的变量用于获取坐标,问题正是出在这个AcGePoint2d上。查了一下帮助:

Acad::ErrorStatus getPointAt(unsigned int unnamed,AcGePoint3d& pt) const;

unnamedInput the index (0 based) of the vertex
ptOutput copy of point data at vertex index

This function sets pt to the 3D location of the vertex index in World Coordinates.

Returns Acad::eOk if successful, or Acad::eInvalidIndex if index is not valid for the polyline.


Acad::ErrorStatus getPointAt(unsigned int index,AcGePoint2d& pt) const;

indexInput the index (0 based) of the vertex
ptOutput copy of point data at vertex index

This function sets pt to the 2D location of the vertex index in the polyline's own ojbect coordinate system (OCS).

Returns Acad::eOk if successful, or Acad::eInvalidIndex if index is not valid for the polyline.

终于找到问题所在了。

写代码的时候图方便(因为有些地方使用了不少类似AcGeLineSeg2d一类的对象),因此在使用变量时使用了AcGePoint2d,而不是AcGePoint3d,在尝试编译发现通过后就没有再管了。在多数情况下,传入AcGePoint2d也没问题,但在一些特殊情况下,问题就出现了。把相关的地方都改过来,问题解决了。

嗯,看来以后还是要更小心一些。自己以后设计函数重载的时候,也要尽量避免此类问题。这个陷阱确实不容易发现。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值