### Author Topic: INSIDEPT - Question  (Read 14551 times)

0 Members and 1 Guest are viewing this topic.

#### Alexander Rivilis

• Bull Frog
• Posts: 212
• Programmer from Kyiv (Ukraine)
##### Re: INSIDEPT - Question
« Reply #15 on: March 18, 2006, 04:16:10 PM »
It is my solution (without selecting entities):
Code: [Select]
`namespace ContourContour {  enum Status {    Inside1         =  1,  // Contour 1 inside contour 2    Inside2         =  2,  // Contour 2 inside contour 1    Equal           =  3,  // Contours are equal    Outside         =  4,  // Outside    Intersect       =  0,  // Intersect    SelfIntersect1  = -1,  // Contour 1 is selfcrossing    SelfIntersect2  = -2,  // Contour 2 is selfcrossing    Error           = -99  // Error  };    inline Status is_curve_in_curve(AcDbCurve *pCurv1, AcDbCurve *pCurv2, double fuzz)  {    Acad::ErrorStatus es;    AcDbPolyline   *pPoly1   = AcDbPolyline::cast(pCurv1);    AcDb2dPolyline *p2Poly1  = AcDb2dPolyline::cast(pCurv1);    AcDbCircle     *pCircle1 = AcDbCircle::cast(pCurv1);    AcDbPolyline   *pPoly2   = AcDbPolyline::cast(pCurv2);    AcDb2dPolyline *p2Poly2  = AcDb2dPolyline::cast(pCurv2);    AcDbCircle     *pCircle2 = AcDbCircle::cast(pCurv2);    AcGePoint2dArray pts;    AcGeDoubleArray  blg;    // For optimizing:    AcDbExtents exts1;  pCurv1->getGeomExtents(exts1);    AcDbExtents exts2;  pCurv2->getGeomExtents(exts2);    const double DD = AcGeContext::gTol.equalPoint();    bool is_outer =       (exts1.minPoint()[X] > exts2.maxPoint()[X]+2*DD) || (exts2.minPoint()[X] > exts1.maxPoint()[X]+2*DD) ||      (exts1.minPoint()[Y] > exts2.maxPoint()[Y]+2*DD) || (exts2.minPoint()[Y] > exts1.maxPoint()[Y]+2*DD);    if (is_outer) return Outside;    // Are valid entities?    if (!pPoly1 && !p2Poly1 && !pCircle1) return Error;    if (!pPoly2 && !p2Poly2 && !pCircle2) return Error;    // Testing contour 1 for selfcrossing    AcDbMPolygon mpol1;    if (pPoly1) {      if ((es=mpol1.appendLoopFromBoundary(pPoly1,true,fuzz))   != Acad::eOk) return SelfIntersect1;    } else if (p2Poly1) {      if ((es=mpol1.appendLoopFromBoundary(p2Poly1,true,fuzz))  != Acad::eOk) return SelfIntersect1;    } else if (pCircle1) {      if ((es=mpol1.appendLoopFromBoundary(pCircle1,true,fuzz)) != Acad::eOk) return SelfIntersect1;    }    mpol1.getMPolygonLoopAt(0,pts,blg);    // Testing contour 2 for selfcrossing    AcDbMPolygon mpol2;    if (pPoly2) {      if ((es=mpol2.appendLoopFromBoundary(pPoly2,true,fuzz))   != Acad::eOk) return SelfIntersect2;      if ((es=mpol1.appendLoopFromBoundary(pPoly2,true,fuzz))   != Acad::eOk) return Intersect;    } else if (p2Poly2) {      if ((es=mpol2.appendLoopFromBoundary(p2Poly2,true,fuzz))  != Acad::eOk) return SelfIntersect2;      if ((es=mpol1.appendLoopFromBoundary(p2Poly2,true,fuzz))  != Acad::eOk) return Intersect;    } else if (pCircle2) {      if ((es=mpol2.appendLoopFromBoundary(pCircle2,true,fuzz)) != Acad::eOk) return SelfIntersect2;      if ((es=mpol1.appendLoopFromBoundary(pCircle2,true,fuzz)) != Acad::eOk) return Intersect;    }    mpol2.appendMPolygonLoop(pts,blg,true,fuzz);    // Testing for equal and insiding    AcGeIntArray aIdx10,aIdx11,aIdx20,aIdx21;    mpol1.getChildLoops(0,aIdx10); mpol1.getChildLoops(1,aIdx11);    mpol2.getChildLoops(0,aIdx20); mpol2.getChildLoops(1,aIdx21);    if (aIdx10.length()>0 && aIdx20.length()>0) return Equal;    if (aIdx10.length()>0) return Inside2;    if (aIdx11.length()>0) return Inside1;    return Outside;  }};////////////////////////////////////////////////////////////////////////////                   (is_curve_in_curve en1 en2 [fuzz])///////////////////////////////////////////////////////////////////////////static int ads_is_curve_in_curve(void){  struct resbuf *pArgs = acedGetArgs () ;  AcDbObjectId objId1,objId2;  double fuzz = AcDbMPolygonCrossingFuzz;  acedRetInt(ContourContour::Error);  if (pArgs && pArgs->restype == RTENAME &&      pArgs->rbnext && pArgs->rbnext->restype == RTENAME)    {      if (acdbGetObjectId(objId1,pArgs->resval.rlname) == Acad::eOk &&          acdbGetObjectId(objId2,pArgs->rbnext->resval.rlname) == Acad::eOk) {          AcDbObjectPointer<AcDbCurve> pCurv1(objId1,AcDb::kForRead);          AcDbObjectPointer<AcDbCurve> pCurv2(objId2,AcDb::kForRead);          if (pCurv1.openStatus() == Acad::eOk && pCurv2.openStatus() == Acad::eOk) {            if (pArgs->rbnext->rbnext && pArgs->rbnext->rbnext->restype == RTREAL) {              fuzz = pArgs->rbnext->rbnext->resval.rreal;            }            ContourContour::Status i =                ContourContour::is_curve_in_curve(pCurv1.object(),pCurv2.object(),fuzz);            acedRetInt(i);          }        }    }    return (RSRSLT) ;  }`

#### LE

• Guest
##### Re: INSIDEPT - Question
« Reply #16 on: March 18, 2006, 04:33:02 PM »
Thank you Alex,

I like the way you write the code... is no way that I can match that  [please wait some few years, and you'll see]....

#### Alexander Rivilis

• Bull Frog
• Posts: 212
• Programmer from Kyiv (Ukraine)
##### Re: INSIDEPT - Question
« Reply #17 on: March 18, 2006, 04:36:37 PM »
Thank you Alex,
I like the way you write the code... is no way that I can match that  [please wait some few years, and you'll see]....
Ok!

#### LE

• Guest
##### Re: INSIDEPT - Question
« Reply #18 on: March 18, 2006, 04:52:18 PM »
Alex;

Did you wrote is_curve_in_curve on the fly? or it was part of your library functions?

Thanks.

#### Alexander Rivilis

• Bull Frog
• Posts: 212
• Programmer from Kyiv (Ukraine)
##### Re: INSIDEPT - Question
« Reply #19 on: March 18, 2006, 05:08:57 PM »
Did you wrote is_curve_in_curve on the fly? or it was part of your library functions?
No I did not write such function on the fly. This function I was writing for Евгений Елпанов and now this function is a part of library. I only translate comment from Russion for you and other forum members. I think this library will be a part of next book of Nikolay Poleshchuk:  http://www.private.peterlink.ru/poleshchuk/cad/eng.html
« Last Edit: March 18, 2006, 05:13:19 PM by Rivilis »

#### LE

• Guest
##### Re: INSIDEPT - Question
« Reply #20 on: March 18, 2006, 05:19:24 PM »
The reason I asked is because you mention "not very difficult"... and once I saw your code, man it does not look easy...

What do you think of the function I did?...

So, Евгений Елпанов does not write in ARX?....

I wonder if that book is going to be available in English... ? [it will be all about ObjectARX no?]

Thanks!

#### ElpanovEvgeniy

• Water Moccasin
• Posts: 1542
• Moscow (Russia)
##### Re: INSIDEPT - Question
« Reply #21 on: March 18, 2006, 05:30:27 PM »
So, Евгений Елпанов does not write in ARX?....
No, I use only Lisp...

#### LE

• Guest
##### Re: INSIDEPT - Question
« Reply #22 on: March 18, 2006, 05:38:54 PM »
No, I use only Lisp...

Thanks, so you work for МАЭСТРО too?

#### ElpanovEvgeniy

• Water Moccasin
• Posts: 1542
• Moscow (Russia)
##### Re: INSIDEPT - Question
« Reply #23 on: March 18, 2006, 05:47:46 PM »
Thanks, so you work for МАЭСТРО too?
Again is no.
I work in firm "Kovcheg-parquet"
http://www.rusparquet.com/

#### Alexander Rivilis

• Bull Frog
• Posts: 212
• Programmer from Kyiv (Ukraine)
##### Re: INSIDEPT - Question
« Reply #24 on: March 19, 2006, 04:39:10 AM »
The reason I asked is because you mention "not very difficult"... and once I saw your code, man it does not look easy...
What do you think of the function I did?...
Yours function is well, but do not reflect some variants (contour's touching, contour 1 inside contour 2, etc.)

I wonder if that book is going to be available in English... ? [it will be all about ObjectARX no?]
This book not only about ObjectARX, and its 200 pages of ObjectARX is for novice (http://www.private.peterlink.ru/poleshchuk/cad/book15-05e.htm), but some of examples on CD is more complicated as far as is_curve_in_curve, dyndraw, etc. Maybe next edition of this book will has more pages about ObjectARX and .NET.

P.S. Евгений Елпанов is my friend from Moscow, and I sometimes make arx for him. Exactly he has brought me on this forum.
« Last Edit: March 19, 2006, 05:03:59 AM by Rivilis »

#### LE

• Guest
##### Re: INSIDEPT - Question
« Reply #25 on: March 19, 2006, 01:24:51 PM »
Thank you Alex;

I am keeping the URL link for future reference.

And welcome again...