Re: access violation - again ???

Patrick Van Laake <[email protected]> Thu, 19 Aug 2004 14:04:11 +0000 (UTC)
Newsgroups gmane.comp.gis.dspatial.devel
Message-ID <[email protected]>
Arioch /BDV/ <the_Arioch <at> nm.ru> writes:

> For all integer-flavored Histo's thelast line looks like
> 
>   scale := FBins / (Max - Min + 1);
> 
> But for float - there is no that '+1' - what to do ?
> 
Hi Arioch,

For float types there is no real equivalent. The problem arises when there is a 
float value *exactly* equal to FMax. In that case the statement:

  Inc(FHisto[Floor((dp^ - FMin) * scale)]);

tries to update FHisto[Length(FHisto)], which obviously does not exist. The 
problem is that the math dictates that FMax will fall outside of the range, 
i.e. [FMin, FMax>, which is not very elegant. The solution would be to add a 
test to see if the data value equals FMax (i.e. if dp^ = FMax then Inc(FHisto
[FBins-1]) else ...), but this adds to the processing time. Alternatively (what 
I typically do), pass a max value to the constructor that is slightly larger 
than the maximum value (i.e. multiply by 1.0000000000001).

Cheers,
Patrick



-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285