1 /*****************************************************************************
5 ** Purpose: Routines for phantom objects
6 ** Progammer: Kevin Rosenberg
7 ** Date Started: Aug 1984
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2000 Kevin Rosenberg
12 ** $Id: phantom.cpp,v 1.6 2000/07/13 07:03:21 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
31 // CLASS IDENTIFICATION
35 Phantom::Phantom (void)
41 Phantom::Phantom (const char* const phmName)
44 createFromPhantom (phmName);
56 m_composition = P_PELEMS;
61 Phantom::~Phantom (void)
63 for (PElemIterator i = m_listPElem.begin(); i != m_listPElem.end(); i++) {
70 Phantom::convertPhantomIDToName (const PhantomID phmID)
72 const char *name = "";
74 if (phmID == PHM_HERMAN)
75 name = PHM_HERMAN_STR;
76 else if (phmID == PHM_BHERMAN)
77 name = PHM_BHERMAN_STR;
78 else if (phmID == PHM_ROWLAND)
79 name = PHM_ROWLAND_STR;
80 else if (phmID == PHM_BROWLAND)
81 name = PHM_BROWLAND_STR;
82 else if (phmID == PHM_UNITPULSE)
83 name = PHM_UNITPULSE_STR;
89 Phantom::convertNameToPhantomID (const char* const phmName)
91 PhantomID id = PHM_INVALID;
93 if (strcasecmp (phmName, PHM_HERMAN_STR) == 0)
95 else if (strcasecmp (phmName, PHM_BHERMAN_STR) == 0)
97 else if (strcasecmp (phmName, PHM_ROWLAND_STR) == 0)
99 else if (strcasecmp (phmName, PHM_BROWLAND_STR) == 0)
101 else if (strcasecmp (phmName, PHM_UNITPULSE_STR) == 0)
109 Phantom::createFromPhantom (const char* const phmName)
111 PhantomID phmid = convertNameToPhantomID (phmName);
112 if (phmid == PHM_INVALID) {
114 m_failMessage = "Invalid phantom name ";
115 m_failMessage += phmName;
120 createFromPhantom (phmid);
125 Phantom::createFromPhantom (const PhantomID phmid)
133 addStdHermanBordered();
139 addStdRowlandBordered ();
142 m_composition = P_UNIT_PULSE;
143 addPElem ("rectangle", 0., 0., 100., 100., 0., 0.); // outline
144 addPElem ("ellipse", 0., 0., 1., 1., 0., 1.); // pulse
148 m_failMessage = "Illegal phantom id ";
149 m_failMessage += phmid;
159 /* METHOD IDENTIFICATION
160 * createFromFile Add PhantomElements from file
163 * createFromFile (filename)
166 * true if pelem were added
167 * false if an pelem not added
171 Phantom::createFromFile (const char* const fname)
173 bool stoploop = false;
177 if ((fp = fopen (fname, "r")) == NULL)
181 double cx, cy, u, v, rot, dens;
183 int n = fscanf (fp, "%79s %lf %lf %lf %lf %lf %lf",
184 pelemtype, &cx, &cy, &u, &v, &rot, &dens);
186 if (n == EOF || n == 0) { /* end of file */
193 addPElem (pelemtype, cx, cy, u, v, rot, dens);
196 } while (stoploop == false);
208 * addPElem (type, cx, cy, u, v, rot, atten)
209 * char *type type of pelem (box, ellipse, etc)
210 * double cx, cy pelem center
211 * double u,v pelem size
212 * double rot rotation angle of pelem (in degrees)
213 * double atten x-ray attenuation cooefficient
217 Phantom::addPElem (const char *type, const double cx, const double cy, const double u, const double v, const double rot, const double atten)
219 PhantomElement *pelem = new PhantomElement (type, cx, cy, u, v, rot, atten);
221 m_listPElem.push_front (pelem);
223 // update phantom limits
224 if (m_xmin > pelem->xmin()) m_xmin = pelem->xmin();
225 if (m_xmax < pelem->xmax()) m_xmax = pelem->xmax();
226 if (m_ymin > pelem->ymin()) m_ymin = pelem->ymin();
227 if (m_ymax < pelem->ymax()) m_ymax = pelem->ymax();
229 if (m_diameter < pelem->diameter())
230 m_diameter = pelem->diameter();
232 // m_diameter = lineLength(m_xmin, m_ymin, m_xmax, m_ymax);
238 /*----------------------------------------------------------------------*/
239 /* Input-Output Routines */
240 /*----------------------------------------------------------------------*/
244 * print Print vertices of Phantom pelems
251 Phantom::print (void) const
253 printf("PRINTING Phantom\n\n");
254 printf("number of pelems in Phantom = %d\n", m_nPElem);
255 printf("limits: xmin=%8.2g ymin=%8.2g xmax=%8.2g ymax=%8.2g\n",
256 m_xmin, m_ymin, m_xmax, m_ymax);
258 for (PElemIterator i = m_listPElem.begin(); i != m_listPElem.end(); i++) {
260 printf("# pts=%3d atten = %7.4f rot = %7.2f (deg)\n",
261 (*i)->nOutlinePoints(), (*i)->atten(), convertRadiansToDegrees ((*i)->rot()));
263 printf("xmin=%7.3g ymin=%7.3g xmax=%7.3g ymax=%7.3g\n",
264 (*i)->xmin(), (*i)->ymin(), (*i)->xmax(), (*i)->ymax());
266 // for (int i = 0; i < m_nPoints; i++)
267 // printf("\t%8.3g %8.3g\n", i->xOutline()[i], i->yOutline()[i]);
273 * show Show vector outline of Phantom to user
281 Phantom::show (void) const
283 double wsize = m_xmax - m_xmin;
284 double xmin = m_xmin;
285 double ymin = m_ymin;
289 if ((m_ymax - m_ymin) > wsize)
290 wsize = m_ymax - m_ymin;
296 printf("Drawing Phantom:\n\n");
297 printf(" data limits: %9.3g, %9.3g, %9.3g, %9.3g\n",
298 m_xmin, m_ymin, m_xmax, m_ymax);
299 printf(" window size: %9.3g, %9.3g, %9.3g, %9.3g\n",
300 xmin, ymin, xmax, ymax);
302 gid = sgp2_init(0, 0, "Phantom Show");
303 sgp2_window (xmin, ymin, xmax, ymax);
313 * draw Draw vector outline of Phantom
321 Phantom::draw (void) const
323 for (PElemIterator i = m_listPElem.begin(); i != m_listPElem.end(); i++)
324 sgp2_polyline_abs ((*i)->xOutline(), (*i)->yOutline(), (*i)->nOutlinePoints());
330 * addStdRowland Make head phantom of S.W. Rowland
333 * S. W. Rowland, "Computer Implementation of Image Reconstruction
334 * Formulas", in "Image Reconstruction from Projections: Implementation
335 * and Applications", edited by G. T. Herman, 1978.
339 Phantom::addStdRowland (void)
341 addPElem("ellipse", 0.0000, 0.0000, 0.6900, 0.9200, 0.0, 1.00);
342 addPElem("ellipse", 0.0000, -0.0184, 0.6624, 0.8740, 0.0, -0.98);
343 addPElem("ellipse", 0.2200, 0.0000, 0.1100, 0.3100, -18.0, -0.02);
344 addPElem("ellipse", -0.2200, 0.0000, 0.1600, 0.4100, 18.0, -0.02);
345 addPElem("ellipse", 0.0000, 0.3500, 0.2100, 0.2500, 0.0, 0.01);
346 addPElem("ellipse", 0.0000, 0.1000, 0.0460, 0.0460, 0.0, 0.01);
347 addPElem("ellipse", 0.0000, -0.1000, 0.0460, 0.0460, 0.0, 0.01);
348 addPElem("ellipse", -0.0800, -0.6050, 0.0460, 0.0230, 0.0, 0.01);
349 addPElem("ellipse", 0.0000, -0.6050, 0.0230, 0.0230, 0.0, 0.01);
350 addPElem("ellipse", 0.0600, -0.6050, 0.0230, 0.0230, 0.0, 0.01);
351 addPElem("ellipse", 0.5538, -0.3858, 0.0330, 0.2060, -18.0, 0.03);
355 Phantom::addStdRowlandBordered (void)
358 addPElem ("ellipse", 0.000, 0.0000, 0.7500, 1.000, 0.0, 0.00);
362 * addStdHerman Standard head phantom of G. T. Herman
365 * G. T. Herman, "Image Reconstructions from Projections: The Fundementals
366 * of Computed Tomography", 1979.
370 Phantom::addStdHerman (void)
372 addPElem("ellipse", 0.000, 1.50, 0.375, 0.3000, 90.00, -0.003);
373 addPElem("ellipse", 0.675, -0.75, 0.225, 0.1500, 140.00, 0.010);
374 addPElem("ellipse", 0.750, 1.50, 0.375, 0.2250, 50.00, 0.003);
375 addPElem("segment", 1.375, -7.50, 1.100, 0.6250, 19.20, -0.204);
376 addPElem("segment", 1.375, -7.50, 1.100, 4.3200, 19.21, 0.204);
377 addPElem("segment", 0.000, -2.25, 1.125, 0.3750, 0.00, -0.003);
378 addPElem("segment", 0.000, -2.25, 1.125, 3.0000, 0.00, 0.003);
379 addPElem("segment", -1.000, 3.75, 1.000, 0.5000, 135.00, -0.003);
380 addPElem("segment", -1.000, 3.75, 1.000, 3.0000, 135.00, 0.003);
381 addPElem("segment", 1.000, 3.75, 1.000, 0.5000, 225.00, -0.003);
382 addPElem("segment", 1.000, 3.75, 1.000, 3.0000, 225.00, 0.003);
383 addPElem("triangle", 5.025, 3.75, 1.125, 0.5000, 110.75, 0.206);
384 addPElem("triangle",-5.025, 3.75, 1.125, 0.9000,-110.75, 0.206);
385 addPElem("ellipse", 0.000, 0.00, 8.625, 6.4687, 90.00, 0.416);
386 addPElem("ellipse", 0.000, 0.00, 7.875, 5.7187, 90.00, -0.206);
390 Phantom::addStdHermanBordered (void)
392 addPElem("ellipse", 0., 0., 6.6, 5.9, 90., 0.);
397 * convertToImagefile Make image array from Phantom
400 * pic_to_imagefile (pic, im, nsample)
401 * Phantom& pic Phantom definitions
402 * ImageFile *im Computed pixel array
403 * int nsample Number of samples along each axis for each pixel
404 * (total samples per pixel = nsample * nsample)
408 Phantom::convertToImagefile (ImageFile& im, const int in_nsample, const int trace) const
410 convertToImagefile (im, in_nsample, trace, 0, im.nx());
414 Phantom::convertToImagefile (ImageFile& im, const int in_nsample, const int trace, const int colStart, const int colCount) const
418 if (nx < 2 || ny < 2)
421 int nsample = in_nsample;
425 double dx = m_xmax - m_xmin;
426 double dy = m_ymax - m_ymin;
427 double xcent = m_xmin + dx / 2;
428 double ycent = m_ymin + dy / 2;
429 double phmlen = (dx > dy ? dx : dy);
431 double phmradius = phmlen / 2;
433 double xmin = xcent - phmradius;
434 double xmax = xcent + phmradius;
435 double ymin = ycent - phmradius;
436 double ymax = ycent + phmradius;
438 // Each pixel holds the average of the intensity of the cell with (ix,iy) at the center of the pixel
439 // Set major increments so that the last cell v[nx-1][ny-1] will start at xmax - xinc, ymax - yinc).
440 // Set minor increments so that sample points are centered in cell
442 double xinc = (xmax - xmin) / nx;
443 double yinc = (ymax - ymin) / ny;
445 double kxinc = xinc / nsample; /* interval between samples */
446 double kyinc = yinc / nsample;
447 double kxofs = kxinc / 2; /* offset of 1st point */
448 double kyofs = kyinc / 2;
450 im.setAxisExtent (xmin, xmax, ymin, ymax);
451 im.setAxisIncrement (xinc, yinc);
453 ImageFileArray v = im.getArray();
455 double x_start = xmin + (colStart * xinc);
456 for (PElemConstIterator pelem = m_listPElem.begin(); pelem != m_listPElem.end(); pelem++) {
459 for (ix = 0, x = x_start; ix < colCount; ix++, x += xinc) {
460 for (iy = 0, y = ymin; iy < ny; iy++, y += yinc) {
461 for (kx = 0, xi = x + kxofs; kx < nsample; kx++, xi += kxinc) {
462 for (ky = 0, yi = y + kyofs; ky < nsample; ky++, yi += kyinc)
463 if ((*pelem)->isPointInside (xi, yi, PHM_COORD) == TRUE)
464 v[ix][iy] += (*pelem)->atten();
472 double factor = 1.0 / (nsample * nsample);
474 for (int ix = 0; ix < colCount; ix++)
475 for (int iy = 0; iy < ny; iy++)
480 ////////////////////////////////////////////////////////////////////////////////////////////////////////
481 // CLASS IDENTIFICATION
487 ////////////////////////////////////////////////////////////////////////////////////////////////////////
490 PhantomElement::PhantomElement (const char *type, const double cx, const double cy, const double u, const double v, const double rot, const double atten)
491 : m_cx(cx), m_cy(cy), m_u(u), m_v(v), m_atten(atten), m_nPoints(0), m_xOutline(0), m_yOutline(0)
493 m_rot = convertDegreesToRadians (rot); // convert angle to radians
495 m_type = convertNameToType (type);
497 makeTransformMatrices (); // calc transform matrices between phantom and normalized phantomelement
498 makeVectorOutline (); // calculate vector outline of pelem
500 // Find maximum diameter of Object
502 for (int i = 0; i < m_nPoints; i++) {
503 double r2 = (m_xOutline[i] * m_xOutline[i]) + (m_yOutline[i] * m_yOutline[i]);
507 m_diameter = 2 * sqrt( r2Max );
509 m_rectLimits[0] = m_xmin; m_rectLimits[1] = m_ymin;
510 m_rectLimits[2] = m_xmax; m_rectLimits[3] = m_ymax;
514 PhantomElement::~PhantomElement (void)
521 PhantomElement::convertNameToType (const char* const typeName)
523 PhmElemType type = PELEM_INVALID;
525 if (strcasecmp (typeName, "rectangle") == 0)
526 type = PELEM_RECTANGLE;
527 else if (strcasecmp (typeName, "triangle") == 0)
528 type = PELEM_TRIANGLE;
529 else if (strcasecmp (typeName, "ellipse") == 0)
530 type = PELEM_ELLIPSE;
531 else if (strcasecmp (typeName, "sector") == 0)
533 else if (strcasecmp (typeName, "segment") == 0)
534 type = PELEM_SEGMENT;
536 sys_error (ERR_WARNING, "Unknown PhantomElement type %s [PhantomElement::PhantomElement]", type);
542 PhantomElement::makeTransformMatrices (void)
546 // To map normalized Pelem coords to world Phantom
549 // translate by (cx, cy)
551 scale_mtx2 (m_xformObjToPhm, m_u, m_v);
552 rot_mtx2 (temp, m_rot);
553 mult_mtx2 (m_xformObjToPhm, temp, m_xformObjToPhm);
554 xlat_mtx2 (temp, m_cx, m_cy);
555 mult_mtx2 (m_xformObjToPhm, temp, m_xformObjToPhm);
557 // to map world Phantom coodinates to normalized PElem coords
558 // translate by (-cx, -cy)
560 // scale by (1/u, 1/v)
562 xlat_mtx2 (m_xformPhmToObj, -m_cx, -m_cy);
563 rot_mtx2 (temp, -m_rot);
564 mult_mtx2 (m_xformPhmToObj, temp, m_xformPhmToObj);
565 scale_mtx2 (temp, 1 / m_u, 1 / m_v);
566 mult_mtx2 (m_xformPhmToObj, temp, m_xformPhmToObj);
571 * pelem_make_points INTERNAL routine to calculate point array for an pelem
574 * makepelempts (pelem)
575 * PELEM *pelem pelem whose points we are calculating
578 * Called by phm_add_pelem()
582 PhantomElement::makeVectorOutline (void)
584 double radius, theta, start, stop;
590 case PELEM_RECTANGLE:
592 m_xOutline = new double [m_nPoints];
593 m_yOutline = new double [m_nPoints];
594 m_xOutline[0] =-m_u; m_yOutline[0] =-m_v;
595 m_xOutline[1] = m_u; m_yOutline[1] =-m_v;
596 m_xOutline[2] = m_u; m_yOutline[2] = m_v;
597 m_xOutline[3] =-m_u; m_yOutline[3] = m_v;
598 m_xOutline[4] =-m_u; m_yOutline[4] =-m_v;
602 m_xOutline = new double [m_nPoints];
603 m_yOutline = new double [m_nPoints];
604 m_xOutline[0] =-m_u; m_yOutline[0] = 0.0;
605 m_xOutline[1] = m_u; m_yOutline[1] = 0.0;
606 m_xOutline[2] = 0.0; m_yOutline[2] = m_v;
607 m_xOutline[3] =-m_u; m_yOutline[3] = 0.0;
610 cpts = numCirclePoints (TWOPI);
612 m_xOutline = new double [m_nPoints];
613 m_yOutline = new double [m_nPoints];
614 calcEllipsePoints (m_xOutline, m_yOutline, cpts, m_u, m_v);
617 radius = sqrt(m_u * m_u + m_v * m_v);
618 theta = atan(m_u / m_v); // angle with y-axis
619 start = 3.0 * HALFPI - theta;
620 stop = 3.0 * HALFPI + theta;
621 cpts = numCirclePoints (stop - start);
622 m_nPoints = 3 + cpts;
623 m_xOutline = new double [m_nPoints];
624 m_yOutline = new double [m_nPoints];
626 m_xOutline[0] = 0.0; m_yOutline[0] = m_v;
627 m_xOutline[1] =-m_u; m_yOutline[1] = 0.0;
628 calcArcPoints (&m_xOutline[2], &m_yOutline[2], cpts, 0.0, m_v, radius, start, stop);
629 m_xOutline[cpts + 2] = 0.0;
630 m_yOutline[cpts + 2] = m_v;
633 radius = sqrt(m_u * m_u + m_v * m_v);
634 theta = atan (m_u / m_v); // angle with y-axis
635 start = 3.0 * HALFPI - theta;
636 stop = 3.0 * HALFPI + theta;
638 cpts = numCirclePoints (stop - start);
639 m_nPoints = cpts + 1;
640 m_xOutline = new double [m_nPoints];
641 m_yOutline = new double [m_nPoints];
643 calcArcPoints (m_xOutline, m_yOutline, cpts, 0.0, m_v, radius, start, stop);
644 m_xOutline[cpts] = -m_u;
645 m_yOutline[cpts] = 0.0;
648 sys_error(ERR_WARNING, "illegal pelem type %d [makeVectorOutline]", m_type);
652 rotate2d (m_xOutline, m_yOutline, m_nPoints, m_rot);
653 xlat2d (m_xOutline, m_yOutline, m_nPoints, m_cx, m_cy);
655 minmax_array (m_xOutline, m_nPoints, m_xmin, m_xmax);
656 minmax_array (m_yOutline, m_nPoints, m_ymin, m_ymax);
658 // increase pelem extent by SCALE_PELEM_EXTENT to eliminate chance of
659 // missing actual pelem maximum due to polygonal sampling
661 xfact = (m_xmax - m_xmin) * SCALE_PELEM_EXTENT;
662 yfact = (m_ymax - m_ymin) * SCALE_PELEM_EXTENT;
672 * calc_arc Calculate outline of a arc of a circle
675 * calc_arc (x, y, xcent, ycent, pts, r, start, stop)
676 * double x[], y[]; Array of points
677 * int pts Number of points in array
678 * double xcent, ycent Center of cirlce
679 * double r Radius of circle
680 * double start, stop Beginning & ending angles
684 PhantomElement::calcArcPoints (double x[], double y[], const int pts, const double xcent, const double ycent, const double r, const double start, const double stop)
687 sys_error (ERR_WARNING, "negative or zero radius in calc_arc()");
689 double theta = (stop - start) / (pts - 1); // angle incr. between points
690 double c = cos(theta);
691 double s = sin(theta);
693 x[0] = r * cos (start) + xcent;
694 y[0] = r * sin (start) + ycent;
696 double xp = x[0] - xcent;
697 double yp = y[0] - ycent;
698 for (int i = 1; i < pts; i++) {
699 double xc = c * xp - s * yp;
700 double yc = s * xp + c * yp;
709 // PhantomElement::calcEllipsePoints Calculate outline of a ellipse
712 // calcEllipsePoints ()
717 PhantomElement::calcEllipsePoints (double x[], double y[], const int pts, const double u, const double v)
719 calcArcPoints (x, y, m_nPoints, 0.0, 0.0, 1.0, 0.0, TWOPI); // make a unit circle
720 scale2d (x, y, m_nPoints, m_u, m_v); // scale to ellipse
725 * circle_pts Calculate number of points to use for circle segment
728 * n = circle_pts (theta)
729 * int n Number of points to use for arc
730 * double theta Length of arc in radians
734 PhantomElement::numCirclePoints (double theta)
736 theta = clamp (theta, 0., TWOPI);
738 return static_cast<int> (POINTS_PER_CIRCLE * theta / TWOPI + 1.5);
743 PhantomElement::clipLineWorldCoords (double& x1, double& y1, double& x2, double &y2) const
745 /* check if ray is outside of pelem extents */
746 double cx1 = x1, cy1 = y1, cx2 = x2, cy2 = y2;
747 if (! clip_rect (cx1, cy1, cx2, cy2, m_rectLimits))
750 // convert phantom coordinates to pelem coordinates
751 xform_mtx2 (m_xformPhmToObj, x1, y1);
752 xform_mtx2 (m_xformPhmToObj, x2, y2);
754 if (! clipLineNormalizedCoords (x1, y1, x2, y2))
757 // convert standard pelem coordinates back to phantom coordinates
758 xform_mtx2 (m_xformObjToPhm, x1, y1);
759 xform_mtx2 (m_xformObjToPhm, x2, y2);
766 * pelem_clip_line Clip pelem against an arbitrary line
769 * pelem_clip_line (pelem, x1, y1, x2, y2)
770 * PhantomElement& pelem; Pelem to be clipped
771 * double *x1, *y1, *x2, *y2 Endpoints of line to be clipped
774 * true if line passes through pelem
775 * (x1, y1, x2, y2 hold coordinates of new line)
776 * false if line do not pass through pelem
777 * (x1, y1, x2, y2 are undefined)
781 PhantomElement::clipLineNormalizedCoords (double& x1, double& y1, double& x2, double& y2) const
786 case PELEM_RECTANGLE:
788 rect[0] = -1.0; rect[1] = -1.0;
789 rect[2] = 1.0; rect[3] = 1.0;
790 accept = clip_rect (x1, y1, x2, y2, rect);
793 accept = clip_circle (x1, y1, x2, y2, 0.0, 0.0, 1.0, 0.0, 0.0);
796 accept = clip_triangle (x1, y1, x2, y2, 1.0, 1.0, true);
799 accept = clip_segment (x1, y1, x2, y2, m_u, m_v);
802 accept = clip_sector (x1, y1, x2, y2, m_u, m_v);
805 sys_error (ERR_WARNING, "Illegal pelem type %d [pelem_clip_line]", m_type);
813 // METHOD IDENTIFICATION
814 // PhantomElement::isPointInside Check if point is inside pelem
817 // is_point_inside (pelem, x, y, coord_type)
818 // double x, y Point to see if lies in pelem
819 // int coord_type Coordinate type (PELEM_COORD or PHM_COORD)
822 // true if point lies within pelem
823 // false if point lies outside of pelem
826 PhantomElement::isPointInside (double x, double y, const CoordType coord_type)
828 if (coord_type == PHM_COORD) {
829 xform_mtx2 (m_xformPhmToObj, x, y);
830 } else if (coord_type != PELEM_COORD) {
831 sys_error(ERR_WARNING, "Illegal coordinate type in pelem_is_point_inside");
836 case PELEM_RECTANGLE:
837 if (x > 1. || x < -1. || y > 1. || y < -1.)
843 if (y < 0. || y > 1. - x || y > 1. + x)
849 if (x > 1. || x < -1. || y > 1. || y < -1.)
851 if (x * x + y * y > 1.) // check if inside unit circle
857 // for clipping segments & sectors, must NOT scale by (1/u, 1/v)
858 // because this destroys information about size of arc component
861 if (x > 1. || x < -1. || y > 0.)
862 return (false); // clip against y > 0
863 x *= m_u; // put back u & v scale
865 if (x * x + (y-m_v) * (y-m_v) > m_u * m_u + m_v * m_v)
866 return (false); // clip against circle, r = sqrt(@)
871 if (x > 1. || x < -1. || y > 1.) // extent
873 if (y > 1. - x || y > 1. + x) // triangle
874 return (false); // clip against triangle
875 x *= m_u; // circle: put back u & v scale
877 if (x * x + (y-m_v) * (y-m_v) > m_u * m_u + m_v * m_v)
878 return (false); // clip against circle
883 sys_error (ERR_WARNING, "Illegal pelem type in pelem_is_point_inside()");