private boolean completeRotationGroup ( Rotation ... additionalRots ) { PermutationGroup g = new PermutationGroup ( ) ; for ( Rotation s : rotations ) { g . addPermutation ( s . getPermutation ( ) ) ; } for ( Rotation s : additionalRots ) { g . addPermutation ( s . getPermutation ( ) ) ; // inputs should not have been added already assert evaluatedPermutations . get ( s . getPermutation ( ) ) == null ; } g . completeGroup ( ) ; // the group is complete, nothing to do if ( g . getOrder ( ) == rotations . getOrder ( ) + additionalRots . length ) { for ( Rotation s : additionalRots ) { addRotation ( s ) ; } return true ; } // try to complete the group List < Rotation > newRots = new ArrayList <> ( g . getOrder ( ) ) ; // First, quick check for whether they're allowed for ( List < Integer > permutation : g ) { if ( evaluatedPermutations . containsKey ( permutation ) ) { Rotation rot = evaluatedPermutations . get ( permutation ) ; if ( rot == null ) { return false ; } } else { if ( ! isAllowedPermutation ( permutation ) ) { return false ; } } } // Slower check including the superpositions for ( List < Integer > permutation : g ) { Rotation rot ; if ( evaluatedPermutations . containsKey ( permutation ) ) { rot = evaluatedPermutations . get ( permutation ) ; } else { rot = isValidPermutation ( permutation ) ; } if ( rot == null ) { // if any induced rotation is invalid, abort return false ; } if ( ! evaluatedPermutations . containsKey ( permutation ) ) { //novel newRots . add ( rot ) ; } } // Add rotations for ( Rotation rot : newRots ) { addRotation ( rot ) ; } return true ; }
Combine current rotations to make all possible permutations . If these are all valid add them to the rotations