Subject: New Direction algorithm

From: Tim Phipps <[email-masked]>
Date: Wed, 12 Jan 2000 13:09:09 +0000

The Direction func isn't working as well as it usd to.  Quite often it
will pick a window at right angles to direction which seems counter
intuitive. The diff below show the relevan change that caused this:

     /* Calculate score for this window.  The smaller the better. */
-    score = 1024 * offset / distance + 2 * distance + 2 * offset;
+    score = 1024 * offset * distance + 2 * distance + 2 * offset;

The new style (+) does not penalize large "offset" when the "distance"
is very small, which is the case when a windows center is at right
angles to the desired direction.  The "offset / distance" in the old
style was a sort of tan() function that added in a penalty for
off-direction windows.

What was the reason for the change?  Could we have the old style back?
I tend to arrange my windows as a 2x2 tile so I hit the right angle case
very often.

Cheers,
Tim.
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Dominik Vogt <[email-masked]>
Date: Wed, 12 Jan 2000 16:35:08 +0100

> I tend to arrange my windows as a 2x2 tile so I hit the right angle case

The reason is that the old logic penalised close windows because
'lowest score wins':

  +-------+
  |       |
  |   A   |
  |       |
  +-------+
  +-------+
  |       |
  |   B   |
  |       |
  +-------+
  +-------+
  |       |
  |   C   |
  |       |
  +-------+

Let's assume window A has the focus and you call 'South Focus'.
The old code gave 'C' the focus because it was farther away.

Also, in this situation it didn't do what you expect:

  +-----+
  |  A  |
  +-----+
  +----------------------------------------------------------+
  |                            B                             |
  +----------------------------------------------------------+

To switch from 'A' to 'B' you had to use 'East' or 'SouthEast',
but 'South' didn't select 'B'.

Bye

Dominik ^_^

P.S.: Please forward this mail to the list, I'm still not sure
I can mail there again.

-- 
Dominik Vogt, Agilent Technologies, Dept. BVS
Herrenberger Str.130, 71034 Boeblingen, Germany
phone: 07031/464-4596, fax: 07031/464-3883, [email-masked]
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Tim Phipps <[email-masked]>
Date: Thu, 13 Jan 2000 14:02:02 +0000

> The old code gave 'C' the focus because it was farther away.

This can't be right. The diagram above looks like 'offset' = 0 in which
case the old and new formulas give the same results. They both pick B.
> Also, in this situation it didn't do what you expect:

Do you mean 'South' would pick a window below 'B' like 'C' in this
example:
 +-----+
 |  A  |
 +-----+
 +----------------------------------------------------------+
 |                            B                             |
 +----------------------------------------------------------+
 +-----+
 |  C  |
 +-----+

If so then I think the old formula was better, you just have to remember
that it works on window centres.

My problem with then new formula

> > +    score = 1024 * offset * distance + 2 * distance + 2 * offset;

is that when both 'offset' and distance are more than 10 the formula
becomes 

score ~= 1024 * offset * distance

the other terms disappear and the formula will pick the nearest window
within 90 degrees of the direction.  It just looks bad when I hit North
and the focus moves East instead of North just because the eastwards
window is closer then the northwards window.

How about scraping the formula and using a two stage criteria:

1) find the closest window in the chosen direction only considering
windows where 'offset' is less than 'distance' (45 degrees either side
of the direction vector)

2) if none found pick the closest where 'direction' is not negative (90
degrees)

Should I try this?

Cheers,
Tim.

---

From: Tim Phipps <[email-masked]>
Date: Thu, 13 Jan 2000 15:13:04 +0000

> 2) if none found pick the closest where 'direction' is not negative (90
This turns out to be quite simple and doesn't need two passes:

    /* Calculate score for this window.  The smaller the better. */
    score = distance + offset;
    /* windows more than 45 degrees off the direction are heavily
penalized
     * and will only be chosen if nothing else within a million pixels
*/
    if (offset > distance)
      score += 1000000;
    if (best_score == -1 || score < best_score)
    {
      best_window = window;
      best_score = score;
    }

Plus there's no need for doubles, it's all integer addition.

Could you try this Dominik and see if it's acceptable?

Cheers,
Tim.

---

From: Dominik Vogt <[email-masked]>
Date: Thu, 13 Jan 2000 16:16:14 +0100

> case the old and new formulas give the same results. They both pick B.

With the old algorithm:

  distance = 2,   offset = 1 ==> score = 518
  distance = 200, offset = 1 ==> score = 407  <-- this one wins

> Do you mean 'South' would pick a window below 'B' like 'C' in this

No, I mean that the old formula doesn't even consider B to be
south of A.  It would even select C if C was 25 pages down and
12 pages to the left of A. BTW, the new formula has the same
problem.

>  |  A  |

I'm not happy with this logic, but I definitely won't touch it
before 2.4.
 
> window is closer then the northwards window.

For me, B is definitely *not* east of A.

> 2) if none found pick the closest where 'direction' is not negative (90

I'm not sure that would make the complainers of the old formula's bug happy.
In the end they prefer that B is selected in your example and you
prefer C.  I started to write an algorithm that doesn't use window
centers but all four corners instead, but that was too complicated
for me to.  Give it a try if you like, though.  Personally I don't
care about the algorithm as long as it's fairly understandable

Bye

Dominik ^_^