1  /**
     2   * com.sekati.convert.PointConversion
     3   * @version 1.0.0
     4   * @author jason m horwitz | sekati.com
     5   * Copyright (C) 2008  jason m horwitz, Sekat LLC. All Rights Reserved.
     6   * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
     7   */
     8  import com.sekati.geom.Point;
     9  import com.sekati.except.IllegalArgumentException;
    10  
    11  /**
    12   * Point Conversion utilities
    13   */
    14  class com.sekati.convert.PointConversion {
    15  
    16  	/**
    17  	 * Conversion utility for {@link Polygon.draw() }. Accepts condensed string 
    18  	 * data (usually from XML) & converts to a proper Point array for use with draw.
    19  	 * @param coords (String) - formatting "x,y|x,y|x,y" (e.g. "524,176|599,160|618,252|543,268")
    20  	 * @return Array - of points
    21  	 * {@code Usage:
    22  	 * 	var pointArray:Array = PointConversion.toPointArray( "524,176|599,160|618,252|543,268" );
    23  	 * 	Polygon.draw( polyMc, pointArray, 0xff00ff, 50, 1, 0x00ffff, 100 );
    24  	 * }
    25  	 */
    26  	public static function toPointArray(coords:String):Array {
    27  		var pointArray:Array = new Array( );
    28  		var strArray:Array = coords.split( "|" );
    29  		if (strArray.length < 1) {
    30  			throw new IllegalArgumentException( PointConversion, "@@@ com.sekati.convert.PointConversion.toPointArray() Error: method requires a properly formatted coords string argument ('x,y|x,y|x,y') with at least 1 stringified points.", arguments );	
    31  		}
    32  		var len:Number = strArray.length;
    33  		for (var i:Number = 0; i < len ; i++) {
    34  			var p:Array = strArray[i].split( "," );
    35  			pointArray.push( new Point( Number( p[0] ), Number( p[1] ) ) );
    36  		}
    37  		return pointArray;
    38  	}	
    39  }
    40