linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
To: Henrik Rydberg <rydberg@euromail.se>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Hans de Goede <hdegoede@redhat.com>
Cc: Peter Hutterer <peter.hutterer@who-t.net>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC 5/6] Input: mt: document adjust_dual()
Date: Mon, 19 Jan 2015 15:53:54 -0500	[thread overview]
Message-ID: <1421700835-22157-6-git-send-email-benjamin.tissoires@redhat.com> (raw)
In-Reply-To: <1421700835-22157-1-git-send-email-benjamin.tissoires@redhat.com>

adjust_dual() is really cryptic right now.
To try to understand what the function does, replace the variable names
with the following:
f -> first
p -> cur
s -> stop
c -> center

Also add a partial doc that needs to be filled by someone who knows
what the function is actually doing.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/input/input-mt.c | 44 ++++++++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c
index e43c33c..c7b3752 100644
--- a/drivers/input/input-mt.c
+++ b/drivers/input/input-mt.c
@@ -293,33 +293,45 @@ void input_mt_sync_frame(struct input_dev *dev)
 }
 EXPORT_SYMBOL(input_mt_sync_frame);
 
+/**
+ * adjust_dual() -
+ * @begin
+ * @step
+ * @end
+ * @eq
+ *
+ * FIXME -- can someone tell what this function does???
+ */
 static int adjust_dual(int *begin, int step, int *end, int eq)
 {
-	int f, *p, s, c;
+	int first, *cur, stop, center;
 
 	if (begin == end)
 		return 0;
 
-	f = *begin;
-	p = begin + step;
-	s = p == end ? f + 1 : *p;
+	first = *begin;
+	cur = begin + step;
+	stop = cur == end ? first + 1 : *cur;
 
-	for (; p != end; p += step)
-		if (*p < f)
-			s = f, f = *p;
-		else if (*p < s)
-			s = *p;
+	for (; cur != end; cur += step) {
+		if (*cur < first) {
+			stop = first;
+			first = *cur;
+		} else if (*cur < stop) {
+			stop = *cur;
+		}
+	}
 
-	c = (f + s + 1) / 2;
-	if (c == 0 || (c > 0 && !eq))
+	center = (first + stop + 1) / 2;
+	if (center == 0 || (center > 0 && !eq))
 		return 0;
-	if (s < 0)
-		c *= 2;
+	if (stop < 0)
+		center *= 2;
 
-	for (p = begin; p != end; p += step)
-		*p -= c;
+	for (cur = begin; cur != end; cur += step)
+		*cur -= center;
 
-	return (c < s && s <= 0) || (f >= 0 && f < c);
+	return (center < stop && stop <= 0) || (first >= 0 && first < center);
 }
 
 /**
-- 
2.1.0

  parent reply	other threads:[~2015-01-19 20:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-19 20:53 [RFC 0/6] Input: mt: Document in-kernel tracking and solve jumping cursors issues Benjamin Tissoires
2015-01-19 20:53 ` [RFC 1/6] Input: mt: make input_mt_assign_slots() a little bit more readable Benjamin Tissoires
2015-01-19 20:53 ` [RFC 2/6] Input: mt: Document input_mt_set_slots() Benjamin Tissoires
2015-01-19 20:53 ` [RFC 3/6] Input: mt: document input_mt_set_matrix() Benjamin Tissoires
2015-01-19 20:53 ` [RFC 4/6] Input: mt: document find_reduced_matrix() Benjamin Tissoires
2015-01-19 20:53 ` Benjamin Tissoires [this message]
2015-01-19 20:53 ` [RFC 6/6] Input: mt: introduce dmax in in-kernel tracking Benjamin Tissoires
2015-01-19 21:03   ` Benjamin Tissoires

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1421700835-22157-6-git-send-email-benjamin.tissoires@redhat.com \
    --to=benjamin.tissoires@redhat.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=hdegoede@redhat.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peter.hutterer@who-t.net \
    --cc=rydberg@euromail.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).