home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / assembly / clip.lha / polyclip2.code < prev   
Mailbox/MIME Entity  |  1989-10-24  |  6.1 KB

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text

This file was processed as: Mailbox/MIME Entity (archive/mbox).

You can browse this item here: polyclip2.code

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert Mailbox/MIME Entity (archive/mbox) magic Supported
100% dexvert Internet Message Format (text/imf) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file Mailbox text, 1st line "From cm26+@andrew.cmu.edu Tue May 2 13:37:33 1989" default
99% file C source text default
98% file C source, ASCII text default
100% TrID E-Mail message (Var. 2) default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried x-fmt/111 Plain Text File default
100% detectItEasy Format: plain text[LF] default (weak)
100% xdgMime application/mbox default



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 46 72 6f 6d 20 63 6d 32 | 36 2b 40 61 6e 64 72 65 |From cm2|6+@andre|
|00000010| 77 2e 63 6d 75 2e 65 64 | 75 20 54 75 65 20 4d 61 |w.cmu.ed|u Tue Ma|
|00000020| 79 20 20 32 20 31 33 3a | 33 37 3a 33 33 20 31 39 |y 2 13:|37:33 19|
|00000030| 38 39 0a 50 61 74 68 3a | 20 6c 65 61 68 21 63 73 |89.Path:| leah!cs|
|00000040| 64 34 2e 6d 69 6c 77 2e | 77 69 73 63 2e 65 64 75 |d4.milw.|wisc.edu|
|00000050| 21 6d 61 69 6c 72 75 73 | 21 62 62 6e 21 72 6f 63 |!mailrus|!bbn!roc|
|00000060| 68 65 73 74 65 72 21 70 | 74 2e 63 73 2e 63 6d 75 |hester!p|t.cs.cmu|
|00000070| 2e 65 64 75 21 61 6e 64 | 72 65 77 2e 63 6d 75 2e |.edu!and|rew.cmu.|
|00000080| 65 64 75 21 63 6d 32 36 | 2b 0a 46 72 6f 6d 3a 20 |edu!cm26|+.From: |
|00000090| 63 6d 32 36 2b 40 61 6e | 64 72 65 77 2e 63 6d 75 |cm26+@an|drew.cmu|
|000000a0| 2e 65 64 75 20 28 43 75 | 72 74 20 4d 63 44 6f 77 |.edu (Cu|rt McDow|
|000000b0| 65 6c 6c 29 0a 4e 65 77 | 73 67 72 6f 75 70 73 3a |ell).New|sgroups:|
|000000c0| 20 63 6f 6d 70 2e 67 72 | 61 70 68 69 63 73 0a 53 | comp.gr|aphics.S|
|000000d0| 75 62 6a 65 63 74 3a 20 | 52 65 3a 20 70 6f 6c 79 |ubject: |Re: poly|
|000000e0| 67 6f 6e 20 63 6c 69 70 | 70 69 6e 67 20 61 6c 67 |gon clip|ping alg|
|000000f0| 2e 0a 4d 65 73 73 61 67 | 65 2d 49 44 3a 20 3c 38 |..Messag|e-ID: <8|
|00000100| 59 4c 53 52 52 79 30 30 | 6a 61 49 4d 59 66 31 4e |YLSRRy00|jaIMYf1N|
|00000110| 68 40 61 6e 64 72 65 77 | 2e 63 6d 75 2e 65 64 75 |h@andrew|.cmu.edu|
|00000120| 3e 0a 44 61 74 65 3a 20 | 32 20 4d 61 79 20 38 39 |>.Date: |2 May 89|
|00000130| 20 31 37 3a 33 37 3a 33 | 33 20 47 4d 54 0a 52 65 | 17:37:3|3 GMT.Re|
|00000140| 66 65 72 65 6e 63 65 73 | 3a 20 3c 35 36 32 40 6f |ferences|: <562@o|
|00000150| 75 63 73 61 63 65 2e 63 | 73 2e 4f 48 49 4f 55 2e |ucsace.c|s.OHIOU.|
|00000160| 45 44 55 3e 0a 44 69 73 | 74 72 69 62 75 74 69 6f |EDU>.Dis|tributio|
|00000170| 6e 3a 20 75 73 61 0a 4f | 72 67 61 6e 69 7a 61 74 |n: usa.O|rganizat|
|00000180| 69 6f 6e 3a 20 43 61 72 | 6e 65 67 69 65 20 49 6e |ion: Car|negie In|
|00000190| 73 74 69 74 75 74 65 20 | 6f 66 20 54 65 63 68 6e |stitute |of Techn|
|000001a0| 6f 6c 6f 67 79 2c 20 43 | 61 72 6e 65 67 69 65 20 |ology, C|arnegie |
|000001b0| 4d 65 6c 6c 6f 6e 2c 20 | 50 69 74 74 73 62 75 72 |Mellon, |Pittsbur|
|000001c0| 67 68 2c 20 50 41 0a 4c | 69 6e 65 73 3a 20 32 33 |gh, PA.L|ines: 23|
|000001d0| 35 0a 49 6e 2d 52 65 70 | 6c 79 2d 54 6f 3a 20 3c |5.In-Rep|ly-To: <|
|000001e0| 35 36 32 40 6f 75 63 73 | 61 63 65 2e 63 73 2e 4f |562@oucs|ace.cs.O|
|000001f0| 48 49 4f 55 2e 45 44 55 | 3e 0a 0a 54 68 65 20 66 |HIOU.EDU|>..The f|
|00000200| 6f 6c 6c 6f 77 69 6e 67 | 20 69 73 20 61 20 70 61 |ollowing| is a pa|
|00000210| 63 6b 61 67 65 20 77 68 | 69 63 68 20 6d 61 69 6e |ckage wh|ich main|
|00000220| 74 61 69 6e 73 20 70 6f | 6c 79 67 6f 6e 73 20 61 |tains po|lygons a|
|00000230| 6e 64 20 69 6e 63 6c 75 | 64 65 73 20 61 0a 72 6f |nd inclu|des a.ro|
|00000240| 75 74 69 6e 65 20 74 6f | 20 63 6c 69 70 20 70 6f |utine to| clip po|
|00000250| 6c 79 67 6f 6e 73 20 74 | 6f 20 61 20 72 65 63 74 |lygons t|o a rect|
|00000260| 61 6e 67 6c 65 2e 20 20 | 49 74 20 69 73 20 77 72 |angle. |It is wr|
|00000270| 69 74 74 65 6e 20 69 6e | 20 61 6e 0a 6f 62 6a 65 |itten in| an.obje|
|00000280| 63 74 2d 6f 72 69 65 6e | 74 65 64 20 73 74 79 6c |ct-orien|ted styl|
|00000290| 65 2e 20 20 49 74 20 77 | 6f 72 6b 73 20 71 75 69 |e. It w|orks qui|
|000002a0| 74 65 20 77 65 6c 6c 2e | 20 20 54 68 65 20 66 69 |te well.| The fi|
|000002b0| 72 73 74 20 66 69 6c 65 | 20 69 73 20 61 6e 0a 65 |rst file| is an.e|
|000002c0| 78 61 6d 70 6c 65 20 6f | 66 20 68 6f 77 20 79 6f |xample o|f how yo|
|000002d0| 75 27 64 20 70 75 74 20 | 69 74 20 74 6f 20 75 73 |u'd put |it to us|
|000002e0| 65 2c 20 74 68 65 20 73 | 65 63 6f 6e 64 20 69 73 |e, the s|econd is|
|000002f0| 20 61 20 73 69 6d 70 6c | 65 20 64 65 66 69 6e 69 | a simpl|e defini|
|00000300| 74 69 6f 6e 20 6f 66 0a | 61 20 76 69 65 77 70 6f |tion of.|a viewpo|
|00000310| 72 74 20 28 63 6c 69 70 | 70 69 6e 67 20 72 65 63 |rt (clip|ping rec|
|00000320| 74 61 6e 67 6c 65 29 2c | 20 74 68 65 20 74 68 69 |tangle),| the thi|
|00000330| 72 64 20 69 73 20 74 68 | 65 20 70 6f 6c 79 67 6f |rd is th|e polygo|
|00000340| 6e 20 68 65 61 64 65 72 | 20 66 69 6c 65 20 74 6f |n header| file to|
|00000350| 0a 62 65 20 69 6e 63 6c | 75 64 65 64 20 62 79 20 |.be incl|uded by |
|00000360| 6f 74 68 65 72 20 6d 6f | 64 75 6c 65 73 2c 20 61 |other mo|dules, a|
|00000370| 6e 64 20 74 68 65 20 66 | 6f 75 72 74 68 20 69 73 |nd the f|ourth is|
|00000380| 20 74 68 65 20 70 6f 6c | 79 67 6f 6e 20 63 6f 64 | the pol|ygon cod|
|00000390| 65 20 66 69 6c 65 2e 0a | 0a 43 75 72 74 20 4d 63 |e file..|.Curt Mc|
|000003a0| 44 6f 77 65 6c 6c 0a 43 | 61 72 6e 65 67 69 65 20 |Dowell.C|arnegie |
|000003b0| 4d 65 6c 6c 6f 6e 20 55 | 6e 69 76 65 72 73 69 74 |Mellon U|niversit|
|000003c0| 79 0a 0a 2d 2d 2d 20 46 | 49 4c 45 20 45 58 41 4d |y..--- F|ILE EXAM|
|000003d0| 50 4c 45 2e 43 20 2d 2d | 2d 0a 23 69 6e 63 6c 75 |PLE.C --|-.#inclu|
|000003e0| 64 65 20 3c 73 74 64 69 | 6f 2e 68 3e 0a 23 69 6e |de <stdi|o.h>.#in|
|000003f0| 63 6c 75 64 65 20 3c 70 | 6f 6c 79 67 6f 6e 2e 68 |clude <p|olygon.h|
|00000400| 3e 0a 23 69 6e 63 6c 75 | 64 65 20 3c 76 69 65 77 |>.#inclu|de <view|
|00000410| 70 6f 72 74 2e 68 3e 0a | 0a 6d 61 69 6e 28 61 72 |port.h>.|.main(ar|
|00000420| 67 63 2c 20 61 72 67 76 | 29 0a 63 68 61 72 20 2a |gc, argv|).char *|
|00000430| 2a 61 72 67 76 3b 0a 7b | 0a 20 20 20 20 73 74 72 |*argv;.{|. str|
|00000440| 75 63 74 20 70 6f 6c 79 | 67 6f 6e 20 2a 70 3b 0a |uct poly|gon *p;.|
|00000450| 20 20 20 20 73 74 72 75 | 63 74 20 76 69 65 77 70 | stru|ct viewp|
|00000460| 6f 72 74 20 76 3b 0a 0a | 20 20 20 20 70 20 3d 20 |ort v;..| p = |
|00000470| 70 6f 6c 79 67 6f 6e 5f | 4e 65 77 28 29 3b 0a 0a |polygon_|New();..|
|00000480| 20 20 20 20 70 6f 6c 79 | 67 6f 6e 5f 49 6e 73 65 | poly|gon_Inse|
|00000490| 72 74 28 70 2c 20 31 30 | 2c 20 31 30 30 29 3b 0a |rt(p, 10|, 100);.|
|000004a0| 20 20 20 20 70 6f 6c 79 | 67 6f 6e 5f 49 6e 73 65 | poly|gon_Inse|
|000004b0| 72 74 28 70 2c 20 2e 2e | 2e 2c 20 2e 2e 2e 29 3b |rt(p, ..|., ...);|
|000004c0| 0a 20 20 20 20 2e 2e 2e | 20 65 74 63 20 2e 2e 2e |. ...| etc ...|
|000004d0| 3b 0a 0a 20 20 20 20 76 | 2e 6c 65 66 74 20 3d 20 |;.. v|.left = |
|000004e0| 31 3b 0a 20 20 20 20 76 | 2e 74 6f 70 20 3d 20 2e |1;. v|.top = .|
|000004f0| 2e 2e 3b 0a 20 20 20 20 | 76 2e 77 69 64 74 68 20 |..;. |v.width |
|00000500| 3d 20 2e 2e 2e 3b 0a 20 | 20 20 20 76 2e 68 65 69 |= ...;. | v.hei|
|00000510| 67 68 74 20 3d 20 2e 2e | 2e 3b 0a 0a 20 20 20 20 |ght = ..|.;.. |
|00000520| 70 6f 6c 79 67 6f 6e 5f | 43 6c 69 70 28 70 2c 20 |polygon_|Clip(p, |
|00000530| 26 76 29 3b 0a 0a 20 20 | 20 20 70 72 69 6e 74 66 |&v);.. | printf|
|00000540| 28 22 43 6c 69 70 70 65 | 64 20 70 6f 6c 79 67 6f |("Clippe|d polygo|
|00000550| 6e 3a 5c 6e 22 29 3b 0a | 0a 20 20 20 20 66 6f 72 |n:\n");.|. for|
|00000560| 20 28 69 20 3d 20 30 3b | 20 69 20 3c 20 70 2d 3e | (i = 0;| i < p->|
|00000570| 6e 3b 20 69 2b 2b 29 0a | 20 20 20 20 20 20 20 20 |n; i++).| |
|00000580| 70 72 69 6e 74 66 28 22 | 28 25 64 2c 25 64 29 5c |printf("|(%d,%d)\|
|00000590| 6e 22 2c 20 70 2d 3e 78 | 5b 69 5d 2c 20 70 2d 3e |n", p->x|[i], p->|
|000005a0| 79 5b 69 5d 29 3b 0a 7d | 0a 0a 2d 2d 2d 20 46 49 |y[i]);.}|..--- FI|
|000005b0| 4c 45 20 56 49 45 57 50 | 4f 52 54 2e 48 20 2d 2d |LE VIEWP|ORT.H --|
|000005c0| 2d 0a 73 74 72 75 63 74 | 20 76 69 65 77 70 6f 72 |-.struct| viewpor|
|000005d0| 74 20 7b 0a 20 20 20 20 | 69 6e 74 20 6c 65 66 74 |t {. |int left|
|000005e0| 2c 20 74 6f 70 3b 0a 20 | 20 20 20 69 6e 74 20 77 |, top;. | int w|
|000005f0| 69 64 74 68 2c 20 68 65 | 69 67 68 74 3b 0a 7d 3b |idth, he|ight;.};|
|00000600| 0a 2d 2d 2d 20 46 49 4c | 45 20 50 4f 4c 59 47 4f |.--- FIL|E POLYGO|
|00000610| 4e 2e 48 20 2d 2d 2d 0a | 2f 2a 0a 20 2a 20 50 6f |N.H ---.|/*. * Po|
|00000620| 6c 79 67 6f 6e 20 64 61 | 74 61 20 73 74 72 75 63 |lygon da|ta struc|
|00000630| 74 75 72 65 0a 20 2a 2f | 0a 0a 73 74 72 75 63 74 |ture. */|..struct|
|00000640| 20 70 6f 6c 79 67 6f 6e | 20 7b 0a 20 20 20 20 73 | polygon| {. s|
|00000650| 68 6f 72 74 20 6e 2c 20 | 61 6c 6c 6f 63 3b 0a 20 |hort n, |alloc;. |
|00000660| 20 20 20 73 68 6f 72 74 | 20 2a 78 2c 20 2a 79 3b | short| *x, *y;|
|00000670| 0a 7d 3b 0a 0a 23 64 65 | 66 69 6e 65 20 70 6f 6c |.};..#de|fine pol|
|00000680| 79 67 6f 6e 5f 43 6c 65 | 61 72 28 70 29 20 28 28 |ygon_Cle|ar(p) ((|
|00000690| 70 29 2d 3e 6e 20 3d 20 | 30 29 0a 0a 65 78 74 65 |p)->n = |0)..exte|
|000006a0| 72 6e 20 73 74 72 75 63 | 74 20 70 6f 6c 79 67 6f |rn struc|t polygo|
|000006b0| 6e 20 2a 70 6f 6c 79 67 | 6f 6e 5f 4e 65 77 28 29 |n *polyg|on_New()|
|000006c0| 3b 0a 65 78 74 65 72 6e | 20 76 6f 69 64 20 70 6f |;.extern| void po|
|000006d0| 6c 79 67 6f 6e 5f 49 6e | 73 65 72 74 28 29 3b 0a |lygon_In|sert();.|
|000006e0| 65 78 74 65 72 6e 20 76 | 6f 69 64 20 70 6f 6c 79 |extern v|oid poly|
|000006f0| 67 6f 6e 5f 44 65 73 74 | 72 6f 79 28 29 3b 0a 65 |gon_Dest|roy();.e|
|00000700| 78 74 65 72 6e 20 76 6f | 69 64 20 70 6f 6c 79 67 |xtern vo|id polyg|
|00000710| 6f 6e 5f 43 6c 69 70 28 | 29 3b 0a 2d 2d 2d 20 46 |on_Clip(|);.--- F|
|00000720| 49 4c 45 20 50 4f 4c 59 | 47 4f 4e 2e 43 20 2d 2d |ILE POLY|GON.C --|
|00000730| 2d 0a 2f 2a 0a 20 2a 20 | 50 6f 6c 79 67 6f 6e 20 |-./*. * |Polygon |
|00000740| 6f 62 6a 65 63 74 0a 20 | 2a 20 62 79 20 43 75 72 |object. |* by Cur|
|00000750| 74 20 4d 63 44 6f 77 65 | 6c 6c 2c 20 43 4d 55 20 |t McDowe|ll, CMU |
|00000760| 49 6e 66 6f 72 6d 61 74 | 69 6f 6e 20 54 65 63 68 |Informat|ion Tech|
|00000770| 6e 6f 6c 6f 67 79 20 43 | 65 6e 74 65 72 0a 20 2a |nology C|enter. *|
|00000780| 0a 20 2a 20 54 68 69 73 | 20 63 6f 64 65 20 63 6f |. * This| code co|
|00000790| 6d 65 73 20 75 6e 64 65 | 72 20 74 68 65 20 49 42 |mes unde|r the IB|
|000007a0| 4d 20 43 6f 70 79 72 69 | 67 68 74 20 6f 66 20 74 |M Copyri|ght of t|
|000007b0| 68 65 20 41 6e 64 72 65 | 77 20 54 6f 6f 6c 6b 69 |he Andre|w Toolki|
|000007c0| 74 2c 0a 20 2a 20 77 68 | 69 63 68 20 69 73 20 74 |t,. * wh|ich is t|
|000007d0| 6f 20 73 61 79 2c 20 79 | 6f 75 20 63 61 6e 20 64 |o say, y|ou can d|
|000007e0| 6f 20 61 6e 79 74 68 69 | 6e 67 20 62 75 74 20 73 |o anythi|ng but s|
|000007f0| 65 6c 6c 20 69 74 2e 0a | 20 2a 2f 0a 0a 23 69 6e |ell it..| */..#in|
|00000800| 63 6c 75 64 65 20 3c 70 | 6f 6c 79 67 6f 6e 2e 68 |clude <p|olygon.h|
|00000810| 3e 0a 23 69 6e 63 6c 75 | 64 65 20 3c 76 69 65 77 |>.#inclu|de <view|
|00000820| 70 6f 72 74 2e 68 3e 0a | 0a 63 68 61 72 20 2a 6d |port.h>.|.char *m|
|00000830| 61 6c 6c 6f 63 28 29 2c | 20 2a 72 65 61 6c 6c 6f |alloc(),| *reallo|
|00000840| 63 28 29 3b 0a 0a 2f 2a | 20 53 69 6d 69 6c 61 72 |c();../*| Similar|
|00000850| 20 74 72 69 61 6e 67 6c | 65 20 6d 61 63 72 6f 3a | triangl|e macro:|
|00000860| 0a 20 2a 20 47 69 76 65 | 6e 20 74 68 72 65 65 20 |. * Give|n three |
|00000870| 63 6f 6f 72 64 69 6e 61 | 74 65 73 20 61 6c 6f 6e |coordina|tes alon|
|00000880| 67 20 61 78 69 73 20 31 | 20 61 6e 64 20 74 77 6f |g axis 1| and two|
|00000890| 0a 20 2a 20 61 6c 6f 6e | 67 20 61 78 69 73 20 32 |. * alon|g axis 2|
|000008a0| 2c 20 66 69 6e 64 73 20 | 74 68 65 20 74 68 69 72 |, finds |the thir|
|000008b0| 64 20 6f 6e 20 61 78 69 | 73 20 32 20 77 68 69 63 |d on axi|s 2 whic|
|000008c0| 68 0a 20 2a 20 66 61 6c | 6c 73 20 62 65 74 77 65 |h. * fal|ls betwe|
|000008d0| 65 6e 20 74 68 65 20 74 | 77 6f 20 6f 6e 20 61 78 |en the t|wo on ax|
|000008e0| 69 73 20 31 2e 20 2a 2f | 0a 0a 23 64 65 66 69 6e |is 1. */|..#defin|
|000008f0| 65 20 43 6c 69 70 43 61 | 73 65 28 6c 65 66 74 2c |e ClipCa|se(left,|
|00000900| 20 6d 69 64 64 6c 65 2c | 20 72 69 67 68 74 2c 20 | middle,| right, |
|00000910| 73 74 61 72 74 2c 20 65 | 6e 64 29 20 5c 0a 20 20 |start, e|nd) \. |
|00000920| 20 20 20 28 28 28 73 74 | 61 72 74 29 20 2a 20 28 | (((st|art) * (|
|00000930| 28 72 69 67 68 74 29 20 | 2d 20 28 6d 69 64 64 6c |(right) |- (middl|
|00000940| 65 29 29 20 2b 20 5c 0a | 20 20 20 20 20 20 20 28 |e)) + \.| (|
|00000950| 65 6e 64 29 20 2a 20 28 | 28 6d 69 64 64 6c 65 29 |end) * (|(middle)|
|00000960| 20 2d 20 28 6c 65 66 74 | 29 29 29 20 2f 20 28 28 | - (left|))) / ((|
|00000970| 72 69 67 68 74 29 20 2d | 20 28 6c 65 66 74 29 29 |right) -| (left))|
|00000980| 29 0a 0a 2f 2a 20 50 6f | 6c 79 67 6f 6e 20 6d 61 |)../* Po|lygon ma|
|00000990| 6e 69 70 75 6c 61 74 69 | 6f 6e 3a 0a 20 2a 20 44 |nipulati|on:. * D|
|000009a0| 79 6e 61 6d 69 63 61 6c | 6c 79 20 61 6c 6c 6f 63 |ynamical|ly alloc|
|000009b0| 61 74 65 64 20 70 6f 6c | 79 67 6f 6e 20 73 74 72 |ated pol|ygon str|
|000009c0| 75 63 74 75 72 65 0a 20 | 2a 20 55 73 65 20 74 68 |ucture. |* Use th|
|000009d0| 69 73 20 74 6f 20 63 72 | 65 61 74 65 20 61 6e 64 |is to cr|eate and|
|000009e0| 20 64 65 73 74 72 6f 79 | 20 70 6f 6c 79 67 6f 6e | destroy| polygon|
|000009f0| 73 20 74 6f 20 62 65 0a | 20 2a 20 70 61 73 73 65 |s to be.| * passe|
|00000a00| 64 20 74 6f 20 74 68 65 | 20 63 6c 69 70 70 69 6e |d to the| clippin|
|00000a10| 67 20 61 6e 64 20 66 69 | 6c 6c 69 6e 67 20 72 6f |g and fi|lling ro|
|00000a20| 75 74 69 6e 65 73 2e 20 | 2a 2f 0a 0a 73 74 72 75 |utines. |*/..stru|
|00000a30| 63 74 20 70 6f 6c 79 67 | 6f 6e 20 2a 70 6f 6c 79 |ct polyg|on *poly|
|00000a40| 67 6f 6e 5f 4e 65 77 28 | 29 0a 7b 0a 20 20 20 20 |gon_New(|).{. |
|00000a50| 73 74 72 75 63 74 20 70 | 6f 6c 79 67 6f 6e 20 2a |struct p|olygon *|
|00000a60| 70 3b 0a 20 20 20 20 70 | 20 3d 20 28 73 74 72 75 |p;. p| = (stru|
|00000a70| 63 74 20 70 6f 6c 79 67 | 6f 6e 20 2a 29 20 6d 61 |ct polyg|on *) ma|
|00000a80| 6c 6c 6f 63 28 73 69 7a | 65 6f 66 20 28 73 74 72 |lloc(siz|eof (str|
|00000a90| 75 63 74 20 70 6f 6c 79 | 67 6f 6e 29 29 3b 0a 20 |uct poly|gon));. |
|00000aa0| 20 20 20 70 2d 3e 61 6c | 6c 6f 63 20 3d 20 38 3b | p->al|loc = 8;|
|00000ab0| 0a 20 20 20 20 70 2d 3e | 78 20 3d 20 28 73 68 6f |. p->|x = (sho|
|00000ac0| 72 74 20 2a 29 20 6d 61 | 6c 6c 6f 63 28 70 2d 3e |rt *) ma|lloc(p->|
|00000ad0| 61 6c 6c 6f 63 20 2a 20 | 73 69 7a 65 6f 66 20 28 |alloc * |sizeof (|
|00000ae0| 73 68 6f 72 74 29 29 3b | 0a 20 20 20 20 70 2d 3e |short));|. p->|
|00000af0| 79 20 3d 20 28 73 68 6f | 72 74 20 2a 29 20 6d 61 |y = (sho|rt *) ma|
|00000b00| 6c 6c 6f 63 28 70 2d 3e | 61 6c 6c 6f 63 20 2a 20 |lloc(p->|alloc * |
|00000b10| 73 69 7a 65 6f 66 20 28 | 73 68 6f 72 74 29 29 3b |sizeof (|short));|
|00000b20| 0a 20 20 20 20 70 2d 3e | 6e 20 3d 20 30 3b 0a 20 |. p->|n = 0;. |
|00000b30| 20 20 20 72 65 74 75 72 | 6e 20 70 3b 0a 7d 0a 0a | retur|n p;.}..|
|00000b40| 76 6f 69 64 20 70 6f 6c | 79 67 6f 6e 5f 49 6e 73 |void pol|ygon_Ins|
|00000b50| 65 72 74 28 70 2c 20 78 | 2c 20 79 29 0a 73 74 72 |ert(p, x|, y).str|
|00000b60| 75 63 74 20 70 6f 6c 79 | 67 6f 6e 20 2a 70 3b 0a |uct poly|gon *p;.|
|00000b70| 73 68 6f 72 74 20 78 2c | 20 79 3b 0a 7b 0a 20 20 |short x,| y;.{. |
|00000b80| 20 20 69 66 20 28 70 2d | 3e 6e 20 3d 3d 20 70 2d | if (p-|>n == p-|
|00000b90| 3e 61 6c 6c 6f 63 29 20 | 7b 0a 20 20 20 20 20 20 |>alloc) |{. |
|00000ba0| 20 20 70 2d 3e 61 6c 6c | 6f 63 20 2a 3d 20 32 3b | p->all|oc *= 2;|
|00000bb0| 0a 20 20 20 20 20 20 20 | 20 70 2d 3e 78 20 3d 20 |. | p->x = |
|00000bc0| 28 73 68 6f 72 74 20 2a | 29 20 72 65 61 6c 6c 6f |(short *|) reallo|
|00000bd0| 63 28 70 2d 3e 78 2c 20 | 70 2d 3e 61 6c 6c 6f 63 |c(p->x, |p->alloc|
|00000be0| 20 2a 20 73 69 7a 65 6f | 66 20 28 73 68 6f 72 74 | * sizeo|f (short|
|00000bf0| 29 29 3b 0a 20 20 20 20 | 20 20 20 20 70 2d 3e 79 |));. | p->y|
|00000c00| 20 3d 20 28 73 68 6f 72 | 74 20 2a 29 20 72 65 61 | = (shor|t *) rea|
|00000c10| 6c 6c 6f 63 28 70 2d 3e | 79 2c 20 70 2d 3e 61 6c |lloc(p->|y, p->al|
|00000c20| 6c 6f 63 20 2a 20 73 69 | 7a 65 6f 66 20 28 73 68 |loc * si|zeof (sh|
|00000c30| 6f 72 74 29 29 3b 0a 20 | 20 20 20 7d 0a 20 20 20 |ort));. | }. |
|00000c40| 20 70 2d 3e 78 5b 70 2d | 3e 6e 5d 20 3d 20 78 3b | p->x[p-|>n] = x;|
|00000c50| 0a 20 20 20 20 70 2d 3e | 79 5b 70 2d 3e 6e 5d 20 |. p->|y[p->n] |
|00000c60| 3d 20 79 3b 0a 20 20 20 | 20 70 2d 3e 6e 2b 2b 3b |= y;. | p->n++;|
|00000c70| 0a 7d 0a 0a 76 6f 69 64 | 20 70 6f 6c 79 67 6f 6e |.}..void| polygon|
|00000c80| 5f 44 65 73 74 72 6f 79 | 28 70 29 0a 73 74 72 75 |_Destroy|(p).stru|
|00000c90| 63 74 20 70 6f 6c 79 67 | 6f 6e 20 2a 70 3b 0a 7b |ct polyg|on *p;.{|
|00000ca0| 0a 20 20 20 20 66 72 65 | 65 28 70 2d 3e 78 29 3b |. fre|e(p->x);|
|00000cb0| 0a 20 20 20 20 66 72 65 | 65 28 70 2d 3e 79 29 3b |. fre|e(p->y);|
|00000cc0| 0a 20 20 20 20 66 72 65 | 65 28 70 29 3b 0a 7d 0a |. fre|e(p);.}.|
|00000cd0| 0a 2f 2a 0a 20 2a 20 43 | 6c 69 70 20 50 6f 6c 79 |./*. * C|lip Poly|
|00000ce0| 67 6f 6e 20 61 73 73 6f | 63 69 61 74 65 64 20 63 |gon asso|ciated c|
|00000cf0| 6f 64 65 0a 20 2a 2f 0a | 0a 23 64 65 66 69 6e 65 |ode. */.|.#define|
|00000d00| 20 65 64 67 65 5f 4c 45 | 46 54 20 20 20 20 20 20 | edge_LE|FT |
|00000d10| 20 30 0a 23 64 65 66 69 | 6e 65 20 65 64 67 65 5f | 0.#defi|ne edge_|
|00000d20| 52 49 47 48 54 20 20 20 | 20 20 20 31 0a 23 64 65 |RIGHT | 1.#de|
|00000d30| 66 69 6e 65 20 65 64 67 | 65 5f 41 42 4f 56 45 20 |fine edg|e_ABOVE |
|00000d40| 20 20 20 20 20 32 0a 23 | 64 65 66 69 6e 65 20 65 | 2.#|define e|
|00000d50| 64 67 65 5f 42 45 4c 4f | 57 20 20 20 20 20 20 33 |dge_BELO|W 3|
|00000d60| 0a 0a 73 74 61 74 69 63 | 20 73 68 6f 72 74 20 49 |..static| short I|
|00000d70| 6e 73 69 64 65 28 78 2c | 20 79 2c 20 76 2c 20 77 |nside(x,| y, v, w|
|00000d80| 68 69 63 68 29 0a 73 68 | 6f 72 74 20 78 2c 20 79 |hich).sh|ort x, y|
|00000d90| 3b 0a 73 74 72 75 63 74 | 20 76 69 65 77 70 6f 72 |;.struct| viewpor|
|00000da0| 74 20 2a 76 3b 0a 73 68 | 6f 72 74 20 77 68 69 63 |t *v;.sh|ort whic|
|00000db0| 68 3b 0a 7b 0a 20 20 20 | 20 73 77 69 74 63 68 20 |h;.{. | switch |
|00000dc0| 28 77 68 69 63 68 29 20 | 7b 0a 20 20 20 20 20 20 |(which) |{. |
|00000dd0| 20 20 63 61 73 65 20 65 | 64 67 65 5f 41 42 4f 56 | case e|dge_ABOV|
|00000de0| 45 3a 0a 20 20 20 20 20 | 20 20 20 20 20 20 20 72 |E:. | r|
|00000df0| 65 74 75 72 6e 20 28 79 | 20 3e 3d 20 76 2d 3e 74 |eturn (y| >= v->t|
|00000e00| 6f 70 29 3b 0a 20 20 20 | 20 20 20 20 20 63 61 73 |op);. | cas|
|00000e10| 65 20 65 64 67 65 5f 42 | 45 4c 4f 57 3a 0a 20 20 |e edge_B|ELOW:. |
|00000e20| 20 20 20 20 20 20 20 20 | 20 20 72 65 74 75 72 6e | | return|
|00000e30| 20 28 79 20 3c 20 76 2d | 3e 74 6f 70 20 2b 20 76 | (y < v-|>top + v|
|00000e40| 2d 3e 68 65 69 67 68 74 | 29 3b 0a 20 20 20 20 20 |->height|);. |
|00000e50| 20 20 20 63 61 73 65 20 | 65 64 67 65 5f 4c 45 46 | case |edge_LEF|
|00000e60| 54 3a 0a 20 20 20 20 20 | 20 20 20 20 20 20 20 72 |T:. | r|
|00000e70| 65 74 75 72 6e 20 28 78 | 20 3e 3d 20 76 2d 3e 6c |eturn (x| >= v->l|
|00000e80| 65 66 74 29 3b 0a 20 20 | 20 20 20 20 20 20 63 61 |eft);. | ca|
|00000e90| 73 65 20 65 64 67 65 5f | 52 49 47 48 54 3a 0a 20 |se edge_|RIGHT:. |
|00000ea0| 20 20 20 20 20 20 20 20 | 20 20 20 72 65 74 75 72 | | retur|
|00000eb0| 6e 20 28 78 20 3c 20 76 | 2d 3e 6c 65 66 74 20 2b |n (x < v|->left +|
|00000ec0| 20 76 2d 3e 77 69 64 74 | 68 29 3b 0a 20 20 20 20 | v->widt|h);. |
|00000ed0| 7d 0a 7d 0a 0a 73 74 61 | 74 69 63 20 76 6f 69 64 |}.}..sta|tic void|
|00000ee0| 20 49 6e 74 65 72 73 65 | 63 74 28 70 78 2c 20 70 | Interse|ct(px, p|
|00000ef0| 79 2c 20 66 78 2c 20 66 | 79 2c 20 74 78 2c 20 74 |y, fx, f|y, tx, t|
|00000f00| 79 2c 20 76 2c 20 77 68 | 69 63 68 29 0a 73 68 6f |y, v, wh|ich).sho|
|00000f10| 72 74 20 2a 70 78 2c 20 | 2a 70 79 3b 0a 73 68 6f |rt *px, |*py;.sho|
|00000f20| 72 74 20 66 78 2c 20 66 | 79 2c 20 74 78 2c 20 74 |rt fx, f|y, tx, t|
|00000f30| 79 3b 0a 73 74 72 75 63 | 74 20 76 69 65 77 70 6f |y;.struc|t viewpo|
|00000f40| 72 74 20 2a 76 3b 0a 73 | 68 6f 72 74 20 77 68 69 |rt *v;.s|hort whi|
|00000f50| 63 68 3b 0a 7b 0a 20 20 | 20 20 73 77 69 74 63 68 |ch;.{. | switch|
|00000f60| 20 28 77 68 69 63 68 29 | 20 7b 0a 20 20 20 20 20 | (which)| {. |
|00000f70| 20 20 20 63 61 73 65 20 | 65 64 67 65 5f 41 42 4f | case |edge_ABO|
|00000f80| 56 45 3a 0a 20 20 20 20 | 20 20 20 20 20 20 20 20 |VE:. | |
|00000f90| 2a 70 79 20 3d 20 76 2d | 3e 74 6f 70 3b 0a 20 20 |*py = v-|>top;. |
|00000fa0| 20 20 20 20 20 20 20 20 | 20 20 2a 70 78 20 3d 20 | | *px = |
|00000fb0| 43 6c 69 70 43 61 73 65 | 28 66 79 2c 20 2a 70 79 |ClipCase|(fy, *py|
|00000fc0| 2c 20 74 79 2c 20 66 78 | 2c 20 74 78 29 3b 0a 20 |, ty, fx|, tx);. |
|00000fd0| 20 20 20 20 20 20 20 20 | 20 20 20 62 72 65 61 6b | | break|
|00000fe0| 3b 0a 20 20 20 20 20 20 | 20 20 63 61 73 65 20 65 |;. | case e|
|00000ff0| 64 67 65 5f 42 45 4c 4f | 57 3a 0a 20 20 20 20 20 |dge_BELO|W:. |
|00001000| 20 20 20 20 20 20 20 2a | 70 79 20 3d 20 76 2d 3e | *|py = v->|
|00001010| 74 6f 70 20 2b 20 76 2d | 3e 68 65 69 67 68 74 20 |top + v-|>height |
|00001020| 2d 20 31 3b 0a 20 20 20 | 20 20 20 20 20 20 20 20 |- 1;. | |
|00001030| 20 2a 70 78 20 3d 20 43 | 6c 69 70 43 61 73 65 28 | *px = C|lipCase(|
|00001040| 66 79 2c 20 2a 70 79 2c | 20 74 79 2c 20 66 78 2c |fy, *py,| ty, fx,|
|00001050| 20 74 78 29 3b 0a 20 20 | 20 20 20 20 20 20 20 20 | tx);. | |
|00001060| 20 20 62 72 65 61 6b 3b | 0a 20 20 20 20 20 20 20 | break;|. |
|00001070| 20 63 61 73 65 20 65 64 | 67 65 5f 4c 45 46 54 3a | case ed|ge_LEFT:|
|00001080| 0a 20 20 20 20 20 20 20 | 20 20 20 20 20 2a 70 78 |. | *px|
|00001090| 20 3d 20 76 2d 3e 6c 65 | 66 74 3b 0a 20 20 20 20 | = v->le|ft;. |
|000010a0| 20 20 20 20 20 20 20 20 | 2a 70 79 20 3d 20 43 6c | |*py = Cl|
|000010b0| 69 70 43 61 73 65 28 66 | 78 2c 20 2a 70 78 2c 20 |ipCase(f|x, *px, |
|000010c0| 74 78 2c 20 66 79 2c 20 | 74 79 29 3b 0a 20 20 20 |tx, fy, |ty);. |
|000010d0| 20 20 20 20 20 20 20 20 | 20 62 72 65 61 6b 3b 0a | | break;.|
|000010e0| 20 20 20 20 20 20 20 20 | 63 61 73 65 20 65 64 67 | |case edg|
|000010f0| 65 5f 52 49 47 48 54 3a | 0a 20 20 20 20 20 20 20 |e_RIGHT:|. |
|00001100| 20 20 20 20 20 2a 70 78 | 20 3d 20 76 2d 3e 6c 65 | *px| = v->le|
|00001110| 66 74 20 2b 20 76 2d 3e | 77 69 64 74 68 20 2d 20 |ft + v->|width - |
|00001120| 31 3b 0a 20 20 20 20 20 | 20 20 20 20 20 20 20 2a |1;. | *|
|00001130| 70 79 20 3d 20 43 6c 69 | 70 43 61 73 65 28 66 78 |py = Cli|pCase(fx|
|00001140| 2c 20 2a 70 78 2c 20 74 | 78 2c 20 66 79 2c 20 74 |, *px, t|x, fy, t|
|00001150| 79 29 3b 0a 20 20 20 20 | 20 20 20 20 20 20 20 20 |y);. | |
|00001160| 62 72 65 61 6b 3b 0a 20 | 20 20 20 7d 0a 7d 0a 0a |break;. | }.}..|
|00001170| 73 74 61 74 69 63 20 76 | 6f 69 64 20 43 6c 69 70 |static v|oid Clip|
|00001180| 45 64 67 65 28 69 6e 2c | 20 6f 75 74 2c 20 76 2c |Edge(in,| out, v,|
|00001190| 20 77 68 69 63 68 29 0a | 73 74 72 75 63 74 20 70 | which).|struct p|
|000011a0| 6f 6c 79 67 6f 6e 20 2a | 69 6e 2c 20 2a 6f 75 74 |olygon *|in, *out|
|000011b0| 3b 0a 73 74 72 75 63 74 | 20 76 69 65 77 70 6f 72 |;.struct| viewpor|
|000011c0| 74 20 2a 76 3b 0a 73 68 | 6f 72 74 20 77 68 69 63 |t *v;.sh|ort whic|
|000011d0| 68 3b 0a 7b 0a 20 20 20 | 20 73 68 6f 72 74 20 69 |h;.{. | short i|
|000011e0| 2c 20 69 78 2c 20 69 79 | 3b 0a 0a 20 20 20 20 69 |, ix, iy|;.. i|
|000011f0| 20 3d 20 30 3b 0a 20 20 | 20 20 6f 75 74 2d 3e 6e | = 0;. | out->n|
|00001200| 20 3d 20 30 3b 0a 0a 20 | 20 20 20 64 6f 20 7b 0a | = 0;.. | do {.|
|00001210| 20 20 20 20 20 20 20 20 | 2f 2a 20 63 61 73 65 20 | |/* case |
|00001220| 49 20 6c 6f 6f 70 20 61 | 73 20 6c 6f 6e 67 20 61 |I loop a|s long a|
|00001230| 73 20 69 6e 73 69 64 65 | 20 2a 2f 0a 20 20 20 20 |s inside| */. |
|00001240| 20 20 20 20 77 68 69 6c | 65 20 28 69 20 3c 20 69 | whil|e (i < i|
|00001250| 6e 2d 3e 6e 20 26 26 20 | 49 6e 73 69 64 65 28 69 |n->n && |Inside(i|
|00001260| 6e 2d 3e 78 5b 69 5d 2c | 20 69 6e 2d 3e 79 5b 69 |n->x[i],| in->y[i|
|00001270| 5d 2c 20 76 2c 20 77 68 | 69 63 68 29 29 20 7b 0a |], v, wh|ich)) {.|
|00001280| 20 20 20 20 20 20 20 20 | 20 20 20 20 70 6f 6c 79 | | poly|
|00001290| 67 6f 6e 5f 49 6e 73 65 | 72 74 28 6f 75 74 2c 20 |gon_Inse|rt(out, |
|000012a0| 69 6e 2d 3e 78 5b 69 5d | 2c 20 69 6e 2d 3e 79 5b |in->x[i]|, in->y[|
|000012b0| 69 5d 29 3b 0a 20 20 20 | 20 20 20 20 20 20 20 20 |i]);. | |
|000012c0| 20 69 2b 2b 3b 0a 20 20 | 20 20 20 20 20 20 7d 0a | i++;. | }.|
|000012d0| 20 20 20 20 20 20 20 20 | 69 66 20 28 69 20 3c 20 | |if (i < |
|000012e0| 69 6e 2d 3e 6e 29 20 7b | 0a 20 20 20 20 20 20 20 |in->n) {|. |
|000012f0| 20 20 20 20 20 2f 2a 20 | 63 61 73 65 20 49 49 20 | /* |case II |
|00001300| 75 6e 6c 65 73 73 20 66 | 69 72 73 74 20 70 6f 69 |unless f|irst poi|
|00001310| 6e 74 20 69 73 20 6f 75 | 74 73 69 64 65 20 2a 2f |nt is ou|tside */|
|00001320| 0a 20 20 20 20 20 20 20 | 20 20 20 20 20 69 66 20 |. | if |
|00001330| 28 69 20 3e 20 30 29 20 | 7b 0a 20 20 20 20 20 20 |(i > 0) |{. |
|00001340| 20 20 20 20 20 20 20 20 | 20 20 49 6e 74 65 72 73 | | Inters|
|00001350| 65 63 74 28 26 69 78 2c | 20 26 69 79 2c 20 69 6e |ect(&ix,| &iy, in|
|00001360| 2d 3e 78 5b 69 20 2d 20 | 31 5d 2c 20 69 6e 2d 3e |->x[i - |1], in->|
|00001370| 79 5b 69 20 2d 20 31 5d | 2c 0a 20 20 20 20 20 20 |y[i - 1]|,. |
|00001380| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001390| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 69 6e | | in|
|000013a0| 2d 3e 78 5b 69 5d 2c 20 | 69 6e 2d 3e 79 5b 69 5d |->x[i], |in->y[i]|
|000013b0| 2c 20 76 2c 20 77 68 69 | 63 68 29 3b 0a 20 20 20 |, v, whi|ch);. |
|000013c0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 70 6f 6c | | pol|
|000013d0| 79 67 6f 6e 5f 49 6e 73 | 65 72 74 28 6f 75 74 2c |ygon_Ins|ert(out,|
|000013e0| 20 69 78 2c 20 69 79 29 | 3b 0a 20 20 20 20 20 20 | ix, iy)|;. |
|000013f0| 20 20 20 20 20 20 7d 0a | 20 20 20 20 20 20 20 20 | }.| |
|00001400| 20 20 20 20 2f 2a 20 63 | 61 73 65 20 49 49 49 20 | /* c|ase III |
|00001410| 6c 6f 6f 70 20 61 73 20 | 6c 6f 6e 67 20 61 73 20 |loop as |long as |
|00001420| 6f 75 74 73 69 64 65 20 | 2a 2f 0a 20 20 20 20 20 |outside |*/. |
|00001430| 20 20 20 20 20 20 20 77 | 68 69 6c 65 20 28 69 20 | w|hile (i |
|00001440| 3c 20 69 6e 2d 3e 6e 20 | 26 26 20 21 20 49 6e 73 |< in->n |&& ! Ins|
|00001450| 69 64 65 28 69 6e 2d 3e | 78 5b 69 5d 2c 20 69 6e |ide(in->|x[i], in|
|00001460| 2d 3e 79 5b 69 5d 2c 20 | 76 2c 20 77 68 69 63 68 |->y[i], |v, which|
|00001470| 29 29 0a 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |)). | |
|00001480| 20 20 20 69 2b 2b 3b 0a | 20 20 20 20 20 20 20 20 | i++;.| |
|00001490| 20 20 20 20 2f 2a 20 63 | 61 73 65 20 49 56 20 6f | /* c|ase IV o|
|000014a0| 75 74 73 69 64 65 20 74 | 6f 20 69 6e 73 69 64 65 |utside t|o inside|
|000014b0| 20 2a 2f 0a 20 20 20 20 | 20 20 20 20 20 20 20 20 | */. | |
|000014c0| 69 66 20 28 69 20 3c 20 | 69 6e 2d 3e 6e 29 20 7b |if (i < |in->n) {|
|000014d0| 0a 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |. | |
|000014e0| 20 49 6e 74 65 72 73 65 | 63 74 28 26 69 78 2c 20 | Interse|ct(&ix, |
|000014f0| 26 69 79 2c 20 69 6e 2d | 3e 78 5b 69 20 2d 20 31 |&iy, in-|>x[i - 1|
|00001500| 5d 2c 20 69 6e 2d 3e 79 | 5b 69 20 2d 20 31 5d 2c |], in->y|[i - 1],|
|00001510| 0a 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |. | |
|00001520| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001530| 20 20 20 20 20 69 6e 2d | 3e 78 5b 69 5d 2c 20 69 | in-|>x[i], i|
|00001540| 6e 2d 3e 79 5b 69 5d 2c | 20 76 2c 20 77 68 69 63 |n->y[i],| v, whic|
|00001550| 68 29 3b 0a 20 20 20 20 | 20 20 20 20 20 20 20 20 |h);. | |
|00001560| 20 20 20 20 70 6f 6c 79 | 67 6f 6e 5f 49 6e 73 65 | poly|gon_Inse|
|00001570| 72 74 28 6f 75 74 2c 20 | 69 78 2c 20 69 79 29 3b |rt(out, |ix, iy);|
|00001580| 0a 20 20 20 20 20 20 20 | 20 20 20 20 20 7d 0a 20 |. | }. |
|00001590| 20 20 20 20 20 20 20 7d | 0a 20 20 20 20 7d 20 77 | }|. } w|
|000015a0| 68 69 6c 65 20 28 69 20 | 3c 20 69 6e 2d 3e 6e 29 |hile (i |< in->n)|
|000015b0| 3b 0a 0a 20 20 20 20 2f | 2a 20 4e 6f 77 20 63 68 |;.. /|* Now ch|
|000015c0| 65 63 6b 20 69 66 20 74 | 68 65 72 65 27 73 20 61 |eck if t|here's a|
|000015d0| 20 63 72 6f 73 73 69 6e | 67 20 62 65 74 77 65 65 | crossin|g betwee|
|000015e0| 6e 20 74 68 65 20 6c 61 | 73 74 20 26 20 66 69 72 |n the la|st & fir|
|000015f0| 73 74 20 70 6f 69 6e 74 | 73 20 2a 2f 0a 0a 20 20 |st point|s */.. |
|00001600| 20 20 69 66 20 28 49 6e | 73 69 64 65 28 69 6e 2d | if (In|side(in-|
|00001610| 3e 78 5b 69 6e 2d 3e 6e | 20 2d 20 31 5d 2c 20 69 |>x[in->n| - 1], i|
|00001620| 6e 2d 3e 79 5b 69 6e 2d | 3e 6e 20 2d 20 31 5d 2c |n->y[in-|>n - 1],|
|00001630| 20 76 2c 20 77 68 69 63 | 68 29 20 5e 0a 20 20 20 | v, whic|h) ^. |
|00001640| 20 20 20 20 20 49 6e 73 | 69 64 65 28 69 6e 2d 3e | Ins|ide(in->|
|00001650| 78 5b 30 5d 2c 20 69 6e | 2d 3e 79 5b 30 5d 2c 20 |x[0], in|->y[0], |
|00001660| 76 2c 20 77 68 69 63 68 | 29 29 20 7b 0a 20 20 20 |v, which|)) {. |
|00001670| 20 20 20 20 20 49 6e 74 | 65 72 73 65 63 74 28 26 | Int|ersect(&|
|00001680| 69 78 2c 20 26 69 79 2c | 20 69 6e 2d 3e 78 5b 69 |ix, &iy,| in->x[i|
|00001690| 6e 2d 3e 6e 20 2d 20 31 | 5d 2c 20 69 6e 2d 3e 79 |n->n - 1|], in->y|
|000016a0| 5b 69 6e 2d 3e 6e 20 2d | 20 31 5d 2c 0a 20 20 20 |[in->n -| 1],. |
|000016b0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000016c0| 20 20 20 20 20 20 20 20 | 20 69 6e 2d 3e 78 5b 30 | | in->x[0|
|000016d0| 5d 2c 20 69 6e 2d 3e 79 | 5b 30 5d 2c 20 76 2c 20 |], in->y|[0], v, |
|000016e0| 77 68 69 63 68 29 3b 0a | 20 20 20 20 20 20 20 20 |which);.| |
|000016f0| 70 6f 6c 79 67 6f 6e 5f | 49 6e 73 65 72 74 28 6f |polygon_|Insert(o|
|00001700| 75 74 2c 20 69 78 2c 20 | 69 79 29 3b 0a 20 20 20 |ut, ix, |iy);. |
|00001710| 20 7d 0a 7d 0a 0a 76 6f | 69 64 20 70 6f 6c 79 67 | }.}..vo|id polyg|
|00001720| 6f 6e 5f 43 6c 69 70 28 | 70 2c 20 76 29 0a 73 74 |on_Clip(|p, v).st|
|00001730| 72 75 63 74 20 70 6f 6c | 79 67 6f 6e 20 2a 70 3b |ruct pol|ygon *p;|
|00001740| 0a 73 74 72 75 63 74 20 | 76 69 65 77 70 6f 72 74 |.struct |viewport|
|00001750| 20 2a 76 3b 0a 7b 0a 20 | 20 20 20 73 74 61 74 69 | *v;.{. | stati|
|00001760| 63 20 73 74 72 75 63 74 | 20 70 6f 6c 79 67 6f 6e |c struct| polygon|
|00001770| 20 2a 74 20 3d 20 30 3b | 20 20 2f 2a 20 74 65 6d | *t = 0;| /* tem|
|00001780| 70 6f 72 61 72 79 20 70 | 6f 6c 79 67 6f 6e 2c 20 |porary p|olygon, |
|00001790| 73 74 61 79 73 20 61 72 | 6f 75 6e 64 20 2a 2f 0a |stays ar|ound */.|
|000017a0| 0a 20 20 20 20 69 66 20 | 28 74 20 3d 3d 20 30 29 |. if |(t == 0)|
|000017b0| 0a 20 20 20 20 20 20 20 | 20 74 20 3d 20 70 6f 6c |. | t = pol|
|000017c0| 79 67 6f 6e 5f 4e 65 77 | 28 29 3b 0a 20 20 20 20 |ygon_New|();. |
|000017d0| 65 6c 73 65 0a 20 20 20 | 20 20 20 20 20 74 2d 3e |else. | t->|
|000017e0| 6e 20 3d 20 30 3b 0a 0a | 20 20 20 20 43 6c 69 70 |n = 0;..| Clip|
|000017f0| 45 64 67 65 28 70 2c 20 | 74 2c 20 76 2c 20 65 64 |Edge(p, |t, v, ed|
|00001800| 67 65 5f 41 42 4f 56 45 | 29 3b 0a 20 20 20 20 43 |ge_ABOVE|);. C|
|00001810| 6c 69 70 45 64 67 65 28 | 74 2c 20 70 2c 20 76 2c |lipEdge(|t, p, v,|
|00001820| 20 65 64 67 65 5f 42 45 | 4c 4f 57 29 3b 0a 20 20 | edge_BE|LOW);. |
|00001830| 20 20 43 6c 69 70 45 64 | 67 65 28 70 2c 20 74 2c | ClipEd|ge(p, t,|
|00001840| 20 76 2c 20 65 64 67 65 | 5f 4c 45 46 54 29 3b 0a | v, edge|_LEFT);.|
|00001850| 20 20 20 20 43 6c 69 70 | 45 64 67 65 28 74 2c 20 | Clip|Edge(t, |
|00001860| 70 2c 20 76 2c 20 65 64 | 67 65 5f 52 49 47 48 54 |p, v, ed|ge_RIGHT|
|00001870| 29 3b 0a 7d 0a 0a 0a | |);.}... | |
+--------+-------------------------+-------------------------+--------+--------+