topical media & game development

talk show tell print

lib-flex-book-com-rubenswieringa-geom-SuperRectangle.ax

lib-flex-book-com-rubenswieringa-geom-SuperRectangle.ax (swf ) [ flash ] flex


  package com.rubenswieringa.geom {
  
          import flash.geom.*;
          import mx.graphics.RoundedRectangle;
  
          
          
Provides functionality for working with Rectangles. This class extends the RoundedRectangle class and thus has all of its functionality (and also the functionality of the Rectangle class, which RoundedRectangle extends). @author Ruben Swieringa ruben.swieringa@gmail.com www.rubenswieringa.com www.rubenswieringa.com/blog @version 1.0.0 edit 5b* * This class is a slightly stripped-down version of the original @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle class (the unfinished method getCornersInbetween() has been removed) Before modifying and/or redistributing this class, please contact Ruben Swieringa (ruben.swieringa@gmail.com). View code documentation at: http://www.rubenswieringa.com/code/as3/flex/Geom/docs/ *

  
          public class @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle extends RoundedRectangle {
                  
                  
                  public static const NONE:int = -1;
                  public static const TOP:int = 0;
                  public static const RIGHT:int = 1;
                  public static const BOTTOM:int = 2;
                  public static const LEFT:int = 3;
                  
                  
                  
Constructor.

  
                  public function @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle (x:Number=0, y:Number=0, 
                                                                                  width:Number=0, height:Number=0, 
                                                                                  cornerRadius:Number=0):void {
                          super(x, y, width, height, cornerRadius);
                  }
                  
                  
                  
Takes a Rectangle instance and returns it as a @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle with the same position, width, height, and (if applicable) corner-radius. @param rect Rectangle @return rect as a @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle.

  
                  public static function create@ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle (rect:Rectangle):@ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle {
                          if (rect is @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle){
                                  return @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle(rect);
                          }
                          var newRect:@ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle = new @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle(rect.x, rect.y, rect.width, rect.height);
                          if (rect is RoundedRectangle){
                                  newRect.cornerRadius = RoundedRectangle(rect).cornerRadius;
                          }
                          return newRect;
                  }
                  
                  
                  
Indicates on which side of this @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle a Point is. Note that if the Point is not on the @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle its border, -1 will be the return-value. @param point A coordinate. @see @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle#NONE @see @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle#TOP @see @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle#RIGHT @see @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle#BOTTOM @see @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle#LEFT @return An integer indicating on which side a given coordinate is. 0 stands for he top-side, 1 for right-side, etc. Use the constants of the @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle class for improved code-readability.

  
                  public function isOnSide (point:Point):int {
                          var lines:Array = this.getLines();
                          for (var i:int=0; i<lines.length; i++){
                                  if (lines[i].containsPoint(point)){
                                          switch (i){
                                                  case 0 : return @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle.TOP;
                                                  case 1 : return @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle.RIGHT;
                                                  case 2 : return @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle.BOTTOM;
                                                  case 3 : return @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle.LEFT;
                                          }
                                  }
                          }
                          return @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle.NONE;
                  }
                  
                  
                  
Returns an Array with Point instances indicating the corners of the @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle. The first index (0) is the top-left corner, the second (1) the top-right, etc. @return Array

  
                  public function getCorners ():Array {
                          return [this.topLeft, this.topRight, this.bottomRight, this.bottomLeft];
                  }
                  
Returns an Array with Point instances indicating the 4 sides of this @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle as Lines. @see Line @return Array

  
                  public function getLines ():Array {
                          var lines:Array = [];
                          var corners:Array = this.getCorners();
                          lines.push(new Line(corners[0], corners[1]));
                          lines.push(new Line(corners[1], corners[2]));
                          lines.push(new Line(corners[2], corners[3]));
                          lines.push(new Line(corners[3], corners[0]));
                          return lines;
                  }
                  
@copy @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle#getCorners() @see @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle#getCorners() @return Array

  
                  public function toArray ():Array {
                          return this.getCorners();
                  }
                  
                  
                  
The center of the @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle.

  
                  public function get center ():Point {
                          return Point.interpolate(this.bottomRight, this.topLeft, 0.5);
                  }
                  
                  
                  
Point representing the lower left corner of this @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle.

  
                  public function get bottomLeft ():Point {
                          return new Point(this.left, this.bottom);
                  }
                  
Point representing the upper right corner of this @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle.

  
                  public function get topRight ():Point {
                          return new Point(this.right, this.top);
                  }
                  
                  
                  
The center of this @ax-lib-flex-book-com-rubenswieringa-geom-SuperRectangle instance.

  
                  public function get middle ():Point {
                          var point:Point = new Point();
                          point.x = this.x + this.width/2;
                          point.y = this.y + this.height/2;
                          return point;
                  }
                  
                  
          }
          
          
  }


(C) Æliens 18/6/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.