-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
181 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,66 @@ | ||
use cubing::kpuzzle::KPattern; | ||
use std::cmp::min; | ||
|
||
pub(crate) fn mask(source_pattern: &KPattern, mask_pattern: &KPattern) -> KPattern { | ||
use cubing::kpuzzle::{KPattern, OrientationWithMod}; | ||
|
||
use crate::scramble::PuzzleError; | ||
|
||
pub(crate) fn mask( | ||
source_pattern: &KPattern, | ||
mask_pattern: &KPattern, | ||
) -> Result<KPattern, PuzzleError> { | ||
let mut masked_pattern = mask_pattern.clone(); | ||
for orbit_info in source_pattern.kpuzzle().orbit_info_iter() { | ||
for i in 0..orbit_info.num_pieces { | ||
let old_piece = source_pattern.get_piece(orbit_info, i); | ||
let old_piece_mapped = mask_pattern.get_piece(orbit_info, old_piece); | ||
masked_pattern.set_piece(orbit_info, i, old_piece_mapped); | ||
let orientation_with_mod = source_pattern.get_orientation_with_mod(orbit_info, i); | ||
masked_pattern.set_orientation_with_mod(orbit_info, i, orientation_with_mod); | ||
|
||
let source_orientation_with_mod = | ||
source_pattern.get_orientation_with_mod(orbit_info, i); | ||
let mask_orientation_with_mod = mask_pattern.get_orientation_with_mod(orbit_info, i); | ||
|
||
if mask_orientation_with_mod.orientation != 0 { | ||
return Err(PuzzleError { | ||
description: "Masks cannot currently have piece orientation".to_owned(), | ||
}); | ||
}; | ||
|
||
dbg!("1"); | ||
|
||
let source_mod = source_orientation_with_mod.orientation_mod; | ||
let source_mod = if source_mod == 0 { | ||
orbit_info.num_orientations | ||
} else { | ||
source_mod | ||
}; | ||
dbg!("2"); | ||
|
||
let mask_mod = mask_orientation_with_mod.orientation_mod; | ||
let mask_mod = if mask_mod == 0 { | ||
orbit_info.num_orientations | ||
} else { | ||
mask_mod | ||
}; | ||
dbg!("3", mask_mod, source_mod); | ||
|
||
if source_mod % mask_mod != 0 && mask_mod % source_mod != 0 { | ||
return Err(PuzzleError { | ||
description: "Incompatible orientation mod in mask".to_owned(), | ||
}); | ||
}; | ||
|
||
let masked_mod = min(source_mod, mask_mod); | ||
let orientation_with_mod = OrientationWithMod { | ||
orientation: source_orientation_with_mod.orientation % masked_mod, | ||
orientation_mod: if masked_mod == orbit_info.num_orientations { | ||
0 | ||
} else { | ||
masked_mod | ||
}, | ||
}; | ||
|
||
masked_pattern.set_orientation_with_mod(orbit_info, i, &orientation_with_mod); | ||
} | ||
} | ||
masked_pattern | ||
Ok(masked_pattern) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters