Hello FlashCoder... 

maybe it's because it's late but it's getting a little confusing, and google is 
not being friendly right now. 
seems to works fine with positive numbers, however - i am trying to normalise a 
range of positive and negative numbers... ( code simplified not to find min and 
max values ). 

I am currently am coming up a little short... hope this code does not give 
anyone a headache; if you fancy a stab, or if you can point me in the right 
direction 
... otherwise ...  will post results when i get there...

Code:

public function test() {
        
        trace('------------------------------------')
        trace( testNormalizeNumbers( [  1 , 1.5 , 2 ] , 2 , 1 ).toString() );
        
        trace('------------------------------------')
        trace( testNormalizeNumbers( [  1 , 1.5 , 5 , 1 , 6.4 , 6, 3, -2.6, -1 
, 3.5 ] , 6.4 , -2.6 ).toString() );
        trace('------------------------------------')
        trace( testNormalizeNumbers( [  -1 , -1.5 , -5 , -1 , -6.4 , -6, -3, 
-2.6, -1 , -3.5 ] ,-1 , -6.4 ).toString() );
        
}

public function testNormalizeNumbers( a : Array , max : Number , min : Number ) 
: Array {

        var result      : Array         = new Array();                  
        var nMax        : Number        = ( min > 0 ) ? max - min : max + 
Math.abs( min );
        
        for ( var c : int = 0 ; c < a.length ; c++ ){
                
                var pRangedValue                : Number = ( min > 0 ) ? a[c] - 
min : a[c] + Math.abs( min );
                var normalizedValue     : Number = pRangedValue / nMax;
                
                result.push( normalizedValue );
                
        }
        
        return result;
        
}



Thanks


Karim _______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to