/** Find the parent chain between a parent and a child (inclusive)

We keep track of the HexBlocks of size `$size` within a `grid_distance($size)` radius of $child,
until we read `$size == $child.size + 1` for which there is only a single solution
if `$parent` and `$child` are indeed related.

Returns None if the sizes are not right.
Panics if they are not parent and child.
*/


Returns None if the sizes are not right.
Panics if they are not parent and child.
Returns None if the sizes are not right . Panics if they are not parent and child .
fn find_parents(small_child: HexBlock, parent: HexBlock) -> Option<HexChain> {
	if parent.size - small_child.size < 1 {
		return None;
	}
	let parent_size = parent.size;
	let mut parent_chains: Vec<HexChain> = vec![ HexChain(vec![parent]) ];
	for gridsize in (small_child.size + 1 .. parent_size).rev() {
		let mut next_parent_chains = Vec::with_capacity(parent_chains.len());
		for chain in parent_chains {
			let chain_head = chain.last().unwrap();
			for child in chain_head.ring_children().unwrap().iter() {
				debug_assert!(gridsize == child.size);
				if dist(&small_child, child) <= grid_distance(gridsize) {
					let mut new_chain = chain.clone();
					new_chain.push(child.clone());
					next_parent_chains.push(new_chain);
				}
			}
		}
		parent_chains = next_parent_chains;
	}
	// We should have gridsize == small_child.size + 1
	/* A HexBlock of size n+1 is a (hex) circle of diameter 1 of HexBlocks of size n,
	which means we can use the distance equality */
	let mut parents = parent_chains.into_iter()
		.find(|e| dist(&small_child, e.last().unwrap()) == grid_distance(small_child.size))
		.expect("parent and child should be related");
	parents.push(small_child);
	Some(parents)
}
fn find_parents ( small_child : HexBlock , parent : HexBlock ) -> Option < HexChain > { if parent . size - small_child . size < 1 { return None ; } let parent_size = parent . size ; let mut parent_chains : Vec < HexChain > = vec ! [ HexChain ( vec [ parent ] ) ] ; for gridsize in ( small_child . size + 1 .. parent_size ) . rev ( ) { let mut next_parent_chains = Vec :: with_capacity ( parent_chains . len ( ) ) ; for chain in parent_chains { let chain_head = chain . last ( ) . unwrap ( ) ; for child in chain_head . ring_children ( ) . unwrap ( ) . iter ( ) { debug_assert ! ( gridsize child size ) ; if dist ( & small_child , child ) <= grid_distance ( gridsize ) { let mut new_chain = chain . clone ( ) ; new_chain . push ( child . clone ( ) ) ; next_parent_chains . push ( new_chain ) ; } } } parent_chains = next_parent_chains ; } // We should have gridsize == small_child.size + 1 /* A HexBlock of size n+1 is a (hex) circle of diameter 1 of HexBlocks of size n,
	which means we can use the distance equality */ let mut parents = parent_chains . into_iter ( ) . find ( | e | dist ( & small_child , e . last ( ) . unwrap ( ) ) == grid_distance ( small_child . size ) ) . expect ( " " ) ; parents . push ( small_child ) ; Some ( parents ) }
Find the parent chain between a parent and a child (inclusive)
We keep track of the HexBlocks of size `$size` within a `grid_distance($size)` radius of $child,
until we read `$size == $child.size + 1` for which there is only a single solution
if `$parent` and `$child` are indeed related.
Find the parent chain between a parent and a child ( inclusive ) We keep track of the HexBlocks of size ` $size ` within a ` grid_distance ( $size ) ` radius of $child until we read ` $size == $child . size + 1 ` for which there is only a single solution if ` $parent ` and ` $child ` are indeed related .
small_child
HexBlock
parent
HexBlock