ObjectARX, AutoCAD. Среда программирования библиотеки C++



         

Типовое ObjectARX-приложение - часть 3


acdbFail(/*MSG4*/"Argument should be positive.");

return RTERROR;

} else if (x > 170) { // Avoid floating-point overflow

acdbFail(/*MSG5*/"Argument should be 170 or less.");

return RTERROR;

}

acedRetReal(rfact(x)); // Call the function itself, and

// return the value to AutoLISP

return RTNORM;

}

// This is the implementation of the actual external factorial

// function.

static ads_real rfact(int n)

{

ads_real ans = 1.0;

while (n)

ans *= n--;

return ans;

}

// SQUAREROOT -- First set up the argument, then call the root

// function.

static int

squareroot(struct resbuf *rb)

{

ads_real x;

if (rb == NULL)

return RTERROR; // A proper error msg would

// be better.

if (rb->restype == RTSHORT) { // Save in local variable.

x = (ads_real) rb->resval.rint;

} else if (rb->restype == RTREAL) {

x = rb->resval.rreal; // Can accept either real

// or integer.

} else {

acdbFail(

/*MSG6*/

"Argument should be a real or integer value.");

return RTERROR;

}

if (x < 0) { // Check argument range.

acdbFail(/*MSG7*/"Argument should be positive.");

return RTERROR;

}

acedRetReal(rsqr(x)); // Call the function itself, and

// return the value to AutoLISP.

return RTNORM;

}

// This is the implementation of the actual external function

static ads_real rsqr(ads_real x) // Square root by Newton’s  method.

{

int n = 50;

ads_real y, c, cl;

if (x == 0.0) {

return 0.0;

}

y = (x * 2 + .1) / (x + 1.0);

c = (y - x / y) / 2;

cl= 0.0;

while ((c != cl) && (n-- > 0)) {

y -= c;

cl = c;

c = (y - x / y) / 2;

}

return y;

}




Содержание  Назад  Вперед