Skip to content

Commit 3e5d37a

Browse files
author
Jihye Hong
committed
Update the description about distance function
The changes are based on https://wicg.github.io/spatial-navigation/tests/ux/result.html#summary-of-the-proposal
1 parent d424b2a commit 3e5d37a

1 file changed

Lines changed: 50 additions & 22 deletions

File tree

css-nav-1/Overview.bs

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,34 +1242,62 @@ follow the following steps:
12421242
of <var>searchOrigin</var> and P2 inside the boundary box of <var>candidate</var>.
12431243
2. Else if the <var>searchOrigin</var> is a point, then let the point <var>P1</var> be the <var>searchOrigin</var>
12441244
and find the point <var>P2</var> inside the <a>boundary box</a>.
1245-
3. Let intersectRect is intersected area between a candidate and the search origin.
1246-
4. Select the <var>P1</var> and <var>P2</var> that make the smallest <var>distance</var> between those two points,
1247-
when <var>distance</var> is defined as follows:
1248-
1249-
<dl>
1250-
<dt><var>distance</var>:
1251-
<dd><var>A</var> - <var>B</var> + <var>C</var> - <var>D</var>
1252-
1253-
<dt><var>A</var>:
1254-
<dd>The euclidian distance between <var>P1</var> and <var>P2</var>
1255-
1256-
<dt><var>B</var>:
1257-
<dd>The degree of alignment in <var>dir</var> between <var>searchOrigin</var> and <var>candidate</var>
1258-
1259-
<dt><var>C</var>:
1260-
<dd>The degree of dislocation in <var>dir</var> between <var>searchOrigin</var> and <var>candidate</var>
1261-
1262-
<dt><var>D</var>:
1263-
<dd>The square root of the area of intersection between the <a>boundary boxes</a> of <var>candidate</var> and <var>searchOrigin</var>
1264-
</dl>
1265-
3. Return the item of the <var>candidates</var> set that has the smallest <var>distance</var>.
1245+
3. Let <var>intersectRect</var> is intersected area between a candidate and the search origin.
1246+
4. Select the <var>P1</var> and <var>P2</var> that make the smallest <var>distance</var> between those two points by
1247+
<a>calculating the distance</a>.
1248+
5. Return the item of the <var>candidates</var> set that has the smallest <var>distance</var>.
12661249
If several have the same distance,
12671250
return the first one in document order,
12681251
unless its [=boundary box=] overlaps with the [=boundary box=] of an other item at the same distance,
12691252
and that item is higher in the CSS [=painting order=].
12701253
In that case, return that item instead,
1271-
unless it too is overlapped with another higher item at the same distance, recursively.
1254+
unless it too is overlapped with another higher item at the same distance, recursively.
1255+
</div>
1256+
1257+
<div algorithm="to calculate the distance">
1258+
To <dfn lt="calculating the distance | to calculate the distance">calculate the <var>distance</var></dfn>, the function is defined as below:
1259+
1260+
<var>distance</var> = <var>euclidian</var> - <var>alignment</var> + <var>displacement</var> - <var>sqrt(Overlap)</var>
1261+
1262+
The meaning of each factor in the function is as follows:
1263+
1264+
<dl>
1265+
<dt><var>euclidian</var>:
1266+
<dd>The euclidian distance between <var>P1</var> and <var>P2</var>
1267+
<dd>formula = sqrt(pow(P1, 2) + pow(P2, 2))
1268+
1269+
<dt><var>alignment</var>:
1270+
<dd>The degree of alignment in <var>dir</var> between <var>searchOrigin</var> and <var>candidate</var>
1271+
<dd>formula = <var>alignBias</var> * <var>alignWeight</var>
1272+
1273+
* <var>alignBias</var>
1274+
1275+
* If the <var>dir</var> is left or right, height of <var>intersectRect</var> / the height of the candidate
1276+
* Else if the <var>dir</var> is up or down, width of <var>intersectRect</var> / the width of the candidate
1277+
1278+
* <var>alignWeight</var> is 5
1279+
1280+
<dt><var>displacement</var>:
1281+
<dd>The degree of displacement in <var>dir</var> between <var>searchOrigin</var> and <var>candidate</var>
1282+
<dd>formula = (absolute distance on the axis orthogonal to <var>dir</var> + <var>orthogonalBias</var>) * <var>orthogonalWeight</var>
1283+
1284+
* <var>orthogonalBias</var>:
1285+
* If the <var>dir</var> is left or right, height of <var>searchOrigin</var> / 2
1286+
* Else if the <var>dir</var> is up or down, width of <var>searchOrigin</var> / 2
1287+
1288+
* <var>orthogonalWeight</var>:
1289+
* If the <var>dir</var> is left or right, 30
1290+
* Else if the <var>dir</var> is up or down, 2
1291+
1292+
<dt><var>sqrt(Overlap)</var>:
1293+
<dd>The square root of the <var>intersectRect</var>(overlapped area) between the <a>boundary boxes</a> of <var>candidate</var> and <var>searchOrigin</var>
1294+
<dd>formula = sqrt(height of <var>intersectRect</var> * width of <var>intersectRect</var>)
1295+
</dl>
12721296

1297+
NOTE: The values of <var>alignWeight</var> and <var>orthogonalWeight</var> in the function are decided based on
1298+
the collected <a href="https://wicg.github.io/spatial-navigation/tests/ux/list.html">UX test cases</a>.
1299+
It aims to show the general expected result in the real pages.
1300+
Everyone is welcome to contribute to the test cases!
12731301

12741302
</div>
12751303

0 commit comments

Comments
 (0)