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:
parent
35697b5b7d
commit
f911c7bd2a
2 changed files with 6 additions and 1 deletions
|
@ -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 × j) mod 2 + (i × j) mod 3</option>
|
<option value="(row*col)%2+(row*col)%3">Mask 5-101 | (i × j) mod 2 + (i × j) mod 3</option>
|
||||||
<option value="((row*col)%2+(row*col)%3)%2">Mask 6-110 | ((i × j) mod 2 + (i × j) mod 3) mod 2</option>
|
<option value="((row*col)%2+(row*col)%3)%2">Mask 6-110 | ((i × j) mod 2 + (i × j) mod 3) mod 2</option>
|
||||||
<option value="((row+col)%2+(row*col)%3)%2">Mask 7-111 | ((i + j) mod 2 + (i × j) mod 3) mod 2</option>
|
<option value="((row+col)%2+(row*col)%3)%2">Mask 7-111 | ((i + j) mod 2 + (i × j) mod 3) mod 2</option>
|
||||||
|
|
|
@ -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")
|
||||||
|
|
Loading…
Add table
Reference in a new issue