pub unsafe extern "C" fn inside(
p: *const c_double,
lv: *const c_int,
xv: *const c_double,
yv: *const c_double,
zv: *const c_double,
nv: *const c_int,
listv: *const c_int,
ier: *mut c_int,
) -> boolExpand description
Determines if a point is inside a polygonal region.
This function locates a point p relative to a polygonal region r on the surface of the unit sphere, returning inside = true if and only if p is contained in r. r is defined by a cyclically ordered sequence of vertices which form a positively-oriented simple closed curve. Adjacent vertices need not be distinct but the curve must not be self-intersecting. Also, while polygon edges are by definition restricted to a single hemisphere, r is not so restricted. Its interior is the region to the left as the vertices are traversed in order.
The algorithm consists of selecting a point q in r and then finding all points at which the great circle defined by p and q intersects the boundary of r. p lies inside r if and only if there is an even number of intersection points between q and p. q is taken to be a point immediately to the left of a directed boundary edge – the first one that results in no consistency-check failures.
If p is close to the polygon boundary, the problem is ill-conditioned and the decision may be incorrect. Also, an incorrect decision may result from a poor choice of q (if, for example, a boundary edge lies on the great circle defined by p and q). A more reliable result could be obtained by a sequence of calls to inside with the vertices cyclically permuted before each call (to alter the choice of q).
§Arguments
p[3]- Input. The coordinates of the point (unit vector) to be located.lv- Input. The length of the arraysxv,yv, andzv.xv[lv],yv[lv],zv[lv]- Input. The coordinates of unit vectors (points on the unit sphere).nv- Input. The number of vertices in the polygon.3 <= nv <= lv.listv[nv]- Input. The indexes (forxv,yv, andzv) of a cyclically-ordered (and CCW-ordered) sequence of vertices that definer. The last vertex (indexed bylistv[nv]) is followed by the first (indexed bylistv[1]).listventries must be in the range1tolv.ier- Output. Error indicator:0, if no errors were encountered.1, iflvornvis outside its valid range.2, if alistventry is outside its valid range.3, if the polygon boundary was found to be self-intersecting. This error will not necessarily be detected.4, if every choice ofq(one for each boundary edge) led to failure of some internal consistency check. The most likely cause of this error is invalid input:p = (0, 0, 0), a null or self-intersecting polygon, etc.
§Returns
True if and only if p lies inside r unless ier != 0, in which case the value is not altered.