X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Frasterize;a=blobdiff_plain;f=common.h;fp=common.h;h=dd6f034bc9171fa9dd67e5d73d52e0ef7550de13;hp=6224c80cc13eab493ed6cbae0b8d99b3ea0e572f;hb=b0a8ea303e942930350bf85c860afc969442c7a4;hpb=c875478cdd823c7df8fdc859941bd9e5948c9315 diff --git a/common.h b/common.h index 6224c80..dd6f034 100644 --- a/common.h +++ b/common.h @@ -37,6 +37,7 @@ typedef double scal_t; #define scal_ceil ceil #define scal_min fmin #define scal_max fmax +#define scal_abs fabs #define scal_pow pow #define scal_sqrt sqrt #define scal_sin sin @@ -53,6 +54,7 @@ typedef float scal_t; #define scal_ceil ceilf #define scal_min fminf #define scal_max fmaxf +#define scal_abs fabsf #define scal_pow powf #define scal_sqrt sqrtf #define scal_sin sinf @@ -66,6 +68,26 @@ typedef float scal_t; #define scal_min2(A,B,C) scal_min(scal_min(A,B),C) #define scal_max2(A,B,C) scal_max(scal_max(A,B),C) +#define SCAL_EPSILON (S(0.000001)) + +/* + * Check if two scalars are mostly equal, given a margin of error. + */ +INLINE_MAYBE +bool scal_isequal2(scal_t a, scal_t b, scal_t e) +{ + return scal_abs(a -b) < e; +} + +/* + * Check if two scalars are mostly equal. + */ +INLINE_MAYBE +bool scal_isequal(scal_t a, scal_t b) +{ + return scal_isequal2(a, b, SCAL_EPSILON); +} + /* * Clamp a scalar between two values. */