tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_distance_of_path_function.html (5225B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <script src='/resources/testharness.js'></script>
      4 <script src='/resources/testharnessreport.js'></script>
      5 <script src='../testcommon.js'></script>
      6 <div id="log"></div>
      7 <script type='text/javascript'>
      8 'use strict';
      9 
     10 test(function(t) {
     11  var target = addDiv(t);
     12  var dist = getDistance(target, 'offset-path', 'none', 'none');
     13  assert_equals(dist, 0, 'none and none');
     14 }, 'none and none');
     15 
     16 test(function(t) {
     17  var target = addDiv(t);
     18  var dist = getDistance(target, 'offset-path', 'path("M 10 10")', 'none');
     19  assert_equals(dist, 0, 'path("M 10 10") and none');
     20 }, 'Path and none');
     21 
     22 test(function(t) {
     23  var target = addDiv(t);
     24  var dist = getDistance(target, 'offset-path',
     25                         'path("M 10 10 H 10")',
     26                         'path("M 10 10 H 10 H 10")');
     27  assert_equals(dist, 0, 'path("M 10 10 H 10") and ' +
     28                         'path("M 10 10 H 10 H 10")');
     29 }, 'Mismatched path functions');
     30 
     31 test(function(t) {
     32  var target = addDiv(t);
     33  var dist = getDistance(target, 'offset-path',
     34                         'path("M 10 10")',
     35                         'path("M 20 20")');
     36  assert_equals(dist,
     37                Math.sqrt(10 * 10 * 2),
     38                'path("M 10 10") and path("M 30 30")');
     39 }, 'The moveto commands');
     40 
     41 test(function(t) {
     42  var target = addDiv(t);
     43  var dist = getDistance(target, 'offset-path',
     44                         'path("M 0 0 L 10 10")',
     45                         'path("M 0 0 L 20 20")');
     46  assert_equals(dist,
     47                Math.sqrt(10 * 10 * 2),
     48                'path("M 0 0 L 10 10") and path("M 0 0 L 20 20")');
     49 }, 'The lineto commands');
     50 
     51 test(function(t) {
     52  var target = addDiv(t);
     53  var dist = getDistance(target, 'offset-path',
     54                         'path("M 0 0 H 10")',
     55                         'path("M 0 0 H 20")');
     56  assert_equals(dist, 10, 'path("M 0 0 H 10") and path("M 0 0 H 20")');
     57 }, 'The horizontal lineto commands');
     58 
     59 test(function(t) {
     60  var target = addDiv(t);
     61  var dist = getDistance(target, 'offset-path',
     62                         'path("M 0 0 V 10")',
     63                         'path("M 0 0 V 20")');
     64  assert_equals(dist, 10, 'path("M 0 0 V 10") and path("M 0 0 V 20")');
     65 }, 'The vertical lineto commands');
     66 
     67 test(function(t) {
     68  var target = addDiv(t);
     69  var dist = getDistance(target, 'offset-path',
     70                         'path("M 0 0 C 10 10 20 20 30 30")',
     71                         'path("M 0 0 C 20 20 40 40 0 0")');
     72  assert_equals(dist,
     73                Math.sqrt(10 * 10 * 2 + 20 * 20 * 2 + 30 * 30 * 2),
     74                'path("M 0 0 C 10 10 20 20 30 30") and ' +
     75                'path("M 0 0 C 20 20 40 40 0 0")');
     76 }, 'The cubic Bézier curve commands');
     77 
     78 test(function(t) {
     79  var target = addDiv(t);
     80  var dist = getDistance(target, 'offset-path',
     81                         'path("M 0 0 S 20 20 30 30")',
     82                         'path("M 0 0 S 40 40 0 0")');
     83  assert_equals(dist,
     84                Math.sqrt(20 * 20 * 2 + 30 * 30 * 2),
     85                'path("M 0 0 S 20 20 30 30") and ' +
     86                'path("M 0 0 S 40 40 0 0")');
     87 }, 'The smooth cubic Bézier curve commands');
     88 
     89 test(function(t) {
     90  var target = addDiv(t);
     91  var dist = getDistance(target, 'offset-path',
     92                         'path("M 0 0 Q 10 10 30 30")',
     93                         'path("M 0 0 Q 20 20 0 0")');
     94  assert_equals(dist,
     95                Math.sqrt(10 * 10 * 2 + 30 * 30 * 2),
     96                'path("M 0 0 Q 10 10 30 30") and ' +
     97                'path("M 0 0 Q 20 20 0 0")');
     98 }, 'The quadratic cubic Bézier curve commands');
     99 
    100 test(function(t) {
    101  var target = addDiv(t);
    102  var dist = getDistance(target, 'offset-path',
    103                         'path("M 0 0 T 30 30")',
    104                         'path("M 0 0 T 0 0")');
    105  assert_equals(dist,
    106                Math.sqrt(30 * 30 * 2),
    107                'path("M 0 0 T 30 30") and ' +
    108                'path("M 0 0 T 0 0")');
    109 }, 'The smooth quadratic cubic Bézier curve commands');
    110 
    111 test(function(t) {
    112  var target = addDiv(t);
    113  var dist = getDistance(target, 'offset-path',
    114                         'path("M 0 0 A 5 5 10 0 1 30 30")',
    115                         'path("M 0 0 A 4 4 5 0 0 20 20")');
    116  assert_equals(dist,
    117                Math.sqrt(1 * 1 * 2 + // radii
    118                          5 * 5 +     // angle
    119                          1 * 1 +     // flag
    120                          10 * 10 * 2),
    121                'path("M 0 0 A 5 5 10 0 1 30 30") and ' +
    122                'path("M 0 0 A 4 4 5 0 0 20 20")');
    123 }, 'The elliptical arc curve commands');
    124 
    125 test(function(t) {
    126  var target = addDiv(t);
    127  var dist = getDistance(target, 'offset-path',
    128                         'path("m 10 20 h 30 v 60 h 10 v -10 l 110 60")',
    129                   // == 'path("M  10  20 H  40 V  80 H  50 V  70 L 160 130")'
    130                         'path("M 130 140 H 120 V 160 H 130 V 150 L 200 170")');
    131  assert_equals(dist,
    132                Math.sqrt(120 * 120 * 2 +
    133                          80 * 80 * 4 +
    134                          40 * 40 * 2),
    135                'path("m 10 20 h 30 v 60 h 10 v -10 l 110 60") and ' +
    136                'path("M 130 140 H 120 V 160 H 130 V 150 L 200 170")');
    137 }, 'The distance of paths with absolute and relative coordinates');
    138 
    139 </script>
    140 </html>