|
|
1.1 ! root 1: .ds ZZ DEVELOPMENT PACKAGE ! 2: .TH POLYGON 3L "630 MTG" ! 3: .XE "polyf()" ! 4: .XE "ptinpoly()" ! 5: .SH NAME ! 6: polygon: polyf, ptinpoly \- polygon routines ! 7: .SH SYNOPSIS ! 8: .ft B ! 9: #include <dmd.h> ! 10: .sp ! 11: int polyf (bp, poly, np, t, f) ! 12: .sp ! 13: int ptinpoly (pt, poly, np) ! 14: .sp ! 15: Bitmap \(**bp; ! 16: .br ! 17: Point poly[ ]; ! 18: .br ! 19: short np; ! 20: .br ! 21: Texture16 \(**t; ! 22: .br ! 23: Code f; ! 24: .br ! 25: Point pt; ! 26: .SH DESCRIPTION ! 27: The ! 28: .I polyf ! 29: function ! 30: is used to fill a closed polygon defined by the ! 31: .I np ! 32: Points in the array of Points ! 33: .IR poly . ! 34: The Points are absolute with respect to the Bitmap ! 35: .I bp. ! 36: The polygon is filled with the Texture16 ! 37: .I t ! 38: using Code ! 39: .I f. ! 40: The ! 41: .I polyf ! 42: call ! 43: returns 0 if the polygon is filled and -1 if a memory allocation ! 44: error occurred during processing, in which case the polygon ! 45: is not filled. ! 46: .PP ! 47: The ! 48: .I ptinpoly ! 49: call ! 50: determines whether the Point ! 51: .I pt ! 52: is contained in the polygon defined by ! 53: .I poly ! 54: and ! 55: .I np. ! 56: The ! 57: .I ptinpoly ! 58: function ! 59: returns 1 if the Point is inside the polygon, ! 60: 0 if the Point is not inside the polygon, ! 61: and -1 if a memory allocation error occurs. ! 62: .PP ! 63: The polygon can consist of an arbitrary number of filled and unfilled ! 64: regions. ! 65: For example, a doughnut shape could be formed ! 66: without filling ! 67: the portion of the Bitmap corresponding to the hole of the doughnut. ! 68: This permits a preservation of any background information previously ! 69: placed in the Bitmap. ! 70: Each region, filled or unfilled, is delimited ! 71: by a Point whose x-coordinate has a value of ! 72: .I \s-1POLY_F\s+1 ! 73: (defined in \f3dmd.h\f1). ! 74: This Point in ! 75: .I poly ! 76: is ignored and merely serves as a flag indicating ! 77: the start of a new region. ! 78: There is always an assumed line connecting the first and last Point ! 79: of each region. ! 80: .SH EXAMPLE ! 81: The following code permits interactive drawing of ! 82: a polygon with interior regions, fills it, and then ! 83: uses \f2ptinpoly\f1 to determine if the mouse is inside the polygon. ! 84: Button 1 is used to draw the points, and button 2 sets a point to \f2POLY_F\f1. After the polygon fills, clicking button 1 with the mouse inside the polygon will ring the terminal bell. Clicking button 3 will exit ! 85: the drawing and exit the program. ! 86: .bp ! 87: .PP ! 88: .RS 3 ! 89: .nf ! 90: \s-1 ! 91: .ft CM ! 92: #include <dmd.h> ! 93: ! 94: Point npoly[1000]; ! 95: ! 96: main() ! 97: { ! 98: register int i, j; ! 99: register char c; ! 100: ! 101: request (MOUSE|KBD); ! 102: ! 103: i = 0; ! 104: for (;;) ! 105: { ! 106: while (i < 1000){ ! 107: wait (MOUSE); ! 108: if( button1 () ){ ! 109: npoly[i++] = mouse.xy; ! 110: point (&display, mouse.xy, ! 111: F_STORE); ! 112: sleep (10); ! 113: continue; ! 114: } ! 115: if( button2 () ){ ! 116: npoly[i++].x = POLY_F; ! 117: continue; ! 118: } ! 119: if( button3 () ) break; ! 120: } ! 121: polyf (&display, npoly, i, &T_black, ! 122: F_STORE); ! 123: ! 124: wait(MOUSE); ! 125: ! 126: while( !button3() ){ ! 127: wait (MOUSE); ! 128: if( button1() && ptinpoly ! 129: (mouse.xy, npoly, i) ) ! 130: ringbell(); ! 131: ! 132: } ! 133: break; ! 134: } ! 135: } ! 136: \fR ! 137: .fi ! 138: .RE ! 139: \s+1
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.