Guest User

Untitled

a guest
Jan 21st, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // find optimal (largest) tile size
  2.             private function FinOptimalVideoSize(nbvideo:int):void{
  3.                
  4.                 var desiredAspectRatio:Number = 1.33;
  5.                 // used to hold the new size of the children after resizing
  6.                 var newSize:Object = new Object();
  7.                 // holds the original size of the children
  8.                 var rectangleSize:Object = new Object();
  9.                 rectangleSize.Width = desiredAspectRatio;
  10.                 rectangleSize.Height = 1;
  11.                
  12.                 var numColumns:Number = Math.sqrt((nbvideo * rectangleSize.Height * this.width) / (this.height * rectangleSize.Width));
  13.                
  14.                 var lowBoundColumns:Number = Math.floor(numColumns);
  15.                 var highBoundColumns:Number = Math.ceil(numColumns);
  16.                
  17.                 var lowNumRows:Number = Math.ceil(nbvideo / lowBoundColumns);
  18.                 var highNumRows:Number = Math.ceil(nbvideo / highBoundColumns);
  19.                
  20.                 var VerticalScale:Number = this.height / lowNumRows * rectangleSize.Height;
  21.                 var HorizontalScale:Number = this.width / (highBoundColumns * rectangleSize.Width);
  22.                
  23.                 var MaxHorizontalArea:Number = (HorizontalScale * rectangleSize.Width) * ((HorizontalScale * rectangleSize.Width) / desiredAspectRatio);
  24.                 var MaxVerticalArea:Number = (VerticalScale * rectangleSize.Height) * ((VerticalScale * rectangleSize.Height) * desiredAspectRatio);
  25.                
  26.                 var rowsMaximized:Boolean;
  27.                 // the horizontal area is greater than
  28.                 // the max area then we maximize by columns
  29.                 if (MaxHorizontalArea >= MaxVerticalArea)
  30.                 {                  
  31.                     newSize.Width = this.width / highBoundColumns;
  32.                                
  33.                     newSize.Height = newSize.Width / desiredAspectRatio; // A = w/h or h= w/A
  34.                     rowsMaximized = false;//used for testing
  35.                    
  36.                     if (newSize.Height * Math.ceil(nbvideo /
  37.                         highBoundColumns) > this.height)
  38.                     {
  39.                         //in this case the best solution is usually to maximize by rows instead
  40.                         var newHeight:Number = this.height / highNumRows;
  41.                         var newWidth:Number = newHeight * desiredAspectRatio;
  42.                         rowsMaximized = true;
  43.                        
  44.                         if (newWidth * nbvideo < this.width)
  45.                         {
  46.                            
  47.                             newWidth = this.width / Math.ceil(numColumns++);
  48.                             newHeight = newWidth / desiredAspectRatio;
  49.                             rowsMaximized = false;
  50.                            
  51.                             while (newWidth * nbvideo > this.width)
  52.                             {
  53.                                 newWidth = this.width / Math.ceil(numColumns++);
  54.                                 newHeight = newWidth / desiredAspectRatio;
  55.                             }
  56.                            
  57.                             if (newHeight > this.height)
  58.                             {
  59.                                 newHeight = this.height;
  60.                                 newWidth = newHeight * desiredAspectRatio;
  61.                                 rowsMaximized = true;
  62.                             }
  63.                         }
  64.                         var currentCols:Number = Math.floor(this.width / newWidth);
  65.                         var currentRows:Number = Math.ceil(nbvideo / currentCols);
  66.                        
  67.                         if ((newWidth * currentCols) < this.width &&
  68.                             (newHeight * Math.ceil(nbvideo /
  69.                                 currentCols)) < this.height)
  70.                         {
  71.                             newWidth = this.width / currentCols;
  72.                             newHeight = newSize.Width / desiredAspectRatio;
  73.                             rowsMaximized = false;
  74.                            
  75.                             if (newHeight * Math.ceil(nbvideo /
  76.                                 currentCols) > this.height)
  77.                             {
  78.                                 newHeight = this.height / currentRows;
  79.                                 newWidth = newHeight * desiredAspectRatio;
  80.                                 rowsMaximized = true;
  81.                             }
  82.                         }
  83.                        
  84.                         newSize.Height = newHeight;
  85.                         newSize.Width = newWidth;
  86.                     }
  87.                 }
  88.                 else
  89.                 {
  90.                     newSize.Height = this.height / lowNumRows;
  91.                     newSize.Width = newSize.Height * desiredAspectRatio;
  92.                     rowsMaximized = true;
  93.                 }
  94.                
  95.                 trace("Alrorith 1 thinks Width: " +  newSize.Width + " Height: " + newSize.Height)
  96.                 tileWidth = newSize.Width;
  97.                 tileHeight = newSize.Height;
  98.                            
  99.             }
Add Comment
Please, Sign In to add comment