void compute_angular_endpoints_2planes(
	unsigned int tune_low_weight_limit,
	const block_size_descriptor& bsd,
	const float* dec_weight_quant_uvalue,
	const float* dec_weight_quant_sig,
	float low_value1[WEIGHTS_MAX_BLOCK_MODES],
	float high_value1[WEIGHTS_MAX_BLOCK_MODES],
	float low_value2[WEIGHTS_MAX_BLOCK_MODES],
	float high_value2[WEIGHTS_MAX_BLOCK_MODES]
) {
	float low_values1[WEIGHTS_MAX_DECIMATION_MODES][12];
	float high_values1[WEIGHTS_MAX_DECIMATION_MODES][12];
	float low_values2[WEIGHTS_MAX_DECIMATION_MODES][12];
	float high_values2[WEIGHTS_MAX_DECIMATION_MODES][12];

	promise(bsd.decimation_mode_count > 0);
	for (unsigned int i = 0; i < bsd.decimation_mode_count; i++)
	{
		const decimation_mode& dm = bsd.decimation_modes[i];
		if (dm.maxprec_2planes < 0 || !dm.percentile_hit)
		{
			continue;
		}

		unsigned int weight_count = bsd.decimation_tables[i]->weight_count;

		if (weight_count < tune_low_weight_limit)
		{
			compute_angular_endpoints_for_quant_levels_lwc(
				weight_count,
				dec_weight_quant_uvalue + i * BLOCK_MAX_WEIGHTS,
				dec_weight_quant_sig + i * BLOCK_MAX_WEIGHTS,
				dm.maxprec_2planes, low_values1[i], high_values1[i]);

			compute_angular_endpoints_for_quant_levels_lwc(
				weight_count,
				dec_weight_quant_uvalue + i * BLOCK_MAX_WEIGHTS + WEIGHTS_PLANE2_OFFSET,
				dec_weight_quant_sig + i * BLOCK_MAX_WEIGHTS + WEIGHTS_PLANE2_OFFSET,
				dm.maxprec_2planes, low_values2[i], high_values2[i]);
		}
		else
		{
			compute_angular_endpoints_for_quant_levels(
				weight_count,
				dec_weight_quant_uvalue + i * BLOCK_MAX_WEIGHTS,
				dec_weight_quant_sig + i * BLOCK_MAX_WEIGHTS,
				dm.maxprec_2planes, low_values1[i], high_values1[i]);

			compute_angular_endpoints_for_quant_levels(
				weight_count,
				dec_weight_quant_uvalue + i * BLOCK_MAX_WEIGHTS + WEIGHTS_PLANE2_OFFSET,
				dec_weight_quant_sig + i * BLOCK_MAX_WEIGHTS + WEIGHTS_PLANE2_OFFSET,
				dm.maxprec_2planes, low_values2[i], high_values2[i]);
		}
	}

	promise(bsd.block_mode_count > 0);
	for (unsigned int i = 0; i < bsd.block_mode_count; ++i)
	{
		const block_mode& bm = bsd.block_modes[i];
		if (!bm.is_dual_plane || !bm.percentile_hit)
		{
			continue;
		}

		unsigned int quant_mode = bm.quant_mode;
		unsigned int decim_mode = bm.decimation_mode;

		low_value1[i] = low_values1[decim_mode][quant_mode];
		high_value1[i] = high_values1[decim_mode][quant_mode];
		low_value2[i] = low_values2[decim_mode][quant_mode];
		high_value2[i] = high_values2[decim_mode][quant_mode];
	}
}
void compute_angular_endpoints_2planes(
	unsigned int tune_low_weight_limit,
	const block_size_descriptor& bsd,
	const float* dec_weight_quant_uvalue,
	const float* dec_weight_quant_sig,
	float low_value1[WEIGHTS_MAX_BLOCK_MODES],
	float high_value1[WEIGHTS_MAX_BLOCK_MODES],
	float low_value2[WEIGHTS_MAX_BLOCK_MODES],
	float high_value2[WEIGHTS_MAX_BLOCK_MODES]
) {
	float low_values1[WEIGHTS_MAX_DECIMATION_MODES][12];
	float high_values1[WEIGHTS_MAX_DECIMATION_MODES][12];
	float low_values2[WEIGHTS_MAX_DECIMATION_MODES][12];
	float high_values2[WEIGHTS_MAX_DECIMATION_MODES][12];

	promise(bsd.decimation_mode_count > 0);
	for (unsigned int i = 0; i < bsd.decimation_mode_count; i++)
	{
		const decimation_mode& dm = bsd.decimation_modes[i];
		if (dm.maxprec_2planes < 0 || !dm.percentile_hit)
		{
			continue;
		}

		unsigned int weight_count = bsd.decimation_tables[i]->weight_count;

		if (weight_count < tune_low_weight_limit)
		{
			compute_angular_endpoints_for_quant_levels_lwc(
				weight_count,
				dec_weight_quant_uvalue + i * BLOCK_MAX_WEIGHTS,
				dec_weight_quant_sig + i * BLOCK_MAX_WEIGHTS,
				dm.maxprec_2planes, low_values1[i], high_values1[i]);

			compute_angular_endpoints_for_quant_levels_lwc(
				weight_count,
				dec_weight_quant_uvalue + i * BLOCK_MAX_WEIGHTS + WEIGHTS_PLANE2_OFFSET,
				dec_weight_quant_sig + i * BLOCK_MAX_WEIGHTS + WEIGHTS_PLANE2_OFFSET,
				dm.maxprec_2planes, low_values2[i], high_values2[i]);
		}
		else
		{
			compute_angular_endpoints_for_quant_levels(
				weight_count,
				dec_weight_quant_uvalue + i * BLOCK_MAX_WEIGHTS,
				dec_weight_quant_sig + i * BLOCK_MAX_WEIGHTS,
				dm.maxprec_2planes, low_values1[i], high_values1[i]);

			compute_angular_endpoints_for_quant_levels(
				weight_count,
				dec_weight_quant_uvalue + i * BLOCK_MAX_WEIGHTS + WEIGHTS_PLANE2_OFFSET,
				dec_weight_quant_sig + i * BLOCK_MAX_WEIGHTS + WEIGHTS_PLANE2_OFFSET,
				dm.maxprec_2planes, low_values2[i], high_values2[i]);
		}
	}

	promise(bsd.block_mode_count > 0);
	for (unsigned int i = 0; i < bsd.block_mode_count; ++i)
	{
		const block_mode& bm = bsd.block_modes[i];
		if (!bm.is_dual_plane || !bm.percentile_hit)
		{
			continue;
		}

		unsigned int quant_mode = bm.quant_mode;
		unsigned int decim_mode = bm.decimation_mode;

		low_value1[i] = low_values1[decim_mode][quant_mode];
		high_value1[i] = high_values1[decim_mode][quant_mode];
		low_value2[i] = low_values2[decim_mode][quant_mode];
		high_value2[i] = high_values2[decim_mode][quant_mode];
	}
}