Commit 416944c3 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added function set_center_point_plane_projection() and set_cell_corners_plane_projection().

parent 4fa1c0f4
Pipeline #4496 passed with stages
in 16 minutes and 45 seconds
......@@ -349,30 +349,7 @@ compute_child_from_bounds(CellIndex *cellindex2, long ncells2, double *grid_cent
bool invert_result = false;
if (cell_corners_xyz[coordinate_to_ignore - 1] < 0) invert_result = true;
switch (coordinate_to_ignore)
{
case 1:
for (int corner_no = 0; corner_no <= ncorner; corner_no++)
{
cell_corners_plane_projection[corner_no * 2 + 0] = cell_corners_xyz[corner_no * 3 + 1];
cell_corners_plane_projection[corner_no * 2 + 1] = cell_corners_xyz[corner_no * 3 + 2];
}
break;
case 2:
for (int corner_no = 0; corner_no <= ncorner; corner_no++)
{
cell_corners_plane_projection[corner_no * 2 + 0] = cell_corners_xyz[corner_no * 3 + 2];
cell_corners_plane_projection[corner_no * 2 + 1] = cell_corners_xyz[corner_no * 3 + 0];
}
break;
case 3:
for (int corner_no = 0; corner_no <= ncorner; corner_no++)
{
cell_corners_plane_projection[corner_no * 2 + 0] = cell_corners_xyz[corner_no * 3 + 0];
cell_corners_plane_projection[corner_no * 2 + 1] = cell_corners_xyz[corner_no * 3 + 1];
}
break;
}
set_cell_corners_plane_projection(coordinate_to_ignore, ncorner, cell_corners_xyz, cell_corners_plane_projection);
const auto polygon_area = calculate_the_polygon_area(cell_corners_plane_projection, ncorner + 1);
auto is_clockwise = are_polygon_vertices_arranged_in_clockwise_order(polygon_area);
......@@ -390,23 +367,9 @@ compute_child_from_bounds(CellIndex *cellindex2, long ncells2, double *grid_cent
{
gcLLtoXYZ(grid_center_lon1[cell_no1], grid_center_lat1[cell_no1], center_point_xyz);
switch (coordinate_to_ignore)
{
case 1:
center_point_plane_projection[0] = center_point_xyz[1];
center_point_plane_projection[1] = center_point_xyz[2];
break;
case 2:
center_point_plane_projection[0] = center_point_xyz[2];
center_point_plane_projection[1] = center_point_xyz[0];
break;
case 3:
center_point_plane_projection[0] = center_point_xyz[0];
center_point_plane_projection[1] = center_point_xyz[1];
break;
}
set_center_point_plane_projection(coordinate_to_ignore, center_point_xyz, center_point_plane_projection);
int winding_number
auto winding_number
= winding_numbers_algorithm(cell_corners_plane_projection, ncorner + 1, center_point_plane_projection);
// printf("%d %g %g %g %g %d\n", cell_no2,
// RAD2DEG*grid_center_lon2[cell_no2],
......
......@@ -377,6 +377,54 @@ get_no_unique_center_points(size_t gridsize, size_t nx, const Varray<double> &ce
return no_unique_center_points;
}
void set_center_point_plane_projection(int coordinate_to_ignore, const double (&center_point_xyz)[3], double (&center_point_plane_projection)[2])
{
switch (coordinate_to_ignore)
{
case 1:
center_point_plane_projection[0] = center_point_xyz[1];
center_point_plane_projection[1] = center_point_xyz[2];
break;
case 2:
center_point_plane_projection[0] = center_point_xyz[2];
center_point_plane_projection[1] = center_point_xyz[0];
break;
case 3:
center_point_plane_projection[0] = center_point_xyz[0];
center_point_plane_projection[1] = center_point_xyz[1];
break;
}
}
void set_cell_corners_plane_projection(int coordinate_to_ignore, int ncorner, const double *cell_corners_xyz,
double *cell_corners_plane_projection)
{
switch (coordinate_to_ignore)
{
case 1:
for (int corner_no = 0; corner_no <= ncorner; corner_no++)
{
cell_corners_plane_projection[corner_no * 2 + 0] = cell_corners_xyz[corner_no * 3 + 1];
cell_corners_plane_projection[corner_no * 2 + 1] = cell_corners_xyz[corner_no * 3 + 2];
}
break;
case 2:
for (int corner_no = 0; corner_no <= ncorner; corner_no++)
{
cell_corners_plane_projection[corner_no * 2 + 0] = cell_corners_xyz[corner_no * 3 + 2];
cell_corners_plane_projection[corner_no * 2 + 1] = cell_corners_xyz[corner_no * 3 + 0];
}
break;
case 3:
for (int corner_no = 0; corner_no <= ncorner; corner_no++)
{
cell_corners_plane_projection[corner_no * 2 + 0] = cell_corners_xyz[corner_no * 3 + 0];
cell_corners_plane_projection[corner_no * 2 + 1] = cell_corners_xyz[corner_no * 3 + 1];
}
break;
}
}
static void
verify_grid(int gridtype, size_t gridsize, size_t nx, int gridno, int ngrids, int ncorner, double *grid_center_lon, double *grid_center_lat,
double *grid_corner_lon, double *grid_corner_lat)
......@@ -562,7 +610,7 @@ verify_grid(int gridtype, size_t gridsize, size_t nx, int gridno, int ngrids, in
for (int corner_no = 0; corner_no < actual_number_of_corners; corner_no++)
{
int off = corner_no * 3;
const auto off = corner_no * 3;
cell_corners_xyz[off + 0] = cell_corners_xyz_without_duplicates[off + 0];
cell_corners_xyz[off + 1] = cell_corners_xyz_without_duplicates[off + 1];
cell_corners_xyz[off + 2] = cell_corners_xyz_without_duplicates[off + 2];
......@@ -572,7 +620,7 @@ verify_grid(int gridtype, size_t gridsize, size_t nx, int gridno, int ngrids, in
cell_corners_xyz[actual_number_of_corners * 3 + 1] = cell_corners_xyz[1];
cell_corners_xyz[actual_number_of_corners * 3 + 2] = cell_corners_xyz[2];
int coordinate_to_ignore = find_coordinate_to_ignore(cell_corners_xyz.data());
const auto coordinate_to_ignore = find_coordinate_to_ignore(cell_corners_xyz.data());
/* The remaining two-dimensional coordinates are extracted into one array for all the cell's corners and into one
* array for the center point. */
......@@ -585,36 +633,8 @@ verify_grid(int gridtype, size_t gridsize, size_t nx, int gridno, int ngrids, in
bool invert_result = false;
if (cell_corners_xyz[coordinate_to_ignore - 1] < 0) invert_result = true;
switch (coordinate_to_ignore)
{
case 1:
for (int corner_no = 0; corner_no <= actual_number_of_corners; corner_no++)
{
cell_corners_plane_projection[corner_no * 2 + 0] = cell_corners_xyz[corner_no * 3 + 1];
cell_corners_plane_projection[corner_no * 2 + 1] = cell_corners_xyz[corner_no * 3 + 2];
}
center_point_plane_projection[0] = center_point_xyz[1];
center_point_plane_projection[1] = center_point_xyz[2];
break;
case 2:
for (int corner_no = 0; corner_no <= actual_number_of_corners; corner_no++)
{
cell_corners_plane_projection[corner_no * 2 + 0] = cell_corners_xyz[corner_no * 3 + 2];
cell_corners_plane_projection[corner_no * 2 + 1] = cell_corners_xyz[corner_no * 3 + 0];
}
center_point_plane_projection[0] = center_point_xyz[2];
center_point_plane_projection[1] = center_point_xyz[0];
break;
case 3:
for (int corner_no = 0; corner_no <= actual_number_of_corners; corner_no++)
{
cell_corners_plane_projection[corner_no * 2 + 0] = cell_corners_xyz[corner_no * 3 + 0];
cell_corners_plane_projection[corner_no * 2 + 1] = cell_corners_xyz[corner_no * 3 + 1];
}
center_point_plane_projection[0] = center_point_xyz[0];
center_point_plane_projection[1] = center_point_xyz[1];
break;
}
set_center_point_plane_projection(coordinate_to_ignore, center_point_xyz, center_point_plane_projection);
set_cell_corners_plane_projection(coordinate_to_ignore, actual_number_of_corners, cell_corners_xyz.data(), cell_corners_plane_projection.data());
// Checking for convexity of the cell.
......
......@@ -17,6 +17,8 @@
#ifndef VERIFYGRID_H
#define VERIFYGRID_H
void set_center_point_plane_projection(int coordinate_to_ignore, const double (&center_point_xyz)[3], double (&center_point_plane_projection)[2]);
void set_cell_corners_plane_projection(int coordinate_to_ignore, int ncorner, const double *cell_corners_xyz, double *cell_corners_plane_projection);
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);
......
Supports Markdown
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