Skip to content

Commit

Permalink
[notation] Rename countAnimatedMoves to countAnimatedLeaves.
Browse files Browse the repository at this point in the history
This reflects the (current) inclusion of `Pause`.
  • Loading branch information
lgarron committed Jul 4, 2021
1 parent 37bad40 commit 0cc1da0
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "../alg";

// TODO: Include Pause, include amounts
class CountAnimatedMoves extends TraversalUp<number, number> {
class CountAnimatedLeaves extends TraversalUp<number, number> {
public traverseAlg(alg: Alg): number {
let total = 0;
for (const part of alg.units()) {
Expand Down Expand Up @@ -51,6 +51,6 @@ class CountAnimatedMoves extends TraversalUp<number, number> {
}
}

const countAnimatedMovesInstance = new CountAnimatedMoves();
export const countAnimatedMoves: (alg: Alg) => number =
countAnimatedMovesInstance.traverseAlg.bind(countAnimatedMovesInstance);
const countAnimatedLeavesInstance = new CountAnimatedLeaves();
export const countAnimatedLeaves: (alg: Alg) => number =
countAnimatedLeavesInstance.traverseAlg.bind(countAnimatedLeavesInstance);
2 changes: 1 addition & 1 deletion src/cubing/notation/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Note: this folder is purposely not built as a package entry point (yet).

export { countMoves } from "./CountMoves";
export { countAnimatedMoves } from "./CountAnimatedMoves";
export { countAnimatedLeaves } from "./CountAnimatedLeaves";
2 changes: 1 addition & 1 deletion src/cubing/puzzle-geometry/PGPuzzles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe("PuzzleGeometry-Puzzles", () => {
algo = new Alg(bms);
const ksp = new KSolvePuzzle(kpuzzledef);
const tai = new TreeAlgIndexer(ksp, algo);
const tr = tai.transformAtIndex(tai.numMoves());
const tr = tai.transformAtIndex(tai.numAnimatedLeaves());
const o = transformationOrder(kpuzzledef, tr as Transformation);
let dat =
name +
Expand Down
6 changes: 3 additions & 3 deletions src/cubing/twisty/animation/cursor/AlgCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class AlgCursor

/** @deprecated */
experimentalTimestampForStartOfLastMove(): MillisecondTimestamp {
const numMoves = this.indexer.numMoves();
const numMoves = this.indexer.numAnimatedLeaves();
if (numMoves > 0) {
return this.indexer.indexToMoveStartTimestamp(numMoves - 1);
}
Expand Down Expand Up @@ -137,7 +137,7 @@ export class AlgCursor
movesInProgress: [],
};

if (this.indexer.numMoves() > 0) {
if (this.indexer.numAnimatedLeaves() > 0) {
const move = this.indexer.getMove(idx)?.as(Move);
if (!move) {
return; // TODO
Expand Down Expand Up @@ -193,7 +193,7 @@ export class AlgCursor
timestamp: MillisecondTimestamp,
direction: Direction.Backwards | Direction.Forwards,
): MillisecondTimestamp | null {
if (this.indexer.numMoves() === 0) {
if (this.indexer.numAnimatedLeaves() === 0) {
return null;
}
// TODO: define semantics of indexing edge cases and remove this hack.
Expand Down
2 changes: 1 addition & 1 deletion src/cubing/twisty/animation/indexer/AlgIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface AlgIndexer<P extends PuzzleWrapper> {
indexToMoveStartTimestamp(index: number): Timestamp;
stateAtIndex(index: number, startTransformation?: State<P>): State<P>;
transformAtIndex(index: number): State<P>;
numMoves(): number;
numAnimatedLeaves(): number;
timestampToIndex(timestamp: Timestamp): number;
algDuration(): Duration;
moveDuration(index: number): number;
Expand Down
8 changes: 4 additions & 4 deletions src/cubing/twisty/animation/indexer/SimpleAlgIndexer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Alg, Move, TraversalUp } from "../../../alg";
import { countAnimatedMoves } from "../../../notation";
import { countAnimatedLeaves } from "../../../notation";
import type { PuzzleWrapper, State } from "../../3D/puzzles/KPuzzleWrapper";
import type { Duration, Timestamp } from "../cursor/CursorTypes";
import { AlgDuration, defaultDurationForAmount } from "./AlgDuration";
Expand Down Expand Up @@ -31,7 +31,7 @@ export class SimpleAlgIndexer<P extends PuzzleWrapper>
public timestampToIndex(timestamp: Timestamp): number {
let cumulativeTime = 0;
let i;
for (i = 0; i < this.numMoves(); i++) {
for (i = 0; i < this.numAnimatedLeaves(); i++) {
cumulativeTime += this.durationFn.traverseMove(this.getMove(i));
if (cumulativeTime >= timestamp) {
return i;
Expand Down Expand Up @@ -62,9 +62,9 @@ export class SimpleAlgIndexer<P extends PuzzleWrapper>
return this.durationFn.traverseAlg(this.moves);
}

public numMoves(): number {
public numAnimatedLeaves(): number {
// TODO: Cache internally once performance matters.
return countAnimatedMoves(this.moves);
return countAnimatedLeaves(this.moves);
}

public moveDuration(index: number): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class SimultaneousMoveIndexer<P extends PuzzleWrapper>
return max;
}

public numMoves(): number {
public numAnimatedLeaves(): number {
// TODO: Cache internally once performance matters.
return this.moves.length;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cubing/twisty/animation/indexer/tree/TreeAlgIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class TreeAlgIndexer implements AlgIndexer<PuzzleWrapper> {
return this.walker.st;
}

public numMoves(): number {
public numAnimatedLeaves(): number {
return this.decoration.moveCount;
}

Expand Down

0 comments on commit 0cc1da0

Please sign in to comment.