MickD 发表于 2009-12-22 08:23:41

三角形中的点

static void ArxPntInTri_getit(void)
{
    ads_point ads_testpnt;
    AcGePoint3d a,b,c,p;
   
    if(acedGetPoint(NULL,_T("\nPick Point to test: "),ads_testpnt) != RTNORM)
    {
      PRNTERR
      return;
    }
    p = asPnt3d(ads_testpnt);
    AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
    AcDbBlockTableRecordPointer pBlockTableRecord(pDb->currentSpaceId(),kForRead);
    TRYRETVOID (pBlockTableRecord.openStatus());
    AcDbBlockTableRecordIterator* pIter;
    TRYRETVOID (pBlockTableRecord->newIterator( pIter ))
   
    for (pIter->start();!pIter->done();pIter->step())
    {
      AcDbObjectId entId;
      TRYMSG(pIter->getEntityId(entId));
      AcDbEntityPointer pEnt(entId,AcDb::kForRead);
      AcDbFace* pFace = AcDbFace::cast(pEnt);
      if(pFace)
      {
      TRYMSG(pFace->getVertexAt(0,a));
      TRYMSG(pFace->getVertexAt(1,b));
      TRYMSG(pFace->getVertexAt(2,c));
      if(isInTriangle(AcGePoint2d(a.x,a.y),AcGePoint2d(b.x,b.y),
                        AcGePoint2d(c.x,c.y),AcGePoint2d(p.x,p.y)))
      {
          TRYMSG(pFace->upgradeOpen());
          TRYMSG(pFace->setColorIndex(1));
      }
      }
    }
    delete pIter;
}
//http://www.blackpawn.com/texts/pointinpoly/default.html
static bool isInTriangle(const AcGePoint2d &a,
                                 const AcGePoint2d &b,
                                 const AcGePoint2d &c,
                                 const AcGePoint2d &p)
{
    AcGeVector2d v0 = c-a;
    AcGeVector2d v1 = b-a;
    AcGeVector2d v2 = p-a;
    doubledot00 = v0.dotProduct(v0);
    doubledot01 = v0.dotProduct(v1);
    doubledot02 = v0.dotProduct(v2);
    doubledot11 = v1.dotProduct(v1);
    doubledot12 = v1.dotProduct(v2);
    double invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
    doubleu = (dot11 * dot02 - dot01 * dot12) * invDenom;
    doublev = (dot00 * dot12 - dot01 * dot02) * invDenom;
    return (u > 0) && (v > 0) && (u + v “带有源代码的汇编”,您可以查看生成的代码。代码
中的一个小t周在构建时会做什么非常有趣。
struct EsChecker
{
    static Acad::ErrorStatus op(Acad::ErrorStatus es)
    {
      if(es != Acad::eOk) {
            EsPrint(es);
      }
      return es;
    }
    __declspec(noinline) static void EsPrint(Acad::ErrorStatus es)
    {
      acutPrintf(_T("\nError: Line %ld [%s]\nIn function %s"),
            __LINE__, acadErrorStatusText(es), _T(__FUNCTION__));
    }
};

用法:
EsChecker::op(pDb->getFilename(pcszFilename));

Kerry 发表于 2009-12-22 15:31:06

但是,如果我想返回上的函数,我需要再次测试错误状态eOk对吗?

MickD 发表于 2009-12-22 18:02:27

我想在es!=eOk
在本例中,宏从函数中返回并打印错误消息。当它们嵌套时,它执行一种堆栈跟踪
我没有尝试过,但在其他地方扩展__FUNCTION__可能无法提供正确的信息。

frtfff 发表于 2009-12-22 18:31:43

我想我可以开始使用异常来展开堆栈。我只是跟随ARX风格和宏节省打字..
你对例外有什么看法?我了解到编译器拒绝展开try catch中的循环
页: [1]
查看完整版本: 三角形中的点