How to use clone method in lisa

Best Python code snippet using lisa_python

model_deploy.py

Source:model_deploy.py Github

copy

Full Screen

...193 clone_loss)194 if regularization_loss is not None:195 tf.summary.scalar('Losses/regularization_loss', regularization_loss)196 return sum_loss197def _optimize_clone(optimizer, clone, num_clones, regularization_losses,198 **kwargs):199 """Compute losses and gradients for a single clone.200 Args:201 optimizer: A tf.Optimizer object.202 clone: A Clone namedtuple.203 num_clones: The number of clones being deployed.204 regularization_losses: Possibly empty list of regularization_losses205 to add to the clone losses.206 **kwargs: Dict of kwarg to pass to compute_gradients().207 Returns:208 A tuple (clone_loss, clone_grads_and_vars).209 - clone_loss: A tensor for the total loss for the clone. Can be None.210 - clone_grads_and_vars: List of (gradient, variable) for the clone.211 Can be empty.212 """213 sum_loss = _gather_clone_loss(clone, num_clones, regularization_losses)214 clone_grad = None215 if sum_loss is not None:216 with tf.device(clone.device):217 clone_grad = optimizer.compute_gradients(sum_loss, **kwargs)218 return sum_loss, clone_grad219def optimize_clones(clones, optimizer,220 regularization_losses=None,221 **kwargs):222 """Compute clone losses and gradients for the given list of `Clones`.223 Note: The regularization_losses are added to the first clone losses.224 Args:225 clones: List of `Clones` created by `create_clones()`.226 optimizer: An `Optimizer` object.227 regularization_losses: Optional list of regularization losses. If None it228 will gather them from tf.GraphKeys.REGULARIZATION_LOSSES. Pass `[]` to229 exclude them.230 **kwargs: Optional list of keyword arguments to pass to `compute_gradients`.231 Returns:232 A tuple (total_loss, grads_and_vars).233 - total_loss: A Tensor containing the average of the clone losses including234 the regularization loss.235 - grads_and_vars: A List of tuples (gradient, variable) containing the sum236 of the gradients for each variable.237 """238 grads_and_vars = []239 clones_losses = []240 num_clones = len(clones)241 if regularization_losses is None:242 regularization_losses = tf.get_collection(243 tf.GraphKeys.REGULARIZATION_LOSSES)244 for clone in clones:245 with tf.name_scope(clone.scope):246 clone_loss, clone_grad = _optimize_clone(247 optimizer, clone, num_clones, regularization_losses, **kwargs)248 if clone_loss is not None:249 clones_losses.append(clone_loss)250 grads_and_vars.append(clone_grad)251 # Only use regularization_losses for the first clone252 regularization_losses = None253 # Compute the total_loss summing all the clones_losses.254 total_loss = tf.add_n(clones_losses, name='total_loss')255 # Sum the gradients across clones.256 grads_and_vars = _sum_clones_gradients(grads_and_vars)257 return total_loss, grads_and_vars258def deploy(config,259 model_fn,260 args=None,...

Full Screen

Full Screen

cmd.js

Source:cmd.js Github

copy

Full Screen

1module('cmd');2test('cmd.wrap', function() {3 var p = K.query('#test-data-01 p'),4 cloneP, div, strong, range, cmd;5 var div = K('<div></div>');6 document.body.appendChild(div.get());7 //18 cloneP = p.cloneNode(true);9 document.body.appendChild(cloneP);10 strong = K.query('strong', cloneP);11 range = K.range(document);12 range.selectNode(strong);13 cmd = K.cmd(range);14 cmd.wrap('<span class="aaa"></span>');15 equals(range.html(), '<strong><span class="aaa">efg</span></strong>');16 document.body.removeChild(cloneP);17 //218 cloneP = p.cloneNode(true);19 document.body.appendChild(cloneP);20 strong = K.query('strong', cloneP);21 range = K.range(document);22 range.selectNode(strong);23 cmd = K.cmd(range);24 cmd.wrap('<span style="color:red;"></span>');25 equals(range.html(), '<strong><span style="color:red;">efg</span></strong>');26 document.body.removeChild(cloneP);27 //328 cloneP = p.cloneNode(true);29 document.body.appendChild(cloneP);30 strong = K.query('strong', cloneP);31 range = K.range(document);32 range.selectNodeContents(cloneP);33 cmd = K.cmd(range);34 cmd.wrap('<span style="color:red;"></span>');35 ok(K.queryAll('span[style]', cloneP).length === 7);36 equals(range.toString(), 'abcdefghijkxyz0123456789');37 document.body.removeChild(cloneP);38 //439 cloneP = p.cloneNode(true);40 document.body.appendChild(cloneP);41 strong = K.query('strong', cloneP);42 range = K.range(document);43 range.selectNodeContents(cloneP);44 cmd = K.cmd(range);45 cmd.wrap('<span class="aaa"></span>');46 ok(K.queryAll('span[class="aaa"]', cloneP).length === 7);47 equals(range.toString(), 'abcdefghijkxyz0123456789');48 document.body.removeChild(cloneP);49 //550 cloneP = p.cloneNode(true);51 document.body.appendChild(cloneP);52 strong = K.query('strong', cloneP);53 range = K.range(document);54 range.setStart(strong.firstChild, 1);55 range.setEnd(strong.firstChild, 2);56 cmd = K.cmd(range);57 cmd.wrap('<span class="aaa"></span>');58 equals(range.html(), '<span class="aaa">f</span>');59 document.body.removeChild(cloneP);60 //661 cloneP = p.cloneNode(true);62 document.body.appendChild(cloneP);63 strong = K.query('strong', cloneP);64 range = K.range(document);65 range.setStart(strong.firstChild, 1);66 range.setEnd(strong.firstChild, 3);67 cmd = K.cmd(range);68 cmd.wrap('<span class="aaa"></span>');69 equals(range.html(), '<strong><span class="aaa">fg</span></strong>');70 document.body.removeChild(cloneP);71 //772 cloneP = p.cloneNode(true);73 document.body.appendChild(cloneP);74 strong = K.query('strong', cloneP);75 range = K.range(document);76 range.setStart(strong.firstChild, 1);77 range.setEnd(strong.firstChild, 2);78 cmd = K.cmd(range);79 cmd.wrap('<strong></strong>');80 equals(range.html(), '<strong>f</strong>');81 document.body.removeChild(cloneP);82 //883 cloneP = p.cloneNode(true);84 document.body.appendChild(cloneP);85 strong = K.query('strong', cloneP);86 range = K.range(document);87 range.setStart(cloneP, 1);88 range.setEnd(strong.firstChild, 3);89 cmd = K.cmd(range);90 cmd.wrap('<strong></strong>');91 equals(range.html(), '<strong>efg</strong>');92 document.body.removeChild(cloneP);93 //994 cloneP = p.cloneNode(true);95 document.body.appendChild(cloneP);96 strong = K.query('strong', cloneP);97 range = K.range(document);98 range.selectNodeContents(strong);99 range.collapse(true);100 cmd = K.cmd(range);101 cmd.wrap('<strong></strong>');102 equals(strong.innerHTML.toLowerCase(), '<strong></strong>efg');103 document.body.removeChild(cloneP);104 //10105 cloneP = p.cloneNode(true);106 document.body.appendChild(cloneP);107 strong = K.query('strong', cloneP);108 range = K.range(document);109 range.selectNodeContents(cloneP);110 cmd = K.cmd(range);111 cmd.wrap('<div></div>');112 equals(K(cloneP).first().name, 'div');113 same(K(cloneP).children().length, 1);114 document.body.removeChild(cloneP);115 //11116 cloneP = p.cloneNode(true);117 document.body.appendChild(cloneP);118 strong = K.query('strong', cloneP);119 range = K.range(document);120 range.setStart(strong.firstChild, 3);121 range.setEnd(strong.nextSibling, 3);122 cmd = K.cmd(range);123 cmd.wrap('<strong></strong>');124 equals(cmd.range.html(), '<strong>hij</strong>');125 document.body.removeChild(cloneP);126 //12127 cloneP = p.cloneNode(true);128 document.body.appendChild(cloneP);129 strong = K.query('strong', cloneP);130 range = K.range(document);131 range.selectNode(strong);132 cmd = K.cmd(range);133 cmd.wrap('<div><p></p></div>');134 equals(range.html().replace(/\s/g, ''), '<div><p><strong>efg</strong></p></div>');135 document.body.removeChild(cloneP);136 //13137 cloneP = p.cloneNode(true);138 document.body.appendChild(cloneP);139 strong = K.query('strong', cloneP);140 range = K.range(document);141 range.setStart(strong.firstChild, 1);142 range.setEnd(strong.firstChild, 2);143 cmd = K.cmd(range);144 cmd.wrap('<span class="aaa"><strong></strong></span>');145 equals(range.html(), '<span class="aaa"><strong>f</strong></span>');146 document.body.removeChild(cloneP);147 //14148 cloneP = p.cloneNode(true);149 document.body.appendChild(cloneP);150 strong = K.query('strong', cloneP);151 range = K.range(document);152 range.setStart(strong.firstChild, 1);153 range.setEnd(strong.firstChild, 2);154 cmd = K.cmd(range);155 cmd.wrap('<span class="aaa"><strong><em></em></strong></span>');156 equals(range.html(), '<span class="aaa"><strong><em>f</em></strong></span>');157 document.body.removeChild(cloneP);158 //15159 cloneP = K('<p>abc</p>').get();160 document.body.appendChild(cloneP);161 range = K.range(document);162 range.selectNodeContents(cloneP);163 cmd = K.cmd(range);164 cmd.wrap('<strong></strong>');165 cmd.wrap('<em></em>');166 equals(range.html(), '<strong><em>abc</em></strong>');167 document.body.removeChild(cloneP);168 //16169 div.html('<p>123</p><p>456</p>');170 range = K.range(document);171 range.setStart(div.first().first()[0], 0);172 range.setEnd(div.last().last()[0], 3);173 cmd = K.cmd(range);174 cmd.wrap('<strong></strong>');175 equals(div.html().replace(/\n/, ''), '<p><strong>123</strong></p><p><strong>456</strong></p>');176 div.html('');177 //17178 div.html('123<strong>4</strong>56');179 range = K.range(document);180 range.setStart(div.first()[0], 2);181 range.setEnd(div.first()[0], 3);182 cmd = K.cmd(range);183 cmd.wrap('<strong></strong>');184 equals(range.html(), '<strong>3</strong>');185 div.html('');186});187test('cmd.remove', function() {188 var p = K.query('#test-data-01 p'),189 cloneP, strong, range, cmd;190 var div = K('<div></div>');191 document.body.appendChild(div[0]);192 //1193 cloneP = p.cloneNode(true);194 document.body.appendChild(cloneP);195 strong = K.query('strong', cloneP);196 range = K.range(document);197 range.selectNode(strong);198 cmd = K.cmd(range);199 cmd.remove({200 strong : '*'201 });202 equals(cmd.range.html(), 'efg');203 document.body.removeChild(cloneP);204 //2205 cloneP = p.cloneNode(true);206 document.body.appendChild(cloneP);207 strong = K.query('strong', cloneP);208 range = K.range(document);209 range.selectNode(strong);210 cmd = K.cmd(range);211 cmd.remove({212 '*' : '*'213 });214 equals(cmd.range.html(), 'efg');215 document.body.removeChild(cloneP);216 //3217 cloneP = p.cloneNode(true);218 document.body.appendChild(cloneP);219 strong = K.query('strong', cloneP);220 range = K.range(document);221 range.selectNode(strong);222 cmd = K.cmd(range);223 cmd.remove({224 'span' : '*'225 });226 equals(cmd.range.html(), '<strong>efg</strong>');227 document.body.removeChild(cloneP);228 //4229 div.html('<strong>efg</strong>');230 range = K.range(document);231 range.setStart(div.first().first()[0], 1);232 range.setEnd(div.first().first()[0], 2);233 cmd = K.cmd(range);234 cmd.remove({235 'strong' : '*'236 });237 equals(div.html(), '<strong>e</strong>f<strong>g</strong>');238 equals(cmd.range.toString(), 'f');239 div.html('');240 //5241 cloneP = p.cloneNode(true);242 document.body.appendChild(cloneP);243 strong = K.query('strong', cloneP);244 range = K.range(document);245 range.setStart(strong.firstChild, 0);246 range.setEnd(strong.firstChild, 3);247 cmd = K.cmd(range);248 cmd.remove({249 'strong' : '*'250 });251 equals(cmd.range.toString(), 'efg');252 document.body.removeChild(cloneP);253 //6254 cloneP = p.cloneNode(true);255 document.body.appendChild(cloneP);256 strong = K.query('strong', cloneP);257 K(strong).addClass('abc').css('color', '#FF0000');258 range = K.range(document);259 range.setStart(strong.firstChild, 1);260 range.setEnd(strong.firstChild, 2);261 cmd = K.cmd(range);262 cmd.remove({263 'strong' : 'class'264 });265 equals(range.html().toLowerCase(), '<strong style="color:#ff0000;">f</strong>');266 document.body.removeChild(cloneP);267 //7268 cloneP = p.cloneNode(true);269 document.body.appendChild(cloneP);270 strong = K.query('strong', cloneP);271 K(strong).addClass('abc').css('color', '#FF0000');272 range = K.range(document);273 range.setStart(strong.firstChild, 1);274 range.setEnd(strong.firstChild, 2);275 cmd = K.cmd(range);276 cmd.remove({277 'strong' : 'class,style'278 });279 equals(cmd.range.html().toLowerCase(), '<strong>f</strong>');280 document.body.removeChild(cloneP);281 //8282 cloneP = p.cloneNode(true);283 document.body.appendChild(cloneP);284 strong = K.query('strong', cloneP);285 K(strong).addClass('abc').css('color', '#FF0000');286 range = K.range(document);287 range.setStart(strong.firstChild, 1);288 range.setEnd(strong.firstChild, 2);289 cmd = K.cmd(range);290 cmd.remove({291 'strong' : 'class,.color,.background-color'292 });293 equals(cmd.range.html().toLowerCase(), '<strong>f</strong>');294 document.body.removeChild(cloneP);295 //9296 cloneP = p.cloneNode(true);297 document.body.appendChild(cloneP);298 strong = K.query('strong', cloneP);299 range = K.range(document);300 range.setStart(cloneP, 1);301 range.setEnd(strong.firstChild, 3);302 cmd = K.cmd(range);303 cmd.remove({304 'strong' : '*'305 });306 equals(range.html(), 'efg');307 document.body.removeChild(cloneP);308 //10309 cloneP = p.cloneNode(true);310 document.body.appendChild(cloneP);311 strong = K.query('strong', cloneP);312 strong.innerHTML = '<strong>efg</strong>';313 range = K.range(document);314 range.setStart(strong.firstChild.firstChild, 1);315 range.setEnd(strong.firstChild.firstChild, 2);316 cmd = K.cmd(range);317 cmd.remove({318 'strong' : '*'319 });320 equals(range.html(), 'f');321 document.body.removeChild(cloneP);322 //11323 cloneP = p.cloneNode(true);324 document.body.appendChild(cloneP);325 strong = K.query('strong', cloneP);326 strong.innerHTML = '<strong>efg</strong>';327 range = K.range(document);328 range.setStart(strong.firstChild.firstChild, 0);329 range.setEnd(strong.firstChild.firstChild, 3);330 cmd = K.cmd(range);331 cmd.remove({332 'strong' : '*'333 });334 equals(K(cloneP).html().substr(0, 11), 'abcdefghijk');335 document.body.removeChild(cloneP);336 //12337 cloneP = p.cloneNode(true);338 document.body.appendChild(cloneP);339 strong = K.query('strong', cloneP);340 range = K.range(document);341 range.setStart(strong.firstChild, 1);342 range.setEnd(strong.firstChild, 1);343 cmd = K.cmd(range);344 cmd.remove({345 'strong' : '*'346 });347 var str = 'abcd<strong>e</strong><strong>fg';348 equals(K(cloneP).html().substr(0, str.length), str);349 document.body.removeChild(cloneP);350 //13351 cloneP = p.cloneNode(true);352 document.body.appendChild(cloneP);353 strong = K.query('strong', cloneP);354 range = K.range(document);355 range.setStart(strong.firstChild, 1);356 range.setEnd(strong.firstChild, 2);357 cmd = K.cmd(range);358 cmd.remove({359 'strong' : '*'360 });361 cmd.wrap('<strong></strong>');362 equals(range.html(), '<strong>f</strong>');363 document.body.removeChild(cloneP);364 //14365 cloneP = p.cloneNode(true);366 document.body.appendChild(cloneP);367 strong = K.query('strong', cloneP);368 range = K.range(document);369 range.selectNodeContents(strong);370 cmd = K.cmd(range);371 cmd.remove({372 strong : '*'373 });374 equals(range.html(), 'efg');375 document.body.removeChild(cloneP);376});377test('cmd.execute', function() {378 var div = K('<div></div>'), node, range;379 document.body.appendChild(div[0]);380 //1381 node = K('<strong>abcd</strong>').get();382 div.append(node);383 range = K.range(document);384 range.selectNode(node);385 cmd = K.cmd(range);386 cmd.bold();387 cmd.bold();388 equals(range.html(), '<strong>abcd</strong>');389 div.html('');390 //2391 div.html('abcd');392 range = K.range(document);393 range.setStart(div.first().get(), 0);394 range.setEnd(div.first().get(), 4);395 cmd = K.cmd(range);396 cmd.bold();397 cmd.italic();398 equals(range.html(), '<strong><em>abcd</em></strong>');399 div.html('');400 //3401 div.html('abcd');402 range = K.range(document);403 range.setStart(div.first().get(), 0);404 range.setEnd(div.first().get(), 4);405 cmd = K.cmd(range);406 cmd.bold();407 cmd.italic();408 cmd.bold();409 equals(range.html(), '<em>abcd</em>');410 div.html('');411 //4412 div.html('<strong>abc</strong><strong>def</strong><strong>ghi</strong>');413 range = K.range(document);414 range.setStart(div.first().first().get(), 3);415 range.setEnd(div.first().next().first().get(), 3);416 cmd = K.cmd(range);417 cmd.bold();418 equals(range.html(), 'def');419 div.html('');420 //5421 div.html('<div>abcd<img /><strong>efg</strong><br />hijk</div>');422 range = K.range(document);423 range.selectNodeContents(div[0]);424 cmd = K.cmd(range);425 cmd.removeformat();426 equals(range.html(), '<div>abcd<img />efg<br />hijk</div>');427 div.html('');428 //6429 div.html('<p>abcd</p><p>1234</p>');430 range = K.range(document);431 range.selectNodeContents(div[0]);432 cmd = K.cmd(range);433 cmd.bold();434 equals(range.html().replace(/\n/, ''), '<p><strong>abcd</strong></p><p><strong>1234</strong></p>');435 cmd.removeformat();436 equals(range.html().replace(/\n/, ''), '<p>abcd</p><p>1234</p>');437 div.html('');438 //7439 div.html('<p><strong>abcd</strong></p><p><strong>1234</strong></p>');440 range = K.range(document);441 range.setStart(div.first().first().last()[0], 0);442 range.setEnd(div.last().last().last()[0], 4);443 cmd = K.cmd(range);444 cmd.removeformat();445 equals(range.html().replace(/\n/, ''), '<p>abcd</p><p>1234</p>');446 div.html('');447 //8448 div.html('<p><strong>abcd</strong></p><p><strong>1234</strong></p>');449 range = K.range(document);450 range.setStart(div.first().first().first()[0], 0);451 range.setEnd(div.last().last().last()[0], 4);452 cmd = K.cmd(range);453 cmd.italic();454 equals(range.html().replace(/\n/, ''), '<p><strong><em>abcd</em></strong></p><p><strong><em>1234</em></strong></p>');455 div.html('');456 //9457 div.html('<p><strong>abcd</strong></p><p><strong>1234</strong></p>');458 range = K.range(document);459 range.setStart(div.first().first()[0], 0);460 range.setEnd(div.last().last()[0], 1);461 cmd = K.cmd(range);462 cmd.italic();463 equals(range.html().replace(/\n/, ''), '<p><strong><em>abcd</em></strong></p><p><strong><em>1234</em></strong></p>');464 div.html('');465 //10466 div.html('<table><tr><td>1</td></tr></table><img>0123456789');467 range = K.range(document);468 range.setStart(div.last()[0], 4);469 range.setEnd(div.last()[0], 6);470 cmd = K.cmd(range);471 cmd.bold();472 cmd.bold();473 cmd.bold();474 equals(range.html().replace(/\n/, ''), '<strong>45</strong>');475 div.html('');476 //11477 div.html('<table><tr><td>1</td></tr></table><img>0123<strong>45</strong>6789');478 range = K.range(document);479 range.setStart(div.last().prev().prev()[0], 4);480 range.setEnd(div.last()[0], 0);481 cmd = K.cmd(range);482 cmd.bold();483 equals(range.html().replace(/\n/, ''), '45');484 div.html('');485 //12486 div.html('<p><strong><em>123456789</em></strong></p>');487 range = K.range(document);488 range.setStart(div.first().first().first()[0], 0);489 range.setEnd(div.first().first().first().first()[0], 9);490 cmd = K.cmd(range);491 cmd.underline();492 equals(div.html().replace(/\n/, ''), '<p><strong><em><u>123456789</u></em></strong></p>');493 div.html('');494 //13495 div.html('<p><strong><em>123456789</em></strong></p>');496 range = K.range(document);497 range.setStart(div.first().first().first()[0], 0);498 range.setEnd(div.first().first().first().first()[0], 9);499 cmd = K.cmd(range);500 cmd.bold();501 equals(div.html().replace(/\n/, ''), '<p><em>123456789</em></p>');502 div.html('');503 //14504 div.html('<p style="background-color:#000000;">1234</p>');505 range = K.range(document);506 range.setStart(div.first().first()[0], 0);507 range.setEnd(div.first().first()[0], 4);508 cmd = K.cmd(range);509 cmd.removeformat();510 equals(div.html().replace(/\n/, ''), '<p>1234</p>');511 div.html('');512 //15513 div.html('<span style="color:#e56600;">abc</span><span><span style="color:#e56600;">d</span><span style="color:#e56600;">efg</span></span>');514 range = K.range(document);515 range.setStart(div[0], 0);516 range.setEnd(div[0], 2);517 cmd = K.cmd(range);518 cmd.removeformat();519 same(range.html(), 'abcdefg');520 div.html('');521 //14522 div.html('\n<span></span><span><span style="font-size:18px;">abcd</span><span style="font-size:18px;"></span><span style="font-size:18px;"></span></span>\n');523 range = K.range(document);524 range.setEnd(div[0], 0);525 range.setEnd(div.first().next()[0], 1);526 cmd = K.cmd(range);527 cmd.removeformat();528 same(range.html(), 'abcd');529 div.html('');530 //15531 div.html('<img src="/kindeditor/plugins/emoticons/images/0.gif" /><strong>abc</strong>');532 range = K.range(document);533 range.selectNodeContents(div.last()[0]);534 cmd = K.cmd(range);535 cmd.bold();536 equals(div.html(), '<img src="/kindeditor/plugins/emoticons/images/0.gif" />abc');537 div.html('');538});539test('cmd.inserthtml', function() {540 //1541 var div = K('<div>1234</div>');542 K(document.body).append(div);543 range = K.range(document);544 range.setStart(div.first()[0], 1);545 range.setEnd(div.first()[0], 1);546 cmd = K.cmd(range);547 cmd.inserthtml('<strong>abcd</strong>');548 equals(div.html().replace(/\n/, ''), '1<strong>abcd</strong>234');549 div.remove();550});551test('cmd.insertimage', function() {552 //1553 var div = K('<div><p align="center">123</p><p align="center"><img style="margin-right:10px;" height="100" width="100" /></p><p align="center">123</p></div>');554 K(document.body).append(div);555 range = K.range(document);556 var img = K('img', div);557 range.selectNode(img[0]);558 cmd = K.cmd(range);559 var url = 'http://www.kindsoft.net/images/logo.png';560 cmd.insertimage(url);561 equals(K('img', div).attr('src'), url);562 div.remove();...

Full Screen

Full Screen

Box2.tests.js

Source:Box2.tests.js Github

copy

Full Screen

...18 QUnit.test( "Instancing", ( assert ) => {19 var a = new Box2();20 assert.ok( a.min.equals( posInf2 ), "Passed!" );21 assert.ok( a.max.equals( negInf2 ), "Passed!" );22 var a = new Box2( zero2.clone(), zero2.clone() );23 assert.ok( a.min.equals( zero2 ), "Passed!" );24 assert.ok( a.max.equals( zero2 ), "Passed!" );25 var a = new Box2( zero2.clone(), one2.clone() );26 assert.ok( a.min.equals( zero2 ), "Passed!" );27 assert.ok( a.max.equals( one2 ), "Passed!" );28 } );29 // PUBLIC STUFF30 QUnit.test( "set", ( assert ) => {31 var a = new Box2();32 a.set( zero2, one2 );33 assert.ok( a.min.equals( zero2 ), "Passed!" );34 assert.ok( a.max.equals( one2 ), "Passed!" );35 } );36 QUnit.test( "setFromPoints", ( assert ) => {37 var a = new Box2();38 a.setFromPoints( [ zero2, one2, two2 ] );39 assert.ok( a.min.equals( zero2 ), "Passed!" );40 assert.ok( a.max.equals( two2 ), "Passed!" );41 a.setFromPoints( [ one2 ] );42 assert.ok( a.min.equals( one2 ), "Passed!" );43 assert.ok( a.max.equals( one2 ), "Passed!" );44 a.setFromPoints( [] );45 assert.ok( a.isEmpty(), "Passed!" );46 } );47 QUnit.todo( "setFromCenterAndSize", ( assert ) => {48 assert.ok( false, "everything's gonna be alright" );49 } );50 QUnit.todo( "clone", ( assert ) => {51 assert.ok( false, "everything's gonna be alright" );52 } );53 QUnit.test( "copy", ( assert ) => {54 var a = new Box2( zero2.clone(), one2.clone() );55 var b = new Box2().copy( a );56 assert.ok( b.min.equals( zero2 ), "Passed!" );57 assert.ok( b.max.equals( one2 ), "Passed!" );58 // ensure that it is a true copy59 a.min = zero2;60 a.max = one2;61 assert.ok( b.min.equals( zero2 ), "Passed!" );62 assert.ok( b.max.equals( one2 ), "Passed!" );63 } );64 QUnit.test( "empty/makeEmpty", ( assert ) => {65 var a = new Box2();66 assert.ok( a.isEmpty(), "Passed!" );67 var a = new Box2( zero2.clone(), one2.clone() );68 assert.ok( ! a.isEmpty(), "Passed!" );69 a.makeEmpty();70 assert.ok( a.isEmpty(), "Passed!" );71 } );72 QUnit.todo( "isEmpty", ( assert ) => {73 assert.ok( false, "everything's gonna be alright" );74 } );75 QUnit.test( "getCenter", ( assert ) => {76 var a = new Box2( zero2.clone(), zero2.clone() );77 var center = new Vector2();78 assert.ok( a.getCenter( center ).equals( zero2 ), "Passed!" );79 var a = new Box2( zero2, one2 );80 var midpoint = one2.clone().multiplyScalar( 0.5 );81 assert.ok( a.getCenter( center ).equals( midpoint ), "Passed!" );82 } );83 QUnit.test( "getSize", ( assert ) => {84 var a = new Box2( zero2.clone(), zero2.clone() );85 var size = new Vector2();86 assert.ok( a.getSize( size ).equals( zero2 ), "Passed!" );87 var a = new Box2( zero2.clone(), one2.clone() );88 assert.ok( a.getSize( size ).equals( one2 ), "Passed!" );89 } );90 QUnit.test( "expandByPoint", ( assert ) => {91 var a = new Box2( zero2.clone(), zero2.clone() );92 var size = new Vector2();93 var center = new Vector2();94 a.expandByPoint( zero2 );95 assert.ok( a.getSize( size ).equals( zero2 ), "Passed!" );96 a.expandByPoint( one2 );97 assert.ok( a.getSize( size ).equals( one2 ), "Passed!" );98 a.expandByPoint( one2.clone().negate() );99 assert.ok( a.getSize( size ).equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );100 assert.ok( a.getCenter( center ).equals( zero2 ), "Passed!" );101 } );102 QUnit.test( "expandByVector", ( assert ) => {103 var a = new Box2( zero2.clone(), zero2.clone() );104 var size = new Vector2();105 var center = new Vector2();106 a.expandByVector( zero2 );107 assert.ok( a.getSize( size ).equals( zero2 ), "Passed!" );108 a.expandByVector( one2 );109 assert.ok( a.getSize( size ).equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );110 assert.ok( a.getCenter( center ).equals( zero2 ), "Passed!" );111 } );112 QUnit.test( "expandByScalar", ( assert ) => {113 var a = new Box2( zero2.clone(), zero2.clone() );114 var size = new Vector2();115 var center = new Vector2();116 a.expandByScalar( 0 );117 assert.ok( a.getSize( size ).equals( zero2 ), "Passed!" );118 a.expandByScalar( 1 );119 assert.ok( a.getSize( size ).equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );120 assert.ok( a.getCenter( center ).equals( zero2 ), "Passed!" );121 } );122 QUnit.test( "containsPoint", ( assert ) => {123 var a = new Box2( zero2.clone(), zero2.clone() );124 assert.ok( a.containsPoint( zero2 ), "Passed!" );125 assert.ok( ! a.containsPoint( one2 ), "Passed!" );126 a.expandByScalar( 1 );127 assert.ok( a.containsPoint( zero2 ), "Passed!" );128 assert.ok( a.containsPoint( one2 ), "Passed!" );129 assert.ok( a.containsPoint( one2.clone().negate() ), "Passed!" );130 } );131 QUnit.test( "containsBox", ( assert ) => {132 var a = new Box2( zero2.clone(), zero2.clone() );133 var b = new Box2( zero2.clone(), one2.clone() );134 var c = new Box2( one2.clone().negate(), one2.clone() );135 assert.ok( a.containsBox( a ), "Passed!" );136 assert.ok( ! a.containsBox( b ), "Passed!" );137 assert.ok( ! a.containsBox( c ), "Passed!" );138 assert.ok( b.containsBox( a ), "Passed!" );139 assert.ok( c.containsBox( a ), "Passed!" );140 assert.ok( ! b.containsBox( c ), "Passed!" );141 } );142 QUnit.test( "getParameter", ( assert ) => {143 var a = new Box2( zero2.clone(), one2.clone() );144 var b = new Box2( one2.clone().negate(), one2.clone() );145 var parameter = new Vector2();146 a.getParameter( zero2, parameter );147 assert.ok( parameter.equals( zero2 ), "Passed!" );148 a.getParameter( one2, parameter );149 assert.ok( parameter.equals( one2 ), "Passed!" );150 b.getParameter( one2.clone().negate(), parameter );151 assert.ok( parameter.equals( zero2 ), "Passed!" );152 b.getParameter( zero2, parameter );153 assert.ok( parameter.equals( new Vector2( 0.5, 0.5 ) ), "Passed!" );154 b.getParameter( one2, parameter );155 assert.ok( parameter.equals( one2 ), "Passed!" );156 } );157 QUnit.test( "intersectsBox", ( assert ) => {158 var a = new Box2( zero2.clone(), zero2.clone() );159 var b = new Box2( zero2.clone(), one2.clone() );160 var c = new Box2( one2.clone().negate(), one2.clone() );161 assert.ok( a.intersectsBox( a ), "Passed!" );162 assert.ok( a.intersectsBox( b ), "Passed!" );163 assert.ok( a.intersectsBox( c ), "Passed!" );164 assert.ok( b.intersectsBox( a ), "Passed!" );165 assert.ok( c.intersectsBox( a ), "Passed!" );166 assert.ok( b.intersectsBox( c ), "Passed!" );167 b.translate( two2 );168 assert.ok( ! a.intersectsBox( b ), "Passed!" );169 assert.ok( ! b.intersectsBox( a ), "Passed!" );170 assert.ok( ! b.intersectsBox( c ), "Passed!" );171 } );172 QUnit.test( "clampPoint", ( assert ) => {173 var a = new Box2( zero2.clone(), zero2.clone() );174 var b = new Box2( one2.clone().negate(), one2.clone() );175 var point = new Vector2();176 a.clampPoint( zero2, point );177 assert.ok( point.equals( new Vector2( 0, 0 ) ), "Passed!" );178 a.clampPoint( one2, point );179 assert.ok( point.equals( new Vector2( 0, 0 ) ), "Passed!" );180 a.clampPoint( one2.clone().negate(), point );181 assert.ok( point.equals( new Vector2( 0, 0 ) ), "Passed!" );182 b.clampPoint( two2, point );183 assert.ok( point.equals( new Vector2( 1, 1 ) ), "Passed!" );184 b.clampPoint( one2, point );185 assert.ok( point.equals( new Vector2( 1, 1 ) ), "Passed!" );186 b.clampPoint( zero2, point );187 assert.ok( point.equals( new Vector2( 0, 0 ) ), "Passed!" );188 b.clampPoint( one2.clone().negate(), point );189 assert.ok( point.equals( new Vector2( - 1, - 1 ) ), "Passed!" );190 b.clampPoint( two2.clone().negate(), point );191 assert.ok( point.equals( new Vector2( - 1, - 1 ) ), "Passed!" );192 } );193 QUnit.test( "distanceToPoint", ( assert ) => {194 var a = new Box2( zero2.clone(), zero2.clone() );195 var b = new Box2( one2.clone().negate(), one2.clone() );196 assert.ok( a.distanceToPoint( new Vector2( 0, 0 ) ) == 0, "Passed!" );197 assert.ok( a.distanceToPoint( new Vector2( 1, 1 ) ) == Math.sqrt( 2 ), "Passed!" );198 assert.ok( a.distanceToPoint( new Vector2( - 1, - 1 ) ) == Math.sqrt( 2 ), "Passed!" );199 assert.ok( b.distanceToPoint( new Vector2( 2, 2 ) ) == Math.sqrt( 2 ), "Passed!" );200 assert.ok( b.distanceToPoint( new Vector2( 1, 1 ) ) == 0, "Passed!" );201 assert.ok( b.distanceToPoint( new Vector2( 0, 0 ) ) == 0, "Passed!" );202 assert.ok( b.distanceToPoint( new Vector2( - 1, - 1 ) ) == 0, "Passed!" );203 assert.ok( b.distanceToPoint( new Vector2( - 2, - 2 ) ) == Math.sqrt( 2 ), "Passed!" );204 } );205 QUnit.test( "intersect", ( assert ) => {206 var a = new Box2( zero2.clone(), zero2.clone() );207 var b = new Box2( zero2.clone(), one2.clone() );208 var c = new Box2( one2.clone().negate(), one2.clone() );209 assert.ok( a.clone().intersect( a ).equals( a ), "Passed!" );210 assert.ok( a.clone().intersect( b ).equals( a ), "Passed!" );211 assert.ok( b.clone().intersect( b ).equals( b ), "Passed!" );212 assert.ok( a.clone().intersect( c ).equals( a ), "Passed!" );213 assert.ok( b.clone().intersect( c ).equals( b ), "Passed!" );214 assert.ok( c.clone().intersect( c ).equals( c ), "Passed!" );215 } );216 QUnit.test( "union", ( assert ) => {217 var a = new Box2( zero2.clone(), zero2.clone() );218 var b = new Box2( zero2.clone(), one2.clone() );219 var c = new Box2( one2.clone().negate(), one2.clone() );220 assert.ok( a.clone().union( a ).equals( a ), "Passed!" );221 assert.ok( a.clone().union( b ).equals( b ), "Passed!" );222 assert.ok( a.clone().union( c ).equals( c ), "Passed!" );223 assert.ok( b.clone().union( c ).equals( c ), "Passed!" );224 } );225 QUnit.test( "translate", ( assert ) => {226 var a = new Box2( zero2.clone(), zero2.clone() );227 var b = new Box2( zero2.clone(), one2.clone() );228 var c = new Box2( one2.clone().negate(), one2.clone() );229 var d = new Box2( one2.clone().negate(), zero2.clone() );230 assert.ok( a.clone().translate( one2 ).equals( new Box2( one2, one2 ) ), "Passed!" );231 assert.ok( a.clone().translate( one2 ).translate( one2.clone().negate() ).equals( a ), "Passed!" );232 assert.ok( d.clone().translate( one2 ).equals( b ), "Passed!" );233 assert.ok( b.clone().translate( one2.clone().negate() ).equals( d ), "Passed!" );234 } );235 QUnit.todo( "equals", ( assert ) => {236 assert.ok( false, "everything's gonna be alright" );237 } );238 } );...

Full Screen

Full Screen

shadowClone.js

Source:shadowClone.js Github

copy

Full Screen

1var CenteringTextElement = require("./util/CenteringTextElement");2var elementTools = require("./util/elementTools")();3var math = require("./util/math")();4module.exports = function (graph) {5 /** variable defs **/6 var ShadowClone = {};7 ShadowClone.nodeId = 10003;8 ShadowClone.parent = undefined;9 ShadowClone.s_x = 0;10 ShadowClone.s_y = 0;11 ShadowClone.e_x = 0;12 ShadowClone.e_y = 0;13 ShadowClone.rootElement = undefined;14 ShadowClone.rootNodeLayer = undefined;15 ShadowClone.pathLayer = undefined;16 ShadowClone.nodeElement = undefined;17 ShadowClone.pathElement = undefined;18 ShadowClone.typus = "shadowClone";19 ShadowClone.type = function () {20 return ShadowClone.typus;21 };22 // TODO: We need the endPoint of the Link here!23 ShadowClone.parentNode = function () {24 return ShadowClone.parent;25 };26 ShadowClone.setParentProperty = function (parentProperty, inverted) {27 ShadowClone.invertedProperty = inverted;28 ShadowClone.parent = parentProperty;29 var renElment;30 if (inverted === true) {31 renElment = parentProperty.inverse().labelObject();32 if (renElment !== undefined) {33 if (renElment.linkRangeIntersection && renElment.linkDomainIntersection) {34 var iiP_range = renElment.linkDomainIntersection;35 var iiP_domain = renElment.linkRangeIntersection;36 ShadowClone.s_x = iiP_domain.x;37 ShadowClone.s_y = iiP_domain.y;38 ShadowClone.e_x = iiP_range.x;39 ShadowClone.e_y = iiP_range.y;40 }41 }42 } else {43 renElment = parentProperty.labelObject();44 if (renElment.linkRangeIntersection && renElment.linkDomainIntersection) {45 var iP_range = renElment.linkRangeIntersection;46 var iP_domain = renElment.linkDomainIntersection;47 ShadowClone.s_x = iP_domain.x;48 ShadowClone.s_y = iP_domain.y;49 ShadowClone.e_x = iP_range.x;50 ShadowClone.e_y = iP_range.y;51 }52 }53 ShadowClone.rootNodeLayer.remove();54 ShadowClone.rootNodeLayer = ShadowClone.rootElement.append('g');55 ShadowClone.rootNodeLayer.datum(parentProperty);56 // ShadowClone.pathElement.remove();57 // ShadowClone.pathElement = ShadowClone.pathLayer.append('line');58 //59 // ShadowClone.pathElement.attr("x1", ShadowClone.s_x)60 // .attr("y1", ShadowClone.s_y)61 // .attr("x2", ShadowClone.e_x)62 // .attr("y2", ShadowClone.e_y);63 ShadowClone.pathElement.remove();64 ShadowClone.pathElement = ShadowClone.pathLayer.append('line');65 ShadowClone.markerElement = ShadowClone.pathLayer.append("marker");66 ShadowClone.markerElement.attr("id", "shadowCloneMarker");67 ShadowClone.pathElement.attr("x1", ShadowClone.e_x)68 .attr("y1", ShadowClone.e_y)69 .attr("x2", ShadowClone.s_x)70 .attr("y2", ShadowClone.s_y);71 ShadowClone.pathElement.classed(parentProperty.linkType(), true);72 if (parentProperty.markerElement()) {73 ShadowClone.markerElement.attr("viewBox", parentProperty.markerElement().attr("viewBox"))74 .attr("markerWidth", parentProperty.markerElement().attr("markerWidth"))75 .attr("markerHeight", parentProperty.markerElement().attr("markerHeight"))76 .attr("orient", parentProperty.markerElement().attr("orient"));77 var markerPath = parentProperty.markerElement().select("path");78 if (!markerPath[0].includes(null)) {79 ShadowClone.markerElement.append("path")80 .attr("d", markerPath.attr("d"))81 .classed(parentProperty.markerType(), true);82 }83 ShadowClone.pathElement.attr("marker-end", "url(#" + "shadowCloneMarker" + ")");84 ShadowClone.markerElement.classed("hidden", !elementTools.isDatatypeProperty(parentProperty));85 }86 var rect = ShadowClone.rootNodeLayer.append("rect")87 .classed(parentProperty.styleClass(), true)88 .classed("property", true)89 .attr("x", -parentProperty.width() / 2)90 .attr("y", -parentProperty.height() / 2)91 .attr("width", parentProperty.width())92 .attr("height", parentProperty.height());93 if (parentProperty.visualAttributes()) {94 rect.classed(parentProperty.visualAttributes(), true);95 }96 rect.classed("datatype", false);97 var bgColor = parentProperty.backgroundColor();98 if (parentProperty.attributes().indexOf("deprecated") > -1) {99 bgColor = undefined;100 rect.classed("deprecatedproperty", true);101 } else {102 rect.classed("deprecatedproperty", false);103 }104 rect.style("fill", bgColor);105 // add Text;106 var equivalentsString = parentProperty.equivalentsString();107 var suffixForFollowingEquivalents = equivalentsString ? "," : "";108 var textElement = new CenteringTextElement(ShadowClone.rootNodeLayer, bgColor);109 textElement.addText(parentProperty.labelForCurrentLanguage(), "", suffixForFollowingEquivalents);110 textElement.addEquivalents(equivalentsString);111 textElement.addSubText(parentProperty.indicationString());112 var cx = 0.5 * (ShadowClone.s_x + ShadowClone.e_x);113 var cy = 0.5 * (ShadowClone.s_y + ShadowClone.e_y);114 ShadowClone.rootNodeLayer.attr("transform", "translate(" + cx + "," + cy + ")");115 ShadowClone.rootNodeLayer.classed("hidden", true);116 ShadowClone.pathElement.classed("hidden", true);117 };118 ShadowClone.hideClone = function (val) {119 if (ShadowClone.rootNodeLayer) ShadowClone.rootNodeLayer.classed("hidden", val);120 if (ShadowClone.pathElement) ShadowClone.pathElement.classed("hidden", val);121 };122 ShadowClone.hideParentProperty = function (val) {123 var labelObj = ShadowClone.parent.labelObject();124 if (labelObj) {125 if (ShadowClone.parent.labelElement().attr("transform") === "translate(0,15)" ||126 ShadowClone.parent.labelElement().attr("transform") === "translate(0,-15)")127 ShadowClone.parent.inverse().hide(val);128 }129 ShadowClone.parent.hide(val);130 };131 /** BASE HANDLING FUNCTIONS ------------------------------------------------- **/132 ShadowClone.id = function (index) {133 if (!arguments.length) {134 return ShadowClone.nodeId;135 }136 ShadowClone.nodeId = index;137 };138 ShadowClone.svgPathLayer = function (layer) {139 ShadowClone.pathLayer = layer.append('g');140 };141 ShadowClone.svgRoot = function (root) {142 if (!arguments.length)143 return ShadowClone.rootElement;144 ShadowClone.rootElement = root;145 ShadowClone.rootNodeLayer = ShadowClone.rootElement.append('g');146 };147 /** DRAWING FUNCTIONS ------------------------------------------------- **/148 ShadowClone.drawClone = function () {149 ShadowClone.pathElement = ShadowClone.pathLayer.append('line');150 ShadowClone.pathElement.attr("x1", 0)151 .attr("y1", 0)152 .attr("x2", 0)153 .attr("y2", 0);154 };155 ShadowClone.updateElement = function () {156 ShadowClone.pathElement.attr("x1", ShadowClone.e_x)157 .attr("y1", ShadowClone.e_y)158 .attr("x2", ShadowClone.s_x)159 .attr("y2", ShadowClone.s_y);160 var cx = 0.5 * (ShadowClone.s_x + ShadowClone.e_x);161 var cy = 0.5 * (ShadowClone.s_y + ShadowClone.e_y);162 ShadowClone.rootNodeLayer.attr("transform", "translate(" + cx + "," + cy + ")");163 };164 ShadowClone.setInitialPosition = function () {165 var renElment = ShadowClone.parent.labelObject();166 if (renElment.linkRangeIntersection && renElment.linkDomainIntersection) {167 var iP_range = renElment.linkRangeIntersection;168 var iP_domain = renElment.linkDomainIntersection;169 ShadowClone.e_x = iP_domain.x;170 ShadowClone.e_y = iP_domain.y;171 ShadowClone.s_x = iP_range.x;172 ShadowClone.s_y = iP_range.y;173 }174 ShadowClone.updateElement();175 return;176 //177 // var rex=ShadowClone.parent.range().x;178 // var rey=ShadowClone.parent.range().y;179 //180 //181 // var dex=ShadowClone.parent.domain().x;182 // var dey=ShadowClone.parent.domain().y;183 //184 //185 // var dir_X= rex-dex;186 // var dir_Y= rey-dey;187 //188 // var len=Math.sqrt(dir_X*dir_X+dir_Y*dir_Y);189 // var nX=dir_X/len;190 // var nY=dir_Y/len;191 // ShadowClone.s_x=rex-nX*ShadowClone.parent.range().actualRadius();192 // ShadowClone.s_y=rey-nY*ShadowClone.parent.range().actualRadius();193 //194 // ShadowClone.e_x=dex+nX*ShadowClone.parent.domain().actualRadius();195 // ShadowClone.e_y=dey+nY*ShadowClone.parent.domain().actualRadius();196 // ShadowClone.updateElement();197 };198 ShadowClone.setPositionDomain = function (e_x, e_y) {199 var rex = ShadowClone.parent.range().x;200 var rey = ShadowClone.parent.range().y;201 if (elementTools.isDatatype(ShadowClone.parent.range()) === true) {202 var intersection = math.calculateIntersection({ x: e_x, y: e_y }, ShadowClone.parent.range(), 0);203 ShadowClone.s_x = intersection.x;204 ShadowClone.s_y = intersection.y;205 } else {206 var dir_X = rex - e_x;207 var dir_Y = rey - e_y;208 var len = Math.sqrt(dir_X * dir_X + dir_Y * dir_Y);209 var nX = dir_X / len;210 var nY = dir_Y / len;211 ShadowClone.s_x = rex - nX * ShadowClone.parent.range().actualRadius();212 ShadowClone.s_y = rey - nY * ShadowClone.parent.range().actualRadius();213 }214 ShadowClone.e_x = e_x;215 ShadowClone.e_y = e_y;216 ShadowClone.updateElement();217 };218 ShadowClone.setPosition = function (s_x, s_y) {219 ShadowClone.s_x = s_x;220 ShadowClone.s_y = s_y;221 // add normalized dir;222 var dex = ShadowClone.parent.domain().x;223 var dey = ShadowClone.parent.domain().y;224 var dir_X = s_x - dex;225 var dir_Y = s_y - dey;226 var len = Math.sqrt(dir_X * dir_X + dir_Y * dir_Y);227 var nX = dir_X / len;228 var nY = dir_Y / len;229 ShadowClone.e_x = dex + nX * ShadowClone.parent.domain().actualRadius();230 ShadowClone.e_y = dey + nY * ShadowClone.parent.domain().actualRadius();231 ShadowClone.updateElement();232 };233 /** MOUSE HANDLING FUNCTIONS ------------------------------------------------- **/234 return ShadowClone;...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful