00001 /* $Id: inpoly.c,v 1.2 2005/04/07 22:17:37 erg Exp $ $Revision: 1.2 $ */ 00002 /* vim:set shiftwidth=4 ts=8: */ 00003 00004 /********************************************************** 00005 * This software is part of the graphviz package * 00006 * http://www.graphviz.org/ * 00007 * * 00008 * Copyright (c) 1994-2004 AT&T Corp. * 00009 * and is licensed under the * 00010 * Common Public License, Version 1.0 * 00011 * by AT&T Corp. * 00012 * * 00013 * Information and Software Systems Research * 00014 * AT&T Research, Florham Park NJ * 00015 **********************************************************/ 00016 00017 /* 00018 * in_poly 00019 * 00020 * Test if a point is inside a polygon. 00021 * The polygon must be convex with vertices in CW order. 00022 */ 00023 00024 #include <stdlib.h> 00025 #include <vispath.h> 00026 #include <pathutil.h> 00027 00028 #ifdef DMALLOC 00029 #include "dmalloc.h" 00030 #endif 00031 00032 int in_poly(Ppoly_t poly, Ppoint_t q) 00033 { 00034 int i, i1; /* point index; i1 = i-1 mod n */ 00035 int n; 00036 Ppoint_t *P; 00037 00038 P = poly.ps; 00039 n = poly.pn; 00040 for (i = 0; i < n; i++) { 00041 i1 = (i + n - 1) % n; 00042 if (wind(P[i1],P[i],q) == 1) return FALSE; 00043 } 00044 return TRUE; 00045 }