@@ -38,34 +38,27 @@ const state = {
3838} ;
3939
4040function resizeCanvas ( ) {
41- const dpr = window . devicePixelRatio || 1 ;
42- const width = canvas . clientWidth * dpr ;
43- const height = canvas . clientHeight * dpr ;
44- if ( canvas . width !== width || canvas . height !== height ) {
45- canvas . width = width ;
46- canvas . height = height ;
47- }
41+ const dpr = window . devicePixelRatio || 1 ;
42+ canvas . width = canvas . clientWidth * dpr ;
43+ canvas . height = canvas . clientHeight * dpr ;
4844}
4945
5046function getBoardMetrics ( ) {
51- const dpr = window . devicePixelRatio || 1 ;
52- const boardSize = Math . min ( canvas . width , canvas . height ) - PADDING * 2 * dpr ;
53- const spacing = boardSize / ( ( GRID_SIZE - 1 ) * Math . SQRT2 ) ;
54- return {
55- spacing,
56- centerX : canvas . width / 2 ,
57- centerY : canvas . height / 2 ,
58- } ;
47+ const dpr = window . devicePixelRatio || 1 ;
48+ const boardSize = Math . min ( canvas . width , canvas . height ) - PADDING * 2 * dpr ;
49+ const spacing = boardSize / ( ( GRID_SIZE - 1 ) * Math . SQRT2 ) ;
50+ return { spacing, centerX : canvas . width / 2 , centerY : canvas . height / 2 } ;
5951}
6052
6153function dotPosition ( row , col ) {
62- const { spacing, centerX, centerY } = getBoardMetrics ( ) ;
63- const offset = ( GRID_SIZE - 1 ) / 2 ;
64- const gridX = ( col - offset ) * spacing ;
65- const gridY = ( row - offset ) * spacing ;
66- const x = ( gridX - gridY ) / Math . SQRT2 + centerX ;
67- const y = ( gridX + gridY ) / Math . SQRT2 + centerY ;
68- return { x, y } ;
54+ const { spacing, centerX, centerY } = getBoardMetrics ( ) ;
55+ const offset = ( GRID_SIZE - 1 ) / 2 ;
56+ const gridX = ( col - offset ) * spacing ;
57+ const gridY = ( row - offset ) * spacing ;
58+ return {
59+ x : ( gridX - gridY ) / Math . SQRT2 + centerX ,
60+ y : ( gridX + gridY ) / Math . SQRT2 + centerY
61+ } ;
6962}
7063
7164function drawBoxes ( ) {
0 commit comments