Date: Tue, 14 Jan 2003 10:07:29 +1100 From: Mat Ballard User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2) Gecko/20021126 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.delphi.graphics Subject: Re: Polygon pixel testing References: <3e233fbf@newsgroups.borland.com> In-Reply-To: <3e233fbf@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 138.194.49.218 Message-ID: <3e2346e0$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1042499296 138.194.49.218 (13 Jan 2003 15:08:16 -0800) Lines: 77 Path: newsgroups.borland.com!not-for-mail Xref: newsgroups.borland.com borland.public.delphi.graphics:54901 unit Polytest; {The code below was posted by: "John Hutchings" Date: Fri, 19 Oct 2001 06:20:44 +1000 Newsgroups: borland.public.delphi.graphics // The code below is from Wm. Randolph Franklin // with some minor modifications for speed. It returns 1 for strictly // interior points, 0 for strictly exterior, and 0 or 1 for points on // the boundary. Comment: returns a Boolean ! } interface uses Classes, SysUtils, {$IFDEF WINDOWS} Wintypes; {$ENDIF} {$IFDEF WIN32} Windows; {$ENDIF} {$IFDEF LINUX} Types, Untranslated; {$ENDIF} function PointInPolygonTest(x, y, N: Integer; aList: Array of TPoint): Boolean; implementation function PointInPolygonTest(x, y, N: Integer; aList: Array of TPoint): Boolean; var I, J : Integer; Function xp(aVal:Integer):Integer; Begin Result:= PPoint(@aList[aVal]).X; end; Function yp(aVal:Integer):Integer; Begin Result:= PPoint(@aList[aVal]).Y; end; begin Result := False; {L := Length(aList);} if (N = 0) then exit; J := N-1; for I := 0 to N-1 do begin if ((((yp(I) <= y) and (y < yp(J))) or ((yp(J) <= y) and (y < yp(I)))) and (x < (xp(J)-xp(I))*(y-yp(I))/(yp(J)-yp(I))+xp(I))) then Result := not Result; J:=I; end; end; end. ________________________________________ rm -rf /mnt/windows/ ________________________________________ Dr Mat Ballard, mat.ballard@Chemware.hypermart.net http://Chemware.hypermart.net/ Linux Registered User #6854