@wodzik/cubecore 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bluetooth/rotations.js +6 -3
- package/package.json +1 -1
- package/render/layers.js +6 -4
package/bluetooth/rotations.js
CHANGED
|
@@ -42,15 +42,18 @@ export function heldTokens(moves, startRotation, rotations) {
|
|
|
42
42
|
let r = 0;
|
|
43
43
|
for (let i = 0; i <= moves.length; i++) {
|
|
44
44
|
let target = grip;
|
|
45
|
-
|
|
45
|
+
// Several at one place (a peek at the back and back: x x' x) are one net
|
|
46
|
+
// rotation — timed by the first: that's when it began (a slice's rotation
|
|
47
|
+
// then still sits with its face moves).
|
|
48
|
+
let t = null;
|
|
46
49
|
while (r < rots.length && rots[r].after <= i) {
|
|
47
50
|
target = rotateGrip(target, rots[r].move);
|
|
48
|
-
t
|
|
51
|
+
t ??= rots[r].t;
|
|
49
52
|
r++;
|
|
50
53
|
}
|
|
51
54
|
const net = rotationBetween(grip, target);
|
|
52
55
|
if (net)
|
|
53
|
-
tokens.push({ kind: "rotation", move: net, t, after: i });
|
|
56
|
+
tokens.push({ kind: "rotation", move: net, t: t ?? 0, after: i });
|
|
54
57
|
grip = target;
|
|
55
58
|
if (i < moves.length)
|
|
56
59
|
tokens.push({ kind: "move", move: heldMove(moves[i].move, grip), t: moves[i].t, index: i });
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.6",
|
|
7
7
|
"description": "A 3×3×3 cube library for the web, built around smart (Bluetooth) cubes: state, notation, methods, solvers and scrambles, a three.js renderer with skins, pictures, web components, React bindings.",
|
|
8
8
|
"license": "MPL-2.0",
|
|
9
9
|
"author": "Tomasz Wodzikowski <wodziszczakow@gmail.com>",
|
package/render/layers.js
CHANGED
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
* switches to S·m with nothing rotated. The two pictures coincide, so there is
|
|
8
8
|
* no pop — and the scene never has to track which physical cubie is where.
|
|
9
9
|
*/
|
|
10
|
-
import { FAMILY,
|
|
10
|
+
import { FAMILY, writtenQuarters } from "../core/index.js";
|
|
11
11
|
export function layerTurn(move) {
|
|
12
12
|
const def = FAMILY[move.family];
|
|
13
|
-
// A family's clockwise turn is `def.q` CCW quarters about +axis; the
|
|
14
|
-
|
|
13
|
+
// A family's clockwise turn is `def.q` CCW quarters about +axis; the turn as written multiplies it
|
|
14
|
+
// (U2' goes the other way than U2 — the state is the same, the hands aren't).
|
|
15
|
+
const quarters = def.q * writtenQuarters(move);
|
|
15
16
|
return {
|
|
16
17
|
axis: def.axis,
|
|
17
18
|
angle: (quarters * Math.PI) / 2,
|
|
@@ -20,5 +21,6 @@ export function layerTurn(move) {
|
|
|
20
21
|
}
|
|
21
22
|
/** Default animation length for a move, scaled by how far it turns (half turns take longer). */
|
|
22
23
|
export function defaultDuration(move, quarterMs = 120) {
|
|
23
|
-
|
|
24
|
+
const q = Math.abs(writtenQuarters(move));
|
|
25
|
+
return q === 1 ? quarterMs : quarterMs * (1 + 0.5 * (q - 1));
|
|
24
26
|
}
|