1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/test_isPointInStroke.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,244 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <meta charset="utf-8"> 1.8 + <title>Canvas test: isPointInStroke</title> 1.9 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.10 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.11 +</head> 1.12 +<body> 1.13 +<canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> 1.14 +<script type="application/javascript"> 1.15 + 1.16 +var canvas = document.getElementById('c'); 1.17 +var ctx = canvas.getContext('2d'); 1.18 + 1.19 + 1.20 +ctx.lineWidth = 5; 1.21 + 1.22 + 1.23 +ok(ctx.isPointInStroke(50, 25) === false, 'ctx.isPointInStroke(50, 25) === false'); 1.24 + 1.25 + 1.26 +ctx.beginPath(); 1.27 +ctx.rect(0, 0, 20, 20); 1.28 + 1.29 +ok(ctx.isPointInStroke(-4, -4) === false, 'ctx.isPointInStroke(-4, -4) === false'); 1.30 +ok(ctx.isPointInStroke(4, 4) === false, 'ctx.isPointInStroke(4, 4) === false'); 1.31 +ok(ctx.isPointInStroke(16, 16) === false, 'ctx.isPointInStroke(16, 16) === false'); 1.32 +ok(ctx.isPointInStroke(24, 24) === false, 'ctx.isPointInStroke(24, 24) === false'); 1.33 + 1.34 +ok(ctx.isPointInStroke(-2, -2) === true, 'ctx.isPointInStroke(-2, -2) === true'); 1.35 +ok(ctx.isPointInStroke(2, 2) === true, 'ctx.isPointInStroke(2, 2) === true'); 1.36 +ok(ctx.isPointInStroke(18, 18) === true, 'ctx.isPointInStroke(18, 18) === true'); 1.37 +ok(ctx.isPointInStroke(22, 22) === true, 'ctx.isPointInStroke(22, 22) === true'); 1.38 + 1.39 + 1.40 +ctx.beginPath(); 1.41 +ctx.rect(25, 25, 20, 20); 1.42 + 1.43 +ok(ctx.isPointInStroke(21, 21) === false, 'ctx.isPointInStroke(21, 21) === false'); 1.44 +ok(ctx.isPointInStroke(29, 29) === false, 'ctx.isPointInStroke(29, 29) === false'); 1.45 +ok(ctx.isPointInStroke(42, 42) === false, 'ctx.isPointInStroke(42, 42) === false'); 1.46 +ok(ctx.isPointInStroke(50, 50) === false, 'ctx.isPointInStroke(50, 50) === false'); 1.47 + 1.48 +ok(ctx.isPointInStroke(23, 23) === true, 'ctx.isPointInStroke(23, 23) === true'); 1.49 +ok(ctx.isPointInStroke(27, 27) === true, 'ctx.isPointInStroke(27, 27) === true'); 1.50 +ok(ctx.isPointInStroke(43, 43) === true, 'ctx.isPointInStroke(43, 43) === true'); 1.51 +ok(ctx.isPointInStroke(47, 47) === true, 'ctx.isPointInStroke(47, 47) === true'); 1.52 + 1.53 + 1.54 +ctx.beginPath(); 1.55 +ctx.moveTo(25, 25); 1.56 +ctx.bezierCurveTo(50, -50, 50, 100, 75, 25); 1.57 + 1.58 +ok(ctx.isPointInStroke(23, 26) === false, 'ctx.isPointInStroke(23, 26) === false'); 1.59 +ok(ctx.isPointInStroke(75, 23) === false, 'ctx.isPointInStroke(75, 23) === false'); 1.60 +ok(ctx.isPointInStroke(37, 8) === false, 'ctx.isPointInStroke(37, 8) === false'); 1.61 +ok(ctx.isPointInStroke(61, 42) === false, 'ctx.isPointInStroke(61, 42) === false'); 1.62 + 1.63 +ok(ctx.isPointInStroke(24, 24) === true, 'ctx.isPointInStroke(24, 24) === true'); 1.64 +ok(ctx.isPointInStroke(74, 25) === true, 'ctx.isPointInStroke(74, 25) === true'); 1.65 +ok(ctx.isPointInStroke(37, 2) === true, 'ctx.isPointInStroke(37, 2) === true'); 1.66 +ok(ctx.isPointInStroke(61, 47) === true, 'ctx.isPointInStroke(61, 47) === true'); 1.67 + 1.68 + 1.69 +ctx.beginPath(); 1.70 +ctx.arc(50, 25, 10, 0, Math.PI, false); 1.71 + 1.72 +ok(ctx.isPointInStroke(39, 23) === false, 'ctx.isPointInStroke(39, 23) === false'); 1.73 +ok(ctx.isPointInStroke(50, 15) === false, 'ctx.isPointInStroke(50, 15) === false'); 1.74 +ok(ctx.isPointInStroke(60, 23) === false, 'ctx.isPointInStroke(60, 23) === false'); 1.75 +ok(ctx.isPointInStroke(50, 25) === false, 'ctx.isPointInStroke(50, 25) === false'); 1.76 + 1.77 +ok(ctx.isPointInStroke(39, 26) === true, 'ctx.isPointInStroke(39, 26) === true'); 1.78 +ok(ctx.isPointInStroke(45, 33) === true, 'ctx.isPointInStroke(45, 33) === true'); 1.79 +ok(ctx.isPointInStroke(53, 33) === true, 'ctx.isPointInStroke(53, 33) === true'); 1.80 +ok(ctx.isPointInStroke(59, 26) === true, 'ctx.isPointInStroke(59, 26) === true'); 1.81 + 1.82 + 1.83 +ctx.beginPath(); 1.84 +ctx.arc(50, 25, 10, 0, 2 * Math.PI, false); 1.85 + 1.86 +ok(ctx.isPointInStroke(34, 25) === false, 'ctx.isPointInStroke(34, 25) === false'); 1.87 +ok(ctx.isPointInStroke(44, 25) === false, 'ctx.isPointInStroke(44, 25) === false'); 1.88 +ok(ctx.isPointInStroke(49, 30) === false, 'ctx.isPointInStroke(49, 30) === false'); 1.89 +ok(ctx.isPointInStroke(49, 40) === false, 'ctx.isPointInStroke(49, 40) === false'); 1.90 + 1.91 +ok(ctx.isPointInStroke(39, 23) === true, 'ctx.isPointInStroke(39, 23) === true'); 1.92 +ok(ctx.isPointInStroke(50, 15) === true, 'ctx.isPointInStroke(50, 15) === true'); 1.93 +ok(ctx.isPointInStroke(60, 23) === true, 'ctx.isPointInStroke(60, 23) === true'); 1.94 +ok(ctx.isPointInStroke(49, 34) === true, 'ctx.isPointInStroke(49, 34) === true'); 1.95 + 1.96 + 1.97 +ctx.beginPath(); 1.98 +ctx.save(); 1.99 +ctx.translate(20, 20); 1.100 +ctx.rect(0, 0, 20, 20); 1.101 + 1.102 +ok(ctx.isPointInStroke(16, 16) === false, 'ctx.isPointInStroke(16, 16) === false'); 1.103 +ok(ctx.isPointInStroke(24, 24) === false, 'ctx.isPointInStroke(24, 24) === false'); 1.104 +ok(ctx.isPointInStroke(36, 36) === false, 'ctx.isPointInStroke(36, 36) === false'); 1.105 +ok(ctx.isPointInStroke(44, 44) === false, 'ctx.isPointInStroke(44, 44) === false'); 1.106 + 1.107 +ok(ctx.isPointInStroke(18, 18) === true, 'ctx.isPointInStroke(18, 18) === true'); 1.108 +ok(ctx.isPointInStroke(22, 22) === true, 'ctx.isPointInStroke(22, 22) === true'); 1.109 +ok(ctx.isPointInStroke(38, 38) === true, 'ctx.isPointInStroke(38, 38) === true'); 1.110 +ok(ctx.isPointInStroke(42, 42) === true, 'ctx.isPointInStroke(42, 42) === true'); 1.111 + 1.112 +ctx.restore(); 1.113 + 1.114 + 1.115 +ctx.beginPath(); 1.116 +ctx.save(); 1.117 +ctx.scale(-1, 1); 1.118 +ctx.rect(-30, 20, 20, 20); 1.119 + 1.120 +ok(ctx.isPointInStroke(16, 16) === false, 'ctx.isPointInStroke(16, 16) === false'); 1.121 +ok(ctx.isPointInStroke(14, 24) === false, 'ctx.isPointInStroke(14, 24) === false'); 1.122 +ok(ctx.isPointInStroke(26, 36) === false, 'ctx.isPointInStroke(26, 36) === false'); 1.123 +ok(ctx.isPointInStroke(34, 44) === false, 'ctx.isPointInStroke(34, 44) === false'); 1.124 + 1.125 +ok(ctx.isPointInStroke(8, 18) === true, 'ctx.isPointInStroke(8, 18) === true'); 1.126 +ok(ctx.isPointInStroke(12, 22) === true, 'ctx.isPointInStroke(12, 22) === true'); 1.127 +ok(ctx.isPointInStroke(28, 38) === true, 'ctx.isPointInStroke(28, 38) === true'); 1.128 +ok(ctx.isPointInStroke(32, 42) === true, 'ctx.isPointInStroke(32, 42) === true'); 1.129 + 1.130 +ctx.restore(); 1.131 + 1.132 + 1.133 +ctx.beginPath(); 1.134 +ctx.save(); 1.135 +ctx.lineWidth = 2; 1.136 +ctx.translate(50, 25); 1.137 +ctx.rotate(180 * Math.PI / 180); 1.138 +ctx.scale(5, 5); 1.139 +ctx.arc(0, 0, 2, 0, Math.PI, false); 1.140 + 1.141 +ok(ctx.isPointInStroke(39, 26) === false, 'ctx.isPointInStroke(39, 26) === false'); 1.142 +ok(ctx.isPointInStroke(45, 33) === false, 'ctx.isPointInStroke(45, 33) === false'); 1.143 +ok(ctx.isPointInStroke(53, 33) === false, 'ctx.isPointInStroke(53, 33) === false'); 1.144 +ok(ctx.isPointInStroke(59, 26) === false, 'ctx.isPointInStroke(59, 26) === false'); 1.145 + 1.146 +ok(ctx.isPointInStroke(39, 23) === true, 'ctx.isPointInStroke(39, 23) === true'); 1.147 +ok(ctx.isPointInStroke(45, 15) === true, 'ctx.isPointInStroke(50, 15) === true'); 1.148 +ok(ctx.isPointInStroke(55, 15) === true, 'ctx.isPointInStroke(50, 25) === true'); 1.149 +ok(ctx.isPointInStroke(60, 23) === true, 'ctx.isPointInStroke(60, 23) === true'); 1.150 + 1.151 +ctx.restore(); 1.152 + 1.153 + 1.154 +ctx.beginPath(); 1.155 + 1.156 +ctx.moveTo(10, 10); 1.157 +ctx.lineTo(30, 10); 1.158 +ctx.save(); 1.159 +ctx.lineWidth = 2; 1.160 +ctx.scale(5, 5); 1.161 +ctx.lineTo(6, 6); 1.162 +ctx.lineTo(2, 6); 1.163 +ctx.restore(); 1.164 +ctx.closePath(); 1.165 + 1.166 +ok(ctx.isPointInStroke(6, 6) === false, 'ctx.isPointInStroke(6, 6) === false'); 1.167 +ok(ctx.isPointInStroke(14, 14) === false, 'ctx.isPointInStroke(14, 14) === false'); 1.168 +ok(ctx.isPointInStroke(26, 26) === false, 'ctx.isPointInStroke(26, 26) === false'); 1.169 +ok(ctx.isPointInStroke(34, 34) === false, 'ctx.isPointInStroke(34, 34) === false'); 1.170 + 1.171 +ok(ctx.isPointInStroke(8, 8) === true, 'ctx.isPointInStroke(8, 8) === true'); 1.172 +ok(ctx.isPointInStroke(12, 12) === true, 'ctx.isPointInStroke(12, 12) === true'); 1.173 +ok(ctx.isPointInStroke(28, 28) === true, 'ctx.isPointInStroke(28, 28) === true'); 1.174 +ok(ctx.isPointInStroke(32, 32) === true, 'ctx.isPointInStroke(32, 32) === true'); 1.175 + 1.176 + 1.177 +ctx.beginPath(); 1.178 +ctx.rect(-30, -30, 20, 20); 1.179 + 1.180 +ok(ctx.isPointInStroke(-34, -34) === false, 'ctx.isPointInStroke(-34, -34) === false'); 1.181 +ok(ctx.isPointInStroke(-26, -26) === false, 'ctx.isPointInStroke(-26, -26) === false'); 1.182 +ok(ctx.isPointInStroke(-14, -14) === false, 'ctx.isPointInStroke(-14, -14) === false'); 1.183 +ok(ctx.isPointInStroke(-6, -6) === false, 'ctx.isPointInStroke(-6, -6) === false'); 1.184 + 1.185 +ok(ctx.isPointInStroke(-32, -32) === true, 'ctx.isPointInStroke(-32, -32) === true'); 1.186 +ok(ctx.isPointInStroke(-28, -28) === true, 'ctx.isPointInStroke(-28, -28) === true'); 1.187 +ok(ctx.isPointInStroke(-12, -12) === true, 'ctx.isPointInStroke(-12, -12) === true'); 1.188 +ok(ctx.isPointInStroke(-8, -8) === true, 'ctx.isPointInStroke(-8, -8) === true'); 1.189 + 1.190 + 1.191 +ctx.beginPath(); 1.192 +ctx.moveTo(20, 25); 1.193 +ctx.lineTo(80, 25); 1.194 + 1.195 +ok(ctx.isPointInStroke(19, 25) === false, 'ctx.isPointInStroke(19, 25) === false'); 1.196 +ok(ctx.isPointInStroke(50, 21) === false, 'ctx.isPointInStroke(50, 21) === false'); 1.197 +ok(ctx.isPointInStroke(81, 25) === false, 'ctx.isPointInStroke(81, 25) === false'); 1.198 +ok(ctx.isPointInStroke(50, 29) === false, 'ctx.isPointInStroke(50, 29) === false'); 1.199 + 1.200 +ok(ctx.isPointInStroke(21, 25) === true, 'ctx.isPointInStroke(21, 25) === true'); 1.201 +ok(ctx.isPointInStroke(50, 23) === true, 'ctx.isPointInStroke(50, 23) === true'); 1.202 +ok(ctx.isPointInStroke(79, 25) === true, 'ctx.isPointInStroke(79, 25) === true'); 1.203 +ok(ctx.isPointInStroke(50, 27) === true, 'ctx.isPointInStroke(50, 27) === true'); 1.204 + 1.205 + 1.206 +ctx.lineWidth = 15; 1.207 +ctx.lineCap = 'round'; 1.208 + 1.209 + 1.210 +ctx.beginPath(); 1.211 +ctx.moveTo(20, 25); 1.212 +ctx.lineTo(80, 25); 1.213 + 1.214 +ok(ctx.isPointInStroke(13, 18) === false, 'ctx.isPointInStroke(13, 18) === false'); 1.215 +ok(ctx.isPointInStroke(13, 31) === false, 'ctx.isPointInStroke(13, 31) === false'); 1.216 +ok(ctx.isPointInStroke(86, 18) === false, 'ctx.isPointInStroke(86, 18) === false'); 1.217 +ok(ctx.isPointInStroke(86, 31) === false, 'ctx.isPointInStroke(86, 31) === false'); 1.218 + 1.219 +ok(ctx.isPointInStroke(13, 25) === true, 'ctx.isPointInStroke(13, 25) === true'); 1.220 +ok(ctx.isPointInStroke(50, 18) === true, 'ctx.isPointInStroke(50, 18) === true'); 1.221 +ok(ctx.isPointInStroke(86, 25) === true, 'ctx.isPointInStroke(86, 25) === true'); 1.222 +ok(ctx.isPointInStroke(50, 31) === true, 'ctx.isPointInStroke(50, 31) === true'); 1.223 + 1.224 + 1.225 +ctx.lineJoin = 'round'; 1.226 + 1.227 + 1.228 +ctx.beginPath(); 1.229 +ctx.moveTo(20, 15); 1.230 +ctx.lineTo(80, 15); 1.231 +ctx.lineTo(80, 35); 1.232 + 1.233 +ok(ctx.isPointInStroke(86, 8) === false, 'ctx.isPointInStroke(86, 8) === false'); 1.234 +ok(ctx.isPointInStroke(70, 24) === false, 'ctx.isPointInStroke(70, 24) === false'); 1.235 +ok(ctx.isPointInStroke(73, 41) === false, 'ctx.isPointInStroke(73, 41) === false'); 1.236 +ok(ctx.isPointInStroke(86, 41) === false, 'ctx.isPointInStroke(86, 41) === false'); 1.237 + 1.238 +ok(ctx.isPointInStroke(14, 15) === true, 'ctx.isPointInStroke(14, 15) === true'); 1.239 +ok(ctx.isPointInStroke(81, 15) === true, 'ctx.isPointInStroke(81, 15) === true'); 1.240 +ok(ctx.isPointInStroke(79, 41) === true, 'ctx.isPointInStroke(79, 41) === true'); 1.241 +ok(ctx.isPointInStroke(73, 21) === true, 'ctx.isPointInStroke(73, 21) === true'); 1.242 + 1.243 +</script> 1.244 +</pre> 1.245 +</body> 1.246 +</html> 1.247 +