Graphviz 13.0.0~dev.20241220.2304
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 <pathplan/pathutil.h>
19#include <pathplan/vispath.h>
20#include <stdbool.h>
21#include <stddef.h>
22#include <stdlib.h>
23
24bool in_poly(const Ppoly_t poly, Ppoint_t q) {
25 const Ppoint_t *P = poly.ps;
26 const size_t n = poly.pn;
27 for (size_t i = 0; i < n; i++) {
28 const size_t i1 = (i + n - 1) % n; // point index; i1 = i-1 mod n
29 if (wind(P[i1], P[i], q) == 1)
30 return false;
31 }
32 return true;
33}
bool in_poly(const 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