Skip to content

Commit 6461126

Browse files
committed
Fix multi-face cube rotation regression
1 parent c158f93 commit 6461126

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

src/renderers/isometric/depthPiece.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { StrokeData, Svg } from "@svgdotjs/svg.js";
22
import { Orientation } from "honeycomb-grid";
33
import { IsometricPieces, IsoPiece, Colourfuncs } from "../../schemas/schema";
44
import { generateCubes, CubeFaceFills } from "./cubes";
5-
import { permuteCubeFacesForProjection } from "./cubeOrientation";
5+
import { permuteCubeFacesForProjection, effectiveCubeYaw } from "./cubeOrientation";
66
import { generateCylinders } from "./cylinders";
77
import { generateHexes } from "./hexes";
88
import { ISO_PROJECTION_PRESETS, IsoProjectionParams } from "./projection";
@@ -75,7 +75,8 @@ const generateDepthShadedSymbol = (opts: {
7575
const effPiece = effectivePieceType(pc, numRotations);
7676

7777
if (isMultiFaceCube(pc)) {
78-
const visible = permuteCubeFacesForProjection(pc.faces, yaw, projection);
78+
const effectiveYaw = effectiveCubeYaw(yaw, numRotations * 90);
79+
const visible = permuteCubeFacesForProjection(pc.faces, effectiveYaw, projection);
7980
const top = resolveColour(visible.top, "#000") as string;
8081
const left = resolveColour(visible.left, "#000") as string;
8182
const right = resolveColour(visible.right, "#000") as string;

test/isometric.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,39 @@ describe("IsometricRenderer depth cues", () => {
738738
expect(frontFill).to.equal(isoDepthModulate(isoShadeFace(base, "left"), 1).toLowerCase());
739739
});
740740

741+
it("should keep multi-face cube colours when depth-shaded at board rotation", () => {
742+
const draw = makeDraw();
743+
const renderer = new IsometricRenderer();
744+
const east = "#0000ff";
745+
const south = "#ffff00";
746+
const rep: APRenderRep = {
747+
renderer: "isometric",
748+
board: { style: "squares", width: 3, height: 3 },
749+
legend: {
750+
D: {
751+
piece: "cube",
752+
height: 30,
753+
faces: {
754+
top: "#ff0000",
755+
north: "#00ff00",
756+
east,
757+
south,
758+
west: "#ff00ff",
759+
},
760+
},
761+
},
762+
pieces: [[[], [], []], [[], [{ glyph: "D" }], []], [[], [], []]],
763+
};
764+
renderer.render(rep, draw, { ...baseOptions, rotate: 90 });
765+
766+
const shadedSymbol = [...draw.find("[id^='D__y1__db']")].map((el) => el.id())[0];
767+
expect(shadedSymbol).to.not.equal(undefined);
768+
const leftFill = rectFill(draw, `isoRectSide30_${shadedSymbol}_L`);
769+
expect(leftFill.startsWith("#0000")).to.equal(true);
770+
expect(leftFill).to.not.equal(isoShadeFace(south, "left").toLowerCase());
771+
expect(leftFill).to.not.equal(isoDepthModulate(isoShadeFace(south, "left"), 0.5).toLowerCase());
772+
});
773+
741774
it("should omit depth-shaded symbols when no-iso-depth-shade is set", () => {
742775
const draw = makeDraw();
743776
const renderer = new IsometricRenderer();

0 commit comments

Comments
 (0)