All files / domain OrientationStabilizer.res.mjs

100% Statements 30/30
93.75% Branches 15/16
100% Functions 5/5
100% Lines 30/30

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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96            2x   2x   2x   2x               2x           1x       2x       19x               19x 19x 19x 19x 19x 19x 19x   19x 13x 13x 13x 12x 12x   1x     6x   19x 19x                         15x 15x 15x 15x 15x                              
// Generated by ReScript, PLEASE EDIT WITH CARE
 
import * as Quaternion$WsteinRegripCore from "./Quaternion.res.mjs";
import * as CubeSymmetry$WsteinRegripCore from "./CubeSymmetry.res.mjs";
import * as MagneticDetent$WsteinRegripCore from "./MagneticDetent.res.mjs";
 
let defaults_radiusDeg = MagneticDetent$WsteinRegripCore.defaults.radiusDeg;
 
let defaults_snapDeg = MagneticDetent$WsteinRegripCore.defaults.snapDeg;
 
let defaults_velocityMax = MagneticDetent$WsteinRegripCore.defaults.velocityMax;
 
let defaults = {
  radiusDeg: defaults_radiusDeg,
  snapDeg: defaults_snapDeg,
  hysteresisDeg: 5,
  velocityMax: defaults_velocityMax,
  driftDegPerSec: 2
};
 
let initial = {
  lockedPose: undefined,
  driftOffset: Quaternion$WsteinRegripCore.identity
};
 
function reset(param) {
  return initial;
}
 
function lockedPose(state) {
  return state.lockedPose;
}
 
function detentConfig(config) {
  return {
    radiusDeg: config.radiusDeg,
    snapDeg: config.snapDeg,
    velocityMax: config.velocityMax
  };
}
 
function stepSample(state, raw, velocityOpt, dtSecondsOpt, configOpt) {
  let velocity = velocityOpt !== undefined ? velocityOpt : 0;
  let dtSeconds = dtSecondsOpt !== undefined ? dtSecondsOpt : 0;
  let config = configOpt !== undefined ? configOpt : defaults;
  let corrected = Quaternion$WsteinRegripCore.multiply(state.driftOffset, raw);
  let target = CubeSymmetry$WsteinRegripCore.nearest(corrected, state.lockedPose, Quaternion$WsteinRegripCore.degreesToRadians(config.hysteresisDeg));
  let velocityGate = 1 - Math.min(1, Math.abs(velocity) / config.velocityMax);
  let maximumStep = Quaternion$WsteinRegripCore.degreesToRadians(config.driftDegPerSec) * dtSeconds * velocityGate;
  let driftOffset;
  if (maximumStep > 0) {
    let difference = Quaternion$WsteinRegripCore.multiply(target, Quaternion$WsteinRegripCore.conjugate(corrected));
    let differenceAngle = Quaternion$WsteinRegripCore.angle(corrected, target);
    if (differenceAngle > 0) {
      let fraction = Math.min(1, maximumStep / differenceAngle);
      driftOffset = Quaternion$WsteinRegripCore.multiply(Quaternion$WsteinRegripCore.slerp(Quaternion$WsteinRegripCore.identity, difference, fraction), state.driftOffset);
    } else {
      driftOffset = state.driftOffset;
    }
  } else {
    driftOffset = state.driftOffset;
  }
  let adjusted = Quaternion$WsteinRegripCore.multiply(driftOffset, raw);
  return [
    {
      lockedPose: target,
      driftOffset: driftOffset
    },
    {
      driftCorrected: adjusted,
      stabilized: MagneticDetent$WsteinRegripCore.apply(adjusted, target, velocity, detentConfig(config))
    }
  ];
}
 
function step(state, raw, velocityOpt, dtSecondsOpt, configOpt) {
  let velocity = velocityOpt !== undefined ? velocityOpt : 0;
  let dtSeconds = dtSecondsOpt !== undefined ? dtSecondsOpt : 0;
  let config = configOpt !== undefined ? configOpt : defaults;
  let match = stepSample(state, raw, velocity, dtSeconds, config);
  return [
    match[0],
    match[1].stabilized
  ];
}
 
export {
  defaults,
  initial,
  reset,
  lockedPose,
  stepSample,
  step,
}
/* CubeSymmetry-WsteinRegripCore Not a pure module */