2
* This file is part of the dis-Emi-A HaXe Library. Copyright (c) edA-qa mort-ora-y
3
* For full copyright and license information please refer to doc/license.txt.
6
typedef FastList<T> = Array<T>;
9
* Simple array utilities that seem to be missing from haxe...?
13
static public function seedFill_8<T>( colorMap : Matrix<T>,
14
seeds : FastList<MatPoint>, match1 : T, fill : T )
16
//PERFORMANCE: In AS3 Compiler Array is far faster than List! (TODO: choose based on compiler options?)
17
var sX = new FastList<Int>();
18
var sY = new FastList<Int>();
23
colorMap.set( i.x, i.y, fill ); //pre-fill these (to avoid duplicate fills later) (TODO: promote to others)
26
while( sX.length > 0 )
31
colorMap.set( ccX, ccY, fill );
34
//PERFORANCE: No static arrays, and minimize if comparisons
63
//Strangely, this is better than putting continues in the switch
64
//statement on possibly invalid items (at least for size 8, 4 the continues were fine)
65
if( nx >= 0 && ny >= 0
66
&& nx < colorMap.size.x && ny < colorMap.size.y
67
&& colorMap.get(nx,ny) == match1
70
colorMap.set( nx, ny, fill );
85
public function new( ax : Int, ay : Int )
97
private var data : Array<T>;
98
public var sizeX(default,null) : Int;
99
public var sizeY(default,null) : Int;
101
public function get( x : Int, y : Int ) : T
103
//assert validIndex(x,y);
104
return data[ y*sizeX + x ];
107
public function set( x : Int, y : Int, val : T )
109
//assert validIndex(x, y );
110
data[y*sizeX + x] = val;
113
//only static functions can create a new matrix
114
private function new()
119
* Creates a matrix with the default value given
121
static public function create<Q>( cols : Int, rows : Int, init : Q ) : Matrix<Q>
123
var m = new Matrix<Q>();
126
m.data = new Array<Q>();
128
for( i in 0...m.size.y )
129
for( j in 0...m.size.x )
139
static var matSize = 50;
140
static var loop = 10;
141
static function main()
143
var norm = Matrix.create( matSize, matSize, 0 );
144
var lastTime = flash.Lib.getTimer();
147
var lo = new FastList<MatPoint>();
148
lo.push( new MatPoint( 0, 0 ) );
149
MatrixUtil.seedFill_8( norm, lo, i, i+1 );
153
var nTime = flash.Lib.getTimer();
154
trace( "time: " + (nTime - lastTime) );