Added canvas cache to isPointInPath and isPointInStroke

This commit is contained in:
kkapsner 2020-05-24 23:39:44 +02:00
parent da5a9f4509
commit 253d3f68b1
3 changed files with 44 additions and 13 deletions

View File

@ -244,6 +244,31 @@
} }
} }
const isPointCache = Object.create(null);
function getIsPointCacheIndex(x, y, values){
return String.fromCodePoint(...values, x, y);
}
function getIsPointValue({func, x, y, index, originalValue, window, prefs}){
const useCanvasCache = prefs("useCanvasCache");
let cacheIndex;
const values = [originalValue, func(x^1, y), func(x, y^1), func(x^1, y^1)];
if (useCanvasCache){
cacheIndex = getIsPointCacheIndex(x, y, values);
const cached = isPointCache[cacheIndex];
if ((typeof cached) === "boolean"){
return cached;
}
}
const rng = randomSupply.getIndexRng(1, 4, window);
const res = values[rng(index)];
if (useCanvasCache){
isPointCache[cacheIndex] = res;
}
return res;
}
// changed functions and their fakes // changed functions and their fakes
scope.changedFunctions = { scope.changedFunctions = {
getContext: { getContext: {
@ -348,13 +373,16 @@
fakeGenerator: function(checker){ fakeGenerator: function(checker){
return function isPointInPath(x, y){ return function isPointInPath(x, y){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {notify, window, original} = check; const {prefs, notify, window, original} = check;
const rng = randomSupply.getValueRng(1, window);
const originalValue = original.call(this, ...args); const originalValue = original.call(this, ...args);
if ((typeof originalValue) === "boolean"){ if ((typeof originalValue) === "boolean"){
notify("fakedReadout"); notify("fakedReadout");
const index = x + this.width * y; return getIsPointValue({
return original.call(this, rng(x, index), rng(y, index), args[2]); func: (x, y) => original.call(this, x, y, args[2]),
x, y,
index: x + this.width * y,
originalValue, window, prefs
});
} }
else { else {
return originalValue; return originalValue;
@ -370,22 +398,26 @@
fakeGenerator: function(checker){ fakeGenerator: function(checker){
return function isPointInStroke(x, y){ return function isPointInStroke(x, y){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {notify, window, original} = check; const {prefs, notify, window, original} = check;
const rng = randomSupply.getValueRng(1, window);
const originalValue = original.call(this, ...args); const originalValue = original.call(this, ...args);
if ((typeof originalValue) === "boolean"){ if ((typeof originalValue) === "boolean"){
notify("fakedReadout"); notify("fakedReadout");
let func;
if (x instanceof window.Path2D){ if (x instanceof window.Path2D){
let path = x; let path = x;
x = y; x = y;
y = args[2]; y = args[2];
let index = x + this.width * y; func = (x, y) => original.call(this, path, x, y);
return original.call(this, path, rng(x, index), rng(y, index));
} }
else { else {
let index = x + this.width * y; func = (x, y) => original.call(this, x, y);
return original.call(this, rng(x, index), rng(y, index));
} }
return getIsPointValue({
func,
x, y,
index: x + this.width * y,
originalValue, window, prefs
});
} }
else { else {
return originalValue; return originalValue;

View File

@ -1,6 +1,6 @@
Version 1.3: Version 1.3:
changes: changes:
- - added canvas cache to isPointInPath and isPointInStroke
new features: new features:
- added link to FAQ - added link to FAQ

View File

@ -13,8 +13,7 @@
<ul> <ul>
<li>all the hashes should be equal for each test</li> <li>all the hashes should be equal for each test</li>
<li>the hash before and after the "/" do not have to match</li> <li>the hash before and after the "/" do not have to match</li>
<li>"isPointInPath" may vary between tests</li> <li>if "refresh" is clicked the hash must not change</li>
<li>if "refresh" is clicked the hash must not change (but "isPointInPath" may)</li>
<li>upon page reload the hash changes (depending on CanvasBlocker settings - e.g. not in the stealth preset)</li> <li>upon page reload the hash changes (depending on CanvasBlocker settings - e.g. not in the stealth preset)</li>
</ul> </ul>
<h2>Tests</h2> <h2>Tests</h2>