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.15 2000/08/02 18:06:00 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 const int Phantom::PHM_INVALID = -1;
32 const int Phantom::PHM_HERMAN = 0;
33 const int Phantom::PHM_BHERMAN = 1;
34 const int Phantom::PHM_ROWLAND = 2;
35 const int Phantom::PHM_BROWLAND = 3;
36 const int Phantom::PHM_UNITPULSE = 4;
38 const char* Phantom::s_aszPhantomName[] =
47 const char* Phantom::s_aszPhantomTitle[] =
50 {"Herman Head Bordered"},
52 {"Rowland Head Bordered"},
56 const int Phantom::s_iPhantomCount = sizeof(s_aszPhantomName) / sizeof(const char*);
59 // CLASS IDENTIFICATION
69 Phantom::Phantom (const char* const phmName)
72 createFromPhantom (phmName);
84 m_composition = P_PELEMS;
91 for (PElemIterator i = m_listPElem.begin(); i != m_listPElem.end(); i++) {
98 Phantom::convertPhantomIDToName (int phmID)
100 static const char *name = "";
102 if (phmID >= 0 && phmID < s_iPhantomCount)
103 return (s_aszPhantomName[phmID]);
109 Phantom::convertPhantomIDToTitle (int phmID)
111 static const char *title = "";
113 if (phmID >= 0 && phmID < s_iPhantomCount)
114 return (s_aszPhantomName[phmID]);
120 Phantom::convertNameToPhantomID (const char* const phmName)
122 int id = PHM_INVALID;
124 for (int i = 0; i < s_iPhantomCount; i++)
125 if (strcasecmp (phmName, s_aszPhantomName[i]) == 0) {
135 Phantom::createFromPhantom (const char* const phmName)
137 int phmid = convertNameToPhantomID (phmName);
138 if (phmid == PHM_INVALID) {
140 m_failMessage = "Invalid phantom name ";
141 m_failMessage += phmName;
146 createFromPhantom (phmid);
151 Phantom::createFromPhantom (const int phmid)
159 addStdHermanBordered();
165 addStdRowlandBordered ();
168 m_composition = P_UNIT_PULSE;
169 addPElem ("rectangle", 0., 0., 100., 100., 0., 0.); // outline
170 addPElem ("ellipse", 0., 0., 1., 1., 0., 1.); // pulse
174 m_failMessage = "Illegal phantom id ";
175 m_failMessage += phmid;
185 /* METHOD IDENTIFICATION
186 * createFromFile Add PhantomElements from file
189 * createFromFile (filename)
192 * true if pelem were added
193 * false if an pelem not added
197 Phantom::createFromFile (const char* const fname)
199 bool stoploop = false;
203 if ((fp = fopen (fname, "r")) == NULL)
208 double cx, cy, u, v, rot, dens;
211 fgets (str, sizeof(str), fp);
212 int n = sscanf (str, "%79s %lf %lf %lf %lf %lf %lf", pelemtype, &cx, &cy, &u, &v, &rot, &dens);
214 if (n == EOF || n == 0) { /* end of file */
221 addPElem (pelemtype, cx, cy, u, v, rot, dens);
228 } while (stoploop == false);
240 * addPElem (type, cx, cy, u, v, rot, atten)
241 * char *type type of pelem (box, ellipse, etc)
242 * double cx, cy pelem center
243 * double u,v pelem size
244 * double rot rotation angle of pelem (in degrees)
245 * double atten x-ray attenuation cooefficient
249 Phantom::addPElem (const char *type, const double cx, const double cy, const double u, const double v, const double rot, const double atten)
251 PhantomElement *pelem = new PhantomElement (type, cx, cy, u, v, rot, atten);
253 m_listPElem.push_front (pelem);
255 // update phantom limits
256 if (m_xmin > pelem->xmin()) m_xmin = pelem->xmin();
257 if (m_xmax < pelem->xmax()) m_xmax = pelem->xmax();
258 if (m_ymin > pelem->ymin()) m_ymin = pelem->ymin();
259 if (m_ymax < pelem->ymax()) m_ymax = pelem->ymax();
261 if (m_diameter < pelem->diameter())
262 m_diameter = pelem->diameter();
264 // m_diameter = lineLength(m_xmin, m_ymin, m_xmax, m_ymax);
270 /*----------------------------------------------------------------------*/
271 /* Input-Output Routines */
272 /*----------------------------------------------------------------------*/
276 * print Print vertices of Phantom pelems
283 Phantom::print () const
285 printf("PRINTING Phantom\n\n");
286 printf("number of pelems in Phantom = %d\n", m_nPElem);
287 printf("limits: xmin=%8.2g ymin=%8.2g xmax=%8.2g ymax=%8.2g\n",
288 m_xmin, m_ymin, m_xmax, m_ymax);
290 for (PElemIterator i = m_listPElem.begin(); i != m_listPElem.end(); i++) {
292 printf("# pts=%3d atten = %7.4f rot = %7.2f (deg)\n",
293 (*i)->nOutlinePoints(), (*i)->atten(), convertRadiansToDegrees ((*i)->rot()));
295 printf("xmin=%7.3g ymin=%7.3g xmax=%7.3g ymax=%7.3g\n",
296 (*i)->xmin(), (*i)->ymin(), (*i)->xmax(), (*i)->ymax());
298 // for (int i = 0; i < m_nPoints; i++)
299 // printf("\t%8.3g %8.3g\n", i->xOutline()[i], i->yOutline()[i]);
305 * show Show vector outline of Phantom to user
313 Phantom::show () const
315 SGPDriver driverSGP ("Phantom Show");
320 cout << "Press return to continue";
325 Phantom::show (SGP& sgp) const
327 double wsize = m_xmax - m_xmin;
328 if ((m_ymax - m_ymin) > wsize)
329 wsize = m_ymax - m_ymin;
331 double halfWindow = wsize / 2;
333 double xcent = m_xmin + (m_xmax - m_xmin) / 2;
334 double ycent = m_ymin + (m_ymax - m_ymin) / 2;
336 sgp.setWindow (xcent - halfWindow, ycent - halfWindow, xcent + halfWindow, ycent + halfWindow);
344 * draw Draw vector outline of Phantom
352 Phantom::draw (SGP& sgp) const
354 for (PElemIterator i = m_listPElem.begin(); i != m_listPElem.end(); i++)
355 sgp.polylineAbs ((*i)->xOutline(), (*i)->yOutline(), (*i)->nOutlinePoints());
361 * addStdRowland Make head phantom of S.W. Rowland
364 * S. W. Rowland, "Computer Implementation of Image Reconstruction
365 * Formulas", in "Image Reconstruction from Projections: Implementation
366 * and Applications", edited by G. T. Herman, 1978.
370 Phantom::addStdRowland ()
372 addPElem ("ellipse", 0.0000, 0.0000, 0.6900, 0.9200, 0.0, 1.00);
373 addPElem ("ellipse", 0.0000, -0.0184, 0.6624, 0.8740, 0.0, -0.98);
374 addPElem ("ellipse", 0.2200, 0.0000, 0.1100, 0.3100, -18.0, -0.02);
375 addPElem ("ellipse", -0.2200, 0.0000, 0.1600, 0.4100, 18.0, -0.02);
376 addPElem ("ellipse", 0.0000, 0.3500, 0.2100, 0.2500, 0.0, 0.01);
377 addPElem ("ellipse", 0.0000, 0.1000, 0.0460, 0.0460, 0.0, 0.01);
378 addPElem ("ellipse", 0.0000, -0.1000, 0.0460, 0.0460, 0.0, 0.01);
379 addPElem ("ellipse", -0.0800, -0.6050, 0.0460, 0.0230, 0.0, 0.01);
380 addPElem ("ellipse", 0.0000, -0.6050, 0.0230, 0.0230, 0.0, 0.01);
381 addPElem ("ellipse", 0.0600, -0.6050, 0.0230, 0.0230, 0.0, 0.01);
382 addPElem ("ellipse", 0.5538, -0.3858, 0.0330, 0.2060, -18.0, 0.03);
386 Phantom::addStdRowlandBordered ()
389 addPElem ("rectangle", 0.000, 0.0000, 0.7500, 1.000, 0.0, 0.00);
393 * addStdHerman Standard head phantom of G. T. Herman
396 * G. T. Herman, "Image Reconstructions from Projections: The Fundementals
397 * of Computed Tomography", 1979.
401 Phantom::addStdHerman ()
403 addPElem ("ellipse", 0.000, 1.50, 0.375, 0.3000, 90.00, -0.003);
404 addPElem ("ellipse", 0.675, -0.75, 0.225, 0.1500, 140.00, 0.010);
405 addPElem ("ellipse", 0.750, 1.50, 0.375, 0.2250, 50.00, 0.003);
406 addPElem ("segment", 1.375, -7.50, 1.100, 0.6250, 19.20, -0.204);
407 addPElem ("segment", 1.375, -7.50, 1.100, 4.3200, 19.21, 0.204);
408 addPElem ("segment", 0.000, -2.25, 1.125, 0.3750, 0.00, -0.003);
409 addPElem ("segment", 0.000, -2.25, 1.125, 3.0000, 0.00, 0.003);
410 addPElem ("segment", -1.000, 3.75, 1.000, 0.5000, 135.00, -0.003);
411 addPElem ("segment", -1.000, 3.75, 1.000, 3.0000, 135.00, 0.003);
412 addPElem ("segment", 1.000, 3.75, 1.000, 0.5000, 225.00, -0.003);
413 addPElem ("segment", 1.000, 3.75, 1.000, 3.0000, 225.00, 0.003);
414 addPElem ("triangle", 5.025, 3.75, 1.125, 0.5000, 110.75, 0.206);
415 addPElem ("triangle",-5.025, 3.75, 1.125, 0.9000,-110.75, 0.206);
416 addPElem ("ellipse", 0.000, 0.00, 8.625, 6.4687, 90.00, 0.416);
417 addPElem ("ellipse", 0.000, 0.00, 7.875, 5.7187, 90.00, -0.206);
421 Phantom::addStdHermanBordered ()
424 addPElem ("rectangle", 0.000, 0.000, 8.650, 8.650, 0.00, 0.000);
429 * convertToImagefile Make image array from Phantom
432 * pic_to_imagefile (pic, im, nsample)
433 * Phantom& pic Phantom definitions
434 * ImageFile *im Computed pixel array
435 * int nsample Number of samples along each axis for each pixel
436 * (total samples per pixel = nsample * nsample)
440 Phantom::convertToImagefile (ImageFile& im, const int in_nsample, const int trace) const
442 convertToImagefile (im, in_nsample, trace, 0, im.nx());
446 Phantom::convertToImagefile (ImageFile& im, const int in_nsample, const int trace, const int colStart, const int colCount) const
450 if (nx < 2 || ny < 2)
453 int nsample = in_nsample;
457 double dx = m_xmax - m_xmin;
458 double dy = m_ymax - m_ymin;
459 double xcent = m_xmin + dx / 2;
460 double ycent = m_ymin + dy / 2;
461 double phmlen = (dx > dy ? dx : dy);
463 double phmradius = phmlen / 2;
465 double xmin = xcent - phmradius;
466 double xmax = xcent + phmradius;
467 double ymin = ycent - phmradius;
468 double ymax = ycent + phmradius;
470 // Each pixel holds the average of the intensity of the cell with (ix,iy) at the center of the pixel
471 // Set major increments so that the last cell v[nx-1][ny-1] will start at xmax - xinc, ymax - yinc).
472 // Set minor increments so that sample points are centered in cell
474 double xinc = (xmax - xmin) / nx;
475 double yinc = (ymax - ymin) / ny;
477 double kxinc = xinc / nsample; /* interval between samples */
478 double kyinc = yinc / nsample;
479 double kxofs = kxinc / 2; /* offset of 1st point */
480 double kyofs = kyinc / 2;
482 im.setAxisExtent (xmin, xmax, ymin, ymax);
483 im.setAxisIncrement (xinc, yinc);
485 ImageFileArray v = im.getArray();
487 for (int ix = 0; ix < colCount; ix++)
488 for (int iy = 0; iy < ny; iy++)
491 double x_start = xmin + (colStart * xinc);
492 for (PElemConstIterator pelem = m_listPElem.begin(); pelem != m_listPElem.end(); pelem++) {
493 const PhantomElement& rPElem = **pelem;
496 for (ix = 0, x = x_start; ix < colCount; ix++, x += xinc) {
497 for (iy = 0, y = ymin; iy < ny; iy++, y += yinc) {
498 for (kx = 0, xi = x + kxofs; kx < nsample; kx++, xi += kxinc) {
499 for (ky = 0, yi = y + kyofs; ky < nsample; ky++, yi += kyinc)
500 if (rPElem.isPointInside (xi, yi, PHM_COORD) == TRUE)
501 v[ix][iy] += rPElem.atten();
509 double factor = 1.0 / (nsample * nsample);
511 for (int ix = 0; ix < colCount; ix++)
512 for (int iy = 0; iy < ny; iy++)
517 ////////////////////////////////////////////////////////////////////////////////////////////////////////
518 // CLASS IDENTIFICATION
524 ////////////////////////////////////////////////////////////////////////////////////////////////////////
527 PhantomElement::PhantomElement (const char *type, const double cx, const double cy, const double u, const double v, const double rot, const double atten)
528 : m_cx(cx), m_cy(cy), m_u(u), m_v(v), m_atten(atten), m_nPoints(0), m_xOutline(0), m_yOutline(0)
530 m_rot = convertDegreesToRadians (rot); // convert angle to radians
532 m_type = convertNameToType (type);
534 makeTransformMatrices (); // calc transform matrices between phantom and normalized phantomelement
535 makeVectorOutline (); // calculate vector outline of pelem
537 // Find maximum diameter of Object
539 for (int i = 0; i < m_nPoints; i++) {
540 double r2 = (m_xOutline[i] * m_xOutline[i]) + (m_yOutline[i] * m_yOutline[i]);
544 m_diameter = 2 * sqrt( r2Max );
546 m_rectLimits[0] = m_xmin; m_rectLimits[1] = m_ymin;
547 m_rectLimits[2] = m_xmax; m_rectLimits[3] = m_ymax;
551 PhantomElement::~PhantomElement ()
558 PhantomElement::convertNameToType (const char* const typeName)
560 PhmElemType type = PELEM_INVALID;
562 if (strcasecmp (typeName, "rectangle") == 0)
563 type = PELEM_RECTANGLE;
564 else if (strcasecmp (typeName, "triangle") == 0)
565 type = PELEM_TRIANGLE;
566 else if (strcasecmp (typeName, "ellipse") == 0)
567 type = PELEM_ELLIPSE;
568 else if (strcasecmp (typeName, "sector") == 0)
570 else if (strcasecmp (typeName, "segment") == 0)
571 type = PELEM_SEGMENT;
573 sys_error (ERR_WARNING, "Unknown PhantomElement type %s [PhantomElement::PhantomElement]", type);
579 PhantomElement::makeTransformMatrices ()
583 // To map normalized Pelem coords to world Phantom
586 // translate by (cx, cy)
588 scale_mtx2 (m_xformObjToPhm, m_u, m_v);
589 rot_mtx2 (temp, m_rot);
590 mult_mtx2 (m_xformObjToPhm, temp, m_xformObjToPhm);
591 xlat_mtx2 (temp, m_cx, m_cy);
592 mult_mtx2 (m_xformObjToPhm, temp, m_xformObjToPhm);
594 // to map world Phantom coodinates to normalized PElem coords
595 // translate by (-cx, -cy)
597 // scale by (1/u, 1/v)
599 xlat_mtx2 (m_xformPhmToObj, -m_cx, -m_cy);
600 rot_mtx2 (temp, -m_rot);
601 mult_mtx2 (m_xformPhmToObj, temp, m_xformPhmToObj);
602 scale_mtx2 (temp, 1 / m_u, 1 / m_v);
603 mult_mtx2 (m_xformPhmToObj, temp, m_xformPhmToObj);
608 * pelem_make_points INTERNAL routine to calculate point array for an pelem
611 * makepelempts (pelem)
612 * PELEM *pelem pelem whose points we are calculating
615 * Called by phm_add_pelem()
619 PhantomElement::makeVectorOutline ()
621 double radius, theta, start, stop;
627 case PELEM_RECTANGLE:
629 m_xOutline = new double [m_nPoints];
630 m_yOutline = new double [m_nPoints];
631 m_xOutline[0] =-m_u; m_yOutline[0] =-m_v;
632 m_xOutline[1] = m_u; m_yOutline[1] =-m_v;
633 m_xOutline[2] = m_u; m_yOutline[2] = m_v;
634 m_xOutline[3] =-m_u; m_yOutline[3] = m_v;
635 m_xOutline[4] =-m_u; m_yOutline[4] =-m_v;
639 m_xOutline = new double [m_nPoints];
640 m_yOutline = new double [m_nPoints];
641 m_xOutline[0] =-m_u; m_yOutline[0] = 0.0;
642 m_xOutline[1] = m_u; m_yOutline[1] = 0.0;
643 m_xOutline[2] = 0.0; m_yOutline[2] = m_v;
644 m_xOutline[3] =-m_u; m_yOutline[3] = 0.0;
647 cpts = numCirclePoints (TWOPI);
649 m_xOutline = new double [m_nPoints];
650 m_yOutline = new double [m_nPoints];
651 calcEllipsePoints (m_xOutline, m_yOutline, cpts, m_u, m_v);
654 radius = sqrt(m_u * m_u + m_v * m_v);
655 theta = atan(m_u / m_v); // angle with y-axis
656 start = 3.0 * HALFPI - theta;
657 stop = 3.0 * HALFPI + theta;
658 cpts = numCirclePoints (stop - start);
659 m_nPoints = 3 + cpts;
660 m_xOutline = new double [m_nPoints];
661 m_yOutline = new double [m_nPoints];
663 m_xOutline[0] = 0.0; m_yOutline[0] = m_v;
664 m_xOutline[1] =-m_u; m_yOutline[1] = 0.0;
665 calcArcPoints (&m_xOutline[2], &m_yOutline[2], cpts, 0.0, m_v, radius, start, stop);
666 m_xOutline[cpts + 2] = 0.0;
667 m_yOutline[cpts + 2] = m_v;
670 radius = sqrt(m_u * m_u + m_v * m_v);
671 theta = atan (m_u / m_v); // angle with y-axis
672 start = 3.0 * HALFPI - theta;
673 stop = 3.0 * HALFPI + theta;
675 cpts = numCirclePoints (stop - start);
676 m_nPoints = cpts + 1;
677 m_xOutline = new double [m_nPoints];
678 m_yOutline = new double [m_nPoints];
680 calcArcPoints (m_xOutline, m_yOutline, cpts, 0.0, m_v, radius, start, stop);
681 m_xOutline[cpts] = -m_u;
682 m_yOutline[cpts] = 0.0;
685 sys_error(ERR_WARNING, "illegal pelem type %d [makeVectorOutline]", m_type);
689 rotate2d (m_xOutline, m_yOutline, m_nPoints, m_rot);
690 xlat2d (m_xOutline, m_yOutline, m_nPoints, m_cx, m_cy);
692 minmax_array (m_xOutline, m_nPoints, m_xmin, m_xmax);
693 minmax_array (m_yOutline, m_nPoints, m_ymin, m_ymax);
695 // increase pelem extent by SCALE_PELEM_EXTENT to eliminate chance of
696 // missing actual pelem maximum due to polygonal sampling
698 xfact = (m_xmax - m_xmin) * SCALE_PELEM_EXTENT;
699 yfact = (m_ymax - m_ymin) * SCALE_PELEM_EXTENT;
709 * calc_arc Calculate outline of a arc of a circle
712 * calc_arc (x, y, xcent, ycent, pts, r, start, stop)
713 * double x[], y[]; Array of points
714 * int pts Number of points in array
715 * double xcent, ycent Center of cirlce
716 * double r Radius of circle
717 * double start, stop Beginning & ending angles
721 PhantomElement::calcArcPoints (double x[], double y[], const int pts, const double xcent, const double ycent, const double r, const double start, const double stop)
724 sys_error (ERR_WARNING, "negative or zero radius in calc_arc()");
726 double theta = (stop - start) / (pts - 1); // angle incr. between points
727 double c = cos(theta);
728 double s = sin(theta);
730 x[0] = r * cos (start) + xcent;
731 y[0] = r * sin (start) + ycent;
733 double xp = x[0] - xcent;
734 double yp = y[0] - ycent;
735 for (int i = 1; i < pts; i++) {
736 double xc = c * xp - s * yp;
737 double yc = s * xp + c * yp;
746 // PhantomElement::calcEllipsePoints Calculate outline of a ellipse
749 // calcEllipsePoints ()
754 PhantomElement::calcEllipsePoints (double x[], double y[], const int pts, const double u, const double v)
756 calcArcPoints (x, y, m_nPoints, 0.0, 0.0, 1.0, 0.0, TWOPI); // make a unit circle
757 scale2d (x, y, m_nPoints, m_u, m_v); // scale to ellipse
762 * circle_pts Calculate number of points to use for circle segment
765 * n = circle_pts (theta)
766 * int n Number of points to use for arc
767 * double theta Length of arc in radians
771 PhantomElement::numCirclePoints (double theta)
773 theta = clamp (theta, 0., TWOPI);
775 return static_cast<int> (POINTS_PER_CIRCLE * theta / TWOPI + 1.5);
780 PhantomElement::clipLineWorldCoords (double& x1, double& y1, double& x2, double &y2) const
782 /* check if ray is outside of pelem extents */
783 double cx1 = x1, cy1 = y1, cx2 = x2, cy2 = y2;
784 if (! clip_rect (cx1, cy1, cx2, cy2, m_rectLimits))
787 // convert phantom coordinates to pelem coordinates
788 xform_mtx2 (m_xformPhmToObj, x1, y1);
789 xform_mtx2 (m_xformPhmToObj, x2, y2);
791 if (! clipLineNormalizedCoords (x1, y1, x2, y2))
794 // convert standard pelem coordinates back to phantom coordinates
795 xform_mtx2 (m_xformObjToPhm, x1, y1);
796 xform_mtx2 (m_xformObjToPhm, x2, y2);
803 * pelem_clip_line Clip pelem against an arbitrary line
806 * pelem_clip_line (pelem, x1, y1, x2, y2)
807 * PhantomElement& pelem; Pelem to be clipped
808 * double *x1, *y1, *x2, *y2 Endpoints of line to be clipped
811 * true if line passes through pelem
812 * (x1, y1, x2, y2 hold coordinates of new line)
813 * false if line do not pass through pelem
814 * (x1, y1, x2, y2 are undefined)
818 PhantomElement::clipLineNormalizedCoords (double& x1, double& y1, double& x2, double& y2) const
823 case PELEM_RECTANGLE:
825 rect[0] = -1.0; rect[1] = -1.0;
826 rect[2] = 1.0; rect[3] = 1.0;
827 accept = clip_rect (x1, y1, x2, y2, rect);
830 accept = clip_circle (x1, y1, x2, y2, 0.0, 0.0, 1.0, 0.0, 0.0);
833 accept = clip_triangle (x1, y1, x2, y2, 1.0, 1.0, true);
836 accept = clip_segment (x1, y1, x2, y2, m_u, m_v);
839 accept = clip_sector (x1, y1, x2, y2, m_u, m_v);
842 sys_error (ERR_WARNING, "Illegal pelem type %d [pelem_clip_line]", m_type);
850 // METHOD IDENTIFICATION
851 // PhantomElement::isPointInside Check if point is inside pelem
854 // is_point_inside (pelem, x, y, coord_type)
855 // double x, y Point to see if lies in pelem
856 // int coord_type Coordinate type (PELEM_COORD or PHM_COORD)
859 // true if point lies within pelem
860 // false if point lies outside of pelem
863 PhantomElement::isPointInside (double x, double y, const CoordType coord_type) const
865 if (coord_type == PHM_COORD) {
866 xform_mtx2 (m_xformPhmToObj, x, y);
867 } else if (coord_type != PELEM_COORD) {
868 sys_error(ERR_WARNING, "Illegal coordinate type in pelem_is_point_inside");
873 case PELEM_RECTANGLE:
874 if (x > 1. || x < -1. || y > 1. || y < -1.)
880 if (y < 0. || y > 1. - x || y > 1. + x)
886 if (x > 1. || x < -1. || y > 1. || y < -1.)
888 if (x * x + y * y > 1.) // check if inside unit circle
894 // for clipping segments & sectors, must NOT scale by (1/u, 1/v)
895 // because this destroys information about size of arc component
898 if (x > 1. || x < -1. || y > 0.)
899 return (false); // clip against y > 0
900 x *= m_u; // put back u & v scale
902 if (x * x + (y-m_v) * (y-m_v) > m_u * m_u + m_v * m_v)
903 return (false); // clip against circle, r = sqrt(@)
908 if (x > 1. || x < -1. || y > 1.) // extent
910 if (y > 1. - x || y > 1. + x) // triangle
911 return (false); // clip against triangle
912 x *= m_u; // circle: put back u & v scale
914 if (x * x + (y-m_v) * (y-m_v) > m_u * m_u + m_v * m_v)
915 return (false); // clip against circle
920 sys_error (ERR_WARNING, "Illegal pelem type in pelem_is_point_inside()");