Commit dc512a6f authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

winding_numbers_algorithm: changed interface.

parent e0111e83
Pipeline #4508 passed with stages
in 16 minutes and 53 seconds
......@@ -316,9 +316,9 @@ compute_child_from_bounds(CellIndex *cellindex2, long ncells2, double *grid_cent
size_t *nbr_addr = &knnWeights.m_addr[0];
int ncorner = 3;
double center_point_xyz[3];
double cell_corners_xyz[12];
double cell_corners_plane_projection[8];
double center_point_xyz[3];
double center_point_plane_projection[2];
long *child2 = (long *) Malloc(MAX_CHILDS * ncells2 * sizeof(long));
......
......@@ -170,24 +170,25 @@ find_coordinate_to_ignore(const double *cell_corners_xyz)
return coordinate_to_ignore;
}
static double
is_point_left_of_edge(const double (&point_on_line_1)[2], const double (&point_on_line_2)[2], const double *point)
static inline double
is_point_left_of_edge(const double (&point1)[2], const double (&point2)[2], const double (&point)[2])
{
/*
Computes whether a point is left of the line through point_on_line_1 and point_on_line_2. This is part of the
solution to the point in polygon problem. Returns 0 if the point is on the line, > 0 if the point is left of the
line, and < 0 if the point is right of the line. This algorithm is by Dan Sunday (geomalgorithms.com) and is
completely free for use and modification.
*/
Computes whether a point is left of the line through point1 and point2.
This is part of the solution to the point in polygon problem.
auto answer = ((point_on_line_2[0] - point_on_line_1[0]) * (point[1] - point_on_line_1[1])
- (point[0] - point_on_line_1[0]) * (point_on_line_2[1] - point_on_line_1[1]));
Returns: 0 if the point is on the line through point1 and point2
> 0 if the point is left of the line
< 0 if the point is right of the line
This algorithm is by Dan Sunday (geomalgorithms.com) and is completely free for use and modification.
*/
return answer;
return ((point2[0] - point1[0]) * (point[1] - point1[1]) - (point[0] - point1[0]) * (point2[1] - point1[1]));
}
int
winding_numbers_algorithm(const double *cell_corners, int number_corners, const double *point)
winding_numbers_algorithm(const double *cell_corners, int number_corners, const double (&point)[2])
{
/*
Computes whether a point is inside the bounds of a cell. This is the solution to the point in polygon problem.
......@@ -203,20 +204,20 @@ winding_numbers_algorithm(const double *cell_corners, int number_corners, const
{
if (cell_corners[(i + 1) * 2 + 1] > point[1])
{
const double point_on_edge_1[2] = { cell_corners[i * 2 + 0], cell_corners[i * 2 + 1] };
const double point_on_edge_2[2] = { cell_corners[(i + 1) * 2 + 0], cell_corners[(i + 1) * 2 + 1] };
const double point1[2] = { cell_corners[i * 2 + 0], cell_corners[i * 2 + 1] };
const double point2[2] = { cell_corners[(i + 1) * 2 + 0], cell_corners[(i + 1) * 2 + 1] };
if (is_point_left_of_edge(point_on_edge_1, point_on_edge_2, point) > 0) winding_number++;
if (is_point_left_of_edge(point1, point2, point) > 0) winding_number++;
}
}
else
{
if (cell_corners[(i + 1) * 2 + 1] <= point[1])
{
const double point_on_edge_1[2] = { cell_corners[i * 2 + 0], cell_corners[i * 2 + 1] };
const double point_on_edge_2[2] = { cell_corners[(i + 1) * 2 + 0], cell_corners[(i + 1) * 2 + 1] };
const double point1[2] = { cell_corners[i * 2 + 0], cell_corners[i * 2 + 1] };
const double point2[2] = { cell_corners[(i + 1) * 2 + 0], cell_corners[(i + 1) * 2 + 1] };
if (is_point_left_of_edge(point_on_edge_1, point_on_edge_2, point) < 0) winding_number--;
if (is_point_left_of_edge(point1, point2, point) < 0) winding_number--;
}
}
}
......
......@@ -23,6 +23,6 @@ void set_cell_corners_plane_projection(int coordinate_to_ignore, int ncorner, co
int find_coordinate_to_ignore(const double *cell_corners_xyz);
double calculate_the_polygon_area(const double *cell_corners, int number_corners);
bool are_polygon_vertices_arranged_in_clockwise_order(double cell_area);
int winding_numbers_algorithm(const double *cell_corners, int number_corners, const double *point);
int winding_numbers_algorithm(const double *cell_corners, int number_corners, const double (&point)[2]);
#endif /* VERIFYGRID_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment