static void test_lwpoint_set_ordinate(void) { POINT4D p; p.x = 0.0; p.y = 0.0; p.z = 0.0; p.m = 0.0; lwpoint_set_ordinate(&p, 'X', 1.5); CU_ASSERT_EQUAL( p.x, 1.5 ); lwpoint_set_ordinate(&p, 'M', 2.5); CU_ASSERT_EQUAL( p.m, 2.5 ); lwpoint_set_ordinate(&p, 'Z', 3.5); CU_ASSERT_EQUAL( p.z, 3.5 ); }
/** * Given two points, a dimensionality, an ordinate, and an interpolation value * generate a new point that is proportionally between the input points, * using the values in the provided dimension as the scaling factors. */ int point_interpolate(const POINT4D *p1, const POINT4D *p2, POINT4D *p, int hasz, int hasm, char ordinate, double interpolation_value) { static char* dims = "XYZM"; double p1_value = lwpoint_get_ordinate(p1, ordinate); double p2_value = lwpoint_get_ordinate(p2, ordinate); double proportion; int i = 0; if ( ! ( ordinate == 'X' || ordinate == 'Y' || ordinate == 'Z' || ordinate == 'M' ) ) { lwerror("Cannot set %c ordinate.", ordinate); return 0; } if ( FP_MIN(p1_value, p2_value) > interpolation_value || FP_MAX(p1_value, p2_value) < interpolation_value ) { lwerror("Cannot interpolate to a value (%g) not between the input points (%g, %g).", interpolation_value, p1_value, p2_value); return 0; } proportion = fabs((interpolation_value - p1_value) / (p2_value - p1_value)); for ( i = 0; i < 4; i++ ) { double newordinate = 0.0; if ( dims[i] == 'Z' && ! hasz ) continue; if ( dims[i] == 'M' && ! hasm ) continue; p1_value = lwpoint_get_ordinate(p1, dims[i]); p2_value = lwpoint_get_ordinate(p2, dims[i]); newordinate = p1_value + proportion * (p2_value - p1_value); lwpoint_set_ordinate(p, dims[i], newordinate); LWDEBUGF(4, " clip ordinate(%c) p1_value(%g) p2_value(%g) proportion(%g) newordinate(%g) ", dims[i], p1_value, p2_value, proportion, newordinate ); } return 1; }