Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
inpoly.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11/*
12 * in_poly
13 *
14 * Test if a point is inside a polygon.
15 * The polygon must be convex with vertices in CW order.
16 */
17
18#include <stdlib.h>
19#include <pathplan/vispath.h>
20#include <pathplan/pathutil.h>
21#include <stdbool.h>
22#include <stddef.h>
23
25 Ppoint_t *P;
26
27 P = poly.ps;
28 const size_t n = poly.pn;
29 for (size_t i = 0; i < n; i++) {
30 const size_t i1 = (i + n - 1) % n; // point index; i1 = i-1 mod n
31 if (wind(P[i1], P[i], q) == 1) return false;
32 }
33 return true;
34}
bool in_poly(Ppoly_t poly, Ppoint_t q)
Definition inpoly.c:24
PATHUTIL_API int wind(Ppoint_t a, Ppoint_t b, Ppoint_t c)
Definition visibility.c:53