Rewrite FcCompareRange()

Much simpler now.
This commit is contained in:
Behdad Esfahbod 2017-09-12 19:08:36 -04:00
parent e7a0a0a999
commit b4813436a3
1 changed files with 20 additions and 19 deletions

View File

@ -160,42 +160,43 @@ FcCompareRange (FcValue *v1, FcValue *v2)
{ {
FcValue value1 = FcValueCanonicalize (v1); FcValue value1 = FcValueCanonicalize (v1);
FcValue value2 = FcValueCanonicalize (v2); FcValue value2 = FcValueCanonicalize (v2);
FcRange *r1 = NULL, *r2 = NULL; double b1, e1, b2, e2;
double ret = -1.0;
switch ((int) value1.type) { switch ((int) value1.type) {
case FcTypeInteger:
b1 = e1 = value1.u.i;
break;
case FcTypeDouble: case FcTypeDouble:
r1 = FcRangeCreateDouble (value1.u.d, value1.u.d); b1 = e1 = value1.u.d;
break; break;
case FcTypeRange: case FcTypeRange:
r1 = FcRangeCopy (value1.u.r); abort();
b1 = value1.u.r->begin;
e1 = value1.u.r->end;
break; break;
default: default:
goto bail; return -1;
} }
switch ((int) value2.type) { switch ((int) value2.type) {
case FcTypeInteger:
b2 = e2 = value2.u.i;
break;
case FcTypeDouble: case FcTypeDouble:
r2 = FcRangeCreateDouble (value2.u.d, value2.u.d); b2 = e2 = value2.u.d;
break; break;
case FcTypeRange: case FcTypeRange:
r2 = FcRangeCopy (value2.u.r); b2 = value2.u.r->begin;
e2 = value2.u.r->end;
break; break;
default: default:
goto bail; return -1;
} }
if (FcRangeIsInRange (r1, r2)) /* If the ranges overlap, it's a match, otherwise return closest distance. */
ret = 0.0; if (e1 < b2 || e2 < b1)
return FC_MIN (fabs (b2 - e1), fabs (b1 - e2));
else else
ret = FC_MIN (fabs (r1->end - r2->begin), fabs (r1->begin - r2->end)); return 0.0;
bail:
if (r1)
FcRangeDestroy (r1);
if (r2)
FcRangeDestroy (r2);
return ret;
} }
static double static double