<commit_before>package flash.display {
	import flash.events.Event;
	import flash.geom.Rectangle;
	
	public class ConstrainedSprite extends Sprite {
		
		private var _width:Number;
		private var _height:Number;
		
		public function ConstrainedSprite() {
//			addEventListener(Event.ADDED, addedHandler);
		}
		
//		private function addedHandler(event:Event):void {
//			var child:DisplayObject = event.target as DisplayObject;
//			if(child.parent == this) {
//				drawChild(child);
//			}
//		}
		
		public function draw():void {
			drawChildren();
		}
		
		override public function set width(width:Number):void {
			if(width != _width) {
				_width = width;
				drawChildren();
			}
		}
		
		override public function set height(height:Number):void {
			if(height != _height) {
				_height = height;
				drawChildren();
			}
		}
		
		private function drawChildren():void {
			forEach(function(child:DisplayObject, index:int):void {
				drawChild(child);
			});
		}
		
		private function shouldDrawChild(child:DisplayObject):Boolean {
			return (
					!isNaN(_width) && 
					!isNaN(_height) &&
					_width != 0 && 
					_height != 0 && 
					child.width > 0 && 
					child.height > 0);
		}
		
		private function drawChild(child:DisplayObject):void {
			if(shouldDrawChild(child)) {
				var rect:Rectangle;
				
				rect = constrainedSize(child.width, child.height, _width, _height);
				child.width = rect.width;
				child.height = rect.height;
				child.x = Math.round((_width/2) - (child.width/2));
				child.y = Math.round((_height/2) - (child.height/2));
				//trace(">> drawing child with: ", child, rect, "vis", child.visible, "actual w", child.width, "actual h", child.height, "x", child.x, "y", child.y);
			}
		}

		private function forEach(handler:Function):void {
			var len:Number = numChildren;
			var child:DisplayObject;<commit_msg>Fixed aspect ratio problems<commit_after>package flash.display {
	import episodic.core.Playable;
	
	import flash.events.Event;
	import flash.geom.Rectangle;
	import flash.media.Video;
	
	public class ConstrainedSprite extends Sprite {
		
		private var _width:Number;
		private var _height:Number;
		
		public function ConstrainedSprite() {
			addEventListener(Event.ADDED, addedHandler);
		}
		
		private function addedHandler(event:Event):void {
			var child:DisplayObject = event.target as DisplayObject;
			if(child.parent == this) {
				drawChild(child);
			}
		}
		
		public function draw():void {
			drawChildren();
		}
		
		override public function set width(width:Number):void {
			if(width != _width) {
				_width = width;
				drawChildren();
			}
		}
		
		override public function set height(height:Number):void {
			if(height != _height) {
				_height = height;
				drawChildren();
			}
		}
		
		private function drawChildren():void {
			forEach(function(child:DisplayObject, index:int):void {
				drawChild(child);
			});
		}
		
		private function shouldDrawChild(child:DisplayObject):Boolean {
			return (!isNaN(_width) && 
					!isNaN(_height) &&
					_width != 0 && 
					_height != 0 && 
					child.width > 0 && 
					child.height > 0);
		}
		
		private function drawChild(child:DisplayObject):void {
			if(shouldDrawChild(child)) {
				var rect:Rectangle;
				
				var childWidth:Number = child.width;
				var childHeight:Number = child.height;

				// NOTE: This is some ugliness that had to be done
				// because the flash.display.Video object doesn't
				// provide .videoWidth or .videoHeight until AFTER
				// that asset has actually been on screen for an arbitrary
				//  number of frames. SO  - the Stream object now
				// collects those values from metaData and holds onto them				
				if(child.hasOwnProperty('stream')) {
					var stream:Playable = child['stream'] as Playable;
					if(stream.videoWidth > 0 && stream.videoHeight > 0) {
						childWidth = stream.videoWidth;
						childHeight = stream.videoHeight;
					}
					else {
						return;
					}
				}
				
				rect = constrainedSize(childWidth, childHeight, _width, _height);
				child.width = rect.width;
				child.height = rect.height;
				child.x = Math.round((_width/2) - (child.width/2));
				child.y = Math.round((_height/2) - (child.height/2));
				//trace(">> drawing child with: ", child, rect, "vis", child.visible, "actual w", child.width, "actual h", child.height, "x", child.x, "y", child.y);
			}
		}

		private function forEach(handler:Function):void {
			var len:Number = numChildren;
			var child:DisplayObject;
{'fraction_non_alphanumeric': 0.1278835386338186, 'fraction_numerical': 0.004031354983202688, 'mean_word_length': 3.1467038068709376, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '352916', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1357, 'n_words': 324}