 ### 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; int ncorner = 3; double center_point_xyz; double cell_corners_xyz; double cell_corners_plane_projection; double center_point_xyz; double center_point_plane_projection; 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), const double (&point_on_line_2), const double *point) static inline double is_point_left_of_edge(const double (&point1), const double (&point2), const double (&point)) { /* 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 - point_on_line_1) * (point - point_on_line_1) - (point - point_on_line_1) * (point_on_line_2 - point_on_line_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 - point1) * (point - point1) - (point - point1) * (point2 - point1)); } 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)) { /* 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) { const double point_on_edge_1 = { cell_corners[i * 2 + 0], cell_corners[i * 2 + 1] }; const double point_on_edge_2 = { cell_corners[(i + 1) * 2 + 0], cell_corners[(i + 1) * 2 + 1] }; const double point1 = { cell_corners[i * 2 + 0], cell_corners[i * 2 + 1] }; const double point2 = { 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) { const double point_on_edge_1 = { cell_corners[i * 2 + 0], cell_corners[i * 2 + 1] }; const double point_on_edge_2 = { cell_corners[(i + 1) * 2 + 0], cell_corners[(i + 1) * 2 + 1] }; const double point1 = { cell_corners[i * 2 + 0], cell_corners[i * 2 + 1] }; const double point2 = { 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)); #endif /* VERIFYGRID_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!