fn find_optimal_range(
	range: u32,
	range_vals: &mut Vec<(VeraPaletteEntry, Vec<usize>)>,
	align_to_16: bool,
) -> Result<(bool, usize), Error> {
	// convert to permutator lib format
	let mut lists = vec![];
	for val in range_vals.iter() {
		let mut in_vec = vec![];
		for i in val.1.iter() {
			in_vec.push(format!("{}", i));
		}
		lists.push(in_vec);
	}

	// Convert the `Vec<Vec<String>>` into a `Vec<Vec<&str>>`
	let tmp: Vec<Vec<&str>> = lists
		.iter()
		.map(|list| list.iter().map(AsRef::as_ref).collect::<Vec<&str>>())
		.collect();

	// Convert the `Vec<Vec<&str>>` into a `Vec<&[&str]>`
	let vector_of_slices: Vec<&[&str]> = tmp.iter().map(AsRef::as_ref).collect();

	// Initialize the Permutator
	let permutator = Permutator::new(&vector_of_slices);

	// iteration 2: allocates a new buffer for each permutation
	// you may opt to re-allocate or not (see iteration 1)
	for permutation in permutator {
		let max = match permutation
			.iter()
			.map(|v| usize::from_str_radix(&v, 10))
			.filter_map(Result::ok)
			.max()
		{
			Some(i) => i,
			None => {
				return Err(ErrorKind::IteratorError("Finding max index".to_string()).into());
			}
		};
		let mut min = match permutation
			.iter()
			.map(|v| usize::from_str_radix(&v, 10))
			.filter_map(Result::ok)
			.min()
		{
			Some(i) => i,
			None => {
				return Err(ErrorKind::IteratorError("Finding min index".to_string()).into());
			}
		};

		if align_to_16 {
			// Now min needs to be rounded down to the nearest multiple of 16, since pal offsets
			// are calculated as offset * 16
			min -= min % 16;
		}

		// if we're in range, we're done
		if max - min <= range as usize {
			for i in 0..permutation.len() {
				range_vals[i].1 = vec![usize::from_str_radix(permutation[i], 10)?];
			}
			return Ok((true, min));
		}
	}
	Ok((false, 0))
}
/// Attempts to find a solution for a range of possible colours in the palette
/// that fit within the depth mode
Attempts to find a solution for a range of possible colours in the palette
that fit within the depth mode
Attempts to find a solution for a range of possible colours in the palette that fit within the depth mode
fn find_optimal_range(
	range: u32,
	range_vals: &mut Vec<(VeraPaletteEntry, Vec<usize>)>,
	align_to_16: bool,
) -> Result<(bool, usize), Error> {
	// convert to permutator lib format
	let mut lists = vec![];
	for val in range_vals.iter() {
		let mut in_vec = vec![];
		for i in val.1.iter() {
			in_vec.push(format!("{}", i));
		}
		lists.push(in_vec);
	}
	// Convert the `Vec<Vec<String>>` into a `Vec<Vec<&str>>`
	let tmp: Vec<Vec<&str>> = lists
		.iter()
		.map(|list| list.iter().map(AsRef::as_ref).collect::<Vec<&str>>())
		.collect();
	// Convert the `Vec<Vec<&str>>` into a `Vec<&[&str]>`
	let vector_of_slices: Vec<&[&str]> = tmp.iter().map(AsRef::as_ref).collect();
	// Initialize the Permutator
	let permutator = Permutator::new(&vector_of_slices);
	// iteration 2: allocates a new buffer for each permutation
	// you may opt to re-allocate or not (see iteration 1)
	for permutation in permutator {
		let max = match permutation
			.iter()
			.map(|v| usize::from_str_radix(&v, 10))
			.filter_map(Result::ok)
			.max()
		{
			Some(i) => i,
			None => {
				return Err(ErrorKind::IteratorError("Finding max index".to_string()).into());
			}
		};
		let mut min = match permutation
			.iter()
			.map(|v| usize::from_str_radix(&v, 10))
			.filter_map(Result::ok)
			.min()
		{
			Some(i) => i,
			None => {
				return Err(ErrorKind::IteratorError("Finding min index".to_string()).into());
			}
		};
		if align_to_16 {
			// Now min needs to be rounded down to the nearest multiple of 16, since pal offsets
			// are calculated as offset * 16
			min -= min % 16;
		}
		// if we're in range, we're done
		if max - min <= range as usize {
			for i in 0..permutation.len() {
				range_vals[i].1 = vec![usize::from_str_radix(permutation[i], 10)?];
			}
			return Ok((true, min));
		}
	}
	Ok((false, 0))
}
fn find_optimal_range ( range : u32 , range_vals : & mut Vec < ( VeraPaletteEntry , Vec < usize > ) > , align_to_16 : bool , ) -> Result < ( bool , usize ) , Error > { // convert to permutator lib format let mut lists = vec ! [ ] ; for val in range_vals . iter ( ) { let mut in_vec = vec ! [ ] ; for i in val . 1 . iter ( ) { in_vec . push ( format ! ( " " i ) ) ; } lists . push ( in_vec ) ; } // Convert the `Vec<Vec<String>>` into a `Vec<Vec<&str>>` let tmp : Vec < Vec < & str > > = lists . iter ( ) . map ( | list | list . iter ( ) . map ( AsRef :: as_ref ) . collect :: < Vec < & str > > ( ) ) . collect ( ) ; // Convert the `Vec<Vec<&str>>` into a `Vec<&[&str]>` let vector_of_slices : Vec < & [ & str ] > = tmp . iter ( ) . map ( AsRef :: as_ref ) . collect ( ) ; // Initialize the Permutator let permutator = Permutator :: new ( & vector_of_slices ) ; // iteration 2: allocates a new buffer for each permutation // you may opt to re-allocate or not (see iteration 1) for permutation in permutator { let max = match permutation . iter ( ) . map ( | v | usize :: from_str_radix ( & v , 10 ) ) . filter_map ( Result :: ok ) . max ( ) { Some ( i ) => i , None => { return Err ( ErrorKind :: IteratorError ( " " . to_string ( ) ) . into ( ) ) ; } } ; let mut min = match permutation . iter ( ) . map ( | v | usize :: from_str_radix ( & v , 10 ) ) . filter_map ( Result :: ok ) . min ( ) { Some ( i ) => i , None => { return Err ( ErrorKind :: IteratorError ( " " . to_string ( ) ) . into ( ) ) ; } } ; if align_to_16 { // Now min needs to be rounded down to the nearest multiple of 16, since pal offsets // are calculated as offset * 16 min -= min % 16 ; } // if we're in range, we're done if max - min <= range as usize { for i in 0 .. permutation . len ( ) { range_vals [ i ] . 1 = vec ! [ usize from_str_radix ( permutation [ i ] 10 ) ] ; } return Ok ( ( true , min ) ) ; } } Ok ( ( false , 0 ) ) }
Attempts to find a solution for a range of possible colours in the palette
that fit within the depth mode
Attempts to find a solution for a range of possible colours in the palette that fit within the depth mode
range
u32
range_vals
&mut Vec<(VeraPaletteEntry, Vec<usize>)>
align_to_16
bool