topical media & game development

talk show tell print

student-ar-org-papervision3d-core-math-util-FastRectangleTools.ax

student-ar-org-papervision3d-core-math-util-FastRectangleTools.ax [swf] [flash] flex


  package org.papervision3d.core.math.util {
          import flash.geom.Rectangle;        
        
        
*
author: Seb Lee-Delisle Some handy rectangle tools that are faster than the built in Rectangle methods.

  
        public class @ax-student-ar-org-papervision3d-core-math-util-FastRectangleTools 
          {
                  
                  
                                  
                  /* 
  		 * 
  		 * in my tests runs 1/3 faster the Rectangle.intersects
  		 * Rectangle.intersects() Test: 71.4499
  		 * Fast intersect Test: 54.199
  		 * 
  		 * @Author Seb Lee-Delisle
  		 * 
  		 * @param        rect1 
  		 * @param        rect2  
  		 *
returns: true if the rectangles intersect. */
public static function intersects(rect1 : Rectangle, rect2 :Rectangle) : Boolean { if(!((rect1.right<rect2.left)||(rect1.left>rect2.right))) if(!((rect1.bottom<rect2.top)||(rect1.top>rect2.bottom))) return true; return false; } /* benchmarks compared to Rectangle.intersection : Rectangle.intersects() Test : 146.89999999999998 this function (without targetrect) : 133.45 this function (with targetrect) : 72.55*/ public static function intersection(rect1:Rectangle, rect2: Rectangle, targetrect:Rectangle = null) : Rectangle { if(!targetrect) targetrect = new Rectangle(); if(!intersects(rect1, rect2)) { targetrect.x = targetrect.y = targetrect.width = targetrect.height = 0; return targetrect; } targetrect.left = (rect1.left>rect2.left) ? rect1.left : rect2.left; targetrect.right = (rect1.right<rect2.right) ? rect1.right : rect2.right; targetrect.top = (rect1.top>rect2.top) ? rect1.top : rect2.top; targetrect.bottom = (rect1.bottom<rect2.bottom) ? rect1.bottom : rect2.bottom; return targetrect; } } }


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.