Path: utzoo!attcan!uunet!husc6!bbn!uwmcsd1!mailrus!ames!pasteur!agate!sizzlean!lippin
From: lippin@sizzlean.berkeley.edu (The Apathist)
Newsgroups: comp.sys.mac.programmer
Subject: LineRgn
Message-ID: <13382@agate.BERKELEY.EDU>
Date: 18 Aug 88 00:39:14 GMT
Sender: usenet@agate.BERKELEY.EDU
Reply-To: lippin@math.berkeley.edu
Organization: Authorized Service, Incorporated
Lines: 37

About a week ago, I posted a short routine, LineRgn, which converts a
line to a region enclosing the bits Quickdraw would affect when
drawing the line.  Since then, I've realized that the version I posted
doesn't handle the ends of the line correctly, particularly when the
pen size is large.  So here's the corrected version:

void LineRgn(line,start,finish)
  RgnHandle line;
  Point start,finish;
  {
   RgnHandle cap;
   Point start2,finish2;
   start2=start;
   finish2=finish;
   AddPt(thePort->penSize,&start2);
   AddPt(thePort->penSize,&finish2);
   OpenRgn();
   MoveTo(start.h,start.v);
   LineTo(finish.h,finish.v);
   LineTo(finish2.h,finish2.v);
   LineTo(start2.h,start2.v);
   LineTo(start.h,start.v);
   CloseRgn(line);
   cap=NewRgn();
   SetRectRgn(cap,start.h,start.v,start2.h,start2.v);
   UnionRgn(line,cap,line);
   SetRectRgn(cap,finish.h,finish.v,finish2.h,finish2.v);
   UnionRgn(line,cap,line);
   DisposRgn(cap);
  }

					--Tom Lippincott
					..ucbvax!math!lippin

	"Those are line *segments*, sir."
				--Second City,
				"Football Comes to the University of Chicago"