X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fspeedquantizer.cpp;h=f2b14b8a2aa8d6f6d585562739f8c111d548d787;hb=74f8c3beba5a6947a523119e3f26cf745725b511;hp=1098d437c38e76caf7ecb6f1afdd335ae5aaf2e5;hpb=d15ac13f2e170f155b4bbd124df48400c339b644;p=r2c2.git diff --git a/source/libr2c2/speedquantizer.cpp b/source/libr2c2/speedquantizer.cpp index 1098d43..f2b14b8 100644 --- a/source/libr2c2/speedquantizer.cpp +++ b/source/libr2c2/speedquantizer.cpp @@ -10,18 +10,20 @@ SpeedQuantizer::SpeedQuantizer(unsigned n): weight_limit(10) { if(n<1) - throw InvalidParameterValue("Must have at leats one speed step"); + throw invalid_argument("SpeedQuantizer::SpeedQuantizer"); } void SpeedQuantizer::learn(unsigned i, float s, float w) { if(i>=steps.size()) - throw InvalidParameterValue("Speed step index out of range"); + throw out_of_range("SpeedQuantizer::learn"); steps[i].add(s, w); } float SpeedQuantizer::get_speed(unsigned i) const { + if(i>=steps.size()) + throw out_of_range("SpeedQuantizer::get_speed"); if(i==0) return 0; if(steps[i].weight>=weight_limit) @@ -82,7 +84,7 @@ unsigned SpeedQuantizer::find_speed_step(float speed) const else return 0; } - return min(min(static_cast(low*speed/steps[low].speed), steps.size()-1), last+limit); + return min(min(low*speed/steps[low].speed, steps.size()-1), last+limit); } float f = (speed-steps[low].speed)/(steps[high].speed-steps[low].speed);