<commit_before>// for smooth scrolling through z-indices
//
L.TileLayer.OCPLayer = L.TileLayer.extend({

	options: {
		minZoom: 0,
		maxZoom: 18,
		tileSize: 256,
		subdomains: 'abc',
		errorTileUrl: '',
		attribution: '',
		zoomOffset: 0,
		opacity: 1,
    /* begin ocpviz added */
    brightness: 100,
    contrast: 100,
    curtime: 0,
    propagate: 0,
    /* end ocpviz added */
		/*
		maxNativeZoom: null,
		zIndex: null,
		tms: false,
		continuousWorld: false,
		noWrap: false,
		zoomReverse: false,
		detectRetina: false,
		reuseTiles: false,
		bounds: false,
		*/
		unloadInvisibleTiles: L.Browser.mobile,
		updateWhenIdle: L.Browser.mobile
	},

  _tileOnLoad: function () {
    var layer = this._layer;

    //Only if we are loading an actual image
    if (this.src !== L.Util.emptyImageUrl) {
      L.DomUtil.addClass(this, 'leaflet-tile-loaded');
			// hide by default
			L.DomUtil.addClass(this, 'hidden');
      // mark classes by index
      L.DomUtil.addClass(this, 'index-' + ndv.zindex);


      layer.fire('tileload', {
        tile: this,
        url: this.src
      });
    }

    layer._tileLoaded();
  },

  _loadTile: function (tile, tilePoint) {
		tile._layer  = this;
		tile.onload  = this._tileOnLoad;
		tile.onerror = this._tileOnError;

		// don't load negative tiles (ndstore is 0 indexed)
		// TODO don't load tiles > image bounds
		this._adjustTilePoint(tilePoint);
    if (tilePoint.x < 0 || tilePoint.y < 0) {
      tile.src = L.Util.emptyImageUrl
    }
    else {
      tile.src = this.getTileUrl(tilePoint);
    }
		this.fire('tileloadstart', {
			tile: tile,
			url: tile.src
		});
	},

	_createTile: function () {
		var tile = L.DomUtil.create('img', 'leaflet-tile');
		/* required to load tiles as textures */
		tile.setAttribute('crossOrigin','anonymous');

		tile.style.width = tile.style.height = this._getTileSize() + 'px';
		tile.galleryimg = 'no';

		tile.onselectstart = tile.onmousemove = L.Util.falseFn;

		if (L.Browser.ielt9 && this.options.opacity !== undefined) {
			L.DomUtil.setOpacity(tile, this.options.opacity);
		}
		// without this hack, tiles disappear after zoom on Chrome for Android
		// https://github.com/Leaflet/Leaflet/issues/2078
		if (L.Browser.mobileWebkit3d) {
			tile.style.WebkitBackfaceVisibility = 'hidden';
		}
		return tile;
	},

  smoothRedraw: function () {
    if (this._map) {
      var old_tiles = this._tiles;
      this._tiles = {};
      this._tilesToLoad = 0;
      this._update();
      this._clearBgBuffer();

      function unloadTiles() {
        for (key in old_tiles) {
					var tile = old_tiles[key];
					this.fire('tileunload', {tile: tile, url: tile.src});
          //this._tileContainer.removeChild(old_tiles[key]);
        }
        old_tiles = {};
      };

      this.on('load', function () {
          setTimeout(unloadTiles.bind(this), 300);
      });
    }
    return this;
  },

  _smoothRemoveTile: function(tile) {
    this._tileContainer.removeChild(tile);
  },

	_getTileSize: function () {
		var map = this._map,
		    zoom = map.getZoom() + this.options.zoomOffset,
		    zoomN = this.options.maxNativeZoom,
		    tileSize = this.options.tileSize;

		if (zoomN && zoom > zoomN) {
      tileSize = Math.round(map.getZoomScale(zoom) / map.getZoomScale(zoomN) * tileSize);
    }
    else if ( (zoomN == 0) && (zoom > zoomN) ) {
      // another quick for the case where maxNativeZoom is 0
      // AB TODO consider using == undefined in the general case
      tileSize = Math.round(map.getZoomScale(zoom) / map.getZoomScale(zoomN) * tileSize);
    }

		return tileSize;
	},


	_getZoomForUrl: function () {

		var options = this.options,
		    zoom = this._map.getZoom();
		if (options.zoomReverse) {
			if (options.maxNativeZoom) {
        zoom = options.maxNativeZoom - zoom;
			}
			else if (options.maxNativeZoom == 0) {
        // inelegantly handle the case where maxNativeZoom exists and is 0
        zoom = options.maxNativeZoom - zoom;
      }
      else {
        zoom = options.maxZoom - zoom;
			}
		}

		zoom += options.zoomOffset;
		//return options.maxNativeZoom ? Math.min(zoom, options.maxNativeZoom) : zoom;
    return Math.max(0, zoom);
	},

  setBrightness: function (brightness) {
		this.options.brightness = brightness;

		if (this._map) {
			this._updateBrightness();
		}

		return this;
	},

  _updateBrightness: function () {
    L.DomUtil.setBrightnessContrast(this._container, this.options.brightness, this.options.contrast);
  },

  setContrast: function (contrast) {
		this.options.contrast = contrast;

		if (this._map) {
			this._updateContrast();
		}

		return this;
	},

  _updateContrast: function () {
    L.DomUtil.setBrightnessContrast(this._container, this.options.brightness, this.options.contrast);

  },

  setBlendMode: function (blendmode) {
    if (this._map) {
      L.DomUtil.setBlendMode(this._container, blendmode);
    }
    return this;
  },

});

// add updateBrightness and updateContrast methods
// TODO support for Fx
L.extend(L.DomUtil, {
  setBrightnessContrast: function(el, brightness, contrast) {
    if ('filter' in el.style) {
      el.style.setProperty('-webkit-filter', 'brightness(' + brightness + '%) ' + 'contrast(' + contrast + '%)')
    }
  },
  setBlendMode: function(el, mode) {
    // TODO validate this somehow?
    //el.style.setProperty('mix-blend-mode', mode);
  },

});

L.tileLayer.OCPLayer = function (url, options) {
    return new L.TileLayer.OCPLayer(url, options);
};

/* creates a single WebGL rendering context that spans the page */
L.WebGLLayer = L.Class.extend({
	options: {
		minZoom: 0,
		maxZoom: 18,
		tileSize: 256,
		zoomOffset: 0,
		disableScreenRender: false,
	},

	initialize: function(options) {
		//this._bounds = L.latLngBounds(bounds);

		L.setOptions(this, options);
	},

	draw: function() {
		/* WebGL drawing function */
	},

	onAdd: function(map) {
		this._map = map;

		if (!this._renderer) {
			this._initRenderer();
			this._initCamera(map.getSize());
		}

		map._panes.overlayPane.appendChild( this._renderer.domElement );

		map.on({
			'viewreset': this._reset,
			'moveend': this._update
		}, this);

		if (map.options.zoomAnimation) {
			map.on({
				'zoomanim': this._animateZoom,
				'zoomend': this._endZoomAnim,
			}, this);
		}

		this._reset();
		this.draw();
	},

	onRemove: function(map) {
		map.getPanes().overlayPane.removeChild( this._renderer.domElement );

		map.off({
			'viewreset': this._reset,
			'moveend': this._update
		}, this);
		if (map.options.zoomAnimation) {
			map.off({
				'zoomanim': this._animateZoom,
				'zoomend': this._endZoomAnim,
			}, this);
		}
	},

	addTo: function(map) {
		map.addLayer(this);
		return this;
	},

	_animateZoom: function(e) {
		var scale = map.getZoomScale(e.zoom);

		this._camera.zoom = scale;
		this._camera.updateProjectionMatrix();
	},

	_endZoomAnim: function() {
		this._camera.zoom = 1;
		this._camera.updateProjectionMatrix();
	},

	_reset: function() {
		this._setRendererSize(this._map.getSize());
		this._resizeCamera(this._map.getSize());
		//this._setupCamera(this._map.getPixelOrigin());
		//this._setupCamera(this._map.getSize());
	},

	_update: function() {
		if (!this._map) { return; }

		var map = this._map,
			bounds = map.getPixelBounds(), // TODO don't need these?
			origin = map.getPixelOrigin(),
			size = map.getSize();

		//var shift = bounds.min.subtract(origin);
		var position = map._getMapPanePos().multiplyBy(-1);

		L.DomUtil.setPosition( this._renderer.domElement, position );
		this._reset();
		this.draw();
		this._renderToScreen();
	},

	disableScreenRender: function() {
		this.options.disableScreenRender = true;
	},

	enableScreenRender: function() {
		this.options.disableScreenRender = false;
	},

	_renderToScreen: function() {
		if (this._renderTarget && !this.options.disableScreenRender) {
			var worldSize = this._map.getSize();

			var geo = new THREE.PlaneBufferGeometry( worldSize.x, worldSize.y );
			var mat = new THREE.MeshBasicMaterial({map: this._renderTarget});
			var mesh = new THREE.Mesh( geo, mat );
			var scene = new THREE.Scene();
			scene.add(mesh);

			this._renderer.render(scene, this._camera)

			/*
			function render() {
				if (this._screenRepeater) {
					cancelAnimationFrame( this._screenRepeater );
				}
				this._screenRepeater = requestAnimationFrame( render.bind(this) );
			}
			render.bind(this)();
			*/
		}
	},

	_getSize: function() {
		return this._map.getSize();
	},

	_initRenderer: function() {
		this._renderer = new THREE.WebGLRenderer();
	},

	_initCamera: function(origin) {
		this._camera = new THREE.OrthographicCamera( origin.x / -2, origin.x / 2, origin.y / 2, origin.y / -2, 1, 1024.0 );
	},

	_setRendererSize: function(size) {
		this._renderer.setSize( size.x, size.y );
	},

	_resizeCamera: function(origin) {
		this._camera.left = origin.x / -2;
		this._camera.right = origin.x / 2;
		this._camera.top = origin.y / 2;
		this._camera.bottom = origin.y / -2;
		this._camera.updateProjectionMatrix();
		//this._camera = new THREE.OrthographicCamera( origin.x / -2, origin.x / 2, origin.y / 2, origin.y / -2, 1, 1024.0 );
		//this._camera = new THREE.OrthographicCamera( bounds.min.x, bounds.max.x, bounds.min.y, bounds.max.y, 1, 1000 );

	},

	_getTileSize: function () {
		var map = this._map,
		    zoom = map.getZoom() + this.options.zoomOffset,
		    zoomN = this.options.maxNativeZoom,
		    tileSize = this.options.tileSize;<commit_msg>smoother zooming<commit_after>// for smooth scrolling through z-indices
//
L.TileLayer.OCPLayer = L.TileLayer.extend({

	options: {
		minZoom: 0,
		maxZoom: 18,
		tileSize: 256,
		subdomains: 'abc',
		errorTileUrl: '',
		attribution: '',
		zoomOffset: 0,
		opacity: 1,
    /* begin ocpviz added */
    brightness: 100,
    contrast: 100,
    curtime: 0,
    propagate: 0,
    /* end ocpviz added */
		/*
		maxNativeZoom: null,
		zIndex: null,
		tms: false,
		continuousWorld: false,
		noWrap: false,
		zoomReverse: false,
		detectRetina: false,
		reuseTiles: false,
		bounds: false,
		*/
		unloadInvisibleTiles: L.Browser.mobile,
		updateWhenIdle: L.Browser.mobile
	},

  _tileOnLoad: function () {
    var layer = this._layer;

    //Only if we are loading an actual image
    if (this.src !== L.Util.emptyImageUrl) {
      L.DomUtil.addClass(this, 'leaflet-tile-loaded');
			// hide by default
			L.DomUtil.addClass(this, 'hidden');
      // mark classes by index
      L.DomUtil.addClass(this, 'index-' + ndv.zindex);


      layer.fire('tileload', {
        tile: this,
        url: this.src
      });
    }

    layer._tileLoaded();
  },

  _loadTile: function (tile, tilePoint) {
		tile._layer  = this;
		tile.onload  = this._tileOnLoad;
		tile.onerror = this._tileOnError;

		// don't load negative tiles (ndstore is 0 indexed)
		// TODO don't load tiles > image bounds
		this._adjustTilePoint(tilePoint);
    if (tilePoint.x < 0 || tilePoint.y < 0) {
      tile.src = L.Util.emptyImageUrl
    }
    else {
      tile.src = this.getTileUrl(tilePoint);
    }
		this.fire('tileloadstart', {
			tile: tile,
			url: tile.src
		});
	},

	_createTile: function () {
		var tile = L.DomUtil.create('img', 'leaflet-tile');
		/* required to load tiles as textures */
		tile.setAttribute('crossOrigin','anonymous');

		tile.style.width = tile.style.height = this._getTileSize() + 'px';
		tile.galleryimg = 'no';

		tile.onselectstart = tile.onmousemove = L.Util.falseFn;

		if (L.Browser.ielt9 && this.options.opacity !== undefined) {
			L.DomUtil.setOpacity(tile, this.options.opacity);
		}
		// without this hack, tiles disappear after zoom on Chrome for Android
		// https://github.com/Leaflet/Leaflet/issues/2078
		if (L.Browser.mobileWebkit3d) {
			tile.style.WebkitBackfaceVisibility = 'hidden';
		}
		return tile;
	},

  smoothRedraw: function () {
    if (this._map) {
      var old_tiles = this._tiles;
      this._tiles = {};
      this._tilesToLoad = 0;
      this._update();
      this._clearBgBuffer();

      function unloadTiles() {
        for (key in old_tiles) {
					var tile = old_tiles[key];
					this.fire('tileunload', {tile: tile, url: tile.src});
          //this._tileContainer.removeChild(old_tiles[key]);
        }
        old_tiles = {};
      };

      this.on('load', function () {
          setTimeout(unloadTiles.bind(this), 300);
      });
    }
    return this;
  },

  _smoothRemoveTile: function(tile) {
    this._tileContainer.removeChild(tile);
  },

	_getTileSize: function () {
		var map = this._map,
		    zoom = map.getZoom() + this.options.zoomOffset,
		    zoomN = this.options.maxNativeZoom,
		    tileSize = this.options.tileSize;

		if (zoomN && zoom > zoomN) {
      tileSize = Math.round(map.getZoomScale(zoom) / map.getZoomScale(zoomN) * tileSize);
    }
    else if ( (zoomN == 0) && (zoom > zoomN) ) {
      // another quick for the case where maxNativeZoom is 0
      // AB TODO consider using == undefined in the general case
      tileSize = Math.round(map.getZoomScale(zoom) / map.getZoomScale(zoomN) * tileSize);
    }

		return tileSize;
	},


	_getZoomForUrl: function () {

		var options = this.options,
		    zoom = this._map.getZoom();
		if (options.zoomReverse) {
			if (options.maxNativeZoom) {
        zoom = options.maxNativeZoom - zoom;
			}
			else if (options.maxNativeZoom == 0) {
        // inelegantly handle the case where maxNativeZoom exists and is 0
        zoom = options.maxNativeZoom - zoom;
      }
      else {
        zoom = options.maxZoom - zoom;
			}
		}

		zoom += options.zoomOffset;
		//return options.maxNativeZoom ? Math.min(zoom, options.maxNativeZoom) : zoom;
    return Math.max(0, zoom);
	},

  setBrightness: function (brightness) {
		this.options.brightness = brightness;

		if (this._map) {
			this._updateBrightness();
		}

		return this;
	},

  _updateBrightness: function () {
    L.DomUtil.setBrightnessContrast(this._container, this.options.brightness, this.options.contrast);
  },

  setContrast: function (contrast) {
		this.options.contrast = contrast;

		if (this._map) {
			this._updateContrast();
		}

		return this;
	},

  _updateContrast: function () {
    L.DomUtil.setBrightnessContrast(this._container, this.options.brightness, this.options.contrast);

  },

  setBlendMode: function (blendmode) {
    if (this._map) {
      L.DomUtil.setBlendMode(this._container, blendmode);
    }
    return this;
  },

});

// add updateBrightness and updateContrast methods
// TODO support for Fx
L.extend(L.DomUtil, {
  setBrightnessContrast: function(el, brightness, contrast) {
    if ('filter' in el.style) {
      el.style.setProperty('-webkit-filter', 'brightness(' + brightness + '%) ' + 'contrast(' + contrast + '%)')
    }
  },
  setBlendMode: function(el, mode) {
    // TODO validate this somehow?
    //el.style.setProperty('mix-blend-mode', mode);
  },

});

L.tileLayer.OCPLayer = function (url, options) {
    return new L.TileLayer.OCPLayer(url, options);
};

/* creates a single WebGL rendering context that spans the page */
L.WebGLLayer = L.Class.extend({
	options: {
		minZoom: 0,
		maxZoom: 18,
		tileSize: 256,
		zoomOffset: 0,
		disableScreenRender: false,
	},

	initialize: function(options) {
		//this._bounds = L.latLngBounds(bounds);

		L.setOptions(this, options);
	},

	draw: function() {
		/* WebGL drawing function */
	},

	onAdd: function(map) {
		this._map = map;

		if (!this._renderer) {
			this._initRenderer();
			this._initCamera(map.getSize());
		}

		map._panes.overlayPane.appendChild( this._renderer.domElement );

		map.on({
			'viewreset': this._reset,
			'moveend': this._update
		}, this);

		if (map.options.zoomAnimation) {
			map.on({
				'zoomanim': this._animateZoom,
				'zoomend': this._endZoomAnim,
			}, this);
		}

		this._reset();
		this.draw();
	},

	onRemove: function(map) {
		map.getPanes().overlayPane.removeChild( this._renderer.domElement );

		map.off({
			'viewreset': this._reset,
			'moveend': this._update
		}, this);
		if (map.options.zoomAnimation) {
			map.off({
				'zoomanim': this._animateZoom,
				'zoomend': this._endZoomAnim,
			}, this);
		}
	},

	addTo: function(map) {
		map.addLayer(this);
		return this;
	},

	_animateZoom: function(e) {
		var scale = map.getZoomScale(e.zoom);
		console.log(scale);
		this._camera.zoom = scale;
		this._camera.updateProjectionMatrix();
		this._renderToScreen();
		this.disableScreenRender();
	},

	_endZoomAnim: function() {
		this._camera.zoom = 1;
		this._camera.updateProjectionMatrix();
		setTimeout(this.enableScreenRender.bind(this), 200);
	},

	_reset: function() {
		this._setRendererSize(this._map.getSize());
		this._resizeCamera(this._map.getSize());
		//this._setupCamera(this._map.getPixelOrigin());
		//this._setupCamera(this._map.getSize());
	},

	_update: function() {
		if (!this._map) { return; }

		var map = this._map,
			bounds = map.getPixelBounds(), // TODO don't need these?
			origin = map.getPixelOrigin(),
			size = map.getSize();

		//var shift = bounds.min.subtract(origin);
		var position = map._getMapPanePos().multiplyBy(-1);

		L.DomUtil.setPosition( this._renderer.domElement, position );
		this._reset();
		this.draw();
		this._renderToScreen();
	},

	disableScreenRender: function() {
		this.options.disableScreenRender = true;
	},

	enableScreenRender: function() {
		this.options.disableScreenRender = false;
	},

	_renderToScreen: function() {
		if (this._renderTarget && !this.options.disableScreenRender) {
			var worldSize = this._map.getSize();

			var geo = new THREE.PlaneBufferGeometry( worldSize.x, worldSize.y );
			var mat = new THREE.MeshBasicMaterial({map: this._renderTarget});
			var mesh = new THREE.Mesh( geo, mat );
			var scene = new THREE.Scene();
			scene.add(mesh);

			this._renderer.render(scene, this._camera)

		}
	},

	_getSize: function() {
		return this._map.getSize();
	},

	_initRenderer: function() {
		this._renderer = new THREE.WebGLRenderer();
	},

	_initCamera: function(origin) {
		this._camera = new THREE.OrthographicCamera( origin.x / -2, origin.x / 2, origin.y / 2, origin.y / -2, 1, 1024.0 );
	},

	_setRendererSize: function(size) {
		this._renderer.setSize( size.x, size.y );
	},

	_resizeCamera: function(origin) {
		this._camera.left = origin.x / -2;
		this._camera.right = origin.x / 2;
		this._camera.top = origin.y / 2;
		this._camera.bottom = origin.y / -2;
		this._camera.updateProjectionMatrix();
	},

	_getTileSize: function () {
		var map = this._map,
		    zoom = map.getZoom() + this.options.zoomOffset,
		    zoomN = this.options.maxNativeZoom,
		    tileSize = this.options.tileSize;
{'fraction_non_alphanumeric': 0.14734795290050773, 'fraction_numerical': 0.00712973965647618, 'mean_word_length': 3.10077519379845, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7543307', 'n_tokens_mistral': 7042, 'n_tokens_neox': 6274, 'n_words': 1277}