29static int comp_double(
const void *,
const void *);
30static int V__within(
double,
double,
double);
35static void destroy_links(
struct link_head *,
struct Slink *);
36static int Vect__divide_and_conquer(
struct Slink *,
const struct line_pnts *,
59 static int first_time = 1;
63 G_debug(3,
"Vect_get_point_in_area()");
82 for (i = 0; i < n_isles; i++) {
95static int comp_double(
const void *i,
const void *
j)
97 if (*(
const double *)i < *(
const double *)
j)
100 return (*(
const double *)i > *(
const double *)
j);
103static int V__within(
double a,
double x,
double b)
106 return (
x >= a &&
x <
b);
108 return (
x >
b &&
x <= a);
130 double a,
b, c, d,
x;
133 for (i = 1; i < Points->
n_points; i++) {
134 a = Points->
y[i - 1];
137 c = Points->
x[i - 1];
140 if (V__within(a,
y,
b)) {
145 x =
perc * (d - c) + c;
173 double a,
b, c, d,
y;
176 for (i = 1; i < Points->
n_points; i++) {
177 a = Points->
x[i - 1];
180 c = Points->
y[i - 1];
183 if (V__within(a,
x,
b)) {
188 y =
perc * (d - c) + c;
214 static int first_time = 1;
229 G_debug(3,
"Vect_get_point_in_poly(): divide and conquer");
233 for (i = 0; i < Points->
n_points; i++) {
263 G_warning(
"Vect_get_point_in_poly(): %s",
264 _(
"Unable to find point in polygon"));
268 G_debug(3,
"Found point in %d iterations", 10 -
ret);
295static int Vect__divide_and_conquer(
struct Slink *
Head,
300 struct Slink *A, *B, *C;
311 C->x = (A->x + B->x) / 2.;
335 struct Slink *p, *tmp;
374 for (i = 1; i < points->
n_points; i++) {
454 static int first_time = 1;
465 G_debug(3,
"Vect_get_point_in_poly_isl(): n_isles = %d", n_isles);
486 for (i = 0; i < n_isles; i++) {
512 for (i = 0; i < Points->
n_points; i++) {
527 for (i = 0; i < Points->
n_points; i++) {
531 if ((Points->
y[i] >=
cent_y) &&
538 if ((Points->
x[i] >=
cent_x) &&
542 for (i = 0; i < n_isles; i++) {
569 for (i = 0; i < n_isles; i++) {
585 for (i = 0; i <
Intersects->n_points; i += 2) {
610 G_debug(3,
"Vect_get_point_in_poly_isl(): trying x intersect");
621 for (i = 0; i < n_isles; i++) {
637 for (i = 0; i <
Intersects->n_points; i += 2) {
659 G_warning(
"Vect_get_point_in_poly_isl(): collapsed area");
672 G_warning(
"Vect_get_point_in_poly_isl(), the hard way: centroid is on "
673 "outer ring, max dist is %g",
680 for (i = 0; i < n_isles; i++) {
683 G_warning(
"Vect_get_point_in_poly_isl(), the hard way: "
684 "centroid is in isle, max dist is %g",
701static int segments_x_ray(
double X,
double Y,
const struct line_pnts *Points)
703 double x1, x2, y1, y2;
708 G_debug(3,
"segments_x_ray(): x = %f y = %f n_points = %d",
X,
Y,
716 for (n = 1; n < Points->
n_points; n++) {
717 x1 = Points->
x[n - 1];
718 y1 = Points->
y[n - 1];
735 if (y1 >
Y && y2 >
Y)
739 if (y1 <
Y && y2 <
Y)
743 if (x1 <
X && x2 <
X)
747 if ((x1 ==
X && y1 ==
Y) || (x2 ==
X && y2 ==
Y))
751 if (x1 == x2 && x1 ==
X) {
757 if (y1 == y2 && y1 ==
Y) {
769 if ((y1 ==
Y && y2 >
Y) || (y2 ==
Y && y1 >
Y))
775 if (y1 ==
Y && y2 <
Y) {
780 if (y2 ==
Y && y1 <
Y) {
788 if (x1 >=
X && x2 >=
X) {
806 G_warning(
"segments_x_ray() %s: X = %f Y = %f x1 = %f y1 = %f x2 = %f "
808 _(
"conditions failed"),
X,
Y, x1, y1, x2, y2);
828 G_debug(3,
"Vect_point_in_poly(): x = %f y = %f n_points = %d",
X,
Y,
857 static int first = 1;
866 G_debug(3,
"Vect_point_in_area_outer_ring(): x = %f y = %f area = %d",
X,
Y,
875 Area =
Plus->Area[area];
882 for (i = 0; i < Area->
n_lines; i++) {
900 inter = segments_x_ray(
X,
Y, Points);
926 static int first = 1;
935 G_debug(3,
"Vect_point_in_island(): x = %f y = %f isle = %d",
X,
Y,
isle);
950 for (i = 0; i < Isle->
n_lines; i++) {
968 inter = segments_x_ray(
X,
Y, Points);
int Vect_get_point_in_poly_isl(const struct line_pnts *Points, const struct line_pnts **IPoints, int n_isles, double *att_x, double *att_y)
Get point inside polygon but outside the islands specifiled in IPoints.
int Vect_point_in_poly(double X, double Y, const struct line_pnts *Points)
Determines if a point (X,Y) is inside a polygon.
int Vect_get_point_in_poly(const struct line_pnts *Points, double *X, double *Y)
Get point inside polygon.
int Vect_find_poly_centroid(const struct line_pnts *points, double *cent_x, double *cent_y)
Get centroid of polygon.
int Vect__intersect_x_line_with_poly(const struct line_pnts *, double, struct line_pnts *)
int Vect__intersect_y_line_with_poly(const struct line_pnts *, double, struct line_pnts *)
int Vect_point_in_island(double X, double Y, struct Map_info *Map, int isle, struct bound_box *box)
Determines if a point (X,Y) is inside an island.
int Vect_point_in_area_outer_ring(double X, double Y, struct Map_info *Map, int area, struct bound_box *box)
Determines if a point (X,Y) is inside an area outer ring. Islands are not considered.
int Vect_get_point_in_area(struct Map_info *Map, int area, double *X, double *Y)
Get point inside area and outside all islands.
void G_warning(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
VOID_T * link_new(struct link_head *)
void link_dispose(struct link_head *, VOID_T *)
void link_exit_on_error(int)
struct link_head * link_init(int)
int Vect_get_isle_points(struct Map_info *, int, struct line_pnts *)
Returns polygon array of points for given isle.
int Vect_get_area_points(struct Map_info *, int, struct line_pnts *)
Returns polygon array of points (outer ring) of given area.
int Vect_get_area_isle(struct Map_info *, int, int)
Returns isle id for area.
int Vect_read_line(struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int Vect_get_area_num_isles(struct Map_info *, int)
Returns number of isles for given area.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
int Vect_append_point(struct line_pnts *, double, double, double)
Appends one point to the end of a line.
double dig_x_intersect(double, double, double, double, double)
plus_t n_lines
Number of boundary lines.
plus_t * lines
List of boundary lines.
plus_t * lines
List of boundary lines.
plus_t n_lines
Number of boundary lines.
Basic topology-related info.
Feature geometry info - coordinates.
double * y
Array of Y coordinates.
double * x
Array of X coordinates.
int n_points
Number of points.