staticint adjust_dual(int *begin, int step, int *end, int eq, int mu)
{ int f, *p, s, c;
if (begin == end) return0;
f = *begin;
p = begin + step;
s = p == end ? f + 1 : *p;
for (; p != end; p += step) { if (*p < f) {
s = f;
f = *p;
} elseif (*p < s) {
s = *p;
}
}
c = (f + s + 1) / 2; if (c == 0 || (c > mu && (!eq || mu > 0))) return0; /* Improve convergence for positive matrices by penalizing overcovers */ if (s < 0 && mu <= 0)
c *= 2;
for (p = begin; p != end; p += step)
*p -= c;
return (c < s && s <= 0) || (f >= 0 && f < c);
}
staticvoid find_reduced_matrix(int *w, int nr, int nc, int nrc, int mu)
{ int i, k, sum;
for (k = 0; k < nrc; k++) { for (i = 0; i < nr; i++)
adjust_dual(w + i, nr, w + i + nrc, nr <= nc, mu);
sum = 0; for (i = 0; i < nrc; i += nr)
sum += adjust_dual(w + i, 1, w + i + nr, nc <= nr, mu); if (!sum) break;
}
}
staticint input_mt_set_matrix(struct input_mt *mt, conststruct input_mt_pos *pos, int num_pos, int mu)
{ conststruct input_mt_pos *p; struct input_mt_slot *s; int *w = mt->red; int x, y;
for (s = mt->slots; s != mt->slots + mt->num_slots; s++) { if (!input_mt_is_active(s)) continue;
x = input_mt_get_value(s, ABS_MT_POSITION_X);
y = input_mt_get_value(s, ABS_MT_POSITION_Y); for (p = pos; p != pos + num_pos; p++) { int dx = x - p->x, dy = y - p->y;
*w++ = dx * dx + dy * dy - mu;
}
}
return w - mt->red;
}
staticvoid input_mt_set_slots(struct input_mt *mt, int *slots, int num_pos)
{ struct input_mt_slot *s; int *w = mt->red, j;
for (j = 0; j != num_pos; j++)
slots[j] = -1;
for (s = mt->slots; s != mt->slots + mt->num_slots; s++) { if (!input_mt_is_active(s)) continue;
for (j = 0; j != num_pos; j++) { if (w[j] < 0) {
slots[j] = s - mt->slots; break;
}
}
w += num_pos;
}
for (s = mt->slots; s != mt->slots + mt->num_slots; s++) { if (input_mt_is_active(s)) continue;
for (j = 0; j != num_pos; j++) { if (slots[j] < 0) {
slots[j] = s - mt->slots; break;
}
}
}
}
/** *input_mt_assign_slots()-performabest-matchassignment *@dev:inputdevicewithallocatedMTslots *@slots:theslotassignmenttobefilled *@pos:thepositionarraytomatch *@num_pos:numberofpositions *@dmax:maximumABS_MT_POSITIONdisplacement(zeroforinfinite) * *Performsabestmatchagainstthecurrentcontactsandreturns *theslotassignmentlist.Newcontactsareassignedtounused *slots. * *Theassignmentsarebalancedsothatallcoordinatedisplacementsare *belowtheeuclidiandistancedmax.Ifnosuchassignmentcanbefound, *somecontactsareassignedtounusedslots. * *Returnszeroonsuccess,ornegativeerrorincaseoffailure.
*/ int input_mt_assign_slots(struct input_dev *dev, int *slots, conststruct input_mt_pos *pos, int num_pos, int dmax)
{ struct input_mt *mt = dev->mt; int mu = 2 * dmax * dmax; int nrc;
if (!mt || !mt->red) return -ENXIO; if (num_pos > mt->num_slots) return -EINVAL; if (num_pos < 1) return0;
for (s = mt->slots; s != mt->slots + mt->num_slots; s++) if (input_mt_is_active(s) && s->key == key) return s - mt->slots;
for (s = mt->slots; s != mt->slots + mt->num_slots; s++) if (!input_mt_is_active(s) && !input_mt_is_used(mt, s)) {
s->key = key; return s - mt->slots;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.