Skip to content

Commit

Permalink
Fix Janggi arrows and circles
Browse files Browse the repository at this point in the history
  • Loading branch information
gbtami committed Jun 30, 2024
1 parent 9fff653 commit 2be330d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chessgroundx",
"version": "10.6.0",
"version": "10.6.1",
"description": "Extended lichess.org Chess UI",
"type": "module",
"module": "chessground.js",
Expand Down
12 changes: 9 additions & 3 deletions src/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function renderCircle(
): SVGElement {
const o = pos2user(pos, bounds, bd),
widths = circleWidth(),
radius = (bounds.width + bounds.height) / (4 * Math.max(bounds.width, bounds.height));
radius = Math.min(bd.width / (2 * bd.height), (bounds.width / bd.width) / (2 * bounds.height / bd.height));
return setAttributes(createElement('circle'), {
stroke: brush.color,
'stroke-width': widths[current ? 0 : 1],
Expand Down Expand Up @@ -289,7 +289,13 @@ function arrowMargin(shorten: boolean): number {
}

function pos2user(pos: cg.Pos, bounds: ClientRect, bd: cg.BoardDimensions): cg.NumberPair {
const xScale = Math.min(1, bounds.width / bounds.height) * Math.max(1, bd.height / bd.width);
const yScale = Math.min(1, bounds.height / bounds.width) * Math.max(1, bd.width / bd.height);
let xScale, yScale;
if (bounds.width / bounds.height <= bd.width / bd.height) {
xScale = Math.min(1, bounds.width / bounds.height) * Math.max(1, bd.height / bd.width);
yScale = Math.min(1, bounds.height / bounds.width) * Math.max(1, bd.width / bd.height);
} else {
xScale = Math.max(1, bounds.width / bounds.height) * Math.min(1, bd.height / bd.width);
yScale = Math.max(1, bounds.height / bounds.width) * (bd.width / bd.height);
}
return [(pos[0] - (bd.width - 1) / 2) * xScale, ((bd.height - 1) / 2 - pos[1]) * yScale];
}

0 comments on commit 2be330d

Please sign in to comment.