Skip to content

Commit

Permalink
Merge pull request #4 from EiraGe/exceptions
Browse files Browse the repository at this point in the history
Put the cpp exceptions under a compiler flag
  • Loading branch information
casiez authored Sep 22, 2024
2 parents c18c32a + 92033ec commit 492e038
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions cpp/OneEuroFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@

void LowPassFilter::setAlpha(double alpha) {
if (alpha<=0.0 || alpha>1.0)
#ifdef __EXCEPTIONS
throw std::range_error("alpha should be in (0.0., 1.0] and its current value is " + std::to_string(alpha)) ;
#else
alpha = 0.5 ;
#endif
a = alpha ;
}

Expand Down Expand Up @@ -93,12 +97,23 @@ double OneEuroFilter::alpha(double cutoff) {
}

void OneEuroFilter::setFrequency(double f) {
if (f<=0) throw std::range_error("freq should be >0") ;
if (f<=0)
#ifdef __EXCEPTIONS
throw std::range_error("freq should be >0") ;
#else
f= 120 ; // set to 120Hz default
#endif

freq = f ;
}

void OneEuroFilter::setMinCutoff(double mc) {
if (mc<=0) throw std::range_error("mincutoff should be >0") ;
if (mc<=0)
#ifdef __EXCEPTIONS
throw std::range_error("mincutoff should be >0") ;
#else
mc = 1.0 ;
#endif
mincutoff = mc ;
}

Expand All @@ -107,7 +122,12 @@ void OneEuroFilter::setBeta(double b) {
}

void OneEuroFilter::setDerivateCutoff(double dc) {
if (dc<=0) throw std::range_error("dcutoff should be >0") ;
if (dc<=0)
#ifdef __EXCEPTIONS
throw std::range_error("dcutoff should be >0") ;
#else
dc = 1.0 ;
#endif
dcutoff = dc ;
}

Expand Down

0 comments on commit 492e038

Please sign in to comment.