fix: incorrectly computed mask 4 bc of floating point

Made a separate function `intDiv` for integer division,
that's more readable than `Math.floor` inside expression.
The function performs `a / b` and then truncates the fractional part
using the fastest method: binary `~~`
This commit is contained in:
DarkCat09 2024-07-08 12:07:38 +04:00
parent 35697b5b7d
commit f911c7bd2a
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3
2 changed files with 6 additions and 1 deletions

View file

@ -14,7 +14,7 @@
<option value="row%2">Mask 1-001 | i mod 2</option> <option value="row%2">Mask 1-001 | i mod 2</option>
<option value="col%3">Mask 2-010 | j mod 3</option> <option value="col%3">Mask 2-010 | j mod 3</option>
<option value="(row+col)%3">Mask 3-011 | (i + j) mod 3</option> <option value="(row+col)%3">Mask 3-011 | (i + j) mod 3</option>
<option value="(row/2+col/3)%2">Mask 4-100 | (i : 2 + j : 3) mod 2</option> <option value="(intDiv(row,2)+intDiv(col,3))%2">Mask 4-100 | (i : 2 + j : 3) mod 2</option>
<option value="(row*col)%2+(row*col)%3">Mask 5-101 | (i &times; j) mod 2 + (i &times; j) mod 3</option> <option value="(row*col)%2+(row*col)%3">Mask 5-101 | (i &times; j) mod 2 + (i &times; j) mod 3</option>
<option value="((row*col)%2+(row*col)%3)%2">Mask 6-110 | ((i &times; j) mod 2 + (i &times; j) mod 3) mod 2</option> <option value="((row*col)%2+(row*col)%3)%2">Mask 6-110 | ((i &times; j) mod 2 + (i &times; j) mod 3) mod 2</option>
<option value="((row+col)%2+(row*col)%3)%2">Mask 7-111 | ((i + j) mod 2 + (i &times; j) mod 3) mod 2</option> <option value="((row+col)%2+(row*col)%3)%2">Mask 7-111 | ((i + j) mod 2 + (i &times; j) mod 3) mod 2</option>

View file

@ -1,3 +1,8 @@
/// Division with fast fraction truncating
function intDiv(a, b) {
return ~~(a / b)
}
addEventListener('DOMContentLoaded', () => { addEventListener('DOMContentLoaded', () => {
const canvas = document.getElementById("canvas") const canvas = document.getElementById("canvas")
const ctx = canvas.getContext("2d") const ctx = canvas.getContext("2d")