/** * Rearrange point (x, y) in the HEALPix projection by * combining the polar caps into two polar squares. * Put the north polar square in position north_square and * the south polar square in position south_square. * If inverse=1, then uncombine the polar caps. * @param north_square integer between 0 and 3. * @param south_square integer between 0 and 3. **/ static XY combine_caps(double x, double y, int north_square, int south_square, int inverse) { XY xy; double v[2]; double a[2]; double vector[2]; double v_min_c[2]; double ret_dot[2]; CapMap capmap = get_cap(x, y, north_square, south_square, inverse); if (capmap.region == equatorial) { xy.x = capmap.x; xy.y = capmap.y; return xy; } v[0] = x; v[1] = y; if (inverse == 0) { /* Rotate (x, y) about its polar cap tip and then translate it to north_square or south_square. */ int pole = 0; double (*tmpRot)[2]; double c[2] = {capmap.x, capmap.y}; if (capmap.region == north) { pole = north_square; a[0] = (-3.0*M_PI/4.0 + pole*M_PI/2); a[1] = (M_PI/2.0 + pole*0); tmpRot = rot[get_rotate_index(capmap.cn - pole)]; vector_sub(v, c, v_min_c); dot_product(tmpRot, v_min_c, ret_dot); vector_add(ret_dot, a, vector); } else { pole = south_square; a[0] = (-3.0*M_PI/4.0 + pole*M_PI/2); a[1] = (M_PI/-2.0 + pole*0); tmpRot = rot[get_rotate_index(-1*(capmap.cn - pole))]; vector_sub(v, c, v_min_c); dot_product(tmpRot, v_min_c, ret_dot); vector_add(ret_dot, a, vector); } xy.x = vector[0]; xy.y = vector[1]; return xy; } else { /* Inverse function. Unrotate (x, y) and then translate it back. */ int pole = 0; double (*tmpRot)[2]; double c[2] = {capmap.x, capmap.y}; /* disassemble */ if (capmap.region == north) { pole = north_square; a[0] = (-3.0*M_PI/4.0 + capmap.cn*M_PI/2); a[1] = (M_PI/2.0 + capmap.cn*0); tmpRot = rot[get_rotate_index(-1*(capmap.cn - pole))]; vector_sub(v, c, v_min_c); dot_product(tmpRot, v_min_c, ret_dot); vector_add(ret_dot, a, vector); } else { pole = south_square; a[0] = (-3.0*M_PI/4.0 + capmap.cn*M_PI/2); a[1] = (M_PI/-2.0 + capmap.cn*0); tmpRot = rot[get_rotate_index(capmap.cn - pole)]; vector_sub(v, c, v_min_c); dot_product(tmpRot, v_min_c, ret_dot); vector_add(ret_dot, a, vector); } xy.x = vector[0]; xy.y = vector[1]; return xy; } }
inline void combine_caps(T& xy_x, T& xy_y, int north_square, int south_square, int inverse) { static const T half_pi = detail::half_pi<T>(); static const T fourth_pi = detail::fourth_pi<T>(); T v[2]; T c[2]; T vector[2]; T v_min_c[2]; T ret_dot[2]; const double (*tmpRot)[2]; int pole = 0; cap_map<T> capmap = get_cap(xy_x, xy_y, north_square, south_square, inverse); if (capmap.region == cap_map<T>::equatorial) { xy_x = capmap.x; xy_y = capmap.y; return; } v[0] = xy_x; v[1] = xy_y; c[0] = capmap.x; c[1] = capmap.y; if (inverse == 0) { /* Rotate (xy_x, xy_y) about its polar cap tip and then translate it to north_square or south_square. */ if (capmap.region == cap_map<T>::north) { pole = north_square; tmpRot = rot[get_rotate_index(capmap.cn - pole)]; } else { pole = south_square; tmpRot = rot[get_rotate_index(-1*(capmap.cn - pole))]; } } else { /* Inverse function. Unrotate (xy_x, xy_y) and then translate it back. */ /* disassemble */ if (capmap.region == cap_map<T>::north) { pole = north_square; tmpRot = rot[get_rotate_index(-1*(capmap.cn - pole))]; } else { pole = south_square; tmpRot = rot[get_rotate_index(capmap.cn - pole)]; } } vector_sub(v, c, v_min_c); dot_product(tmpRot, v_min_c, ret_dot); { T a[2]; /* Workaround cppcheck git issue */ T* pa = a; // TODO: in proj4 5.0.0 this line is used instead //pa[0] = -3.0*fourth_pi + ((inverse == 0) ? 0 : capmap.cn) *half_pi; pa[0] = -3.0*fourth_pi + ((inverse == 0) ? pole : capmap.cn) *half_pi; pa[1] = half_pi; vector_add(ret_dot, a, vector); } xy_x = vector[0]; xy_y = vector[1]; }