MCPcopy Create free account
hub / github.com/microsoft/SandDance / Bitmap

Function Bitmap

docs/app/js/sanddance-app.js:138687–138760  ·  view source on GitHub ↗
(w, h)

Source from the content-addressed store, hash-verified

138685 RIGHT0[i] = ~RIGHT1[i];
138686}
138687function Bitmap(w, h) {
138688 const array = new Uint32Array(~~((w * h + SIZE) / SIZE));
138689 function _set(index, mask) {
138690 array[index] |= mask;
138691 }
138692 function _clear(index, mask) {
138693 array[index] &= mask;
138694 }
138695 return {
138696 array: array,
138697 get: (x, y)=>{
138698 const index = y * w + x;
138699 return array[index >>> DIV] & 1 << (index & MOD);
138700 },
138701 set: (x, y)=>{
138702 const index = y * w + x;
138703 _set(index >>> DIV, 1 << (index & MOD));
138704 },
138705 clear: (x, y)=>{
138706 const index = y * w + x;
138707 _clear(index >>> DIV, ~(1 << (index & MOD)));
138708 },
138709 getRange: (x, y, x2, y2)=>{
138710 let r = y2, start, end, indexStart, indexEnd;
138711 for(; r >= y; --r){
138712 start = r * w + x;
138713 end = r * w + x2;
138714 indexStart = start >>> DIV;
138715 indexEnd = end >>> DIV;
138716 if (indexStart === indexEnd) {
138717 if (array[indexStart] & RIGHT0[start & MOD] & RIGHT1[(end & MOD) + 1]) return true;
138718 } else {
138719 if (array[indexStart] & RIGHT0[start & MOD]) return true;
138720 if (array[indexEnd] & RIGHT1[(end & MOD) + 1]) return true;
138721 for(let i1 = indexStart + 1; i1 < indexEnd; ++i1){
138722 if (array[i1]) return true;
138723 }
138724 }
138725 }
138726 return false;
138727 },
138728 setRange: (x, y, x2, y2)=>{
138729 let start, end, indexStart, indexEnd, i2;
138730 for(; y <= y2; ++y){
138731 start = y * w + x;
138732 end = y * w + x2;
138733 indexStart = start >>> DIV;
138734 indexEnd = end >>> DIV;
138735 if (indexStart === indexEnd) _set(indexStart, RIGHT0[start & MOD] & RIGHT1[(end & MOD) + 1]);
138736 else {
138737 _set(indexStart, RIGHT0[start & MOD]);
138738 _set(indexEnd, RIGHT1[(end & MOD) + 1]);
138739 for(i2 = indexStart + 1; i2 < indexEnd; ++i2)_set(i2, 0xffffffff);
138740 }
138741 }
138742 },
138743 clearRange: (x, y, x2, y2)=>{
138744 let start, end, indexStart, indexEnd, i3;

Callers 1

scalerFunction · 0.70

Calls 2

_setFunction · 0.70
_clearFunction · 0.70

Tested by

no test coverage detected