home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / ppc / ppcPolyCon.c < prev    next >
C/C++ Source or Header  |  1989-11-14  |  5KB  |  125 lines

  1. /*
  2.  * Copyright IBM Corporation 1987,1988,1989
  3.  *
  4.  * All Rights Reserved
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted,
  8.  * provided that the above copyright notice appear in all copies and that 
  9.  * both that copyright notice and this permission notice appear in
  10.  * supporting documentation, and that the name of IBM not be
  11.  * used in advertising or publicity pertaining to distribution of the
  12.  * software without specific, written prior permission.
  13.  *
  14.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  17.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  18.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  20.  * SOFTWARE.
  21.  *
  22. */
  23.  
  24. /***********************************************************
  25. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  26. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  27.  
  28.                         All Rights Reserved
  29.  
  30. Permission to use, copy, modify, and distribute this software and its 
  31. documentation for any purpose and without fee is hereby granted, 
  32. provided that the above copyright notice appear in all copies and that
  33. both that copyright notice and this permission notice appear in 
  34. supporting documentation, and that the names of Digital or MIT not be
  35. used in advertising or publicity pertaining to distribution of the
  36. software without specific, written prior permission.  
  37.  
  38. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  39. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  40. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  41. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  42. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  43. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  44. SOFTWARE.
  45.  
  46. ******************************************************************/
  47.  
  48. /* $Header: /andrew/X11/R3src/tape/server/ddx/ibm/ppc/RCS/ppcPolyCon.c,v 9.1 88/10/24 04:00:56 paul Exp $ */
  49. /* $Source: /andrew/X11/R3src/tape/server/ddx/ibm/ppc/RCS/ppcPolyCon.c,v $ */
  50.  
  51. #ifndef lint
  52. static char *rcsid = "$Header: /andrew/X11/R3src/tape/server/ddx/ibm/ppc/RCS/ppcPolyCon.c,v 9.1 88/10/24 04:00:56 paul Exp $";
  53. #endif
  54.  
  55. #include "X.h"
  56. #include "gcstruct.h"
  57. #include "windowstr.h"
  58. #include "pixmapstr.h"
  59. #include "mifpoly.h"
  60.  
  61. static int GetFPolyYBounds();
  62.  
  63. /*
  64.  *    Written by Todd Newman; April. 1987.
  65.  *
  66.  *    Fill a convex polygon.  If the given polygon
  67.  *    is not convex, then the result is undefined.
  68.  *    The algorithm is to order the edges from smallest
  69.  *    y to largest by partitioning the array into a left
  70.  *    edge list and a right edge list.  The algorithm used
  71.  *    to traverse each edge is digital differencing analyzer
  72.  *    line algorithm with y as the major axis. There's some funny linear
  73.  *    interpolation involved because of the subpixel postioning.
  74.  *
  75.  *    Given the opportunity to write non-portable code, I would replace
  76.  *     this with a fixed point extended precision Bresenham line algorithm.
  77.  *    Instead of doubles in the SppPointRecs, I'd use 64 bit fixed point
  78.  *    values.  I'd have to write a fixed point math pack in assembler,
  79.  *    but these things are relatively straight forward. (Alas, not portable.)
  80.  *    
  81.  *    It can be shown that given 16 bit values for x and y, there's no
  82.  *    room to extend the precision and still fit intermediate results in
  83.  *    a 32 bit integer.  It should also be clear that trying to write a
  84.  *    extended precision math pack in C would not produce code that runs
  85.  *     much faster than your average floating point coprocessor.  Even
  86.  *    floating point emulation should be able to run faster if the assembly
  87.  *    language coding is handled at all well.
  88.  *
  89.  *    "So why not at least use float, instead of double," my friends ask
  90.  *    me.  Well, C is going to cast everything to double as soon as you
  91.  *     try to do anything with it anyway.  (Check out K&R.)  I'd rather
  92.  *    trade a little space and skip all the superflous type conversions.
  93.  *    (This decision could be revisited if you have an ANSI C compiler.)
  94.  *
  95.  *    So, in sum, I apologize for doing all the wide lines with doubles,
  96.  *    but it seems the best trade off  of complexity, performance, and
  97.  *    time pressure.
  98.  */
  99. void
  100. ppcFillSppPoly(dst, pgc, count, ptsIn, xTrans, yTrans)
  101.     DrawablePtr     dst;
  102.     GCPtr        pgc;
  103.     int            count;          /* number of points */
  104.     SppPointPtr     ptsIn;          /* the points */
  105.     int            xTrans, yTrans;    /* Translate each point by this */
  106. {
  107.     int            i,nOut= 0;
  108.     DDXPointPtr     ptsOut;
  109.  
  110.     ptsOut = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * count);
  111.  
  112.     if(!ptsOut || (count < 3)) {
  113.     DEALLOCATE_LOCAL(ptsOut);
  114.     return;
  115.     }
  116.  
  117.     for (i=0;i<count;i++) {
  118.     ptsOut[i].x= (ptsIn[i].x+xTrans);
  119.     ptsOut[i].y= (ptsIn[i].y+yTrans);
  120.     }
  121.  
  122.     (*pgc->ops->FillPolygon)(dst, pgc, Convex, CoordModeOrigin, count, ptsOut);
  123.     DEALLOCATE_LOCAL(ptsOut);
  124. }
  125.