All files / adapters/three solverFrame.ts

100% Statements 14/14
100% Branches 0/0
100% Functions 0/0
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50                                  37x 37x 39x   37x 19x   58x 37x 1x     37x 52x 52x                         37x 6x   37x    
import * as VirtualCubeFrame from '@wstein/regrip-core/domain/VirtualCubeFrame';
import type { regripToken as RegripToken } from '@wstein/regrip-core/domain/CubeNotation';
 
export type Vector = readonly [number, number, number];
export type SolverOrientation = {
  right: Vector;
  up: Vector;
  front: Vector;
  faces: { right: string; up: string; front: string };
};
 
/**
 * Maps the cube's fixed body-local BLE face labels into the solver frame established
 * by emitted virtual x/y/z regrips. This is presentation/history state only;
 * the body-local move stream and Twisty player remain in protocol URFDLB.
 */
export function createSolverFrame() {
  let frame = VirtualCubeFrame.make();
  const reset = (): void => {
    frame = VirtualCubeFrame.reset(frame);
  };
  const applyRegrip = (notationToken: RegripToken): void => {
    frame = VirtualCubeFrame.applyRegrip(frame, notationToken);
  };
  const translate = (move: string): string => VirtualCubeFrame.translate(frame, move);
  const solverToken = (bodyToken: RegripToken): RegripToken =>
    VirtualCubeFrame.solverToken(frame, bodyToken);
 
  /** Body directions occupied by the user-facing logical R/U/F axes. */
  const orientation = (): SolverOrientation => {
    const orientation = VirtualCubeFrame.orientation(frame);
    return {
      right: [orientation.right.x, orientation.right.y, orientation.right.z],
      up: [orientation.up.x, orientation.up.y, orientation.up.z],
      front: [orientation.front.x, orientation.front.y, orientation.front.z],
      faces: { right: orientation.rightFace, up: orientation.upFace, front: orientation.frontFace },
    };
  };
 
  /**
   * Express body-local Kociemba facelets in the current solver regrip frame.
   * Both sticker positions/grid orientation and sticker colour labels change.
   * This is an opt-in presentation transform; canonical state exports must not use it.
   */
  const reframeFacelets = (facelets: string): string =>
    VirtualCubeFrame.reframeFacelets(frame, facelets);
 
  return { applyRegrip, orientation, reframeFacelets, reset, solverToken, translate };
}