INNER CODE UNIT · TypeScript
offset
jamesroutley/24a2 · src/engine.ts:390
const offset = this._dotSize + this._gapSize;
// Iterate over all dot locations, and check whether the distance
// between the click and the dot centre is less than the dot's
// radius
for (let y = 0; y < this._gridHeight; y++) {
for (let x = 0; x < this._gridWidth; x++) {
const dx = this._dotSize / 2 + x * offset;
const dy = this._dotSize / 2 + y * offset;
const distance = Math.sqrt(
Math.pow(cx - dx, 2) + Math.pow(cy - dy, 2)
);
if (distance < this._dotSize / 2) {
this._dotClicked(x, y);
// We've found the dot, so exit early
return;
}