All files / domain CubeSymmetry.res.mjs

96.15% Statements 25/26
90% Branches 9/10
100% Functions 6/6
96% Lines 24/25

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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81            4x   4x                                   4x         4x   4x   4x 96x 96x 96x 288x 3508x 92x 92x           3003x 72072x 7205x   64867x     3003x 2416x   587x         2x 12x     12x         4x                
// Generated by ReScript, PLEASE EDIT WITH CARE
 
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
import * as Quaternion$WsteinRegripCore from "./Quaternion.res.mjs";
 
let quarterTurn = Quaternion$WsteinRegripCore.degreesToRadians(90);
 
let generators = [
  Quaternion$WsteinRegripCore.fromEuler({
    x: quarterTurn,
    y: 0,
    z: 0
  }),
  Quaternion$WsteinRegripCore.fromEuler({
    x: 0,
    y: quarterTurn,
    z: 0
  }),
  Quaternion$WsteinRegripCore.fromEuler({
    x: 0,
    y: 0,
    z: quarterTurn
  })
];
 
let quarterTurnGenerators = Belt_Array.concatMany([
  generators,
  generators.map(Quaternion$WsteinRegripCore.conjugate)
]);
 
let found = [Quaternion$WsteinRegripCore.identity];
 
let next = 0;
 
while (next < found.length) {
  let pose = found[next];
  next = next + 1 | 0;
  generators.forEach(generator => {
    let candidate = Quaternion$WsteinRegripCore.normalize(Quaternion$WsteinRegripCore.multiply(pose, generator));
    if (!found.some(existing => Quaternion$WsteinRegripCore.angle(existing, candidate) < 0.00001)) {
      found.push(candidate);
      return;
    }
  });
};
 
function nearest(raw, current, marginRad) {
  let best = Stdlib_Array.reduce(found, Quaternion$WsteinRegripCore.identity, (best, candidate) => {
    if (Quaternion$WsteinRegripCore.angle(raw, candidate) < Quaternion$WsteinRegripCore.angle(raw, best)) {
      return candidate;
    } else {
      return best;
    }
  });
  if (current !== undefined && Quaternion$WsteinRegripCore.angle(raw, best) + marginRad >= Quaternion$WsteinRegripCore.angle(raw, current)) {
    return current;
  } else {
    return best;
  }
}
 
function nearestQuarterTurn(raw) {
  return Stdlib_Array.reduce(quarterTurnGenerators, generators[0], (best, candidate) => {
    Iif (Quaternion$WsteinRegripCore.angle(raw, candidate) < Quaternion$WsteinRegripCore.angle(raw, best)) {
      return candidate;
    } else {
      return best;
    }
  });
}
 
let poses = found;
 
export {
  poses,
  nearest,
  nearestQuarterTurn,
}
/* quarterTurn Not a pure module */