<commit_before>/**
 * @author dmarcos / https://github.com/dmarcos
 * @author mrdoob / http://mrdoob.com
 * @author customlogic / http://custom-logic.com
 *
 * WebVR Spec: http://mozvr.github.io/webvr-spec/webvr.html
 *
 * Firefox: http://mozvr.com/downloads/
 * Chromium: https://webvr.info/get-chrome
 *
 */
module.exports = function( THREE ){

	THREE.VREffect = function ( renderer, onError ) {

		var vrDisplay, vrDisplays;
		var eyeTranslationL = new THREE.Vector3();
		var eyeTranslationR = new THREE.Vector3();
		var renderRectL, renderRectR;
		var headMatrix = new THREE.Matrix4();
		var eyeMatrixL = new THREE.Matrix4();
		var eyeMatrixR = new THREE.Matrix4();

		var frameData = null;

		if ( 'VRFrameData' in window ) {

			frameData = new window.VRFrameData();

		}

		function gotVRDisplays( displays ) {

			vrDisplays = displays;

			if ( displays.length > 0 ) {

				vrDisplay = displays[ 0 ];

			} else {

				if ( onError ) onError( 'HMD not available' );

			}

		}

		if ( navigator.getVRDisplays ) {

			navigator.getVRDisplays().then( gotVRDisplays ).catch( function () {

				console.warn( 'THREE.VREffect: Unable to get VR Displays' );

			} );

		}

		//

		this.isPresenting = false;

		var scope = this;

		var rendererSize = renderer.getSize();
		var rendererUpdateStyle = false;
		var rendererPixelRatio = renderer.getPixelRatio();

		this.getVRDisplay = function () {

			return vrDisplay;

		};

		this.setVRDisplay = function ( value ) {

			vrDisplay = value;

		};

		this.getVRDisplays = function () {

			console.warn( 'THREE.VREffect: getVRDisplays() is being deprecated.' );
			return vrDisplays;

		};

		this.setSize = function ( width, height, updateStyle ) {

			rendererSize = { width: width, height: height };
			rendererUpdateStyle = updateStyle;

			if ( scope.isPresenting ) {

				var eyeParamsL = vrDisplay.getEyeParameters( 'left' );
				//  The intention here is to only call render.setPixelRatio if we need to
				//  because that call redundantly calls renderer.setSize()
				//  and that can easily add 300ms overhead.
				if (renderer.getPixelRatio() !== 1) renderer.setPixelRatio(1);
				renderer.setSize( eyeParamsL.renderWidth * 2  * VRResolutionRatio, eyeParamsL.renderHeight  * VRResolutionRatio, false );

			} else {

				renderer.setPixelRatio( rendererPixelRatio );
				renderer.setSize( width, height, updateStyle );

			}

		};

		// VR presentation

		var canvas = renderer.domElement;
		var defaultLeftBounds = [ 0.0, 0.0, 0.5, 1.0 ];
		var defaultRightBounds = [ 0.5, 0.0, 0.5, 1.0 ];
		var VRResolutionRatio = 1.0;
		var FOVRenderRatio = 1.0;

		function onVRDisplayPresentChange() {

			var wasPresenting = scope.isPresenting;
			scope.isPresenting = vrDisplay !== undefined && vrDisplay.isPresenting;

			if ( scope.isPresenting ) {

				var eyeParamsL = vrDisplay.getEyeParameters( 'left' );
				var eyeWidth = eyeParamsL.renderWidth;
				var eyeHeight = eyeParamsL.renderHeight;

				if ( ! wasPresenting ) {

					rendererPixelRatio = renderer.getPixelRatio();
					rendererSize = renderer.getSize();

					//  The intention here is to only call render.setPixelRatio if we need to
					//  because that call redundantly calls renderer.setSize()
					//  and that can easily add 300ms overhead.
					if (rendererPixelRatio !== 1) renderer.setPixelRatio(1);
					renderer.setSize(eyeWidth * 2 * VRResolutionRatio, eyeHeight * VRResolutionRatio, false);

					scope.setVRResolutionRatio(VRResolutionRatio)
				}

			} else if ( wasPresenting ) {

				renderer.setPixelRatio( rendererPixelRatio );
				renderer.setSize( rendererSize.width, rendererSize.height, rendererUpdateStyle );

			}
			

			//renderer.domElement.style.width = rendererSize.width + "px";
			//renderer.domElement.style.height = rendererSize.height + "px";
		}

		window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );

		// Set the resolution draw and presented in VR. This ratio only affects the area of the
		// canvas we render to and submit to VRDisplay (no canvas resizing required), so 
		// this function is fast enough to call every frame
		this.setVRResolutionRatio = function (ratio) {
			VRResolutionRatio = THREE.Math.clamp(ratio, 0, 1.0);

			if ( vrDisplay !== undefined && vrDisplay.isPresenting ) {

				// since we're already presenting, this doesn't need to be initiated by user interaction
				requestPresentToVRDisplay();
			}

		}

		this.setFOVRenderRatio = function (ratio) {
			FOVRenderRatio = Math.max(Math.min(ratio, 1), 0);
		}

		function requestPresentToVRDisplay() {
			var eyeParamsL = vrDisplay.getEyeParameters( 'left' );

			// render size of each divided by total canvas size 
			var boundsWidth = Math.floor(eyeParamsL.renderWidth * VRResolutionRatio) / canvas.width;
			var boundsHeight = Math.floor(eyeParamsL.renderHeight * VRResolutionRatio) / canvas.height;

			console.log("VR Effect VRResolutionRatio: ", VRResolutionRatio, " ", eyeParamsL.renderWidth * VRResolutionRatio, "x", eyeParamsL.renderHeight * VRResolutionRatio);

			return vrDisplay.requestPresent([{
	         	source: canvas,
	      	 	leftBounds: [0.0, 0.0, boundsWidth, boundsHeight],
	      	 	rightBounds: [boundsWidth, 0.0, boundsWidth, boundsHeight]
	        }]);
		}


		this.setFullScreen = function ( boolean ) {

			return new Promise( function ( resolve, reject ) {

				if ( vrDisplay === undefined ) {<commit_msg>force resize of canvas<commit_after>/**
 * @author dmarcos / https://github.com/dmarcos
 * @author mrdoob / http://mrdoob.com
 * @author customlogic / http://custom-logic.com
 *
 * WebVR Spec: http://mozvr.github.io/webvr-spec/webvr.html
 *
 * Firefox: http://mozvr.com/downloads/
 * Chromium: https://webvr.info/get-chrome
 *
 */
module.exports = function( THREE ){

	THREE.VREffect = function ( renderer, onError ) {

		var vrDisplay, vrDisplays;
		var eyeTranslationL = new THREE.Vector3();
		var eyeTranslationR = new THREE.Vector3();
		var renderRectL, renderRectR;
		var headMatrix = new THREE.Matrix4();
		var eyeMatrixL = new THREE.Matrix4();
		var eyeMatrixR = new THREE.Matrix4();

		var frameData = null;

		if ( 'VRFrameData' in window ) {

			frameData = new window.VRFrameData();

		}

		function gotVRDisplays( displays ) {

			vrDisplays = displays;

			if ( displays.length > 0 ) {

				vrDisplay = displays[ 0 ];

			} else {

				if ( onError ) onError( 'HMD not available' );

			}

		}

		if ( navigator.getVRDisplays ) {

			navigator.getVRDisplays().then( gotVRDisplays ).catch( function () {

				console.warn( 'THREE.VREffect: Unable to get VR Displays' );

			} );

		}

		//

		this.isPresenting = false;

		var scope = this;

		var rendererSize = renderer.getSize();
		var rendererUpdateStyle = false;
		var rendererPixelRatio = renderer.getPixelRatio();

		this.getVRDisplay = function () {

			return vrDisplay;

		};

		this.setVRDisplay = function ( value ) {

			vrDisplay = value;

		};

		this.getVRDisplays = function () {

			console.warn( 'THREE.VREffect: getVRDisplays() is being deprecated.' );
			return vrDisplays;

		};

		this.setSize = function ( width, height, updateStyle ) {

			rendererSize = { width: width, height: height };
			rendererUpdateStyle = updateStyle;

			if ( scope.isPresenting ) {

				var eyeParamsL = vrDisplay.getEyeParameters( 'left' );
				//  The intention here is to only call render.setPixelRatio if we need to
				//  because that call redundantly calls renderer.setSize()
				//  and that can easily add 300ms overhead.
				if (renderer.getPixelRatio() !== 1) renderer.setPixelRatio(1);
				renderer.setSize( eyeParamsL.renderWidth * 2  * VRResolutionRatio, eyeParamsL.renderHeight  * VRResolutionRatio, false );

			} else {

				renderer.setPixelRatio( rendererPixelRatio );
				renderer.setSize( width, height, updateStyle );

			}

		};

		// VR presentation

		var canvas = renderer.domElement;
		var defaultLeftBounds = [ 0.0, 0.0, 0.5, 1.0 ];
		var defaultRightBounds = [ 0.5, 0.0, 0.5, 1.0 ];
		var VRResolutionRatio = 1.0;
		var FOVRenderRatio = 1.0;

		function onVRDisplayPresentChange() {

			var wasPresenting = scope.isPresenting;
			scope.isPresenting = vrDisplay !== undefined && vrDisplay.isPresenting;

			if ( scope.isPresenting ) {

				var eyeParamsL = vrDisplay.getEyeParameters( 'left' );
				var eyeWidth = eyeParamsL.renderWidth;
				var eyeHeight = eyeParamsL.renderHeight;

				if ( ! wasPresenting ) {

					rendererPixelRatio = renderer.getPixelRatio();
					rendererSize = renderer.getSize();

					//  The intention here is to only call render.setPixelRatio if we need to
					//  because that call redundantly calls renderer.setSize()
					//  and that can easily add 300ms overhead.
					if (rendererPixelRatio !== 1) renderer.setPixelRatio(1);
					renderer.setSize(eyeWidth * 2 * VRResolutionRatio, eyeHeight * VRResolutionRatio, false);

					scope.setVRResolutionRatio(VRResolutionRatio)
				}

			} else if ( wasPresenting ) {

				renderer.setPixelRatio( rendererPixelRatio );
				renderer.setSize( rendererSize.width, rendererSize.height, rendererUpdateStyle );

			}
			

			//renderer.domElement.style.width = rendererSize.width + "px";
			//renderer.domElement.style.height = rendererSize.height + "px";
		}

		window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );

		// Set the resolution draw and presented in VR. This ratio only affects the area of the
		// canvas we render to and submit to VRDisplay (no canvas resizing required), so 
		// this function is fast enough to call every frame
		this.setVRResolutionRatio = function (ratio) {
			VRResolutionRatio = THREE.Math.clamp(ratio, 0, 1.0);

			if ( vrDisplay !== undefined && vrDisplay.isPresenting ) {

				const resizeCanvas = true; // TODO: allow dynamic resize without resizing the canvas
				if ( scope.isPresenting && resizeCanvas ) {
					var eyeParamsL = vrDisplay.getEyeParameters( 'left' );
					var eyeWidth = eyeParamsL.renderWidth;
					var eyeHeight = eyeParamsL.renderHeight;

					renderer.setSize(eyeWidth * 2 * VRResolutionRatio, eyeHeight * VRResolutionRatio, false);
				}

				// since we're already presenting, this doesn't need to be initiated by user interaction
				requestPresentToVRDisplay();
			}

		}

		this.setFOVRenderRatio = function (ratio) {
			FOVRenderRatio = Math.max(Math.min(ratio, 1), 0);
		}

		function requestPresentToVRDisplay() {
			var eyeParamsL = vrDisplay.getEyeParameters( 'left' );

			console.log("VR Effect VRResolutionRatio: ", VRResolutionRatio, " ", eyeParamsL.renderWidth * VRResolutionRatio, "x", eyeParamsL.renderHeight * VRResolutionRatio);

			return vrDisplay.requestPresent([{
	         	source: canvas
	        }]);
		}


		this.setFullScreen = function ( boolean ) {

			return new Promise( function ( resolve, reject ) {

				if ( vrDisplay === undefined ) {
{'fraction_non_alphanumeric': 0.11204352637403173, 'fraction_numerical': 0.008760604942825526, 'mean_word_length': 3.3712212817412333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2929008', 'n_tokens_mistral': 4011, 'n_tokens_neox': 3323, 'n_words': 844}